9

I'm using amsart class.

I know how to change the value of \contentsname (default is Contents). We can make use of \def or \renewcommand.

But I'd like to know why it does not work if I use those commands on preamble?

I only can change its value using, for example, \renewcommand\contentsname{List of Abstracts} after \begin{document}.

Why??

jub0bs
  • 58,916
Sigur
  • 37,330
  • 1
    \documentclass{amsart}\def\contentsname{foo}\begin{document}bar\end{document} compiles without mishap, here. Same with \renewcommand. Can you post some minimal code? – jub0bs Jan 09 '14 at 15:10
  • 3
    Are you using babel? I guess so. Please, make a minimal example. Also look for \addto and babel. – egreg Jan 09 '14 at 15:24
  • @egreg, you're right. Removing babel solve the problem. Thanks a lot. If you wish, answer. – Sigur Jan 09 '14 at 15:43

2 Answers2

16

This is a standard feature. At the beginnings, most of the fixed tags were harcoded into lplain.tex, the main file for the LaTeX kernel or in the class files (at the time “style files”). When European users started using LaTeX with different languages than English, the need for translating those fixed words emerged.

The first versions of babel patched several commands from the kernel or the class files. When LaTeX2e was released, for every fixed word a command was defined, so for babel it was easier hooking into LaTeX by changing the meaning of those commands. Thus, for Italian, it was easy to define \contentsname to mean “Indice” and not “Contents”.

The babel package stores the fixed tags for a language in the command \captions<language>. For Italian we have something like

\def\captionsitalian{%
  \def\prefacename{Prefazione}%
  \def\refname{Riferimenti bibliografici}%
  \def\abstractname{Sommario}%
  \def\bibname{Bibliografia}%
  \def\chaptername{Capitolo}%
  ...
}

When babel switches from one language to another, it executes the corresponding \captions<language> command. The first switch happens when \begin{document} is being executed. Of course, if babel is not loaded, nothing happens and the default fixed tags for English are used.

Coming to your problem, you have two strategies:

\documentclass{amsart}

\renewcommand{\contentsname}{List of abstracts}

\begin{document}

without babel. If, however, one of your abstracts is, say, in French, you'd like to load French and English with babel. The redefinition above would not work, because of the execution of \captionsenglish at \begin{document}. Here's the correct workaround:

\documentclass{amsart}
\usepackage[T1]{fontenc} % French wants it
\usepackage[french,english]{babel} % English is the default

\addto\captionsenglish{\renewcommand{\contentsname}{List of abstracts}}

\begin{document}

In this way, the redefinition of \contentsname is appendend to the list of commands executed by \captionsenglish. So, any time you load babel, a change to a fixed tag must be made with \addto\captions<language>.

egreg
  • 1,121,712
  • Thanks so much for this public talk. As always, now it is clear when we learn the theory behind the scene. So I suppose that \addto adds the \renew.... at the end of the command \captionsenglish to overwrite the contentsname, right? – Sigur Jan 09 '14 at 16:08
  • @Sigur Yes, it just appends the contents of the argument to the meaning of \captionsenglish. – egreg Jan 09 '14 at 16:10
12

As stated by egreg, using babel makes \renewcommand{\contentsname}{New Contents Name} stop working correctly. If you dont wantto use \addto solution, I find using hooks are a simple workaround.

    \documentclass{article}
    \usepackage[english]{babel}
    \AtBeginDocument{\renewcommand{\contentsname}{New Contents Name}}

I had the same trouble just now, and found this method by intuition. (my first answer here (: )