% \iffalse meta-comment % % Copyright 1989-2008 Johannes L. Braams and any individual authors % listed elsewhere in this file. All rights reserved. % % This file is part of the Babel system. % -------------------------------------- % % It may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either version 1.3 % of this license or (at your option) any later version. % The latest version of this license is in % http://www.latex-project.org/lppl.txt % and version 1.3 or later is part of all distributions of LaTeX % version 2003/12/01 or later. % % This work has the LPPL maintenance status "maintained". % % The Current Maintainer of this work is Johannes Braams. % % The list of all files belonging to the Babel system is % given in the file `manifest.bbl. See also `legal.bbl' for additional % information. % % The list of derived (unpacked) files belonging to the distribution % and covered by LPPL is defined by the unpacking scripts (with % extension .ins) which are part of the distribution. % \fi %%% ==================================================================== %%% @TeX-file{ %%% author = "Johannes L. Braams", %%% version = "1.04", %%% date = "06 January 1997", %%% time = "23:15:14 MET", %%% filename = "tb1202.tex", %%% address = "TeXniek, %%% Kersengaarde 33 %%% 2723 BP Zoetermeer %%% The Netherlands", %%% telephone = "+31 79 352 28 19", %%% FAX = "+31 70 343 23 95", %%% checksum = "19810 933 5016 39417", %%% email = "babel@braams.cistron.nl (Internet)", %%% codetable = "ISO/ASCII", %%% keywords = "", %%% supported = "yes", %%% abstract = "", %%% docstring = "The article on babel that apeared in %%% TuGboat Volume 12, No. 2. %%% %%% The checksum field above contains a CRC-16 %%% checksum as the first value, followed by the %%% equivalent of the standard UNIX wc (word %%% count) utility output of lines, words, and %%% characters. This is produced by Robert %%% Solovay's checksum utility.", %%% } %%% ==================================================================== % tb32braa.ltx \NeedsTeXFormat{LaTeX2e} \IfFileExists{ltugboat.cls}{% \documentclass{ltugboat} \def\rtitlex{TUGboat, Volume 12 (1991), No. 2} \def\midrtitle{} \def\PrelimDraftfooter{} \let\TBmaketitle\maketitle \SelfDocumenting \setcounter{page}{291} }{% \documentclass{article} \newcommand\address[1]{} \newcommand\netaddress[1]{} \newcommand\TUB{\textsl{TUGboat\/}} \newcommand\TeXhax{\TeX hax}} \usepackage{shortvrb} \MakeShortVerb{\|} \newcommand{\file}[1]{\texttt{#1}} \newcommand{\Lopt}[1]{\textsf{#1}} \newcommand{\babel}{\textsf{babel}} \makeatletter % ------------------------------------------------- % Definitions copied from doc.sty by FMi % ------------------------------------------------- {\obeyspaces% \gdef\meta{\begingroup\obeyspaces% \def {\egroup\space\hbox\bgroup\it}\m@ta}} \def\m@ta#1{\hbox\bgroup$\langle$\it#1\/$\rangle$\egroup\endgroup} % ------------------------------------------------- % define \dlqq so that we can give an example of "' % ------------------------------------------------- \gdef\dlqq{{\setbox\tw@=\hbox{,}\setbox\z@=\hbox{''}% \dimen\z@=\ht\z@ \advance\dimen\z@-\ht\tw@ \setbox\z@=\hbox{\lower\dimen\z@\box\z@}\ht\z@=\ht\tw@ \dp\z@=\dp\tw@ \box\z@\kern-.04em}} % % ------------------------------------------------- % To demonstrate german double quotes (from german.tex) % ------------------------------------------------- \def\allowhyphens{\penalty\@M \hskip\z@skip} \def\set@low@box#1{\setbox\tw@\hbox{,}\setbox\z@\hbox{#1}\dimen\z@\ht\z@ \advance\dimen\z@ -\ht\tw@ \setbox\z@\hbox{\lower\dimen\z@ \box\z@}\ht\z@\ht\tw@ \dp\z@\dp\tw@ } % (this lowers the german left quotes to the same level as the comma.) \def\@glqq{{\ifhmode \edef\@SF{\spacefactor\the\spacefactor}\else \let\@SF\empty \fi \leavevmode \set@low@box{''}\box\z@\kern-.04em\allowhyphens\@SF\relax}} \def\glqq{\protect\@glqq} \def\@grqq{\ifhmode \edef\@SF{\spacefactor\the\spacefactor}\else \let\@SF\empty \fi \kern-.07em``\kern.07em\@SF\relax}%'' \def\grqq{\protect\@grqq} % % ------------------------------------------------- % To demonstrate french double quotes (from german.tex) % ------------------------------------------------- \def\@flqq{\ifhmode \edef\@SF{\spacefactor\the\spacefactor}\else \let\@SF\empty \fi \ifmmode \ll \else \leavevmode \raise .2ex \hbox{$\scriptscriptstyle \ll $}\fi \@SF\relax} \def\flqq{\protect\@flqq} \def\@frqq{\ifhmode \edef\@SF{\spacefactor\the\spacefactor}\else \let\@SF\empty \fi \ifmmode \gg \else \leavevmode \raise .2ex \hbox{$\scriptscriptstyle \gg $}\fi \@SF\relax} \def\frqq{\protect\@frqq} %+ % Some extra definitions needed in the article %- \def\bsl{\char'134} \makeatother \begin{document} \title {Babel, a multilingual style-option system for use with \LaTeX's standard document styles% \thanks{During the development ideas from Nico Poppelier, Piet van Oostrum and many others have been used.} } \author{Johannes Braams} \address{% \TeX niek\\ Kersengaarde 33\\ 2723 BP Zoetermeer\\ The Netherlands} \netaddress{babel@braams.cistron.nl} \date{06 January 1997 \\ Version 1.04} \maketitle \begin{abstract} The standard distribution of \LaTeX\ contains a number of document styles that are meant to be used, but also serve as examples for other users to create their own document styles. These styles have become very popular among \LaTeX\ users. But it should be kept in mind that they were designed for American tastes and contain a number of hard-wired texts. This article describes a set of document-style options that can be used in combination with the standard styles, which makes the latter adaptable to other languages. \end{abstract} \section{Introduction} Although Leslie Lamport has stated~\cite{LLth} that one should not try and write \emph{one} document-style option to be used with \emph{all} the standard document styles of \LaTeX, that is exactly what I~have done with this system of style options. The reasons for this approach will be explained in section~\ref{why}. A lot of the ideas incorporated in this set of files come from the work of Hubert Partl~\cite{HP}, \file{german.tex}. Some parts in the implementation are different, others are the same. It will be shown that \file{german.tex} can be modified to fit into this scheme of style options. \section{Why \babel?}\label{why} When I~first started using \LaTeX\ I~was very happy with just the style files that are distributed with the standard distributions of \TeX\ and \LaTeX. That means, as long as I~made texts in English I~was happy. Then as other users found out about \LaTeX\ and its advantages, they started using it for texts in languages other than English. As I~was the most experienced \LaTeX\ user at the time, they came to me and asked me `When I'm writing a report in Dutch I~don't want chapters to be named ``Chapter'', I~want them to be named ``Hoofdstuk'', how do you change that?'. At that time I~didn't know, but I soon found out. The first thing I~found was that Leslie Lamport states~\cite[pages 85--86]{LLbook} that you have to redefine the command |\@chapapp| to get the desired result. This looked rather promising to me, so I~had a look at the style files to find out how other such strings as ``Figure'' might be redefined. It was then that I~found out that |\@chapapp| is the \emph{only} string defined this way, whereas all others are hard-wired into the style. My first solution to this problem was to create a new document style file called \file{artikel.sty} as a ``Dutch'' counterpart to \file{article.sty}. The same was done for \file{report.sty}. This is exactly what Leslie Lamport suggests~\cite{LLth}. This approach has one major drawback however: you get two copies of basically the same file to maintain. This was discovered when newer releases of the styles reached our site. The standard styles had to be replaced \emph{and} edited all over again to get the ``Dutch'' versions back. About the same time, in early 1988, a discussion on this subject appeared in \TeXhax. One of the persons commenting was Hubert Partl. The method he suggested was to modify the standard document styles by replacing the hard-wired texts by macros such as |\@chapapp|. This led me to my second attempt at a solution. I~modified the standard styles (all four of them) as suggested, but while doing that added an option, implemented like the option \texttt{draft}, by defining a command |\ds@dutch|. This command would set a variable to indicate which language was requested. This variable I~used later on in a |\case| statement. In this |\case| statement a choice is made between English, Dutch and possibly other languages for texts such as ``Figure'' and ``Contents''. Unfortunately, some of this implied changing the secondary style files \file{xxx10.sty}, \file{xxx11.sty} and \file{xxx12.sty}. This was unfortunate because one of the research groups in our laboratories complained their document style didn't work properly. It turned out that their style was a modified \file{article.sty} that had been given a different name, but it still loaded \file{art10.sty} etc. I~found a temporary solution, but I still wasn't exactly happy with the situation. Besides this, the drawback of replacing the document styles with newer versions still existed. When after a while a new version of the \LaTeX\ distribution arrived at our site, I~began to think about a different way to solve the problem. In the meantime Hubert Partl had his \file{german.sty} published in \TUB~\cite{HP}. His article pointed the way to a different solution. Triggered by the discussion in \TeXhax\ in early 1989 about how to detect which is the main (primary) style when processing a document, I~started work on what is now available as \file{dutch.sty} version~1.0, dated may 1989\footnote{This file is available from \texttt{listserv@hearn.bitnet} as file \file{dutch.old}.}. While working on this style option I~discovered that some parts could be borrowed from \file{german.sty}. This `discovery' and some discussions I had with others at Euro\TeX89, the fourth European \TeX\ Conference, held in september 1989 in Karlsruhe, led me towards a more universal approach. The basic idea behind it was, starting from the algorithm to detect the main style, to design an approach with one common file that contained macro definitions needed by a number of language-specific style options. Users specify the name of any of these language-specific options as an option to the |\documentstyle| command, and internally the common file is read. %This is the situation as it stands now. The rest of this article is %devoted to a description of how the system of style options described %above is implemented and what the possibilities are. I~realize that %with the new \TeX\ 3.0 around and work being done on a new version of %\LaTeX\ as well some of this work may become obsolete in the near %future. But, taking into consideration the widespread use of the %current versions of \TeX\ and \LaTeX\, I~think it may take some time %before {\em everybody} is working with the new releases. %------------------------------------------------------------ % All text above here was copied from babel.doc, the following % section is new for this version of the article %------------------------------------------------------------ \section{\LaTeX\ and document-style files}\label{lat-docstyle} Before the I discuss some of the code in the \babel{} system I would like to discuss the document-style mechanism used by \LaTeX. Every \LaTeX\ document should start with a line like: \begin{verbatim} \documentstyle[opt1,opt2,...]{docstyle} \end{verbatim} This line of code instructs \LaTeX\ to first load the file \file{docstyle.sty}. When that is done the `options' are processed \emph{in the order specified}, by reading the files \file{opt1.sty}\footnote{Except when the documentstyle defines the control sequence {\tt\bsl ds@\meta{opt1}}; in that case this control sequence will be executed.}, \file{opt2.sty}, etc. This implies that definitions, made in the file \file{docstyle.sty} can be overridden in one of the option files. It is even possible to redefine code from the very kernel of \LaTeX, but you have to know what you are doing. Some care has to be taken in writing document-style options, because a number of problems can occur. First of all, if a document-style option should be modest in size; if it tries to redefine most of the code in \file{docstyle.sty} I think you should write (and maintain) your own, complete, document style. Next, as it was possible to override definitions from the main file in an option file, it is of course also possible to override definitions made in another option file. When this happens, your document might depend on the order in which you have specified your document-style options. This mechanism of overriding definitions from the main document style is exploited in the \babel{} system. The macros that contain the hard-wired texts are redefined in the common part of \babel{}, replacing each of these texts with a unique macro. These macros have to be defined in the language-specific files. \section{\LaTeX\ and multilingual documents}\label{lat-lingual} In a european environment it sometimes happens that one wants to write a document that contains more than \emph{one} language. I have an example of a document, published by the {\sc eec}, that contains 9 (nine) different languages. Also in linguistics one can find documents written in more than one language, i.e. to compare two languages. If you have to write such a multilingual document you should try to conform to the typographical conventions in use for each language. A well known example is the type of quotation marks used. \TeX\ supplies the user with ``quoted text'', but a Dutch user might want to have \dlqq quoted text'', whereas a German text should contain \glqq quoted text\grqq\ and a frenchman would perhaps like to see something like \flqq quoted text\frqq. These language specific conventions should be implemented in a document-style option file for each language. These files should then be useable with \emph{all} document styles. In such a multilingual document a user would specify the languages used as options to the |\documentstyle| command. He would also want a mechanism to be able to switch between these languages in a simple way. When he would use \TeX\ version 3.0 for the processing of his document, he would also want the hyphenation to come out right for the different languages. \section{Overview of the \babel{} solution} \subsection{The core of the system} The problems described in sections~\ref{lat-docstyle} and~\ref{lat-lingual} can be solved using the \babel{} system of document-style options. The core of this system currently performs three functions. \begin{enumerate} \item\label{switch} It defines a user interface for switching between languages; \item\label{hyphs} It contains code to dynamically load several sets of hyphenation patterns; \item\label{repair} It `repairs' the document styles provided in the standard distribution of \LaTeX. \end{enumerate} Obviously part~\ref{hyphs} can only be used while running ini\TeX\ to create a new format, whereas part~\ref{repair} should \emph{not} be read by ini\TeX. Part~\ref{repair} should even disappear when \LaTeX\ version 3.0 arrives, as the style files supplied with the new \LaTeX\ will no longer be language specific. Part~\ref{switch} can either be loaded into the format with multiple hyphenation patterns, or it can be read while processing a document. For this reason the core of the \babel{} system is stored in two separate files, \file{babel.switch}, containing parts~\ref{switch} and~\ref{hyphs}, and \file{babel.sty} which contains part~\ref{repair}. The file \file{babel.sty} will instruct \LaTeX\ to load \file{babel.switch} if necessary, the file \file{babel.switch} checks the format to see if hyphenation patterns \emph{can} be loaded. \subsection{Language specifics} The language switching mechanism contains a couple of hooks for the developers of language-specific document-style options. First of all the macro |\originalTeX| should be defined. Its function is to disable special definitions made for a language to bring \TeX\ into a `defined' state. A language-specific document-style option might, for example, introduce an extra active character. It would then also modify the definitions of |\dospecials| and |\@sanitize|. Such an option would then define a macro to restore the original definitions of these macros and restore the extra active character to its normal category code. It would then |\let \originalTeX| to this `restoration' macro. To enable the language-specific definitions three macros are provided in the switching mechanism, |\captions|\meta{language}, |\date|\meta{language} and |\extras|\meta{language}. The macro |\captions|\meta{language} should provide definitions for the macros that replaced the hard-wired texts in the document style and the macro |\date|\meta{language} should provide a definition for |\today|. The real fun starts with the macro |\extras|\meta{language}. This macro should activate all definitions needed for \meta{language}. \section{The user interface} The user interface to the \babel{} system is quite simple. He should specify the languages he wants to use in his document in the list of document-style options. For instance, for a document in which both the English and the Dutch language are used, the first line could read: \begin{verbatim} \documentstyle[a4,dutch,english]{artikel1} \end{verbatim} Please note that in this case the Dutch-specific definitions are inactive when \LaTeX\ has finished processing document-style option files. If the user then wants to switch from English to Dutch he would include the command \begin{verbatim} \selectlanguage{dutch} \end{verbatim} before starting to write Dutch. If a user wants to write a document-style option of his own he might like to define a macro that checks which language is in use at the time the macro is executed. For this purpose the macro |\iflanguage{|\meta{language}|}{|\meta{then-clause}|}{|% \meta{else-clause}|}| is available. \section{Implementation of the core of the system} In this section I would like to discuss some parts of the implementation of the \babel{} system. Not all code will be shown, because some parts of it are just series of slightly modified code from the standard document styles. The files are fully documented and interested readers can print them if they have access to the \texttt{doc} option, described by Frank Mittelbach. The description of the macros that follows is based on an environment using \TeX~3.x, together with a version of \file{lplain.tex} based on \file{plain.tex} version~3.x. The actual implementation allows for other situations as well, i.e a version of \file{babel.sty} for \TeX~2.x will be available. \subsection{Switching languages}\label{lang-switch} For each language to be used in a document a control sequence of the form |\l@|\meta{language} has to be defined. This will either be done while loading hyphenation patterns or while loading the language-specific file. The implementation of \hbox{|\selectlanguage{|\meta{language}|}|} and\\ \hbox{|\iflanguage{|\meta{language}|}{|\meta{then case}|}{|\meta{else case}|}|} is based on the existence of \hbox{|\l@|\meta{language}}. \begin{figure*}[htb] \begin{verbatim} \def\selectlanguage#1{% \@ifundefined{l@#1} {\@nolanerr{#1}} {\originalTeX \language=\expandafter\csname l@#1\endcsname\relax \expandafter\csname captions#1\endcsname \expandafter\csname date#1\endcsname \expandafter\csname extras#1\endcsname \gdef\originalTeX{\expandafter\csname noextras#1\endcsname} } } \end{verbatim} \caption{The definition of {\tt\bsl selectlanguage}.} \label{select} \end{figure*} To switch from one language to another the macro |\selectlanguage| is available. Its definition can be seen in figure~\ref{select}. The first action it takes is to check whether the \meta{language} is known, if it is not an error is signalled. If the language is known |\originalTeX| is called upon to reset any previously set language-specific definitions. Next the register |\language| is updated and the three macros that should activate all language-specific definitions are executed. Finally the macro |\originalTeX| receives a new replacement text in order to be able to deactivate the definitions just activated. \begin{figure*}[htb] \begin{verbatim} \def\iflanguage#1#2#3{% \@ifundefined{l@#1} {\@nolanerr{#1}} {\ifnum\language=\expandafter\csname l@#1\endcsname\relax #2 \else #3 \fi} } \end{verbatim} \caption{The definition of {\tt\bsl iflanguage}} \label{if} \end{figure*} The macro |\iflanguage| (see figure~\ref{if}) will issue a warning when its argument is an `unkown' language. It then goes on to compare the value of |\language| and |\l@|\meta{language} and executes either its secon or third argument. \subsection{Dynamically loading patterns} With the advent of \TeX~3.0 it has become possible to build a format with more than one hyphenation pattern preloaded. The core of the \babel\ system provides code, to be executed by ini\TeX\ \emph{only}, to dynamically load hyphenation patterns. The only restriction is that the implementation of \TeX\ that you use has to have rather high settings of \texttt{trie\_size} and \texttt{trie\_op\_size} to actually load several hyphenation patterns. For the purpose of dynamically loading hyphenation patterns a `configuration file' has to be introduced. This file will be read by ini\TeX. Each line should contain either a comment, nothing or the name of a language and the name of the file that contains the hyphenation patterns for that language. In figure~\ref{config} an example of such a file, instructing ini\TeX\ to load patterns for three languages, English, Dutch and German. \begin{figure*}[htb] \begin{verbatim} % File : language.dat % Purpose : tell iniTeX what files with patterns to load. english english.hyphenations dutch hyphen.dutch % Nederlands german hyphen.ger \end{verbatim} \caption{An example configuration file}\label{config} \end{figure*} The configuration file will be read line by line using \TeX's |\read| primitive. Because the name of a file might be followed by a space-token and comment (as in the example) a macro to process each line is needed. The definition of this macro, |\process@language|, can be found in figure~\ref{process}. As can be seen in the definition of this macro, its second argument \emph{always} has to be followed by a space-token. The effect of this is that any trailing spaces are removed. \begin{figure*}[htb] \begin{verbatim} \def\process@language#1 #2 {% \expandafter\addlanguage\csname l@#1\endcsname \expandafter\language\csname l@#1\endcsname \input #2} \end{verbatim} \caption{The definition of {\tt\bsl process@language}.} \label{process} \end{figure*} The macro strips all spaces following its arguments. It's first argument is used to define |\l@|\meta{language}. The macro |\addlanguage| is basically a non-outer version of the plain \TeX\ macro |\newlanguage|. The second argument of |\process@language| is the name of the file containing the hyphenation patterns. Before the file can be read, the register |\language| has to updated. The configuration file is read in a |\loop| (see figure~\ref{loop}). When a record is read from the input file a check is done whether the record was empty. If it was not, a space token is added to the end of the string of tokens read. The reason for this is that we have to be sure there always is at least \emph{one} space token present. When that has been taken care of the data just read can be processed. The last thing to do is to check the status of the input file, in order to decide whether \TeX\ has to continue processing the |\loop|. When all patterns have been processed the value of |\language| is restored. \begin{figure*}[htb] \begin{verbatim} \loop \read1 to \@config@line \ifx\@config@line\empty \else \edef\@config@line{\@config@line\space} \expandafter\process@language\@config@line \fi \ifeof1 \@morefalse \fi \if@more\repeat \language=0 \end{verbatim} \caption{Reading the configuration file line by line} \label{loop} \end{figure*} \subsection{`Repairing' \LaTeX's standard document styles} A large part of the core of the \babel{} system is dedicated to `repair' the standard document styles. This means redefining the macros in table~\ref{macros}. \begin{table*}[htb] \DeleteShortVerb{\|} \begin{center} \begin{tabular}{l | c c c c} macro & article & report & book & letter \\ \hline \tt\bsl fnum@figure & $\times$ & $\times$ & $\times$ & $\times$ \\ \tt\bsl fnum@table & $\times$ & $\times$ & $\times$ & $\times$ \\ \tt\bsl tableofcontents & $\times$ & $\times$ & $\times$ & \\ \tt\bsl listoffigures & $\times$ & $\times$ & $\times$ & \\ \tt\bsl listoftables & $\times$ & $\times$ & $\times$ & \\ \tt\bsl thebibliography & $\times$ & $\times$ & $\times$ & \\ \tt\bsl theindex & $\times$ & $\times$ & $\times$ & \\ \tt\bsl abstract & $\times$ & $\times$ & $\times$ & \\ \tt\bsl part & $\times$ & $\times$ & $\times$ & \\ \tt\bsl chapter & & $\times$ & $\times$ & \\ \tt\bsl appendix & & $\times$ & $\times$ & \\ \tt\bsl cc & & & & $\times$ \\ \tt\bsl encl & & & & $\times$ \\ \tt\bsl ps@headings & & & & $\times$ \\ \end{tabular} \caption{macros that need to be redefined for the four standard document styles.} \label{macros} \end{center} \MakeShortVerb{\|} \end{table*} As an example of the way the macros have to be redefined, the redefinition of |\tableofcontents| is shown in figure~\ref{content}. \begin{figure*}[htb] \begin{verbatim} \@ifundefined{contentsname} {\def\tableofcontents {\section*{\contentsname \@mkboth{\uppercase\expandafter{\contentsname}} {\uppercase\expandafter{\contentsname}} } \@starttoc{toc} } } {} \end{verbatim} \caption{An example of redefining a command}\label{content} \end{figure*} The standard styles can be distinguished by checking the existence of the macros |\chapter| (not in \file{article} and \texttt{letter}) and |\opening| (only in \texttt{letter}). The result of these checks is stored in the macro |\doc@style|. When |\doc@style| already exists (which is the case when for instance \file{artikel1.sty} is used~\cite{BEP}) it is not superseded (see figure~\ref{maindoc}). \begin{figure*}[htb] \begin{verbatim} \@ifundefined{doc@style} {\def\doc@style{0} \@ifundefined{opening} {\@ifundefined{chapter} {\def\doc@style{1}} {\def\doc@style{2}} }{\def\doc@style{3}} }{\relax} \end{verbatim} \caption{Determining the main document style} \label{maindoc} \end{figure*} \section{Implementing a language specific document-style option file} To illustrate the way a language specific file can be implemented the file \file{dutch.sty} is discussed here. Note that not all of the code containde in the file \file{dutch.sty} is shown here, only those parts that are of interest for the scope of this article are included. If the reader would like to see the complete code, he can print all files in the \babel{} system, using the file \file{doc.sty}, described by Frank Mittelbach in~\cite{docsty}. \subsection{Compatibilty with plain \TeX} The file \file{german.tex}~\cite{HP} was written in such a way that it can be used by both plain \TeX\ users and \LaTeX\ users. This seemed a good idea, so all files in the \babel{} system can be processed by both plain \TeX\ and \LaTeX. But some of the ``useful hacks'' from \LaTeX\ are used, so for a plain \TeX\ user they have to be defined. For this purpose the format is checked at the start of a language specific file. If the format is \texttt{plain} an extra file, called \file{latexhax.sty} is read. \begin{figure*}[htb] \begin{verbatim} {\def\format{plain} \ifx\fmtname\format \expandafter\ifx\csname @ifundefined\endcsname\relax \gdef\next{latexhax.sty} \aftergroup\input\aftergroup\next \fi \fi} \end{verbatim} \caption{Conditonal loading of \file{latexhax.sty}} \end{figure*} This file should be read only once, so another check is done on the existence of one of the commands defined there. A new group is started to keep the definition of the macro |\format|, which is used in the following if statement, local. When the current format turns out to be plain \TeX\ the file \file{latexhax.sty} has to be read. But the definitions in that file should remain valid after the group is closed. This could be accomplished by making all definitions \texttt{global}, but another solution is to tell \TeX\ to process the file \file{latexhax.sty} \emph{after} the current group has been closed. The command |\aftergroup| puts the next token on a list to be processed after the group. \subsection{Switching to the Dutch language} In section~\ref{lang-switch} the names of macros needed to switch to a language have been described. In figure~\ref{switchdutch} these macros and their definition are shown for the Dutch language. \begin{figure*}[htb] \begin{verbatim} \def\captionsdutch{\gdef\refname{Referenties}% \gdef\abstractname{Samenvatting}% \gdef\bibname{Bibliografie}% ... \gdef\pagename{Pagina}} \def\datedutch{% \gdef\today{\number\day~\ifcase\month\or januari\or februari\or maart\or april\or mei\or juni\or juli\or augustus\or september\or oktober\or november\or december\fi \space \number\year}} \begingroup \catcode`\"\active \gdef\extrasdutch{% \global\let\dospecials\dutch@dospecials \global\let\@sanitize\dutch@sanitize \catcode`\"\active \gdef"{\protect\dutch@active@dq} \gdef\"{\protect\@umlaut} }\endgroup \def\noextrasdutch{% \catcode`\"12 \global\let\dospecials\original@dospecials \global\let\@sanitize\original@sanitize \global\let\"\dieresis } \end{verbatim} \caption{The macros needed to switch to the Dutch language} \label{switchdutch} \end{figure*} The definitions of |\captionsdutch| and |\datedutch| are pretty straightforward and need not be discussed. The macro |\extrasdutch| will be discussed in some more detail. First, because for Dutch (as well as for German) the \texttt{"} character is made active, the \LaTeX\ macros |\dospecials| and |\@sanitize| have to be redefined to include this character as well. The new definitions are implemented as two special commands, so we globally |\let| the originals to their new versions. Then the \texttt{"} character is made active and is defined. Then, to prevent an error when |\"| appears in a moving argument, the macro |\"| is redefined and made robust. All this is done inside a group to keep the category code change for the \texttt{"} character local. The macro |\extrasdutch| has a counterpart, |\noextrasdutch|, that cancels the extra definitions made by |\extrasdutch|. It changes the |\catcode| of the \texttt{"} character back to `other' and globally |\let|s the macros |\dospecials| and |\@sanitize| to their original definitions. The original definition of |\"| is restored as well. In figure~\ref{specials} the code needed to redefine |\dospecials| and |\@makeother| is shown. \begin{figure*}[htb] \begin{verbatim} \begingroup \def\do{\noexpand\do\noexpand}% \xdef\dutch@dospecials{\dospecials\do\"}% \expandafter\ifx\csname @sanitize\endcsname\relax % do nothing if \@sanitize is undefined... \else \def\@makeother{\noexpand\@makeother\noexpand}% \xdef\dutch@sanitize{\@sanitize\@makeother\"}% \fi \endgroup \global\let\original@dospecials\dospecials \global\let\original@sanitize\@sanitize \end{verbatim} \caption{Code needed for the redefinition of {\tt\bsl dospecials} and {\tt\bsl @makeother}.} \label{specials} \end{figure*} \subsection{An extra active character} All the code disccussed sofar is necessary because we need an extra active character. This character is then used as indicated in table~\ref{dutch-quote}. One of the reasons for this is that in the Dutch language a word with an umlaut can be hyphenated just before the letter with the umlaut, but the umlaut has to disappear if the word is broken between the previous letter and the accented letter. \begin{table*}[htb] \centering \begin{tabular}{lp{8cm}} \verb="a= & \verb=\"a= which hyphenates as \verb=-a=; also implemented for the other letters. \\ \verb="|= & disable ligature at this position. \\ \verb="-= & an explicit hyphen sign, allowing hyphenation in the rest of the word. \\ \verb="`= & lowered double left quotes (see example below).\\ \verb="'= & normal double right quotes. \\ \verb=\-= & like the old \verb=\-=, but allowing hyphenation in the rest of the word. \end{tabular} \caption{The extra definitions made by \file{dutch.sty}} \label{dutch-quote} \end{table*} In~\cite{treebus} the quoting conventions for the Dutch language are discussed. The preferred convention is the single-quote Anglo-American convention, i.e. `This is a quote'. An alternative is the slightly old-fashioned Dutch method with initial double quotes lowered to the baseline, \dlqq This is a quote'', which should be typed as \texttt{"`This is a quote"'}. \subsubsection{Supporting macro definitions} The definition of the active \texttt{"} character needs a couple of support macros. The macro |\allowhyphens| is used make hyphenation of word possible where it otherwise would be inhibited by \TeX. Basically its definition is nothing more than |\nobreak \hskip 0pt plus 0pt|. \begin{verbatim} \gdef\allowhyphens{\penalty\@M \hskip\z@skip} \end{verbatim} Then a macro is defined to lower the Dutch left double quote to the same level as the comma. It prepares a low double opening quote in box register~0. This macro was copied form \file{german.tex}. \begin{verbatim} \gdef\set@low@box#1{% \setbox\tw@\hbox{,} \setbox\z@\hbox{#1} \dimen\z@\ht\z@ \advance\dimen\z@ -\ht\tw@ \setbox\z@\hbox{\lower\dimen\z@ \box\z@} \ht\z@\ht\tw@ \dp\z@\dp\tw@} \end{verbatim} The macro |\set@low@box| is used to define low opening quotes. Since it may be used in arguments to other macros it needs to be protected. \begin{verbatim} \gdef\dlqq{\protect\@dlqq} \gdef\@dlqq{{% \ifhmode \edef\@SF{\spacefactor\the\spacefactor} \else \let\@SF\empty \fi \leavevmode\set@low@box{''} \box\z@\kern-.04em\allowhyphens\@SF\relax}} \end{verbatim} For reasons of symmetry we also define |"'|. This command is defined similar to |\dlqq|, except that the quotes aren't lowered to the baseline. \begin{verbatim} \gdef\@drqq{{% \ifhmode \edef\@SF{\spacefactor\the\spacefactor} \else \let\@SF\empty \fi ''\@SF\relax}} \end{verbatim} The original double quote character is saved in the macro |\dq| to keep it available. \begin{verbatim} \begingroup \catcode`\"12 \gdef\dq{"} \endgroup \end{verbatim} The original definition of |\"| is stored as |\dieresis|. The resason for this is that if a font with a different encoding scheme is used the definition of |\"| might not be the plain \TeX\ one. \begin{verbatim} \global\let\dieresis\" \end{verbatim} In the Dutch language vowels with a dieresis or umlaut accent are treated specially. If a hyphenation occurs before a vowel-plus-umlaut, the umlaut should disappear. To be able to do this, the hyphenation break behaviour for the five vowels, both lowercase and uppercase, could be defined first in terms of |\discretionary|. But this results in a large |\if|-construct in the definition of the active |"|. As both Knuth and Lamport have pointed out, a user should not use |"| when he really means something like |''|. For this reason no distinction is made between vowels and consonants. Therefore one macro, |\@umlaut|, specifies the hyphenation break behaviour for all letters. \begin{verbatim} \def\@umlaut#1{% \allowhyphens% \discretionary{-}{#1}{\dieresis #1}% \allowhyphens} \end{verbatim} The last support macro to be defined is |\dutch@active@dq|. \begin{verbatim} \gdef\dutch@active@dq#1{% \if\string#1`\dlqq{}% \else\if\string#1'\drqq{}% \else\if\string#1-\allowhyphens-\allowhyphens% \else\if\string#1|\discretionary{-}{}{\kern.03em}% \else\if\string#1i\allowhyphens\discretionary{-}{i}{\dieresis\i}% \allowhyphens% \else\if\string#1j\allowhyphens\discretionary{-}{j}{\dieresis\j}% \allowhyphens% \else \@umlaut{#1}\fi\fi\fi\fi\fi\fi} \end{verbatim} The macro reads the next token and performs some appropriate action. If no special action is defined, it will produce an umlaut accent on top of argument~1. The last definition needed is a replacement for |\-|. The new version of |\-| should indicate an extra hyphenation position, while allowing other hyphenation positions to be generated automatically. The standard behaviour of \TeX\ in this respect is very unfortunate for languages such as Dutch and German, where long compound words are quite normal and all one needs is a means to indicate an extra hyphenation position on top of the ones that \TeX\ can generate from the hyphenation patterns. \begin{verbatim} \def\-{\allowhyphens\discretionary{-}{}{}\allowhyphens} \end{verbatim} \subsection{Activating the definitions} The last action that should be performed by a language specific file, is activating it's definitions. Before doing that the macro |\originalTeX| should be definined. \begin{verbatim} \@ifundefined{originalTeX}{\let\originalTeX\relax}{} \end{verbatim} Also, the macro |\l@|\meta{language} should be defined. If it hasn't already been defined, this means that no hyphenation patterns were loaded for this language. % This means that \emph{no} hyphenation will take place \begin{verbatim} \@ifundefined{l@dutch}{\addlanguage{dutch}}{} \selectlanguage{dutch} \end{verbatim} \section{Conclusion} In this article a system of document-style option files has been presented that supports the multilingual use of \LaTeX. Some of the code involved has been discussed. The actual files will me made available through the international networks. They will be stored in the fileserver in the Netherlands (address: \texttt{LISTSERV@HEARN.BITNET}), the file \file{babel readme} will explain what you need to get to be able to use the system. The system was developed using the \Lopt{doc} option, so the files available are fully documented. \begin{thebibliography}{9} \bibitem{DEK} Donald E. Knuth, \emph{The \TeX book}, Addison-Wesley, 1986. \bibitem{LLbook} Leslie Lamport, \emph{\LaTeX, A document preparation System}, Addison-Wesley, 1986. \bibitem{treebus} K.F. Treebus. \emph{Tekstwijzer, een gids voor het grafisch verwerken van tekst.} SDU Uitgeverij ('s-Gravenhage, 1988). A Dutch book on layout design and typography. \bibitem{HP} Hubert Partl, \emph{German \TeX}, \emph{TUGboat} 9 (1988) \#1, p.~70--72. \bibitem{LLth} Leslie Lamport, in: \TeXhax\ Digest, Volume 89, \#13, 17 februari 1989. \bibitem{docsty}Frank Mittelbach, \emph{The \Lopt{doc}-option}, \emph{TUGboat} 10 (1989) \#2, p.~245--273. \bibitem{BEP}Johannes Braams, Victor Eijkhout and Nico Poppelier, \emph{The development of national \LaTeX\ styles}, \emph{TUGboat} 10 (1989) \#3, p.~401--406. \bibitem{ilatex}Joachim Schrod, \emph{International \LaTeX\ is ready to use}, \emph{TUGboat} 11 (1990) \#1, p.~87--90. \end{thebibliography} \end{document}