Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

If I want to use the babel package and redefine a macro such as \contentsname, what is the right way to go about this? Just putting \renewcommand in the preamble doesn't work.

This sort of works

\documentclass{article}
\usepackage[english]{babel}
\AtBeginDocument{%
        \renewcommand\contentsname{Foo}%
}
\begin{document}
% \selectlanguage{english}
\tableofcontents
\end{document}

but if you uncomment the \selectlanguage{english}, the definition is undone.

The best I could come up with is to use the following.

\usepackage{etoolbox}
\patchcmd\captionsenglish{Contents}{Foo}{}{}
share|improve this question
    
possible duplicate of Multilingual class/style file? –  TH. Jan 9 '11 at 14:44

2 Answers 2

up vote 10 down vote accepted

Use \addto\captionsenglish.

\documentclass{article}
\usepackage[english]{babel}
\addto\captionsenglish{%
  \renewcommand\contentsname{Foo}%
}
\begin{document}
\selectlanguage{english}% For testing purposes
\tableofcontents
\end{document}

EDIT: See e.g p. 78 of the babel documentation, where the definitions are changed for the Esperanto language (\addto\captionsesperanto).

share|improve this answer
    
Thanks! I missed that in the manual. –  TH. Jan 9 '11 at 14:41

Babel provides hooks for this sort of redefinitions as follows, if for example you wish to hook onto the greek option you add captions such as:

\addto\captionsgreek{
  \def\contentsname{prologos}
}

You need to do the same for english

\addto\captionsenglish{%
  \def\contentsname{Foo}
  ...
  }

Also see Multilingual class/style file?

share|improve this answer
    
Yikes. My question is an exact duplicate. This should be closed. –  TH. Jan 9 '11 at 14:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.