Outils pour utilisateurs

Outils du site


issue213:latex

Ceci est une ancienne révision du document !


This time, I will introduce you to the babel package, the modern way to use a language other than English in Latex documents. It is also the modern way to use more than one language in a document. It works with UTF-8 encoding for fonts, essential for many languages. In addition to loading the babel package, you will also need to load a font package that is appropriate for your language of choice. The babel documentation outlines the basics: • Tell babel what language or languages are required. • Select a suitable font or fonts if necessary. • In multilingual documents, switch the language in the text. For example \documentclass[french]{article} \usepackage{babel} \begin{document} Plus \c{c}a change, plus c'est la m\^{e}me chose. \end{document}

The [french] option in the document class informs Latex this document uses the French language and it is monolingual. To make a bilingual (or multilingual) document include two (or more) languages as options in the documentclass instruction. The last one will be the default language. To use French as the primary language and German as an occasional language, the option would be [german,french]. German comes in four variations: german, ngerman, austrian, naustrian. I do not know what the differences are, I assume the differences have to do with letter shapes and/or hyphenation and/or how dates are written and/or other factors important in localizing documents. There are four variations for English as well: English, USenglish, UKenglish, australian. Localization requires a lot more than simply spelling words correctly and using the correct letters. There is a 45-page chapter in volume 2 of The Latex Companion dedicated to this topic. There are more than sixty languages which can be produced with Latex. This includes many languages that use an alphabet and others which do not. Of course in order for a document to be produced, not only must a suitable font be used but the user must also know how to type that particular language. For example, unless you are familiar with typing French, would you have guessed what Latex command to use to generate ç or ê? If you work in two languages, how to switch from one language to another and back in one document? Babel uses the command \selectlanguage for large blocks of text like paragraphs and \foreignlanguage for small bits inside paragraphs. Here is the example used on p. 303 of vol. 2 of The Latex Companion . Because of some limitations in my system I had to use the csquotes package as well in order to generate the appropriate quotation marks..

Typesetting a document in a foreign language is not as simple as changing the words. Many languages require accents. Most languages in the world do not use what is often called the Latin alphabet. So relevant fonts have to be developed and then the font package used in the preamble in the Latex document. Different languages may require different shapes than English for numbers. A very important part of typesetting a document is hyphenation. I do not use hyphenation when I write for FCM. I prefer ragged right margins to fully justified text so I do not need to be concerned about hyphenation. However many magazines, newspapers and journals use columns of text (like FCM) and set fully justified text to indicate the edges of columns. Without hyphenation, full justified text will make rivers of white in the text. Each language has its own rules for hyphenation and those rules are incorporated into the babel package as much as possible. Languages without alphabets like Chinese and Japanese also have rules which can dictate where breaks occur between characters. Punctuation marks differ between languages. The example in the graphic shows three different types of quotation marks. There are other ways quotations are indicated in other languages. Even the simple period is not always used between sentences. In Chinese an open circle is often (although not exclusively) used. Sometimes it appears in the centre of the line of text ◦◦,other times it is on the baseline ₒ. In English North America, the period is also used as the decimal point in currency for example. In Europe and French North America, the comma is often used as a decimal indicator. Instead of a comma to separate powers of ten in many cultures spaces are used to indicate thousands, millions, etc.

