.dat 파일에 ( 또는 * 기호가 포함되어 있으면 \VerbatimInput에서 오류가 발생합니다.

.dat 파일에 ( 또는 * 기호가 포함되어 있으면 \VerbatimInput에서 오류가 발생합니다.

다음과 같이 파일 \VerbatimInput에 대한 호출이 있습니다 .test.dat

 \documentclass[12pt]{article}

 \usepackage[left=2.5cm,top=2.5cm,right=2.5cm,bottom=2.5cm]{geometry}
 \usepackage[utf8]{inputenc}
 \usepackage{enumitem}
 \usepackage{fancyvrb}
 \usepackage{color,soul}
 \usepackage[dvipsnames]{xcolor}


 \begin{document}


 \RecustomVerbatimCommand{\VerbatimInput}{VerbatimInput}%
 {fontsize=\footnotesize,
  %
  frame=lines,  % top and bottom rule only
  framesep=2em, % separation between frame and text
  rulecolor=\color{Gray},
  %
  label=\fbox{\color{Black}test.dat},
  labelposition=topline,
  %
  commandchars=\|\(\), % escape character and argument delimiters for
                  % commands within the verbatim
  commentchar=*        % comment character
 }

 \VerbatimInput{./test.dat}


 \end{document}

파일은 test.dat다음과 같습니다:

 #l.77:
 TEST11

 A3

  (EL = 4) # this is compiled ok
  mH/(C*K) # this is not compiled, giving that error

기호 로 인해 ( * )컴파일 시 다음 오류가 발생합니다.

 Runaway definition?
 -> mH/(C
 ! File ended within \read.
 <read 1> 

 l.97 \VerbatimInput{./test.dat}

이것을 어떻게 컴파일할 수 있나요?

답변1

첫째, 나는 실제로 나 자신을 사용하지 않았다는 것을 말해야 합니다 \VerbatimInput. 그러나 게시한 코드는 다음 답변에 게시된 코드와 똑같습니다..txt의 데이터를 그대로 포함합니다.

저자의 말을 인용하자면:

  • |(/를 이스케이프 문자 및 인수 구분 기호로 지정하면 )이러한 기호가 축어적 텍스트(또는 이 경우 data.txt의 내용)의 일부로 나타날 수 없음을 의미합니다.
  • data.txt의 별표 줄은 *주석 문자로 지정하여 제거되었습니다( %LaTeX의 경우와 유사).

즉, 복사한 코드는 이 네 문자에 특별한 의미를 부여하므로 해당 문자가 포함된 파일에는 사용할 수 없습니다.

이 작업을 수행하는 것으로 보이는 라인은 다음과 같습니다.

commandchars=\|\(\), % escape character and argument delimiters for
              % commands within the verbatim
commentchar=*        % comment character

따라서 코드에서 해당 문자를 제거하거나 파일에 나타나지 않는 다른 문자로 바꾸는 것이 좋습니다.

관련 정보