2

I've been receiving the error Undefined control sequence. <argument> \shorttitle with the following code:

\author{MyName}
\title{ThisPaper}
\date{01 Jan 2015}
\documentclass[12pt]{amsart}

\begin{document}
\maketitle
Text
\end{document}

Is there something wrong with my packages?
Text
\end{document}
2
  • 2
    Which packages?
    – Bernard
    Nov 17, 2015 at 22:48
  • 1
    Put \author etc. after \documentclass. Where does \shorttitle occur?
    – cfr
    Nov 17, 2015 at 22:48

2 Answers 2

5

Put \author etc. after \documentclass - not before.

\documentclass[12pt]{amsart}
\author{MyName}
\title{ThisPaper}
\date{01 Jan 2015}

\begin{document}
\maketitle

Is there something wrong with my packages?
Text
\end{document}

This way, you get the class's definitions of these macros and \shorttitle will be defined automatically when you define \title. If you use \title before, amsart's definitions are not active and \shorttitle will not be defined.

Here's the definition of \title from amsart.cls:

\renewcommand*{\title}[2][]{\gdef\shorttitle{#1}\gdef\@title{#2}}

Notice the \renewcommand rather than \newcommand. The class is replacing the standard LaTeX \title with a definition of its own. The redefined version takes 2 arguments, rather than 1. But the first is optional. Moreover, the first argument is used to define \shorttitle:

\gdef\shorttitle{#1}

This means that if you say just

\title{Title}

then Title will be used for the title and \shorttitle will be defined to be nothing because the default value of the optional argument is [] in the \renewcommand line above.

But if you say \title before \documentclass, you get the standard LaTeX definition:

\def\title#1{\gdef\@title{#1}}

So, in this case, the title will be correctly set to Title but \shorttitle is never defined. This is a problem because \maketitle is used after amsart.cls has redefined it and it expects \shorttitle to be available. Hence, you get the error.

In general, very little, if anything, should go before \documentclass. Unless you are certain it should go before the class is loaded, assume that it either belongs in the preamble - the code after \documentclass and before \begin{document} - or in the document - the code after \begin{document} and before \end{document}.

4
  • 1
    To be fussy, that definition of \title is supplemented by \edef\title{\@nx\@dblarg\@xp\@nx\csname\string\title\endcsname}, which is a very clever trick for making \title{Title} equivalent to \title[Title]{Title} so the short title is defined to be the full one in case no optional argument is given.
    – egreg
    Nov 17, 2015 at 23:10
  • @egreg I saw that, although I did not understand it. But it seemed to me that including that code might not be needed to convey the basic idea, and I was trying to tune the answer to what I guessed the OP's level of experience was based on the code in the question. Do you think I should add something about that? I just didn't want to make what is a relatively straightforward point impenetrable without compelling reason.
    – cfr
    Nov 17, 2015 at 23:22
  • 1
    Having it in the comment is more than sufficient, I believe.
    – egreg
    Nov 17, 2015 at 23:23
  • OK. Good. Thanks. (And thanks for the explanation.)
    – cfr
    Nov 17, 2015 at 23:25
3

\author etc. are LaTeX core commands, but shouldn't be used before \documentclass!

\title defines \shorttitle in amsart.cls but not in the standard classes.

Using it ahead of \documentclass it will never apply the amsart.cls definition of \title but the original 'core' one, so \shorttitle never get's defined -- and \maketitle uses \shorttitle

\documentclass[12pt]{amsart}

\author{MyName}
\title{ThisPaper}
\date{01 Jan 2015}

\begin{document}
\maketitle

Is there something wrong with my packages? -- No, but \verb+\title+ etc. should be used after the \verb+\documentclass+ 
Text
\end{document}

enter image description here

Here's the code from amsart.cls:

\def\maketitle{\par
  \@topnum\z@ % this prevents figures from falling at the top of page 1
  \@setcopyright
  \thispagestyle{firstpage}% this sets first page specifications
  \uppercasenonmath\shorttitle
  \ifx\@empty\shortauthors \let\shortauthors\shorttitle
  \else \andify\shortauthors
  \fi
  \@maketitle@hook
  \begingroup
  \@maketitle
  \toks@\@xp{\shortauthors}\@temptokena\@xp{\shorttitle}%
  \toks4{\def\\{ \ignorespaces}}% defend against questionable usage
  \edef\@tempa{%
    \@nx\markboth{\the\toks4
      \@nx\MakeUppercase{\the\toks@}}{\the\@temptokena}}%
  \@tempa
  \endgroup
  \c@footnote\z@
  \@cleartopmattertags
}
2
  • Could you please explain what \verb+ means?
    – Owen
    Nov 17, 2015 at 22:52
  • \verb+...+ just outputs the text literally, i.e. \author as command, not what \author actually does!
    – user31729
    Nov 17, 2015 at 22:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .