我正在编写一个文档,其中我想同时包含一些图像graphicx
和使用包\includegraphics
显示一些 BNF 语法,但是当我尝试一起使用它们时,我收到了错误syntax
mdwtools
undefined control sequence
有一些文件名。
失败的最小示例:
\documentclass{article}
\usepackage{syntax}
\usepackage{graphicx}
\begin{document}
\includegraphics{logo_uniud_black}
\end{document}
编译此程序时出现以下错误:
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
! Undefined control sequence.
\filename@simple ...#2\\}\fi \edef \filename@base
{#1}
l.8 \includegraphics{logo_uniud_black}
[omissis]
! Undefined control sequence.
\filename@simple ...#2\\}\fi \edef \filename@base
{#1}
l.8 \includegraphics{logo_uniud_black}
(That makes 100 errors; please try again.)
注释掉\usepackage{syntax}
可以修复此问题。使用不包含下划线的文件名也可以,这样此代码就不会失败:
\documentclass{article}
\usepackage{syntax}
\usepackage{graphicx}
\begin{document}
\includegraphics{logouniudblack}
\end{document}
为什么我会收到此错误?它与文件名中的下划线有何关系?有没有办法修复它而不重命名我必须包含的所有文件?
编辑:
实际上,即使带有下划线的部分名称也会产生问题,因此\include
会引发类似的错误,例如源代码:
\documentclass{article}
\usepackage{syntax}
\begin{document}
\include{sintassi_astratta}
\end{document}
我收到这些错误:
(/usr/share/texlive/texmf-dist/tex/latex/mdwtools/syntax.sty) (./bad_doc.aux)
! Undefined control sequence.
\GenericError ...
#4 \errhelp \@err@ ...
l.7 \include{sintassi_astratta}
! Undefined control sequence.
\GenericError ...
\let \@err@ ...
l.7 \include{sintassi_astratta}
! Undefined control sequence.
\GenericError ...
\@empty \def \MessageBreak...
l.7 \include{sintassi_astratta}
! Undefined control sequence.
\GenericError ...
\endgroup
l.7 \include{sintassi_astratta}
! Argument of \reserved@b has an extra }.
<inserted text>
\par
l.7 \include{sintassi_astratta}
Runaway argument?
{\usc@builtindischyphen }\futurelet \@let@token \@ifnch astratta.aux
! Paragraph ended before \reserved@b was complete.
<to be read again>
\par
l.7 \include{sintassi_astratta}
(./sintassi.tex)
! Missing control sequence inserted.
<inserted text>
\inaccessible
l.7 \include{sintassi_astratta}
! Too many }'s.
\@filef@und ...\@let@token \let \discretionary {-}
{}{}\discretionary {-}{}{}...
l.7 \include{sintassi_astratta}
[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./sintassi.tex)
Runaway text?
\@setckpt{sintassi\protect \unhbox \voidb@x \kern .06em\vbox {\hrule \ETC.
! File ended while scanning text of \write.
<inserted text>
}
l.7 \include{sintassi_astratta}
! Unbalanced write command.
<write> ... \@setckpt {sintassi_astratta}\@charlb
l.7 \include{sintassi_astratta}
(./bad_doc.aux
Runaway argument?
{sintassi\protect \global \let \OT 1\textunderscore \unhbox \voidb@x \ETC.
! Paragraph ended before \@input was complete.
<to be read again>
\par
l.5
! Missing { inserted.
l.7 ...or immediate help \endgroup {}\def \par }
)
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
! Missing } inserted.
<inserted text>
}
l.9 \end{document}
! Missing } inserted.
<inserted text>
}
l.9 \end{document}
! Extra \endgroup.
<recently read> \endgroup
l.9 \end{document}
)
如果我没记错的话,不是在寻找而是sintassi_astratta.tex
在寻找sintassi.tex
。这似乎syntax
是在以某种方式重新定义下划线,从而破坏了一切。
答案1
该syntax
包有一个nounderscore
选项;然后您需要使用它\_
作为复合名称。
如果你希望在数学模式之外有_
含义,那么使用\_
\input{\detokenize{file_name}}
\include
对于或也类似\includegraphics
。因此
\documentclass{article}
\usepackage[nounderscore]{syntax}
\usepackage{graphicx}
\begin{document}
\includegraphics{logo_uniud_black}
\end{document}
将会起作用
\documentclass{article}
\usepackage{syntax}
\usepackage{graphicx}
\begin{document}
\includegraphics{\detokenize{logo_uniud_black}}
\end{document}
答案2
用于\string_
下划线
\includegraphics{/tmp/logo\string_uniud\string_black}