Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm writing a document where I want to both include some image via graphicx's \includegraphics and display some BNF grammars using the syntax package of mdwtools, however I receive an error of undefined control sequence when I try to use them together with some filenames.

A minimal example that fails:

\documentclass{article}

\usepackage{syntax}
\usepackage{graphicx}

\begin{document}

\includegraphics{logo_uniud_black}

\end{document}

Compiling this I get the following error:

(/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.)

Commenting out \usepackage{syntax} fixes the problem. Also using a filename that doesn't contain underscore works, so that this code doesn't fail:

\documentclass{article}

\usepackage{syntax}
\usepackage{graphicx}

\begin{document}

\includegraphics{logouniudblack}

\end{document}

Why do I get this error and how is it related to the underscore in the filename? Is there a way to fix it without renaming all the files I have to include?


Edit:

Actually it seems like even section names with underscore create problems, so that \includes raise similar errors, for example with the source:

\documentclass{article}

\usepackage{syntax}

\begin{document}

\include{sintassi_astratta}

\end{document}

I get these errors:

(/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}

 )

If I'm not mistaken instead of looking for sintassi_astratta.tex it is looking for sintassi.tex. It seems like syntax is redefining the underscore in some way that breaks everything.

share|improve this question
    
Yes, syntax makes the underscore active; if you really need it and also need underscores in file names, say \input{\detokenize{sintassi_astratta}} and similarly for \includegraphics or \include. For a better solution, an example of how you're using syntax and knowing if you need the active underscore is needed. –  egreg Mar 20 at 10:17
    
@egreg I believe I don't need _ as active character. Should I just change it \catcode to 11 after loading syntax? –  Bakuriu Mar 20 at 10:30

2 Answers 2

up vote 10 down vote accepted

The syntax package has a nounderscore option; you then need to use \_ for compound names.

If you prefer to have _ meaning \_ outside of math mode, then use

\input{\detokenize{file_name}}

and similarly for \include or \includegraphics. So

\documentclass{article}

\usepackage[nounderscore]{syntax}
\usepackage{graphicx}

\begin{document}

\includegraphics{logo_uniud_black}

\end{document}

will work as well as

\documentclass{article}

\usepackage{syntax}
\usepackage{graphicx}

\begin{document}

\includegraphics{\detokenize{logo_uniud_black}}

\end{document}
share|improve this answer
    
In your example shouldn't nounderscore be used as option to syntax? –  Bakuriu Mar 20 at 10:40
    
@Bakuriu yes:-) –  David Carlisle Mar 20 at 10:59

use \string_ for an underscore

\includegraphics{/tmp/logo\string_uniud\string_black}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.