[latexrefman-discuss] \protect, Mysterious error about missing closing round bracket
Vincent Belaïche
vincent.belaiche at domain.hid
Mon Feb 8 12:24:06 CET 2016
Hello Karl et al.,
\verbatim is a good idea, but the simple silly home-made command which I
was proposing also is fragile, as this definition:
--8<----8<----8<----8<----8<-- begin -->8---->8---->8---->8---->8----
\makeatletter
\newcommand*\MyFragileCmd[1]{%
\def\@tempa{#1}\def\@tempb{e}\ifx\@tempa\@tempb
\'e\else #1\fi
}
\makeatother
--8<----8<----8<----8<----8<-- end -->8---->8---->8---->8---->8----
Will make this in the .lof:
--8<----8<----8<----8<----8<-- begin -->8---->8---->8---->8---->8----
\contentsline {figure}{\numberline {1}{\ignorespaces Company headquarters of La Capon\def {e}\def {e}\'e\def {a}\def {e}\'ele}}{1}
--8<----8<----8<----8<----8<-- end -->8---->8---->8---->8---->8----
for this caption:
--8<----8<----8<----8<----8<-- begin -->8---->8---->8---->8---->8----
\caption{Company headquarters of La Capon\MyFragileCmd e\MyFragileCmd ale}
--8<----8<----8<----8<----8<-- end -->8---->8---->8---->8---->8----
Now, I acknowledge that \MyFragileCmd above may be a bit out-of-scope
wrt to the manual. We should probably just indicate that if you do
commands with low level TeX primitive, then beware...
I tried the following (I though that optional argument use some
\futurelet and as such are supposedly fragilizing the command):
--8<----8<----8<----8<----8<-- begin -->8---->8---->8---->8---->8----
\documentclass{article}
\newcommand*\MyFragileCmd[1][dmmy]{\'#1}
\begin{document}
\listoffigures
\begin{figure}
...
\caption{Company headquarters of La Capon\MyFragileCmd eale}
\end{figure}
\end{document}
--8<----8<----8<----8<----8<-- end -->8---->8---->8---->8---->8----
But there was no compilation error, and when I look at the .lof I am
getting this
--8<----8<----8<----8<----8<-- begin -->8---->8---->8---->8---->8----
\contentsline {figure}{\numberline {1}{\ignorespaces Company headquarters of La Capon\MyFragileCmd eale}}{1}
--8<----8<----8<----8<----8<-- end -->8---->8---->8---->8---->8----
which means that, with my LaTeX distro (MikTeX 2.9), when \newcommand*
is used to define a command with an optional argument, then it
automatically robustify the command. Probably we should also some day
speak about robustification and indicate that \newcommand behaves this
way. Is that something TeXLive does too ?
I will change the examples to \verbatim. Thanks for the suggestion.
Vincent.
Le 06/02/2016 01:07, Karl Berry a écrit :
> Any suggestions ?
>
> \verbatim comes to mind as something unlikely to ever be robust in L2E.
> I suggest we switch the example to use that.
>
> I'm surprised \raisebox was ever fragile. That doesn't make sense to me.
>
> I propose to change the example to some hand-made stuff like this (the
>
> If there was a simple way to construct a fragile command, that would be
> ok. But I don't think there is. More or less by definition, a fragile
> definition makes use of low-level stuff like changing catcodes or
> \futurelet, doesn't it? And we don't want to talk about those since
> they aren't part of LaTeX. -k
>
More information about the latexrefman
mailing list