\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\begin{filecontents}{LEuroTeX.sty}
%%% This is LEuroTeX.Sty, the LaTeX 2.09 equivalent to the above

\input ltugproc.sty

\def \PrelimDeadline {22nd July 1994}%      -  prelim papers due
\def \PreprintDeadline {20th August 1994}%    -  revised papers due
\def \MeetingDate {26th--30th September 1994}%  -  meeting
\def \CameraDeadline {1st September 1994}%    -  final deadline
\def \pfoottext{{\smc Preprint}: 1994 Euro{\TeX} Meeting}
\def \rfoottext{\tenpoint Euro{\TeX} Proccedings 1994}
\def \editor {editor}
\def \Editor {Editor}

%%% \LoadSansFonts  % Use if needed, cf. tugboat.sty & "METAFONT" (below)
\preprint % Comment this line out for final version following meeting
% \let \Now = \null % Uncovering this will remove time stamps on preprints

\emergencystretch = 1 em
\tolerance = 594          %%% adjust these on a per-document basis
\hbadness = 2158          %%%              -- ditto --

\def \sloppy {\emergencystretch = 2 em \tolerance = 5000 }

\def \flushright #1{\rlap {#1}{\parfillskip = 0 pt \par}}
\def \sloppypar {\tolerance = 9999 \par}

\def \stress #1%
    {\begingroup
     \def \next
    	 {\def \next
              {\setbox 0 = \hbox {\nexttoken}%
               \ifdim \ht 0 < \fontdimen 5 \font
	 	      \it #1%
	       \else
		      \it #1\/%
	       \fi
              }%
          \ifcat A\noexpand \nexttoken
                \next
          \else 
                \ifcat 0\noexpand \nexttoken
                        \next
                \else
                        \ifcat \space \noexpand \nexttoken
                        \else
	 	               %%% \message {?: \meaning \nexttoken}%
                        \fi
                        \it #1\/%
                \fi
          \fi
     	  \endgroup
         }%
     \futurelet \nexttoken \next
    }

\let \foreign = \stress

% All the following is necessary because TUGproc doesn't scale maths fonts;
% it's distinctly sub-optimal, but works in the circumstances required.

\def \scalemaths {\expandafter \loadmaths \fontname \font \empty}

