Literate in Listings funktioniert nicht für jeden Artikel

Literate in Listings funktioniert nicht für jeden Artikel

Ich reproduziere den C-Codestil mit Auflistungen. Ich habe es ""als Zeichenfolge definiert, sodass "ff.h"es beim Hinzufügen von Bibliotheken als Zeichenfolge behandelt und blau gedruckt wird. Um das zu vermeiden, verwende ich literate.

Ein Beispiel hierfür:

\documentclass[11pt,fleqn]{article} 

\usepackage[dvipsnames]{xcolor} 

\usepackage{listings}

\lstdefinestyle{styleC}{
  language = C,
  commentstyle = {\color{ForestGreen}},
  stringstyle = {\color{NavyBlue}},
  comment = [l]{//},
  morecomment = [s]{/*}{*/},
  morestring = [b]',
  morestring = [b]",   
}

\lstnewenvironment{C}{
  \lstset{
    style=styleC,
    frame=single,
    literate = {"ff.h"}{"ff.h"}6 {"math.h"}{"math.h"}8 
    }
  }
  {}
  
  
\begin{document}
  
\begin{C}
#include <time.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <complex.h>
#include "ff.h"
#include "ffconf.h"
#include "math.h"
#include "arm_math.h"
#include "audioMoth.h"
\end{C}

\end{document}

mit korrektem Ergebnis: Bildbeschreibung hier eingeben

Aber als ich dies auf alle Bibliotheken angewendet habe:

literate = {"ff.h"}{"ff.h"}6 {"ffconf.h"}{"ffconf.h"}10 {"math.h"}{"math.h"}8   {"arm_math.h"}{"arm_math.h"}12 {"audioMoth.h"}{"audioMoth.h"}13 

Das Ergebnis ist folgendes:

Bildbeschreibung hier eingeben

Was könnte passieren?

Antwort1

Sie müssen die Zahlen in Klammern setzen, wenn sie größer als 9 sind:

\documentclass[11pt,fleqn]{article}

\usepackage[dvipsnames]{xcolor}

\usepackage{listings}

\lstdefinestyle{styleC}{
  language = C,
  commentstyle = {\color{ForestGreen}},
  stringstyle = {\color{NavyBlue}},
  comment = [l]{//},
  morecomment = [s]{/*}{*/},
  morestring = [b]',
  morestring = [b]",
}

\lstnewenvironment{C}{
  \lstset{
    style=styleC,
    frame=single,
    %literate = {"ff.h"}{"ff.h"}6 {"math.h"}{"math.h"}8
    literate = {"ff.h"}{"ff.h"}6 {"ffconf.h"}{"ffconf.h"}{10} {"math.h"}{"math.h"}8   {"arm_math.h"}{"arm\_math.h"}{12} {"audioMoth.h"}{"audioMoth.h"}{13}
    }
  }
  {}


\begin{document}

\begin{C}
#include <time.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <complex.h>
#include "ff.h"
#include "ffconf.h"
#include "math.h"
#include "arm_math.h"
#include "audioMoth.h"
\end{C}

\end{document}

verwandte Informationen