The macro \title
in amsart
is defined in a very indirect way:
\renewcommand*{\title}[2][]{\gdef\shorttitle{#1}\gdef\@title{#2}}
\edef\title{\@nx\@dblarg
\@xp\@nx\csname\string\title\endcsname}
which is very clever, but simply disallows you to do that redefinition. In this case even \LetLtxMacro
is not good, because of this nonstandard definition.
You can do it with xparse
:
\documentclass{amsart}
\usepackage{xparse}
\makeatletter
\RenewDocumentCommand{\title}{om}{%
\IfNoValueTF{#1}
{\gdef\shorttitle{My default running title}}
{\gdef\shorttitle{#1}}%
\gdef\@title{#2}%
}
\makeatother
\title{Article title here}
\author{Author name here}
\begin{document}
\maketitle
\end{document}
Actually, it's a bit mysterious why the definition of \title
is that one. The standard way to define a macro of that kind would be
\def\title{\@dblarg\title@}
\def\title@[#1]#2{%
\gdef\shorttitle{#1}\gdef\@title{#2}%
}
because \@dblarg
takes care that a call such as
\title{Title}
will substitute Title
both for #1
and #2
, while a call such as
\title[Short]{Long title}
will do the expected thing. Instead of \title@
anything else could be used.
The definition in amsart
exploits the fact that
\renewcommand*{\title}[2][]{\gdef\shorttitle{#1}\gdef\@title{#2}}
defines \title
to expand to
\@protected@testopt\title\\title{}
and \\title
(a command with a backslash in its name) as if
\def\\title[#1]#2{\gdef\shorttitle{#1}\gdef\@title{#2}}
The next instruction, with \@nx
and \@xp
replaced by the more comprehensible \noexpand
and \expandafter
, is
\edef\title{%
\noexpand\@dblarg\expandafter\noexpand\csname\string\title\endcsname
}
that is essentially the same as saying
\def\title{\@dblarg\\title}
(with the difference that \\title
needs wome weird trick for being input). So there is no gain whatsoever, because the definition is eventually exactly* the easier one I gave before, except perhaps that the internal macro (\\title
, here) is more difficult to get at for a casual user.
The \LetLtxMacro
from the letltxmacro
package can't work, because \\title
exists, but \title
is not defined as expected, that is, starting with \@protected@testopt
, so it gets confused.
The xparse
way is surely clearer.