\def \extractscale #1 #2\empty 
    {\def \rescaled {\relax}%
     \def \fontmodifier {#2}%
     \ifx \fontmodifier \rescaled 
     \else \edef \rescaled { #2}%
     \fi
    }

\def \loadmaths #1\empty
    {\extractscale #1 \rescaled \empty
     \font \textone = \fontname \textfont 1 \rescaled
     \font \scriptone = \fontname \scriptfont 1 \rescaled
     \font \scriptscriptone = \fontname \scriptscriptfont 1 \rescaled
     \font \texttwo = \fontname \textfont 2 \rescaled
     \font \scripttwo = \fontname \scriptfont 2 \rescaled
     \font \scriptscripttwo = \fontname \scriptscriptfont 2 \rescaled
     \textfont 1 = \textone
     \scriptfont 1 = \scriptone
     \scriptscriptfont 1 = \scriptscriptone
     \textfont 2 = \texttwo
     \scriptfont 2 = \scripttwo
     \scriptscriptfont 2 = \scriptscripttwo
    }

\end{filecontents}
\documentstyle{LEuroTeX}
\british  %select British hyphenation patterns
\hbadness=4913
\title{Surviving in a multi-lingual world with multiple font encodings}
\author{Ji\v r\'\i\ Zlatu\v ska}
\address{Faculty of Informatics\\Masaryk University\\
Bure\v sova 20\\602 00 Brno, Bohemia}
\netaddress{zlatuska@informatics.muni.cz}
\begin{document}
\begin{abstract}
This paper develops constructions needed for utilizing the encoding
scheme concept embedded into \LaTeXe\ in order to develop a system
allowing one to use different font encoding schemes and different languages
within one format and to provide mechanisms for fully functional
switching between them. The concept of language extends that of \TeX\
based just on proper set of hyphenation patterns. A practical demonstration 
of this is
shown in the example defining hyphen-splitting feature as a modification 
to the standard line-breaking behaviour of \TeX\unskip\rlap {.}\nobreak
\hfilneg\hbox{}
\end{abstract}

\maketitle

\section{Introduction}
In the new standard \LaTeX version, \LaTeXe \cite{LaTeX,Companion,LaTeX2e}, 
there is provision for living with more versatile font organizations
than those assumed by Donald Knuth in the \TeX\ book. This version of the
system has incorporated the so-called \emph{New Font Selection Scheme
version~2} (NFSS2) as an integral part of \LaTeXe\ kernel, allowing the
new version not
only to overcome some deficiencies of the original \LaTeX\ as far as
switching between various font styles  is concerned, 
but also to incorporate handling
of fonts 
with differing layouts via the concept of a \emph{font encoding scheme}.

The introduction of font encoding schemes made it possible for
fonts organized in different ways to be  incorporated into a single format.
Standard \LaTeXe\ makes use of it by including both the original font
organization used by Knuth (within \LaTeXe\ called the \emph{old} \TeX\
scheme, OT$n$) and the the so-called \emph{Cork scheme} (denoted T1 as
for extended \TeX\ text scheme within \LaTeXe) designed specifically to
suit most of the European languages.  From the viewpoint of creating a
new standard for portable texts, both of the encodings are important to
be present in the new system: the former provides for backward
compatibility with the world of \TeX\ fonts as used until very recently,
while the latter is a part of a complete set of fonts prepared for 8-bit
\TeX\ (the font organization for 8-bit Math fonts accompanying the text
encoding T1 is yet to come).

Font encoding T1 provides a layout sufficient for typesetting texts in
all European languages based on the Latin alphabet.  Even though it is
desirable to use this ``universal'' font encoding scheme to ensure
portability of the source document texts, for practical reasons of
continuity within local groups or installations it is often desirable to
allow alternative use of different encodings so that backward
compatibility is ensured as well as the
use of local fonts with possibly different layouts. The concept of
an encoding scheme can be used in order to allow for this flexibility,
however some problems emerge when this functionality needs to be
properly coupled with the mechanisms for switching the basic
language-dependent features such as the hyphenation settings. Some of
these problems will be discussed in the present paper along with a
proposal for a low-level interface for hyphenation setting
definitions in the presence of possibly several different font
encodings, and for the functionality needed in order to ensure
transparent behaviour of both font encoding and hyphenation switching.
It is assumed that this low-level interface can be incorporated into
packages which aim at the formation of a complete language-specific
environment such as language-specific style files or an integrated
system providing several of them in a uniform way such as, e.g., the
\emph{Babel} system~\cite{Babel}.\looseness=1

\section{Font encodings}
The concept of font encoding presents a consistent way of introducing
definitions local to a particular font layout and of ensuring that the
proper definition is used within the currently selected font layout.

Within \LaTeXe, font encodings present a parameter to every
font-specific definition. The list of these definitions include commands
specific to a particular encoding. The typical location of these
definitions for encoding \verb|XXX| is the encoding definition file
\verb|XXXenc.def| which is loaded by \LaTeXe\ when the
\verb|\DeclareFontEncoding|
command is processed. Font encoding definition files contain most but
not all of the definitions and settings necessary for the proper function of
a particular font layout within \TeX. Among those missing  are
definitions of the \verb|\catcode|, \verb|\lccode|, \verb|\uccode| and
\verb|\sfcode| values for a particular font layout. These are 
defined once and for all within the \LaTeXe\ kernel---obviously in order
to avoid the overhead of $4\times256$ redefinitions occurring each time
a font with different font encoding is selected (also note that this
number exceeds the ``standard'' number of \emph{save stack} entries
of $600$ assumed by most of the common \TeX\ implementations).

The use of fonts populated by up to $256$ characters brings about the
possibility of introducing language-specific hyphenation patterns based
on a particular font layout. \LaTeXe\ makes this even more accessible by
redefining the accent commands of \verb|plain| such as, e.g., \verb|\v|,
\verb|\'|,
etc., by definitions which do not use the \verb|\accent| primitive of \TeX,
but which instead generate the corresponding composite character as
present directly in the font (if there is no such character, as in the OT1
standard \TeX\ text encoding, it simply falls back to plain \TeX's way
of generating accented characters using the \verb|\accent| primitive). 
This provides an encoding-independent way
(7-bit) of representing the accented letters, yet without sacrificing
features which depend on the proper representation (8-bit) such as,
e.g., the proper use of the hyphenation patterns. As a part of this, all the
language-dependent texts 
in the style
files should be written in this way without committing to any particular
encoding under which the style file can possibly be used.

One of the consequences of the introduction of accent commands which
evaluate directly into the accented letter included in the font is the
possibility of creating \emph{encoding-independent hyphenation pattern
definitions}. \TeX\ expands macros encountered during \verb|initex|
input of the \verb|patterns| command. Therefore if only expandable
tokens and terminal letters are generated (i.e.\ no executable commands
such as \verb|\def|s or \verb|\accent|s), encoding-independent hyphenation
patterns can be processed correctly with the result being dependent on
the actual definition of the accent commands within a particular font
encoding scheme.

\section{Working with multiple encodings}
When working with multiple encodings, one has to ensure that all of the
parameters of \TeX's work which depend on the encoding selected are
changed properly when switching from one encoding into another.

Clearly, there is little problem in doing so as far as
encoding-dependent definitions are concerned. Here \LaTeXe\ already
provides all that is needed: When defining an encoding-specific command
\verb|\com| for encoding \verb|XXX| (e.g., an accent command or a
command generating a glyph from a particular position from an
\verb|XXX|-encoded font), \LaTeXe\ actually defines two macros: one of
them serving just for the internal purposes, \verb|\XXX\com|, and the
other one being the user-level macro \verb|\com|.

The internal macro \verb|\XXX\com| takes as its definition the code
supplied by the user as code defining \verb|\com| in the encoding
\verb|XXX|.
 
The user-accessible macro \verb|\com| 
takes the currently active encoding scheme, \verb|YYY|, 
and then proceeds by invoking the internal command \verb|\YYY\com|, or by
issuing
an error message if the latter is not defined.
The actual definition is slightly more complicated because \verb|\com| is
actually
defined as a \verb|protect|ed macro and for reasons of efficiency one
additional internal macro is used which prevents repeated constructions
of \verb|\YYY\com| using \verb|\csname|\ldots\verb|\endcsname| when
using the same command under an unchanged font encoding scheme. 

A serious problem arises with switching encoding definitions while 
requiring at the same time that hyphenation works correctly within 
each of these encodings. Here \TeX\ allows only a partial solution to
the problem.  When building paragraphs, \TeX works only with the
definitions of the values assigned to \verb|\lccode| at the moment when
the end of the paragraph is reached. Yet the correct assignment of
\verb|\lccode| to each letter within the paragraph to be broken is
essential for the correct working of \TeX's hyphenation algorithm, as
each word tried for hyphenation points is first converted into its
lower-case version. Therefore no matter that \TeX~3 is capable of inserting
the correct \verb|\language| nodes within the paragraph ensuring
proper switching of hyphenation patterns, they will only be processed
correctly when no changes are needed to the \verb|\lccode| values for
any of the encodings which are used within a paragraph.

This feature built into \TeX\-the-program limits the practical usability of
heavy switching between incompatible encoding schemes for the input
text. \LaTeXe\ actually places the definitions of the \verb|\lccode|,
\verb|\uccode|, and \verb|\sfcode| arrays into the kernel and makes them
fixed once the \LaTeXe\ format is generated. Clearly, the underlying
assumption is that T1 is the encoding of choice and the text to
be processed either honours these definitions, or just changes them once
without the need of returning back to them (e.g., for using local
packages which introduce different font encoding conventions). When
working in an installation which needs to support different and
incompatible font encodings (e.g., for historical reasons or local backward
compatibility), one needs to introduce these definitions as a part of
the \verb|\DeclareFontEncoding| definition of the encoding included in
the \verb|fontdef.cfg| installation-dependent file used for format
generation. 

\section{Encoding-specific hyphenation patterns} 
Although it is possible to provide accent command definitions which
allow the argument to the \verb|\patterns| operation to be presented in
an encoding-independent way, the actual way in which patterns are stored
within \TeX\ and subsequently processed into tries used for locating
hyphenation points does depend on the encoding definition---the 
\verb|\lccode| values are essential to this in the same way as during
actual paragraph breaking and of course the codes of accented letters
generated as the result of expansion of the accent commands do matter as
well.

In order to be able to use the same set of hyphenation patterns within
several font encodings, it is therefore necessary to (re-)load a
particular set of hyphenation patterns as a separate ``language'' (in
the terminology of \TeX\ when introducing the \verb|\language|
primitive) versions of the same set. This means the number assigned to
the particular set of patterns loaded no longer corresponds
to the language alone--it is the language \emph{and} the
corresponding encoding instead. 

\section{Language-switching requirements}
As we stated earlier, we are only interested in considering the
requirements of low-level language switching, i.e.\ language
switching ensuring that the text gets properly formatted, but not caring
about the actual texts and/or other language-related higher-level
entities of the document formatting environment.  What is the interface
needed for this low-level language switching?

First, a command for switching into a particular language is needed, yet
it cannot be safely assumed that this could correspond to a particular
\verb|\language| if the possibility of transparent use of several font
encodings is to be ensured. If we take the Czech language as an example,
then the language-switching command should be, e.g., 
\begin{quote}
\verb|\czech|
\end{quote}
or (as in \verb|babel|) 
\begin{quote}
\verb|\selectlanguage{\czech}|
\end{quote}
but the possibility which should be outright excluded is
\verb|\language=|$<$\emph{number}$>$, as this exposes too much
detail of
the internal implementation, and it is clearly impossible to ensure that
the same \verb|\language| number can be used in every installation no
matter which local font encodings are used.

Although \TeX\ treats a ``language'' as merely a set of hyphenation
patterns, it is more natural also to include the setting of other parameters 
as a part of the language-switching action, most notably the
\verb|\lefthyphenmin| and \verb|\righthyphenmin| values (hyphenation
patterns are usually tuned to some particular values of these). 
Non-standard features associated with hyphenation in certain languages
also seem natural to be added at this level---we show an example of this
later in this paper.

Second, the hyphenation patterns need to be
switched automatically when changing font encoding, so that when the
user selects Czech hyphenation with the internal \verb|\language| identifier
equal to $2$ within T1 encoding and then issues
\verb|\fontencoding{IL2}| in order to switch to ISO Latin~2 encoding
scheme, a side effect of this should be a change of the current
\verb|language| setting to an appropriate value, e.g., $3$. This is not the
same as switching to a new font encoding and then issuing the command
for switching into the current language. The user might have changed
some of the parameters associated by default with the language (e.g.,
the \verb|left|/\verb|right|-\verb|hyphenmin| values) and the system
should honour this change---just the \verb|\language| should be updated,
nothing more.

Third, during \verb|initex| processing the definition of new languages
available within the system should be tied to reading the hyphenation
patterns in. Definitions of the hyphenation patterns should be re-read
for each relevant encoding and the appropriate additional actions should
be associated with the set of hyphenation patterns on the level of
language ``declaration''.

\section{Setting up the internals}
\LaTeXe\ has set up quite a high standard of portability of source
documents and excluded many of the possibilities for nonstandard
modifications of the system setup during generation of the format file.
Hence all the extensions can only be made within the configuration files
allowed by the new standard. 

The principal place where essentially all that is needed can be
performed is the file used for configuring the system to a particular
set of hyphenation patterns, i.e.\ \verb|lthyphen.cfg|. All of the
following code can be put in there. The definitions of
language-switching commands can be linked to loading the corresponding
hyphenation patterns in. There will be two kinds of them---one for
encoding-independent languages (e.g., English in most common settings),
and another one for languages where the change of font encoding scheme
implies a change of the \verb|\language| parameter as well. The former
kind corresponds to defining the switching instructions using
\verb|\newcommand|, and the latter to using \verb|\DeclareTextCommand|
for making the definition encoding-specific.

\def\c#1{$<$\emph{#1}$>$}
The basic command providing the setup of hyphenation patterns and
generating the definitions of the corresponding language-switching
commands now has the form:
\begin{quote} 
\verb|\DeclareLanguage[|$<$\emph{cdp}$>^\star$\verb|]|\\
\hspace*{19ex}\verb|{|$<$\emph{file}$>$\verb|}|\\
\hspace*{19ex}\verb|{|$<$\verb|\|\emph{cmd}$>$\verb|}|\\
\hspace*{19ex}\verb|{|$<$\emph{\ldots env\ldots}$>$\verb|}|
\end{quote}
Here $<$\emph{cdp}$>^\star$ is a comma-separated list specifying the 
encodings for which encoding-specific setups should be prepared. As a
part of this,  
the file \c{file} containing the hyphenation patterns and hyphenation
exceptions for the particular language are loaded for each of the
specified encodings (ore just once if the optional part is skipped out.
The language-switching command \verb|\|\c{cmd} is defined as a result of
this declaration, which will be used for switching into the particular
language independently of the encoding used.
The fourth argument defines an additional setup determined by the piece of code
\c{\ldots env\ldots} ensuring that complete setup is done when switching
into the language, not just a change of hyphenation patterns (a similar
feature is provided by the \emph{Babel} system).

When invoking this command with an empty font-encoding list, the resulting
definition of \verb|\|\c{cmd} is obtained simply by direct use of \verb|\def|.
When $<$\emph{cdp}$>^\star$ is non-empty, then for each encoding from
this list the encoding-specific language switching command is generated
by using construction effectively equivalent to
\begin{quote}
\verb|\DeclareTextCommand{|\c{cdp}\verb|}|\\
\hspace*{13ex}\verb|{|\verb|\|\c{cmd}\verb|}|\\
\hspace*{13ex}\verb|{\language=|$n$\\
\hspace*{14ex}\verb|\let\cur@lang=\|\c{cmd}\\
\hspace*{14ex}\c{\ldots env\ldots}\verb|}|
\end{quote}
where $n$ stands for the \verb|\language| number under which the
patterns and exceptions have been loaded. For languages which do not
depend on font encodings (that is, they work with any of the font
encodings used within the installation) it is sufficient to use the ordinary
\verb|\def| command, that is 
\begin{quote}
\verb|\newcommand{|\verb|\|\c{cmd}\verb|}|\\
\hspace*{13ex}\verb|{\language=|$n$\\
\hspace*{14ex}\verb|\let\cur@lang=\|\c{cmd}\\
\hspace*{14ex}\c{\ldots env\ldots}\verb|}|
\end{quote}

These definitions provide for the user-level selection of the language
features. As noted above, another version is needed for internal
hyphenation pattern switching without affecting the other parameters
which might meanwhile have been changed by the user. These definitions
can be defined using just versions of the user-level names,
i.e.
\begin{quote}
\verb|\DeclareTextCommand{|\c{cdp}\verb|}|\\
\hspace*{24ex}\verb|{|\verb|\@|\c{cmd}\verb|}|\\
\hspace*{24ex}\verb|{\language=|$n$\verb|}|
\end{quote}
and
\begin{quote}
\verb|\newcommand{|\verb|\@|\c{cmd}\verb|}|\\
\hspace*{14ex}\verb|{\language=|$n$\verb|}|
\end{quote}
The use of these internal switching commands has to be linked to the
font-encoding switching process. This can most conveniently be done by
including a \verb|\@hyphenation| command into the text settings of the
\verb|DeclareFontEncoding| command (usually found either in
\verb|fontdef.cfg| and/or the encoding definition files
\c{ENC}\verb|enc.def| files) for every encoding definition for which
encoding-specific hyphenation may be loaded. The definition of this
synchronization command just looks at the current language activated and
invokes the corresponding internal command:
\begin{quote}
\begin{verbatim}
\def\@hyphenation{\csname 
         @\expandafter\@gobble
         \string\cur@lang
                  \endcsname
}
\end{verbatim}
\end{quote}

The code outlined above works fine provided that the encodings used
share \verb|\catcode| and \verb|\lccode| definitions. The code
resetting these can be added into \verb|\@hyphenation| so that the
tables defining the characteristics of the setup are updated each time the
encoding scheme is switched. As noted earlier in this paper, this does
not make the behaviour absolutely perfect: It will only work for full
paragraphs because of the way \TeX\ uses the associated information
during paragraph breaking. If used together with delimiting the scope of the
language/encoding specification, it will put an extremely heavy burden
on the save stack---more than the compile-time parameters of most common \TeX\ 
implementations are prepared to withstand.

\section{Loading encoding-independent hyphenation patterns}
Within \LaTeXe's way of optimizing the code of encoding-specific
commands, it is not possible to include accent commands defined using
\verb|\DeclareTextComposite| directly. Firstly, they are
\verb|\protect|ed, and this leads to the \verb|\relax| command. Secondly,
they may use the \verb|\def| command internally. Either of these lead to an
executable command which is not allowed in the expand-only mode used
for \verb|\patterns| processing.

This can be solved by redefining temporarily certain commands invoked
internally during accent command processing so that they work purely
by expansion. In the phase of reading in the hyphenation patterns and
exceptions this can be done locally within a group because both
\verb|\patterns| and \verb|\hyphenation| always work globally. 
Care must be taken however if the language-switching commands are to be
generated at the same time, as there isn't any \verb|\global|
prefix for either the \verb|\newcommand| or \verb|\DeclareTextCommand|
instructions and thus their actual implementation will look slightly
more verbose compared with that shown in the preceding section.

The redefinitions needed for inputting hyphenation patterns prepared
using the accent command are shown in Figure~1 (this code is mostly due to Alan
Jeffery and it works with the \verb|<1994/06/01>| release of \LaTeXe). Note
that the code includes two possibilities for an error condition
discovered and it tries to fire the standard mechanism for reporting
errors. When used within \verb|\patterns|, this will not
work because this
would require also execution, not just expansion. Hence ini\TeX\ reports
``bad patterns'' if issuing an error message is attempted.
\begin{figure*}[t]%%%%\small
\begin{verbatim}
\bgroup
   \lccode`\|=`\\
   \lowercase{
\egroup
   \def\@changed@x@exp|#1|#2\@changed@x{%
      \expandafter\ifx\csname\f@encoding |#2\endcsname\relax
         \@latexerr{Command |#2 undefined in encoding \f@encoding}\@eha
      \else
         \csname\f@encoding |#2\expandafter\endcsname
      \fi}
  }
\def\@text@composite@chk#1#2{%
   \expandafter\ifx\csname\string#1-\string#2\endcsname\relax
         \@latexerr{Undefined accent-character combination.}\@eha
   \else
         \csname\string#1-\string#2\expandafter\endcsname\expandafter
         \@firstofone
   \fi}
\def\expand@accents{%
   \let\protect\@empty
   \let\@changed@x\@changed@x@exp
   \let\@text@composite\text@composite@chk
   \expandafter\let\csname\f@encoding-cmd\endcsname\@empty}
\end{verbatim}
\caption{Code needed for expand-only processing of \LaTeXe\ accent
commands.}
\end{figure*}

\section{Special language-dependent setup}
For proper language-dependent formatting just hyphenation patterns are
clearly not enough. When introducing the \verb|\DeclareLanguage|
command, we have also included a general piece of code as a part of the
setup. In most cases this is just reserved for the \verb|\lefthyphenmin|
and \verb|\righthyphenmin| parameters. In certain situations. however,
this can be
used for the implementation of additional features linked with
hyphenation but but not included in the \TeX\ code.

As an example of a more complicated feature of this kind, let us consider
a modified behaviour of the hyphenation process when single dash is
encountered within a word. The proper typesetting practice in Czech
calls for placing the hyphen twice if hyphenating at this point: the
first one at the end of one line, and the other at the beginning of the
second line. 

The code implementing this hyphen-splitting property is shown on
Figure~2 (part of the code was suggested by Phil Taylor). 
Note that because hyphen characters are also used within \TeX\ 
for inputting negative numbers, the active version of `-' must first
try to narrow the modes in which this feature is meaningfuly applicable.
When any mode other than unrestricted horizontal mode is found,
a token corresponding to the ordinary hyphen character is returned. When
in horizontal mode, the code looks ahead and tries to emulate the
usual ligatures found in Computer Modern typefaces by checking for
numbers of subsequent hyphens and then re-issuing the hyphen characters
so that the ligatures are built by the ligature building mechanism in
order to render this process as font-independent as possible. When
a single hyphen is found, before issuing the \verb|\discretionary| a check
is made for subsequent `l': there is a common suffix `-li' used in Czech
before which the compound word cannot be split unless
\verb|\righthyphenmin|$<3$. 

When attaching this feature to the language-specific code within the
\verb|\DeclareLanguage| command, it has to be activated and de-activated
upon request, so that certain languages can switch this off even though
the language from which they have been called makes active use of it.
The corresponding set of definitions may be used in order to do so:
\begin{quote}
\begin{verbatim}
\newif\if@splithyphens
\newif\if@splitrequested
\def\standardhyphens{\catcode`-=12 
                  \@splithyphensfalse}
\def\splithyphens{\if@splitrequested 
                     \catcode`-\active
                  \fi
                  \@splithyphenstrue}
\def\@requesthyphens{%
                  \if@splithyphens 
                     \catcode`-=\active
                  \fi
                  \@splitrequestedtrue}
\end{verbatim}
\end{quote}
Two conditions are defined here: The first of them, \verb|@splitrequested|, is
satisfied when the hyphen-splitting feature has been activated from the
user level---usually using the \verb|\splithyphens| command no matter
whether the language actually allowed it to become active \emph{or} when
the language activated allows the hyphen-splitting code to be
activated. The second one, \verb|splithyphens|, becomes true when the
hyphen-splitting has been acivated by the user (usually using 
\verb|\splithyphens| for switching on and \verb|\standardhyphens| for
switching off). Languages in which hyphen-splitting is not allowed simply
execute \verb|@splitrequestedfalse| as a part of their \c{\ldots
env\ldots} code specified in the last argument of
\verb|\DeclareLanguage|. Languages for which this feature can be
activated execute \verb|\@requesthyphens|: When \verb|splithyphens| has
already been issued prior to this, \verb|\@requesthyphens| directly
turns the hyphen-splitting feature on. Otherwise it just sets a flag,
upon encountering which a subsequent \verb|splithyphens| will turn it on
instead.

One of the reasons for user-selectable hyphen splitting code is that
that the code for active hyphen is not entirely
fool-proof. It cannot distinguish between single hyphens found in
the running text and within parts of the input scanned in expand-only
mode when searching for numbers in horizontal mode. Specifications such as
\verb|\looseness=-1| won't be processed properly unless some special
care is taken. One remedy might be to steal the commands which can
suffer from this and to define them as commands which switch the
hyphen-splitting feature off and reinstall it again using
\verb|\afterassignment|:
\begin{quote}
\begin{verbatim}
\let\@looseness=\looseness
\def\looseness{%
            \if@splithyphens 
               \standardhyphens
               \afterassignment
                        \splithyphens
            \fi
            \@looseness}
\end{verbatim}
\end{quote}

\section{Conclusion}
We have outlined the way in which 
the concept of a font selection scheme used within
\LaTeXe\ allows one to define alternative encoding schemes corresponding to
a particular language and to generate formats comprising all of them.
This is particularly useful in situations where multiple users share a
common \LaTeX\ installation but for various reasons use different
code pages. One of the motivations for the present work was the
situation with ``official'' encodings for Czech where CSTUG officially
adopted ISO~Latin~2 for Czech character encoding, yet the \LaTeXe\
standard is the Cork DC scheme. Besides these two, other codings
still persist for historical reasons. The principal declarations in the
configuration files for this environment look as follows: Within {\tt
fontdef.cfg}, additional font encodings are defined and the
\verb|@hyphenation| hook is introduced. Note that ISO Latin2 is not
\verb|\lccode|-compatible with T1, and so changes of the code
parameters must be done as well---that's what \verb|\@@XXXCodes| commands
are here for:
\begin{quote}
\begin{verbatim}
\DeclareFontEncoding{T1}%
         {\csname @@T1Codes\endcsname
          \@hyphenation{T1}}{}
\DeclareFontEncoding{OT1}{}{}
\DeclareFontEncoding{KOI}%
         {\@@KOICodes
          \@hyphenation{KOI}}{}
\DeclareFontEncoding{IL2}%
         {\csname @@IL2Codes\endcsname
          \@hyphenation{IL2}}{}
\DeclareFontEncoding{OML}{}{}
\DeclareFontEncoding{OMS}{}{}
\DeclareFontEncoding{OMX}{}{}
\DeclareFontEncoding{U}{}{\noaccents@}
\end{verbatim}
\end{quote}
The actual languages are introduced in configuration file {\tt lthyphen.cfg} 
(declarations of the operations needed are skipped out) and the table for two
versions of English without the possibility of using the split-hyphen
feature, and two languages allowing splitting: Czech and Slovak, each
of them for three different font encodings:
\begin{quote}
\begin{verbatim}
\DeclareLanguage{\english}%
              {hyphen.tex}%
              {\lefthyphenmin=2
               \righthyphenmin=3
               \@splitrequestedfalse}
\DeclareLanguage[T1,KOI,IL2]{\czech}%
              {czhyphen.tex}%
              {\lefthyphenmin=2
               \righthyphenmin=3
               \@requesthyphens}%
\DeclareLanguage[T1,KOI,IL2]{\slovak}%
              {skhyphen.tex}%
              {\lefthyphenmin=2
               \righthyphenmin=3
               \@requesthyphens}%
\DeclareLanguage{\british}%
              {ukhyphen.tex}%
              {\lefthyphenmin=2
               \righthyphenmin=3
               \@splitrequestedfalse}%
\end{verbatim}
\end{quote}

We have presented several requirements for such a multi-lingual
multi-encoding system and shown a way in which they can be implemented.
The concept of environment definition when switching between languages
is similar to that introduced within Babel, and indeed within a
Babel-based system it is possible to use the approach shown within this
paper as a lower-level interface to language switching combined with
encoding switching and the corresponding representation of hyphenation
patterns. Configuration files with local modifications based on this
approach can be found on \verb|ftp.muni.cz| in
\verb|/pub/tex/cstug/csltx2e|. 

\begin{figure*}\small
\begin{verbatim}
\bgroup\catcode`-\active\expandafter\egroup\expandafter
\def\noexpand-{\ifx\protect\relax
                    \ifhmode
                        \ifinner
                            \expandafter\expandafter\expandafter\expandafter
                            \expandafter\expandafter\expandafter-
                        \else
                            \expandafter\expandafter\expandafter\expandafter
                            \expandafter\expandafter\expandafter\firstdash
                        \fi
                    \else%
                        \expandafter\expandafter\expandafter-
                    \fi
               \else
                    \expandafter\string\expandafter\string-
               \fi}
\def\onehyphen{-}
\def\splithyphen{\ifnum\expandafter\hyphenchar\the\font>-1
                       \discretionary{\char`-}{\char\hyphenchar\the\font}{\char`-}
                 \else
                       \discretionary{\char`-}{\char`-}{\char`-}
                 \fi}
\def\boxhyphen{\hbox{-}}
\def\twohyphens{--}
\def\threehyphens{---}
\catcode`\-=\active
\def\firstdash{\ifnexthyphen 
                   \seconddash 
               \else
                    \ifnum\expandafter\hyphenchar\the\font=`-
                        \ifnum\righthyphenmin>2
                            \if l\nextchar
                                \boxhyphen       %   make sure we
                            \else                %   don't chop off `-li'
                                \splithyphen
                            \fi
                        \else
                            \splithyphen
                        \fi
                    \else
                        \onehyphen
                    \fi
               \fii}
\def\seconddash#1{\ifnexthyphen \thirddash  \else \twohyphens \fii}
\def\thirddash#1{\ifnexthyphen \manydash  \else \threehyphens \fii}
\def\manydash#1{\threehyphens\firstdash}
\def\ifnexthyphen#1\else#2\fii{%
            \def\comparechars{\ifx -\nextchar
                                  \def\next{#1}%
                              \else
                                  \def\next{#2}%
                              \fi
                              \next}%
           \futurelet\nextchar\comparechars}
\catcode`-=12
\end{verbatim}

\caption{Hyphen-splitting code}
\end{figure*}

\section{Acknowledgment}
This work has been supported by GA \v CR grant No.~201/93/1269.

\begin{thebibliography}{00}
\bibitem{Babel} J.\,Braams: Babel, a multilingual style-option system
for use with \LaTeX's standard document styles. TUGboat,
Vol.~12~(1991), No.\,2, 291--302.
\bibitem{Companion} M.\,Goosens, F.\,Mittelbach, and A.\,Samarin: The
\LaTeX\ Companion. Addison-Wesley, Reading, MA, 1994.
\bibitem{LaTeX} L.\,Lamport: \LaTeX: a document preparation system, 2nd ed.
Addison-Wesley, Reading, MA, 1994. 
\bibitem{LaTeX2e} \LaTeX3 Project Team: \LaTeXe\ distribution. CTAN
archives, June 1994.
%\bibitem{norma}
\end{thebibliography}

\makesignature
\end{document}

