对包含 $ 的文件使用 \verbatiminput{}

对包含 $ 的文件使用 \verbatiminput{}

我对 LaTEX 还很陌生,我正尝试按照以下说明将文件包含在附录中:

\begin{multicols}{2}
  \footnotesize{\verbatiminput{pattern-representations}}
\end{multicols}

但是,该文件pattern-representations.tex包含很多带$字符的行,从而导致以下错误:

ERROR: Missing $ inserted.

--- TeX said ---
<inserted text> 
                $
l.291 ...e{\verbatiminput{pattern-representations}
                                                  }^^M
--- HELP ---
TeX probably found a command that can be used only in math mode when
it wasn't in math mode.  Remember that unless stated otherwise, all
all the commands of Section 3.3 in LaTeX Book (Lamport) can be used
only in math mode. TeX is not in math mode when it begins processing
the argument of a box-making command, even if that command is inside a
math environment. This error also occurs if TeX encounters a blank
line when it is in math mode.

我怎样才能解决这个问题?

编辑:最小示例:

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{verbatim, multicol}

\DeclareUnicodeCharacter{2260}{\neq}
\DeclareUnicodeCharacter{301}{\'}

\begin{document}
\clearpage
\section{Appendix}
\begin{multicols}{2}
  \footnotesize{\verbatiminput{pattern-representations}}
\end{multicols}
\end{document}

pattern-represetnations内容是这里

答案1

问题在于您将 Unicode字符定义为\neq,这需要数学模式。请修复其定义。

\begin{filecontents*}{\jobname-test.tex}
65 .$(.;)$(.).                  
66 @()@≠()                      
67 @--@...                      
68 @--@..$.$                    
69 @[email protected].                      
70 @-@...                       
71 @-@....                      
72 @-@..$,.$                    
73 @-@..$-.$                    
74 @-@..$.$                     
75 @́@...                        
76 ≠                            
77 ≠,                           
78 ≠,,                          
79 ≠,,,
\end{filecontents*}

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{verbatim, multicol}

\DeclareUnicodeCharacter{2260}{\relax\ifmmode\neq\else\textneq\fi}
\DeclareUnicodeCharacter{0301}{\'}

\DeclareRobustCommand{\textneq}{%
  \begingroup
  \ooalign{\hidewidth/\hidewidth\cr=\cr}\vphantom{/}%
  \endgroup
}

\begin{document}
\clearpage
\section{Appendix}
\begin{multicols}{2}
  \footnotesize{\verbatiminput{\jobname-test.tex}}
\end{multicols}
\end{document}

但请注意,重音符号放在下列的字符:无法在中使用后缀组合字符pdflatex

在此处输入图片描述

相关内容