3

What I (hopefully) understood:


I'm getting a bit into Babel for my Lieder-Package. I want to support all 70 languages listed here.

As far as I understood I can do this (source):

\newcommand*\GFMlistOfSongs{List of Songs}
\@ifpackageloaded{babel}
  {
  \addto\captionsngerman{\def\GFMlistOfSongs{Liederverzeichnis}}
  \addto\captionsgerman{\def\GFMlistOfSongs{Liederr Verrrzaichniss}}
  \addto\captionsfoospeak{\def\GFMlistOfSongs{lista di songos}}
  }

\def\createLOS{
  \GFMlistOfSongs \\ \BoDY % BoDY = somewhere else defined.
}

\begin{document}
\createLOS
\end{document}

which will create some list with the list title in the correct language.


What I don't understand:


I saw \addto\extras<lang.> several times. What is the difference between that and \addto\captions<lang.>?

I had a look into the babel docu, but haven't found anything.

  • 1
    Extras are evaluated at each language change; captions aren't within otherlanguage* and \foreignlanguage. Typically, list names go in captions. – egreg Feb 16 '17 at 11:57
  • @egreg Ok, extras at language change. Are extrasngerman evaluated when the change is from ngerman or to ngerman? What do you mean by "captions aren't used". I would suppose, that inside otherlanguage* the captions of the other language are used. i.e. language=ngerman, otherlanguage=foospeakwill result in lista di songos inside otherlanguage. Is that correct? – MaestroGlanz Feb 16 '17 at 12:05
6

There are basically five ways to change the current language:

  1. \selectlanguage{<language>}

  2. \begin{otherlanguage}{<language>}...\end{otherlanguage}

  3. \begin{otherlanguage*}{<language>}...\end{otherlanguage*}

  4. \foreignlanguage{<language>}{...}

  5. \begin{hyphenrules}{<language>}...\end{hyphenrules}

The difference between 1 and 2 is that in the second case you don't need to change back the language. The difference between 3 and 4 is that method 3 is better for multiparagraph text and 4 is for small phrases inside a paragraph.

With methods 1 and 2, both \captions<language> and \extras<language> are performed; with methods 3 and 4 only \extras<language> is performed. With method 5 only the hyphenation rules change, and neither \captions<language> nor \extras<language> is performed.

Indeed, tags such as \figurename are in \captions<language>, whereas language specific features are in \extras<language>.

If you add something to \extras<language>, the corresponding “reverse setting” should be added to \noextras<language>, which is performed at the next \selectlanguage command.

For instance, in Italian the apostrophe should have a nonzero \lccode in order for hyphenation to work correctly; so the setting \lccode`\'=`\' is part of \extrasitalian. Similarly, language shorthands should be in \extras<language>.

Your code for localizing lists of songs should definitely go in \captions<language>:

\newcommand*\GFMlistOfSongs{List of Songs}

\@ifpackageloaded{babel}
  {%
  \addto\captionsngerman{\def\GFMlistOfSongs{Liederverzeichnis}}%
  \addto\captionsgerman{\def\GFMlistOfSongs{Liederr Verrrzaichniss}}%
  \addto\captionsfoospeak{\def\GFMlistOfSongs{lista di songos}}%
  }{}

\def\createLOS{%
  \GFMlistOfSongs \\ \BoDY % BoDY = somewhere else defined.
}

(don't forget the terminating % and the empty third argument to \@ifpackageloaded).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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