% \iffalse meta-comment % % Copyright (C) 1989-1994 by Johannes Braams % All rights reserved. % For additional copyright information see further down in this file. % % This file is part of the Babel system, release 3.4 patchlevel 1 % --------------------------------------------------------------- % % This file is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. % % % IMPORTANT NOTICE: % % For error reports in case of UNCHANGED versions see readme file. % % Please do not request updates from me directly. Distribution is % done through Mail-Servers and TeX organizations. % % You are not allowed to change this file. % % You are allowed to distribute this file under the condition that % it is distributed together with all files mentioned in manifest.txt. % % If you receive only some of these files from someone, complain! % % You are NOT ALLOWED to distribute this file alone. You are NOT % ALLOWED to take money for the distribution or use of either this % file or a changed version, except for a nominal charge for copying % etc. % \fi %%% ==================================================================== %%% @TeX-file{ %%% author = "Johannes L. Braams", %%% version = "1.0", %%% date = "22 July 1993", %%% time = "06:50:33 MET", %%% filename = "tb-article.tex", %%% address = "PTT Research %%% St. Paulusstraat 4 %%% 2264 XZ Leidschendam %%% The Netherlands", %%% telephone = "(70) 3325051", %%% FAX = "(70) 3326477", %%% checksum = "22652 913 5111 39787", %%% email = "J.L.Braams@research.ptt.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 %\documentstyle[ltugboat,a4]{article} \documentstyle{ltugboat} \ifx\indefined\selectfont \else \def\tensl{\shape{sl}\size{10}{12pt}\selectfont} \fi \def\rtitlex{TUGboat, Volume 12 (1991), No. 2} \def\midrtitle{} \def\PrelimDraftfooter{} \let\TBmaketitle\maketitle \SelfDocumenting \setcounter{page}{291} \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 and Piet van Oostrum have been used.} } \author{Johannes Braams} \address{PTT Research Neher Laboratories\\ P.O. Box 421\\ 2260 AK Leidschendam} \netaddress{J.L.Braams@research.ptt.nl} \date{\today} \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 {\em one\/} document-style option to be used with {\em 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}, {\tt german.tex}. Some parts in the implementation are different, others are the same. It will be shown that {\tt 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 \verb=\@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 \verb=\@chapapp= is the {\em 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 {\tt artikel.sty} as a ``Dutch'' counterpart to {\tt article.sty}. The same was done for {\tt 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 {\em 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 \verb=\@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 {\tt draft}, by defining a command \verb=\ds@dutch=. This command would set a variable to indicate which language was requested. This variable I~used later on in a \verb=\case= statement. In this \verb=\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 {\tt xxx10.sty}, {\tt xxx11.sty} and {\tt 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 {\tt article.sty} that had been given a different name, but it still loaded {\tt 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 {\tt 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 {\tt dutch.sty} version~1.0, dated may 1989\footnote{This file is available from {\tt listserv@hearn.bitnet} as file {\tt dutch.old}.}. While working on this style option I~discovered that some parts could be borrowed from {\tt 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 \verb=\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 {\sf 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 {\tt docstyle.sty}. When that is done the `options' are processed {\em in the order specified\/}, by reading the files {\tt 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.}, {\tt opt2.sty}, etc. This implies that definitions, made in the file {\tt 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 {\tt 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 {\sf babel} system. The macros that contain the hard-wired texts are redefined in the common part of {\sf 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 {\em 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 {\em all\/} document styles. In such a multilingual document a user would specify the languages used as options to the {\tt\bsl 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 {\sf 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 {\sf 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 {\em 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 {\sf babel} system is stored in two separate files, {\sf babel.switch}, containing parts~\ref{switch} and~\ref{hyphs}, and {\tt babel.sty} which contains part~\ref{repair}. The file {\tt babel.sty} will instruct \LaTeX\ to load {\tt babel.switch} if necessary, the file {\tt babel.switch} checks the format to see if hyphenation patterns {\em 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 {\tt\bsl 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 {\tt\bsl dospecials} and {\tt\bsl @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 {\tt\bsl let \bsl originalTeX} to this `restoration' macro. To enable the language-specific definitions three macros are provided in the switching mechanism, {\tt\bsl captions\meta{language}}, {\tt\bsl date\meta{language}} and {\tt\bsl extras\meta{language}}. The macro {\tt\bsl captions\meta{language}} should provide definitions for the macros that replaced the hard-wired texts in the document style and the macro {\tt\bsl date\meta{language}} should provide a definition for {\tt\bsl today}. The real fun starts with the macro {\tt\bsl extras\meta{language}}. This macro should activate all definitions needed for \meta{language}. \section{The user interface} The user interface to the {\sf 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 {\tt\bsl 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 {\sf 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 {\tt 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 {\tt lplain.tex} based on {\tt plain.tex} version~3.x. The actual implementation allows for other situations as well, i.e a version of {\tt 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 \verb+\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{\verb+\selectlanguage{+\meta{language}\verb+}+} and\\ \hbox{\tt\bsl iflanguage\{\meta{language}\}\{\meta{then case}\}\{\meta{else case}\}} is based on the existence of \hbox{\verb+\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 \verb=\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 \verb=\originalTeX= is called upon to reset any previously set language-specific definitions. Next the register \verb=\language= is updated and the three macros that should activate all language-specific definitions are executed. Finally the macro \verb=\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 \verb+\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 \verb+\language+ and \verb+\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\ {\em 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 {\tt trie\_size} and {\tt 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 configurationfile will be read line by line using \TeX's \verb=\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, \verb=\process@language=, can be found in figure~\ref{process}. As can be seen in the definition of this macro, its second argument {\em 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 \verb=\l@=\meta{language}. The macro \verb=\addlanguage= is basically a non-outer version of the plain \TeX\ macro \verb=\newlanguage=. The second argument of \verb=\process@language= is the name of the file containing the hyphenation patterns. Before the file can be read, the register \verb=\language= has to updated. The configuration file is read in a \verb=\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 {\em 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 \verb=\loop=. When all patterns have been processed the value of \verb=\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 {\sf babel} system is dedicated to `repair' the standard document styles. This means redefining the macros in table~\ref{macros}. \begin{table*}[htb] \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} \end{table*} As an example of the way the macros have to be redefined, the redefinition of \verb=\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 \verb=\chapter= (not in {\tt article} and {\tt letter}) and \verb=\opening= (only in {\tt letter}). The result of these checks is stored in the macro \verb=\doc@style=. When \verb=\doc@style= already exists (which is the case when for instance {\tt 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 {\tt dutch.sty} is discussed here. Note that not all of the code containde in the file {\tt 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 {\sf babel} system, using the file {\tt doc.sty}, described by Frank Mittelbach in~\cite{docsty}. \subsection{Compatibilty with plain \TeX} The file {\tt 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 {\sf 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 {\tt plain} an extra file, called {\tt latexhax.tex} 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 {\tt 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 \verb=\format=, which is used in the following if statement, local. When the current format turns out to be plain \TeX\ the file {\tt 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 {\tt global}, but another solution is to tell \TeX\ to process the file {\tt latexhax.sty} {\em after\/} the current group has been closed. The command \verb=\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 \verb=\captionsdutch= and \verb=\datedutch= are pretty straightforward and need not be discussed. The macro \verb=\extrasdutch= will be discussed in some more detail. First, because for Dutch (as well as for German) the {\tt "} character is made active, the \LaTeX\ macros \verb=\dospecials= and \verb=\@sanitize= have to be redefined to include this character as well. The new definitions are implemented as two special commands, so we globally \verb=\let= the originals to their new versions. Then the {\tt "} character is made active and is defined. Then, to prevent an error when \verb=\"= appears in a moving argument, the macro \verb=\"= is redefined and made robust. All this is done inside a group to keep the category code change for the {\tt "} character local. The macro \verb=\extrasdutch= has a counterpart, \verb=\noextrasdutch=, that cancels the extra definitions made by \verb=\extrasdutch=. It changes the \verb=\catcode= of the {\tt "} character back to `other' and globally \verb=\let=s the macros \verb=\dospecials= and \verb=\@sanitize= to their original definitions. The original definition of \verb=\"= is restored as well. In figure~\ref{specials} the code needed to redefine \verb=\dospecials= and \verb=\@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 {\tt 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 {\tt "`This is a quote"'}. \subsubsection{Supporting macro definitions} The definition of the active {\tt "} character needs a couple of support macros. The macro \verb=\allowhyphens= is used make hyphenation of word possible where it otherwise would be inhibited by \TeX. Basically its definition is nothing more than \verb=\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 {\tt 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 \verb=\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 \verb="'=. This command is defined similar to \verb=\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 \verb=\dq= to keep it available. \begin{verbatim} \begingroup \catcode`\"12 \gdef\dq{"} \endgroup \end{verbatim} The original definition of \verb=\"= is stored as \verb=\dieresis=. The resason for this is that if a font with a different encoding scheme is used the definition of \verb=\"= 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 \verb=\discretionary=. But this results in a large \verb=\if=-construct in the definition of the active \verb="=. As both Knuth and Lamport have pointed out, a user should not use \verb="= when he really means something like \verb=''=. For this reason no distinction is made between vowels and consonants. Therefore one macro, \verb=\@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 \verb=\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 \verb=\-=. The new version of \verb=\-= 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 \verb=\originalTeX= should be definined. \begin{verbatim} \@ifundefined{originalTeX}{\let\originalTeX\relax}{} \end{verbatim} Also, the macro \verb=\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 {\em 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: {\tt LISTSERV@HEARN.BITNET}), the file {\tt babel readme} will explain what you need to get to be able to use the system. The system was developed using the {\tt doc} option, so the files available are fully documented. \begin{thebibliography}{9} \bibitem{DEK} Donald E. Knuth, {\em The \TeX book}, Addison-Wesley, 1986. \bibitem{LLbook} Leslie Lamport, {\em \LaTeX, A document preparation System}, Addison-Wesley, 1986. \bibitem{treebus} K.F. Treebus. {\em 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, {\em German \TeX}, {\em TUGboat\/} 9 (1988) \#1, p.~70--72. \bibitem{LLth} Leslie Lamport, in: \TeXhax\ Digest, Volume 89, \#13, 17 februari 1989. \bibitem{docsty}Frank Mittelbach, {\em The {\tt doc}-option\/}, {\em TUGboat\/} 10 (1989) \#2, p.~245--273. \bibitem{BEP}Johannes Braams, Victor Eijkhout and Nico Poppelier, {\em The development of national \LaTeX\ styles\/}, {\em TUGboat\/} 10 (1989) \#3, p.~401--406. \bibitem{ilatex}Joachim Schrod, {\em International \LaTeX\ is ready to use\/}, {\em TUGboat\/} 11 (1990) \#1, p.~87--90. \end{thebibliography} \end{document}