목록의 읽기 쓰기가 모든 항목에 대해 작동하지 않습니다

목록의 읽기 쓰기가 모든 항목에 대해 작동하지 않습니다

목록을 사용하여 C 코드 스타일을 재현하고 있습니다. ""문자열로 정의했기 때문에 라이브러리를 추가하면 "ff.h"문자열로 처리되어 파란색으로 인쇄됩니다. 이를 방지하기 위해 literate.

이에 대한 예:

\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}

올바른 결과: 여기에 이미지 설명을 입력하세요

하지만 이것을 모든 라이브러리에 적용했을 때:

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 

결과는 다음과 같습니다:

여기에 이미지 설명을 입력하세요

무슨 일이 일어날 수 있나요?

답변1

숫자가 9보다 커지면 숫자 주위에 중괄호를 사용해야 합니다.

\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}

관련 정보