2

I have a really weird problem: When changing the babel language in combination with the use of babelbib, certain substitutions stop working altogether. It took me hours to track down this cause. Consider the following minimal example:

\documentclass{article}

\usepackage[american]{babel}

\makeatletter

\title{Test}

\begin{document}

\section*{{\@title}}
This is the {\@title} document.

\end{document}

This yields a nice document:

This document is fine

If I add the babelbib package like this

\documentclass{article}

\usepackage[american]{babel}
\usepackage{babelbib}

\makeatletter

\title{Test}

\begin{document}

\section*{{\@title}}
This is the {\@title} document.

\end{document}

the substitution of \@title stops working:

This document is incorrect

Funny enough, this problem does not appear when the babel language is set to German:

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage{babelbib}

\makeatletter

\title{Test}

\begin{document}

\section*{{\@title}}
This is the {\@title} document.

\end{document}

This yields a perfectly fine document:

This document is fine too

Similarly, using ngerman for babel, but removing babelbib, does not exhibit this problem:

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage{babelbib}

\makeatletter

\title{Test}

\begin{document}

\section*{{\@title}}
This is the {\@title} document.

\end{document}

This document is fine too

My question now is: What is happening here and how can I fix it? I have German documents which use babel and babelbib that I need to translate to English. When changing the babel language and replacing some text, the substitutions stop working as shown in the example below. Is there a way to use babelbib with English as babel language without this problem?

Leaving the babel language at German is not an option since I need the language-specific terms of reference lists, table of contents etc. I am using the latest MiKTeX (32-bit) on Windows 7 and just updated all packages, in case it matters.

2
  • You're abusing \@title.
    – egreg
    Aug 6, 2015 at 13:35
  • Is it not o.k. to access the defined title like this? If so, what is the proper way to access it? Aug 6, 2015 at 13:37

1 Answer 1

3

This is due to babel.def that does

\AtEndOfPackage{%
  \AtBeginDocument{%
    \@ifpackageloaded{hhline}%
      {\expandafter\ifx\csname normal@char\string:\endcsname\relax
       \else
         \makeatletter
         \def\@currname{hhline}\input{hhline.sty}\makeatother
       \fi}%
      {}}}

Your \makeatletter before \begin{document} is so neutralized when \makeatother is executed at the begin document hook.

In any case, your approach is wrong, because it's not recommendable to set a document with \makeatletter in force.

The solution for having the title available in the document is much simpler. Add

\makeatletter
\def\title#1{%
  \gdef\@title{#1}%
  \global\let\thetitle\@title
}
\makeatother

and use \thetitle in the document.

\documentclass{article}

\usepackage[american]{babel}
\usepackage{babelbib}

\makeatletter
\def\title#1{%
  \gdef\@title{#1}%
  \global\let\thetitle\@title
}
\makeatother


\title{Test}

\begin{document}

\section*{\thetitle}
This is the {\thetitle} document.

\end{document}
1
  • Your idea with \thetitle should make into latex.ltx ;-)
    – user31729
    Aug 6, 2015 at 14:01

You must log in to answer this question.

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