About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2024-10-15: New blog post: Tales for Our Times Book Launch.


5.8 Multi-Lingual Support: using the babel package

You may have noticed that the \tableofcontents and \chapter commands have produced English words like “Contents” and “Chapter”[How to change LaTeX's “fixed names”]. If you are writing in another language, this is not appropriate. In this case, you can use the babel package, and specify which language you will be using, either as an option to the babel package, or as an option to the class file[Using a new language with Babel]. If you are writing in more than one language, list all the languages that you will be using where the last named language is the default language[Parallel setting of text]. For example:

\usepackage[english,french]{babel}
or
\documentclass[english,french]{scrreprt}
\usepackage{babel}
You can then switch between the named languages either using the declaration:

\selectlanguage{<language>}

or the otherlanguage environment:

\begin{otherlanguage}{<language>}

These will affect all translations, including the date format and predefined names like “Chapter”. This also changes the hyphenation patterns.

If you only want to set a short section of text in a different language, without affecting the date format or predefined names, then you can either use the command:

\foreignlanguage{<language>}{<text>}

or the starred version of the otherlanguage environment:

\begin{otherlanguage*}{<language>}

You can test to see if a given language is currently selected using:

\iflanguage{<language>}{<true text>}{<false text>}

Example:

\documentclass[UKenglish,USenglish,french]{scrartcl}
% french is the last named option, so that's the current language

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}

\begin{document}
Ce texte est en fran\c{c}ais. La date aujourd'hui est: \today.

\selectlanguage{USenglish}
This text is in US English. Today's date is: \today.

\selectlanguage{UKenglish}
This text is in UK English. Today's date is: \today.
\end{document}

Result:

Image showing typeset output (click here for a more detailed description).

Note:

If you are using the french option, the colon character (:) is made active (that is, it's turned into a special character) so if you are writing in French it's best not to use a colon in labels (so where I've used, say, ch:def you may need to change the colon to something else).


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs