Wednesday 15 February 2012

Missing \endcsname error in LaTeX

One of the most annoying errors when compiling LaTeX documents is "! Missing \endcsname inserted." It seems to occur at random, and means little or nothing to people such as myself who haven't got into the guts of TeX.

Today I faced it as I tried to create a new function that used a counter I had created. Writing the function was fine, using it in the text was fine, but when I came to put it into a \paragraph{} or \subsection{}. Thankfully, I didn't have to struggle with it too long before some lucky searching brought me across this LaTeX Community forum page. Changing \newcommand{\newname}[1]{...} to \DeclareRobustCommand{\newname}[1]{...} did the trick. My new command worked like a charm in the sectioning commands.

No comments: