GeneralStrange missing \endcsname inserted error

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
99sono
Posts: 5
Joined: Wed Jun 03, 2009 5:27 pm

Strange missing \endcsname inserted error

Post by 99sono »

Hi,

Well i am having a strange error when i compile my sources and i just can't figure out why it happens.

Problem:
1) I have defined a command that prints one thing most of the time, but in case of recieving some special input it prints another. It uses the ifthenelse command.
Here it is the command that generates the error (sometimes):

\newcommand{\scenref}[1]{
\ifthenelse{\equal{#1}{scenario:unbounded2}}
{Scenario 007}
{Scenario~\ref{#1}}
}

command explanation:
when \scenref is invoked with any label different then scenario:unbounded2 it prints out the bottom line: {Scenario~\ref{#1}}
Otherwise it prints Scenario 007.

And apparently this command works fine, except:

2) When i use this command inside a caption, more pricesly in the facultative field that goes into the index, i get the error saying that and \endcsname is missing.
Here is an example:

2.1)Bugy code example:
\caption[\scenref{scenario:unbounded2} it blows here]{\scenref{scenario:unbounded2} this side here works ok}

2.2) Working code example:

\caption[Scenario~007 crappy fix]{\scenref{scenario:unbounded2} this side here works ok}

2.3) Compile error of 2.1:
[41] (section/ch4/table_scenario3_input.tex
! Missing \endcsname inserted.
<to be read again>
\let
l.26 ...unded2} input: \codett{PROFILE} instance.}


Even more, i have tries using the a standard example of the ifthenelse command instead of my own command, but it results in the same problem. Would anyone care to try to create a command that uses the ifthenelse command and see if they can get it to work inside the [] area of the \caption command?

I just can get this thing to work. And until i do, i guess i gotta work with a crappy fix.


Thanks in advance,
my best regards.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Strange missing \endcsname inserted error

Post by localghost »

In such cases you unconditionally have to provide a minimal working example (MWE) that reproduces the error. Please keep that in mind for future requests.


Best regards and welcome to the board
Thorsten
99sono
Posts: 5
Joined: Wed Jun 03, 2009 5:27 pm

Strange missing \endcsname inserted error

Post by 99sono »

Here is a mmw:

Code: Select all

\documentclass{article}
\usepackage{ifthen}

\newcommand{\scenref}[1]{
\ifthenelse{\equal{#1}{jondoe}}
{Johndoe}
{Not Johndoe}
}

\begin{document}

\title{Ups You Did it again}
\author{99Sono}
\maketitle
\newpage

\section{working command}
Is John Doe doe john doe? \scenref{I guess not!}
\newpage

\section{Does Caption Like The New command?}

\begin{table}[ht]
Here it works:  \scenref{I guess not!}

\caption[This caption blows \scenref{I guess not!}]{So sorry!}
%\caption[This captioon does not blow:]{It works fine:  \scenref{I guess not!}}
\end{table}

\end{document}
Only thing is this time the error is: that the equal is an undefined command. Instead of being the \endcsname that is missing now this time it is the \equal that is not recognized when it processes the \scenref.
Well the only common denomitor is that the command works everywhere but in the [] field of th caption.

The cause is the same, the effect is the same, only the outputed erros has differed for some reason that escapes my understanding.


Once more, thanks in advance.
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

Re: Strange missing \endcsname inserted error

Post by T3. »

Try \protect\scenref.

Cheers,

Tomek
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Strange missing \endcsname inserted error

Post by sommerfee »

or use

Code: Select all

\DeclareRobustCommand\scenref[1]{...}
instead of

Code: Select all

\newcommand\scenref[1]{...}
Then there is no need to \protect \scenref inside section titles or captions anymore.

HTH,
Axel
99sono
Posts: 5
Joined: Wed Jun 03, 2009 5:27 pm

Re: Strange missing \endcsname inserted error

Post by 99sono »

:D

Cheers mates, i do not know how you did it... but that worked out just fine.

Strange though: in my mmw the error the compiler complained about was the \equal, and in my actual document is the \endcsname. It did however solve the problem.
So ... whatever.
I'll just take it as part of the byzantine world we live in :D.
Post Reply