Post by Dan LueckingOn Wed, 18 Feb 2004 17:32:22 +0100, Morten Høgholm
This particular bug was rather extensively discussed on c.t.t several
months ago. The problem with \label inside \caption is that ntheorem
redefines \label to take an optional argument, thus making it fragile.
I don't know if it is possible now, but I think ntheorem ought to try
Here is a fun definition for making robust command variants (it needs
eTeX, and it is really not a good idea to adapt this for use without
it, since it could make your hash space grow rather uglily). Note
that this works even if the "suffix" is actually a macro. I am not
sure that the interface will remain in this form, so you better not
rely on it.
\def\DeclareSuffix{\@***@or@long\***@declare@suffix}
\def\***@declare@suffix#1{\def\***@next{#1}%
\afterassignment\***@decsuff\let\next= }
\def\***@decsuff{\ifcsname
***@suffix\expandafter\string\***@next\endcsname
\else
\expandafter\let\csname
***@suffix\expandafter\string\***@next
\expandafter\endcsname \***@next
\edef\***@a{\protected\def
\expandafter\noexpand\***@next{%
\noexpand\***@suffixcheck\expandafter\noexpand\***@next}}%
\***@a
\fi\***@ngrel@x\expandafter\def\csname ***@suffix\expandafter\string
\***@next @\meaning\next\endcsname}
\def\***@suffixcheck#1{\begingroup\def\***@next{#1}%
\futurelet\next\***@suffixcheckii}
\def\***@gobblenext{\let\next= }
\def\***@suffixcheckii{\ifcsname ***@suffix\expandafter\string
\***@next @\meaning\next\endcsname
\afterassignment\endgroup
\expandafter\aftergroup
\csname ***@suffix\expandafter\string\***@next
@\meaning\next\endcsname
\expandafter\***@gobblenext
\else
\expandafter\endgroup
\csname ***@suffix\expandafter\string\***@next
\expandafter\endcsname
\fi}
Usage: for example
\DeclareSuffix\=>{\ensuremath{\to}}
And now \=> will produce an arrow, while \=a will still produce
amacron.
\DeclareSuffix\<={\ensuremath{\gets}}
\DeclareSuffix\<\>{\ensuremath{\langle\rangle}}
\DeclareSuffix*\label[#1]#2{This is a label variant #1 of #2.}
The definition is robust, adding more suffixes does not slow down the
execution time, the original definition stays, and the whole stuff is
robust if its components are. You should only try not to use macros
with a long top-level expansion as a suffix: those will turn out to be
slow.
Like everything implemented with \futurelet, this will not distinguish
between things \let to each other, like { and \bgroup.
Probably it would be nicer to call the above "\SuffixDef", and then
add a variant "\SuffixCommand" that can be used like
\SuffixCommand{\newcommand*}\label[[1][]{whatever}
Hmmm. Not much of an improvement here.
or at least
\SuffixCommand\let\label[=\mydefinitionoflabelbracket
or using it on \edef.
Opinions about the naming? It's still easy to fix.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>