Babel provides translations for document element names Latex uses in its document classes. (This feature is not working on my machine.) Terms like chapter name, figure name, table name are called language dependent strings in babel and will be translated using commands like \figurename. Dates are formatted differently in different languages, some languages have more than one way to format dates. In Canada, we cannot decide which method to use. Many organizations use the international standard of largest to smallest: yyyy mm dd. Others reverse this international standard:: dd mm yyyy. Still others use the American standard: mm dd yyyy. Despite the complications which occurred before the year rolled to 2000, many continue to use a two-digit year. Of course there is no problem understanding dates so long as the name of the month is in letters. If in numbers, there can be confusion: is 9/12/2024 the ninth of December or the twelfth of September. Many languages have a standard format for dates. Perhaps the month name is always in letters. In Bulgarian, the month is indicated by upper case Roman numerals. In Greek, numbers can be written with letters (two different systems) or with numbers. Dates in Greek can be written with any of the three possible ways to represent numbers or by spelling the name of the month. Generally, numerical values are shown with the same Arabic numbers we all know. As mentioned in Bulgarian and Greek, numbers can be represented with letters. That is also true in a few other languages, although this usage seems to be slowly disappearing. According to The Latex Companion (vol 2, p. 319), Icelandic documents require special formatting for numbers and need the command \tala. In French, there are shorthand commands to generate the first four ordinal numbers \primo, \secundo, \tertia, \quattro.

If you typeset documents using either the Greek or one of the Cyrillic alphabets, you should read the documentation available in The Latex Companion and any other helpful documentation. The authors recommend using either XeTex or LuaTex instead of pdfTex for Greek. Typing in Chinese or Korean or Japanese requires additional support. It is necessary to be able to input the appropriate code for each character in these languages. In Chinese, the most common method to “spell” a Chinese character is pinyin. The input method accepts the keyboard input and presents a series of choices which match the pinyin which has been typed (something like a spell checker). The writer then picks the correct form and it displays on the screen. That is how I typed these four characters: 我是老师. Unlike Chinese and Japanese, Korean is written using an alphabet. However the letter forms change depending on which vowel is combined with which consonant and in what order. Each syllable is represented by one character, the same as Chinese and Japanese. To write in any of these three languages requires access to character sets which match the input method. The first and best set of packages to give access to the appropriate character sets is CJK. A recent approach is to make some versions of Tex compatible with the Unicode character sets. Unicode gives access to character sets so that almost all existing languages (many ancient ones and some imaginary ones) are available to the user. This is a much better solution than the one offered by CJK and similar packages. \documentclass[12pt]{article} \usepackage{CJKutf8} %Load UTF8 version of CJK \usepackage{noto-serif} %Load a font for this document. \begin{document}

While it is possible to write Chinese in columns starting in the top-right corner of the writing space, normally Chinese is written left-to-right top-down in rows the same as English. I can type pinyin to generate Chinese characters. In order to generate Chinese characters (or Japanese or Korean), I need to add a package to Latex. Either CJK or CTEX are recommended. See image below. As you may know Hebrew and Arabic are written right-to-left. The Hebrew and Arabic alphabets contain only consonants. Arabic consonants change shape depending on their position in a word: beginning, middle, end. The letters in a Mongolian word are written top-down. Words in a Mongolian sentence are written right-to-left. (Humans have used many variations in order to communicate using writing.) The problem of writing in other than left-to-right order requires at least one other package: bidi (for bidirectional). The difficulties caused by Mongolian text are overcome with Unicode. This excursion into the world of typesetting for more than one language points out a feature of Tex that is hidden from users who install a variant of Tex in one language. Some variants of Tex are fully compatible with Unicode, others are not. This is similar to issues between some variations of Linux. For example, to install krecipes on Linux that is not based in Ubuntu requires the addition of many packages because krecipes uses features of Ubuntu that are not normally installed with other variants of Linux. If you never want to use krecipes you never have to think about this situation.

I did find some workaround code that makes my plain vanilla Latex work with and produce characters I do not often use. The other choice would have been to install at least one other version of Tex, probably pdfTex or LuaTex. I chose not to add more files to my machine. This is in keeping with Knuth’s original design idea. Do not make the user install any more bits of software than they need. Unlike some other versions of Latex, mine does not automatically install any required packages. Instead, it generates an error which indicates it cannot find a particular package the user requires. One of the operations I will examine in the near future is the installation of new packages. Depending on when I get to that topic I may also look at updating Latex to a new version. This is the end for this time. Keep exploring Tex / Latex. Ask me any questions you have about it.

issue213/latex.1738773704.txt.gz · Dernière modification : 2025/02/05 17:41 de d52fr