%
% tug_pre_tug2004.tex -- an article in LaTeX to the TUG 2004 proceedings
% by pts@fazekas.hu at Tue Jan  6 10:24:17 CET 2004
% Mon Feb 16 23:03:43 CET 2004
% FINAL at Tue Feb 24 20:43:15 CET 2004
%
% OK: Wizardry
% OK: remove comments \begin{verbatim}
% OK: inputenc of this file
% OK: mikor van a TUG?? (aug.20 körül)
% OK: Portuguese -> portuges == portugál nyelv
% OK: Dat: `on March 16, 2003' is correct in English
% OK: send varioref patch to Frank Mittelbach
% Imp: beker\"ul a Babel-be?
%
% %WF MIÉRT NEM AZ \emph-et használod szavak kiemelésére?
% Javítva \emphsl-re.
%
\documentclass{llncs}
%\usepackage{examplep}
\overfullrule3pt
%\usepackage[foo=bar]{examplep}
%\documentclass[a4paper]{article}
% \def\magyarOptions{defaults=over-1.4}
%\usepackage[magyar]{babel}

\pdfcompresslevel9

\let\myurl\verb
\def\nproduct#1{\textsf{\mdseries#1}}
\def\cs#1{{\ttfamily\char92 #1}}
\edef\csbrace#1{{\noexpand\ttfamily\char\string`\noexpand\{}#1%
  {\noexpand\ttfamily\noexpand\char\string`\noexpand\}}}
\def\emphsl{\textsl}
\hyphenation{ma-gyar}

\title{Implementation tricks\\ in the Hungarian Babel module}
\titlerunning{Hungarian Babel Implementation}
\author{Szab\'o P\'eter}% \inst{1}}

\institute{%
Budapest University of Technology and Ecomomics,\\
Department of Analysis,\\
M\H{u}egyetem rakpart 3--9.,\\
Budapest, Hungary H-1111,\\
\email{pts+tug@math.bme.hu},\\ WWW home page:
\texttt{http://www.inf.bme.hu/\homedir pts/}
% \personalURL{http://www.inf.bme.hu/~pts/}
}

\begin{document}

\maketitle
\begin{abstract}
\nproduct{magyar.ldf}, the Hungarian \nproduct{Babel} module was rewritten in
the autumn of 2003 to obey most of the Hungarian typographical rules. This
article describes some implementation issues, \TeX{} macro programming hacks
and \LaTeX{} typesetting trickery used in \nproduct{magyar.ldf}. All features
of the new \nproduct{magyar.ldf} are enumerated, but only those having
an interesting implementation are presented in detail. Most of the tricks
shown are useful for developing other language modules.
% and a few tricks are not related to \nproduct{Babel}. % too bad page breaks
\end{abstract}

\section{The name of the language}

Usually a \nproduct{Babel} language module has the English name of that language. For
example, the German module is called \nproduct{germanb.ldf}, and not
\nproduct{deutsch.ldf}. The Hungarian module is an exception to this rule,
because it has the name \nproduct{magyar.ldf}, in which ``magyar'' is the
Hungarian adjective meaning Hungarian. A similar exception is
\nproduct{portuges.ldf} for Portuguese. The letter ``a'' in word ``magyar''
has to be pronounced as in ``blah'', and the consonant ``gy'' is the same as
``d'' in due.

The name of a language that a \nproduct{Babel} language module (\texttt{.ldf} file)
defines is specified as an argument of \cs{LdfInit} in the file. Thus, if
\nproduct{czech.ldf} is renamed to \texttt{foo.ldf}, it will
have to be loaded with \verb+\usepackage[foo]{babel}+, but still
\verb+\selectlanguage{czech}+ will have to be used to activate it. This is
not the case with \nproduct{magyar.ldf}, because it detects its loaded
filename using the \cs{CurrentOption} macro set by the \cs{ProcessOptions}
command called from \nproduct{babel.sty}. So whatever \nproduct{magyar.ldf}
is renamed to, that name has to passed to \cs{selectlanguage}.

The only reason why someone wants to rename an \texttt{.ldf} file is to load
two different versions of it in the same \LaTeX{} run. This is possible with
\nproduct{magyar.ldf}, but the user should be aware that the control
sequences defined by the two copies will interact with each other in an
unpredictable way. Experiments have shown that it is possible to load two
copies of \nproduct{magyar.ldf} with different load options (that's
the so-called dual load):
%
\begin{verbatim}
\PassOptionsToPackage{frenchspacing=yes}{magyar.ldf}
\PassOptionsToPackage{frenchspacing=no}{hungarian.ldf}
\usepackage[hungarian,magyar]{babel}
\end{verbatim}
%
Despite the name \texttt{hungarian.ldf} above, the file \nproduct{magyar.ldf}
gets loaded twice, because \nproduct{Babel} translates the language name
\texttt{hungarian} to file name \nproduct{magyar.ldf}, and
\nproduct{magyar.ldf} expects options for \verb+\CurrentOption.ldf+, which depends
on the language name passed to \verb+\usepackage[...]{babel}+.
Since the dual load feature of \nproduct{magyar.ldf} is experimental, most of
the load options cannot be different in the two copies.
So the safest way to load two copies is replacing the
occurences of the word \texttt{magyar} in the second copy with something
else.

\smallskip
The latest \nproduct{magyar.ldf} (version 1.5) is not part of standard
\nproduct{Babel} yet, but it is available as part of \nproduct{Magyar\LaTeX}
(see section \ref{pts:downloads}). Most of the typographical rules it
tries to obey and most problems it addresses were proposed in \cite{bwfinal}.

\section{What an \texttt{.ldf} file contains}

An \texttt{.ldf} file is a \nproduct{Babel} language module, which contains
specific macros for the given language. It is loaded by \nproduct{babel.sty}
in the document preamble, at the time \nproduct{babel.sty} itself is loaded.
The macros defined in \texttt{foo.ldf} take effect only after
\verb+\selectlanguage{foo}+. The default language is the one specified last
in the \verb+\usepackage[...]{babel}+ command.

\nproduct{Babel} itself contains the standard versions of the \texttt{.ldf}
files as \texttt{tex/generic/\allowbreak babel/*.ldf}. In \nproduct{Babel} 3.7 there are
41 of them, most are shorter than $10\,$kB. The longest files are:
the old \nproduct{magyar.ldf} defining the Hungarian language ($25\,$kB),
\nproduct{frenchb.ldf} defining the French language ($23\,$kB),
\nproduct{spanish.ldf} ($21\,$kB),
\nproduct{bulgarian.ldf} ($13\,$kB),
\nproduct{ukraineb.ldf} defining the Ukrainian language ($12\,$kB),
\nproduct{russianb.ldf} ($12\,$kB) and
\nproduct{greek.ldf} ($9\,$kB).
The new version of \nproduct{magyar.ldf} is much larger than any of these: it
is $178\,$kB long. The big size implies much more functionality, but there
are also several features unique to this new \nproduct{magyar.ldf} -- they
will be discussed later in this document.

Now let's enumerate common functionality provided by the \texttt{.ldf}
files, first dealing with features common in most \texttt{.ldf} files, then
proceeding to features unique to \nproduct{magyar.ldf}.

\subsection{Selecting the hyphenation pattern set}\label{pts:hyphenation}

\texttt{foo.ldf} must define the control sequence \cs{l@foo} to be a number
(\cs{newcount}, \cs{chardef} etc.) representing the hyphenation pattern set
to be used for that language.
\verb+\selectlanguage{foo}+ calls
\verb+\language=\l@foo+, which activates the hyphenation patterns for the
language ``foo''. The patterns were defined with the \cs{patterns} primitive
by the time ini\TeX{} was called to generate the format file. The exact
filename containing the \cs{patterns} command is specified in the file
\texttt{language.dat}. For example, if \texttt{language.dat} contains a line
``\texttt{foot fthyph.tex}'', then \verb+\language=\l@foot+ will activate
\cs{patterns} found in \texttt{ft\allowbreak hyph\allowbreak .tex}.
In that case,
\texttt{foo.ldf} should contain a line \verb+\let\l@foo\l@foot+. But this
line is omitted in most actual \texttt{.ldf} files, because the
\nproduct{Babel} language name and the hyphenation pattern set name is the
same (\texttt{language.dat} would contain an entry starting with
\texttt{foo\textvisiblespace} in our example). Note that the file
\texttt{fthyph.tex} is read by ini\TeX{}, not \LaTeX{}, so the format files
have to be re-generated each time \texttt{fthyph.tex} is changed.

%(\TeX{} \cs{language}) to be used when \verb+\selectlanguage{foo}+ is
%active. When \nproduct{ini\TeX} generates the \LaTeX{} format file, it loads
%\texttt{language.dat} which maps filenames to control sequences. For
%example, if \texttt{language.dat} contains a line \texttt{foot fthyph.tex},
%then the Hyphenation set number for the \cs{patterns} defined in the file
%\texttt{fthyph.tex} will be available as \cs{l@foot}. 

Three different hyphenation pattern sets have been proposed for the
Hungarian language (\texttt{huhyph3.tex}, \texttt{huhyphc.tex} and
\texttt{huhyphf.tex}). All of them are maintained by Gyula Mayer
(\cite{huhydok-en}).
The most important difference between these lies in the way they hyphenate
at subword boundary of compound words. The document author can make
\cs{l@magyar} equal to any of these three by providing the appropriate
load option to \nproduct{magyar.ldf} (see later). The options work by
%
%\nproduct{magyar.ldf} allows selecting from three sets of hyphenation
%patterns (contained in \nproduct{huhyph3.tex}, \nproduct{huhyphf.tex}
%and \nproduct{huhyphc.tex} -- \nproduct{huhyph.tex} is a copy of one
%of these), by
redefining \cs{l@magyar} to be one of
\verb+\csname l@magyar3\endcsname+,
\cs{l@magyarf} or \cs{l@magyarc}.
% when \nproduct{magyar.ldf} is loaded.

%The reason why multiple hyphenation pattern sets are needed is that
There are two different correct ways to hyphenate compound words in
Hungarian.
\nproduct{magyarf} hyphenates the most common foreign compound words of
Hungarian text phonetically (e.g.\ szink-ron, meaning synchronous),
\nproduct{magyarc} hyphenates them on the subword boundary (e.g.\ szin-kron).
\nproduct{magyar3} is the old version of the hyphenation patterns which
hyphenates most composite words phonetically (even non-foreign ones), save a
few exceptions listed explicitly. However, in all the three cases,
hyphenation of foreign words cannot be perfect, because \emphsl{all} of them
cannot be specified exhaustively in \cs{patterns}.

\nproduct{magyar.ldf} can redefine \cs{l@magyar} to be any of \cs{l@magyar3},
\cs{l@magyarf} and \cs{l@magyarc}, depending on the \texttt{hyphenation=} load
option. Since some of these pattern sets may be missing from the user's system,
\nproduct{magyar.ldf} falls back to another set
with a meaningful warning message. Hyphenation is disabled not by choosing
\cs{language}\texttt{0}, which \nproduct{Babel} does, because
\cs{language}\texttt{0} may contain valid patterns for a different language, but
\cs{language}\texttt{255} is chosen, which is very likely to be unused since
\LaTeX{} assigns \cs{language} numbers from zero.

\subsection{Defining captions}

\LaTeX{} generates some words and phrases automatically. For example,
\cs{tableof\allowbreak contents} should emit the phrase ``Table of contents'' in the
native language. The same applies for \cs{caption}s of figures and tables,
and also for \cs{chapter} titles. Thus \nproduct{Babel} expects
\texttt{foo.ldf} to define a macro \cs{captionsfoo} containaining
definitions like \verb+\def\abstractname{Absztrakt}+. These definitions are
executed by \cs{selectlanguage} each time the language is activated. So it
is possible to have an English and a Hungarian chapter in a book numbered
``Chapter 1'' and ``2.\ fejezet'', respectively:
%\begin{verbatim}
\verb+\chapter{foo}+%
\verb+\selectlanguage{magyar}+%
\verb+\chapter{bar}+
%\end{verbatim}
\nproduct{magyar.ldf} has the proper definitions with Hungarian phrases.
Some words contain accented letters, which are specified as commands (e.g.\
\verb+\'a+ for ``\'a'') and not 8-bit single characters,
so their interpretation doesn't depend on the active input encoding, i.e.\
the load option of \nproduct{inputenc.sty}.

\subsection{Generating dates}

\texttt{foo.ldf} should define a macro \cs{datefoo}, which defines the
macro \cs{today}, which emits a date (specified by the \cs{year},
\cs{month}, \cs{day} registers) correctly on that language. The month name
should be printed as a non-abbreviated word. The definition of \cs{today} is
used by \cs{@date} invoked in \cs{maketitle} in the standard document
classes.

In addition to defining \cs{today}, \nproduct{magyar.ldf} defines the macro
\cs{ondatemagyar}, which defines \cs{ontoday}, which emits the date with the
Hungarian equivalent of English ``on'' prefix. The Hungarian language has
suffixes instead of prefixes, and each suffix has several forms which must
follow the vowel harmony of the word it is suffixed to. Thus ``on March 15''
is emitted as ``m\'arcius 15-\'en'', but ``on March 16'' is ``m\'arcius
16-\'an'', showing that the \emph{-\'an/-\'en} suffix has two forms.

\subsection{Minimum hyphenation length}

\TeX{} doesn't insert an implicit hyphen into the first
\cs{lefthyphenmin} characters of words, and neither does
it in the last \cs{righthyphenmin} characters. The default \LaTeX{} values
are \verb+\lefthyphenmin=2+ and \verb+\righthyphenmin=3+, which are suitable
for the English language. \texttt{foo.ldf} can override the default by
defining the macro \cs{foohyphenmins} to be $lr$, two digits specifying
the left and the right minimum, respectively.

What \nproduct{magyar.ldf} does depends on its load options. The default is
to follow Hungarian typography: \verb+\def\magyarhyphenmins{22}+.

\bigskip

Nine of the 41 \texttt{.ldf} files in \nproduct{Babel} 3.7 do only the
specializations described so far in this section. 25 languages go a little
beyond these, and 7 languages go much beyond. From those $25+7$ languages
that go beyond, \nproduct{frenchb.ldf} will be compared in detail to
\nproduct{magyar.ldf}, because French and Hungarian share some typographical
rules.

\subsection{Defining special letters}

Many languages have letters missing from the standard OT1 encoding, and some
characters are missing even from T1. These should are implemented in
\texttt{.ldf} files as control sequences. It is a common practice to modify
the meaning of an existing letter, for example \texttt{czech.ldf} contains
\verb+\DeclareTextCompositeCommand+\allowbreak\verb+{\v}{OT1}{t}{...}+. However, this
declaration is contained in \cs{AtBeginDocu\allowbreak ment}, so they are in effect even
when not the Czech language is active. This should have been avoided.

The correct solution is to use the \emph{extras} facility provided by Babel:
\texttt{foo.ldf} can have a macro \cs{extrasfoo}, which is executed each
time the language foo is activated; and the macro \cs{noextrasfoo} is
executed when the active language is about to change (because of a
\cs{selectlanguage} command or when the end-of-group is reached). It is a
common practice in \cs{extrasfoo} to save the meaning of a macro with
\cs{babel@save}, or a meaning of a count, dimen or skip register with
\cs{babel@savevariable}. The saved meanings will be restored just after
\cs{noextrasfoo} is executed. \nproduct{Babel} provides the command
\cs{addto} that can append tokens to the definition of an existing macro.
The idiom \verb+\addto\extrasfoo{+\allowbreak\verb+\babel@save\bar \def\bar{foo-bar}}+ is
typical, which gives a new meaning to \cs{bar} while the language foo is
active.

The macro to be saved for \verb+\DeclareTextCompositeCommand{\v}{OT1}+ is
\cs{OT1\string\v} (with the second backslash part of the control sequence),
but assigning the new meaning would be problematic, since
\cs{DeclareTextCompositeCommand} can be used only in the preamble.
Thus the correct solution would involve fiddling with undocumented \LaTeX{}
internals, probably that's why \nproduct{czech.ldf}
contains the problematic workaround involving \cs{AtBeginDocument}.
% OK: %%WF incorrect workaround involving HELYETT PL. problematic

Fortunately, the non-English letters in the Hungarian language are only
accented vowels (\'a, \'e, \'i, \'o, \"o, \H{o}, \'u, \"u and \H{u}),
which are all part of the T1 encoding. The letters ``\H{o}''
and ``\H{u}'' with the special Hungarian double-acute accent are missing from
the Latin-1 encoding (ISO-8859-1), but are part of Latin-2.
So authors are encouraged to use \verb+\usepackage[latin2]{inputenc}+ with
Hungarian.\footnote{``\~o'' and ``\^u'' are the most popular incorrect letters
found in Hungarian texts: their presence is caused by software incapable to
use Unicode or the Latin-2 encoding. These letters can be seen even on some
huge advertisement banners on streets in Hungary. But these texts were not
typeset by TeX, of course.}
\verb+\usepackage{t1enc}+ is also recommended, so \TeX{}
will be able to hyphenate words containing accented letters.

The finest Hungarian books have accents lowered a little bit.
This is accomplished for the dieresis accent (\"{}) by calling the
\cs{umlautlow} command (defined by \nproduct{Babel}) in \cs{extrasmagyar}.
No serious attempt is made to make this work for all 3 Hungarian
accents, because the technology \cs{umlautlow} is based on
works only for the OT1
encoding (which composes accented letters), but most Hungarian texts
use the T1 encoding to have words with accented letters hyphenated.

The lowering of accents is possible using virtual fonts. But \TeX{} font
families come with too many variations and design sizes, so the virtual font
generation should be automated. The \cs{lower@umlaut} macro in
\nproduct{babel.def} lowers accents by forcing their top to be $1.45\,$ex
above the baseline. The \cs{accent} primitive lowers its accent by
$\hbox{\cs{fontdimen}}5\hbox{\cs{font}}-1\,\mathrm{ex}$, so the top of the
accent can be forced to $1.45\,$ex by setting
$\hbox{\cs{fontdimen}}5\hbox{\cs{font}}:=\hbox{\cs{ht}}0-0.45\,\mathrm{ex}$,
where \cs{ht0} is the height of the accent character (\cs{char}\texttt{127}
in the OT1 encoding).
%
% \fontdimen5-1ex -szel rakja lejjebb =>
% accent teteje \ht0-\fontdimen5+1ex
% új accent teteje \ht0-(\ht0-0.45ex)+1ex == 1.45ex
%
The lowering, in the case of ``\"u'' is as few as $0.43558\,$pt. Even this
few displacement can make a difference: 
``{\fontfamily{cmr}\fontencoding{OT1}\selectfont
%\setbox0=\hbox{\char127}%
%\dimen0=\ht0
%\advance\dimen0-.45ex
%\fontdimen5\font=\dimen0
%\accent127 u
%\vrule height 1.5ex depth -1.45ex width 3pt
\lower0.43558pt\hbox to0pt{\"{}\hss}\kern-.4pt u}${}<{}$%'' and ''%
{\fontfamily{cmr}\fontencoding{OT1}\selectfont \"u}''.
The lowering method could be made
% OK: %WF 0.45ex -- ezt nem hiszem el, ez nagyon sok!
adaptive by rendering the glyphs involved in high resolution, measuring the
number of pixels between the accent and the letter vertically, and then
lowering the accent so the distance will be a prescribed constant value.
% ^^^ Dat: if you make this paragraph shorter, you get an Underfull \hbox

Neither home users nor professionals use lowered accents in Hungary today,
not even with books created with \LaTeX{} -- the original fonts with the T1
encoding are acceptable enough not to bother changing. TypoTeX Ltd., one of
the biggest Hungarian publishing houses that use \TeX{} has developed the OM
fonts in the early 1990s for use with plain \TeX{}. The OM fonts are a
variation of CM fonts with Hungarian accented glyphs added (with lowered
accents). However, it is not worth creating \texttt{.fd} files for the OM
fonts for use with \LaTeX{}, because with an equal amount of work new virtual
fonts cound be created from the EC fonts, that would take advantage of the
full T1 character set, and existing, hinted fonts in Type\,1 formats (such as
the \nproduct{CM-Super} fonts).
% Dat: no hyperlink to TypoTeX: http://www.typotex.hu/

\subsection{Hyphenation of long double consonants}\label{pts:longdouble}

However,
hyphenating long double consonants is still a little inconvenient. The
correct way to hyphenate the double consonant
$\hbox{tty}=\hbox{ty}+\hbox{ty}$ in the word ``hatty\'u'' (meaning: swan) is
``haty-ty\'u''.
%\texttt{\cs{discretionary}\string{ty-\string}\string{ty\string}\string{tty\string}}.
(There is a similar problem in German with words containing ``ck'';
\cite{comp-word-hyph} documents more languages with more exceptions.)
The long double consonants involved are: ccs, ddz, ddzs, ggy, nny, ssz, tty
and zzs.
\TeX's automatic hyphenation algorithm cannot deal with such exceptions, but
adding ligatures dealing with the minus inserted by the implicit hyphenation
can solve the problem. The simple
trick of having \verb+\patterns{t1ty}+
and $\hbox{\tt t}+\hbox{\tt-}\to
\hbox{\tt ty-}$\footnote{\texttt{(LABEL C t) (LIG C - C y)} in the \texttt{.pl}
file} seems to solve the problem, because it makes
``tty'' hyphenated as ``ty-/ty'', but it also inserts an extra ``y'' before
the hyphen in ``fut-szalad''. Normal patterns will also insert an implicit
hyphen into ``botcsin\'alta'', yielding ``bot-csin\'alta''. The ligature program
above would incorrectly change that to ``boty-csin\'alta''. So a more elaborate
set of ligatures have to constructed, which will detect the context of the
hyphen, and insert the ``y'' only into ``t-ty'', yielding ``ty-ty''. Or,
equivalently,
using \verb+\patterns{tt1y gg1y}+ with context-sensitive ligatures
changing ``tt-y'' to ``ty-ty'' and ``gg-y'' to ``gy-gy'' etc.

This solution uses up many character
places from the font, and many many extra ligatures are involved.
The user should also be informed that any
time he wants to see ``t-ty'' (which almost never appears in Hungarian), he
has to type \verb+t{}-ty+. All of this can be accomplished
using virtual fonts. The author has tried that the concept works by
decompiling \nproduct{aer10.vf} to \nproduct{aer10.vpl} and modifying the
\texttt{(LIGTABLE)}. However, the automation of the virtual font generation
is a work remaining to the future.

% Since it is impossible to distinguish implicit
% and explicit hyphens in ligature programs, the solution would be changing
% \cs{hyphenchar} to a character never typed by the user (let it be denoted by
% $\hbar$) and adding ligatures
% $\hbar+\hbox{\tt a}\to \hbox{\tt-a}$ \ldots{}
% $\hbar+\hbox{\tt z}\to \hbox{\tt-z}$.

The hyphenation of the double two-character consonants ``ggy'' and ``ssz''
are similar to ``tty''. However, compound words such as ``leggyakoribb''
(meaning: most frequent) and ``vasszek\'er'' (meaning: iron chariot) should be
hyphenated at the subword boundary without adding extra letters:
``leg-gyakoribb'' and ``vas-szek\'er''. Extra \cs{patterns} may be added to
disable the insertion of ``y'' for each important compound word, for example
\texttt{\cs{patterns}\csbrace{gg1y .leg1g4yakoribb.}}. This is quite
straightforward, because it doesn't need more ligatures (apart from the
context sensitive ligature program changing ``gg-y'' to ``gy-gy'').

(One might suggest that context-sensitive ligatures can be avoided if
``ty'' is introduced as a new single letter. But this won't work,
because, as step (1): ``t\,t\,y'' has to be converted to ``ty\,ty''
using more than one ligatures, and then step (2): further conversion to
``t\,ty'' if there is no line break, but \TeX won't run its hyphenation
algorithm in the middle of ligature processing, between steps (1) and (2).)

%\iffalse
The current approach of \nproduct{magyar.ldf} for handling long double
consonants is a compromise. By default, the patterns do not hyphenate those
consonants, and the character \verb+`+ is made active (with the standard
\nproduct{Babel} command \cs{declare@\allowbreak shorthand}), so that, for example
\verb+`tty+ emits
\verb+t\nobreak\discretionary{y-}{}+\allowbreak\verb+{}ty\nobreak\hskip\z@skip+. The first
\cs{nobreak} is used to enable automatic hyphenation before the \verb+`tty+
construct, and the last \cs{nobreak} plus the \cs{hskip} enable hyphantion
after the construct. Thus the word typed as \texttt{megho\string`sszabb\'it}
will be hyphenated as \texttt{meg-hosz-szab-b\'it}. Similar shorthands are
added for the other long consonants. The compromise is that the user has to
be aware that he has to insert \verb+`+s manually. A Perl
script named \nproduct{ccs\textunderscore extract.pl} has been developed,
that will collect all occurences of double consonants in a document so the
user can review them and decide about the insertion of \verb+`+ for each
different word.

\subsection{Table and figure captions}

The document class defines the \cs{@makecaption} macro, which is responsible
typesetting a caption of tables and figures. Some \texttt{.ldf} files,
including \nproduct{frenchb.ldf} and \nproduct{magyar.ldf} override the
default behaviour. \nproduct{magyar.ldf} Changes to colon separating the
caption heading (e.g.\ ``1.\ t\'abl\'azat'', or ``Table 1'') from the caption
text to a full stop, to match Hungarian typography. Furthermore, the
\texttt{longcaption=} load option controls what should happen when the
caption doesn't fit in a single line: whether it should be centered and
whether there should be a line break after the caption heading.

The \texttt{tablecaptions=} and \texttt{figurecaptions=} load options control
the appearance of the caption heading, by redefining \cs{fnum@table} and
\cs{fnum@figure}. The default in both cases is to
follow Hungarian typography, which requires the form
``$\langle\hbox{number}\rangle$.~$\langle\hbox{table name}\rangle$'' instead of
``$\langle\hbox{table name}\rangle$~$\langle\hbox{number}\rangle$''.

\subsection{Between the section title and the section number}

The default definitions of \cs{@ssect} and \cs{@sect} separate the section
number from the section title with a \cs{quad}.  In Hungarian typopgraphy,
only an \cs{enskip} is needed, and a dot has to be inserted after the number.
The old version of \nproduct{magyar.ldf} changed \cs{@sect} etc., but this
caused conflicts with the AMS document classes and several other packages, so
that strategy has been given up in the new version of \nproduct{magyar.ldf},
and dots were moved into the \cs{numberline} instead, which adds the dot to
\cs{tableofcontents} lines (being careful not to
append the dot twice, see dot stripping code in subsection
\ref{pts:stripdot}), and to \cs{@seccntformat}, which adds a dot and the
\cs{enskip} to the titles. AMS document classes do not use
\cs{@seccntformat}, so the AMS-specific \cs{tocsection} and \cs{tocappendix}
commands had to be modified.

\cs{@numberline} also add a dot after table and figure numbers in the
\cs{listof\allowbreak tables} and \cs{listoffigures}, but the dot is needed there, too,
anyway.

All three TOCs share a common problem related to language changes. Each time the
language is changed, \nproduct{Babel} emits changing commands to the three TOC
files, so the time they are re-read, each line comes in its appropriate
language. The implementation has a main flaw, however, because the \cs{write}
to the TOC files gets executed when the page is shipped out, and the order
of \cs{write}s on the same page follow the document structure: \cs{write}s in
top insertions precede and bottom insertions follow those in the main text.
So when a table or figure is moved to the top of the page, the writing of
its TOC entry, together with the \cs{selectlanguage} command emmitted by
\nproduct{Babel} is moved away, so \cs{selectlanguage} commands
in the TOC files are reordered, which is wrong. The solution is to emit a
\cs{selectlanguage} command for each TOC entry, so the TOC entries can be
freely reordered. \nproduct{magyar.ldf} implements this solution as a local
fix, but it should be fixed generally in the new version of \nproduct{Babel}.

\subsection{Spacing around punctuation}\label{pts:punctuation}

It is quite easy to add extra space \emphsl{after} punctuation
characters with \cs{sfcode} (see ``space factor'' in chapter 13 of \cite{texbook}).
The \LaTeX{} \cs{nonfrenchspacing} command (which
is activated by default) assigns a space factor of 3000 to 
\texttt{.}, \texttt{?} and \texttt{!}, 2000 to \texttt{:},
1500 to \texttt{;}, and 1250 to \texttt{,}.
%by $1.25$ -- all of these are accomplished by setting the \cs{sfcode} of the
%characters mentioned.

However, adding extra space \emphsl{before} punctuation needs a different
approach. Both \nproduct{frenchb.ldf} and \nproduct{magyar.ldf} make the
characters \texttt{:}, \texttt{;}, \texttt{!} and \texttt{?} active with the
\nproduct{Babel} \cs{initiate@active@char} interface, and insert
unbreakable space in horizontal mode (\cs{ifhmode}) just before the
punctuation character. This feature of \nproduct{magyar.ldf} can be turned
off using the \texttt{activespace=} load option, partly because making
these four common characters active %may produce unexpected incompatibility
%problems
may lead to incompatibility with other packages, and partly because the extra space before
punctuation is very rare in present Hungarian documents. In French typography,
about one third of normal space is required before punctuation, and if it is
not possible to add that amount with the typesetting technology, one full
space should be added. However, in Hungarian, the fallback strategy is to
omit the extra space.

The last action the active punctuation character should do is inserting
itself, but typing it verbatim into the definition will lead to an infinite
loop. For example, \verb+\catcode`?=13 \def?{\kern.1em ?}+ will loop
infinitely. The solution is using \verb+\string?+ in place of the last
\texttt{?}, so its catcode will be changed to 12 (other). Using \cs{edef}
with \cs{string} will make the macro a little bit faster, because \cs{string}
will be executed once, at load time.

\subsection{Quoted material}

\expandafter\ifx\csname save@sf@q\endcsname\relax% Babel isn't loaded
\makeatletter
\def\save@sf@q #1{\leavevmode
 \begingroup
  \edef\@SF{\spacefactor \the\spacefactor}#1\@SF
 \endgroup
}
\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@}
\ProvideTextCommand{\quotedblbase}{OT1}{%
  \save@sf@q{\set@low@box{\textquotedblright\/}%
    \box\z@\kern-.04em\nobreak\hskip\z@skip}}
% %%WF a T1-et használd
% Nem ilyen egyszerű, mert direkt az OT1-et akartam !!
\ProvideTextCommandDefault{\quotedblbase}{%
  \UseTextSymbol{OT1}{\quotedblbase}}
\ProvideTextCommand{\quotesinglbase}{OT1}{%
  \save@sf@q{\set@low@box{\textquoteright\/}%
    \box\z@\kern-.04em\nobreak\hskip\z@skip}}
\ProvideTextCommandDefault{\quotesinglbase}{%
  \UseTextSymbol{OT1}{\quotesinglbase}}
\ProvideTextCommand{\guillemotleft}{OT1} {\OTOguillemotleft}
\ProvideTextCommand{\guillemotright}{OT1}{\OTOguillemotright}
\ProvideTextCommandDefault{\guillemotleft}{%
  \UseTextSymbol{OT1}{\guillemotleft}}
\ProvideTextCommandDefault{\guillemotright}{%
  \UseTextSymbol{OT1}{\guillemotright}}
\fi
% vvv OT1 Babel replacement variants are ugly.
\def\TOguillemotright{{\fontencoding{T1}\selectfont\guillemotright}}
\def\TOguillemotleft {{\fontencoding{T1}\selectfont\guillemotleft }}
\def\OTOguillemotleft{%
  \ifmmode\ll\else
    \save@sf@q{\nobreak
      \raise.2ex\hbox{$\scriptscriptstyle\ll$}\nobreak\hskip\z@skip}%
  \fi}
\def\OTOguillemotright{%
  \ifmmode\gg\else
    \save@sf@q{\nobreak
      \raise.2ex\hbox{$\scriptscriptstyle\gg$}\nobreak\hskip\z@skip}%
  \fi}

In English, text can be quoted using `single' or ``double'' quotation marks.
These can be nested into each other both ways. Hungarian provides three
nesting levels:
%
\quotedblbase\nobreak\hskip-.06em\nobreak outer
  \TOguillemotright\nobreak\hskip-.07em\nobreak middle
    \textquoteright\nobreak inner%
    \kern\z@\textquoteright\,%
  \kern-0.05em\TOguillemotleft\,%
\kern\z@\textquotedblright.
% %WF azonos típusok közt kell a \, pl. '\,'', de itt is kell??? nem tudom.
% Szerintem kell, mert így szép. 
%
Although the guillement symbols are missing from the CM fonts with OT1
encoding, this is not a serious problem, since \nproduct{Babel} provides them
(using the \cs{ll} relation:
\OTOguillemotleft{} and \OTOguillemotright), and Hungarian text should be typeset with the T1
font encoding anyway, to get words with accented characters hyphenated.

\nproduct{frenchb.ldf} provides the commands \cs{CyrillicGuillements} and
\cs{LasyGuil\allowbreak lemets} so the user can select the origin of the replacement
guillemets. \nproduct{magyar.ldf} relies on the defaults provied by
\nproduct{Babel} in the hope that the T1 encoding is used, so replacements
are not needed. \nproduct{magyar.ldf} doesn't adjust spacing around the
quotation symbols, but provides a \cs{textqq} command that emits quotation
with proper nesting and spacing. For example, the three-level sample above
can be typed as \verb+\textqq{outer \textqq{middle \textqq{inner}\,}\,}+.
% %WF azonos típusok közt kell a \, pl. '\,'', de itt is kell??? nem tudom.
% Igen, szerintem így szép.
\hskip0pt plus 2pt
\cs{textqq} does English quotation (with two alternating levels) when not the
Hungarian language is active.

\subsection{List environments}

The default spacing, indentation and label item generation of list
environments (such as \verb+\begin{itemize}+ and \verb+\begin{description}+)
are incorrect. The \texttt{la\allowbreak belenums=} and \texttt{labelitems=} load options
control whether labels should be modified to match Hungarian traditions. Five
levels of depth are provided for both \verb+\begin{itemize}+ and
\verb+\begin{enumerate}+. The maximum depth os hard-wired to the \LaTeX{}
definitions of these environments, so the
\verb+\ifnum\@enumdepth>3+ test had to be changed to
\verb+\expandafter\ifx\csname labelenum\romannumeral+\allowbreak\verb+\the+\allowbreak\verb+\@enumdepth\endcsname\relax+
(and similarly for \cs{@itemdepth}).

Although the vertical space the standard document classes leave around lists
is too much, and indentation is also incorrect, these problems have not yet
been solved in \nproduct{magyar.ldf}. (\nproduct{frenchb.ldf} modifies
\cs{itemsep} and other spacing dimensions to match French typographical rules.) 

\subsection{Modularity using load options}\label{pts:options}

%\nproduct{magyar.ldf} is unique among the

The user can customize \texttt{.ldf}s using the language attribute facility
provided by \nproduct{Babel}. For example, \nproduct{greek.ldf} contains the
declaration \cs{bbl@declare@ttribute}\allowbreak\verb+{greek}{polutoniko}{...}+, and if the
user loads \nproduct{greek.ldf} with \verb+\usepackage[+\allowbreak\verb+greek]{babel}+
\verb+\languageattribute{greek}{polutoniko}+, the code in the \texttt{...} is
executed by when \cs{languageattribute} is called. \cs{languageattribute}, if
present, must be part of the document preamble, and the \texttt{.ldf} file
must be already loaded.

The fundamental problem of language attributes is that the user can pass only
declared keywords, and not arbitrary data to the \texttt{.ldf} file, and --
since attributes are processed too late -- they cannot be used to control
which parts of the \texttt{.ldf} files should be loaded. That's why
\nproduct{magyar.ldf} follows a different approach. Options are
$\langle\hbox{key}\rangle\texttt{=}\langle\hbox{value}\rangle$ pairs, which
must be declared any time before \nproduct{magyar.ldf} is loaded. The set of
keys are fixed, but values can be arbitrary. It is the responsibility of the
macro belonging to the key to verify that the syntax of the value is all
right. None of the other \texttt{.ldf} files provide
load option support this flexible.
This option-passing scheme is similar to %the one offered by
\nproduct{keyval.sty}, but \nproduct{magyar.ldf} doesn't use
\nproduct{keyval.sty} because of a general design policy to avoid
dependencies.

Since \texttt{.ldf} file names are the \LaTeX{} options to
\nproduct{babel.sty} in the \verb+\usepackage[+\allowbreak$\cdots$\verb+]{babel}+ line, it is not
possible to pass options to the individual \texttt{.ldf} files directly.
However, \LaTeX{} provides the command \cs{PassOptionsToPackage}, which
declares options for a package before the package is loaded. For example,
\verb+\Pass+\allowbreak\verb+OptionsToPackage{a=b,c=d}{foo.bar}+ appends \verb+a=b,c=d+ to the
macro \cs{opt@\allowbreak foo.bar}. \nproduct{magyar.ldf} examines \cs{opt@magyar.ldf},
so for example \verb+\PassOptions+\allowbreak\verb+ToPackage{titles=\enskip}{magyar.ldf}+
will force the space in section headings between the section number and
the section title to be \cs{enskip}. (For compatibility reasons,
\nproduct{magyar.ldf} also processes the contents of \cs{magyarOptions} as
options. This will be useful when \nproduct{magyar.ldf} will work with plain
\TeX{}.)

\TeX{} macro wizards may enjoy studying the option parsing code in
\nproduct{magyar.ldf}. The entry point of the routine is the
\cs{processOptions} macro, whose argument is a comma-separated option list of
$\langle\hbox{key}\rangle\texttt{=}\langle\hbox{value}\rangle$ pairs. The
routine calls \cs{processOption}\csbrace{$\langle\hbox{key}\rangle$}%
\csbrace{$\langle\hbox{value}\rangle$} for each pair found.

\begin{verbatim}
\def\processOptions#1{\processOptions@a#1,\hfuzz,}
\def\processOptions@a#1,{%
  \if,\noexpand#1,% (1)
    \expandafter\processOptions@a
  \else
    \csname fi\endcsname% (2)
    \processOptions@b#1,=,%
  \fi}
\@gobble\iftrue
\def\processOptions@b#1#2=#3,#4\fi{% (3) (4)
  \ifx\relax#4\relax
    \ifx#1\hfuzz% Terminator
      \expandafter\expandafter\expandafter\@gobble% (5)
    \else
      \if,\noexpand#1% OnlySpace
      \else% MissingArg; #2 ends by comma 
        \if=\noexpand#1\missingKey#2%
        \else          \missingVal#1#2\fi
      \fi
    \fi
  \else% Normal
    \processOption{#1#2}{#3}%
  \fi
  \processOptions@a}
\def\missingKey#1,{\errmessage{Key missing for value: #1}}
\def\missingVal#1,{\errmessage{Value (=) missing for option: #1}}
\def\processOption#1#2{\typeout{Got option key=(#1) val=(#2)}}
\end{verbatim}

Comments:
(1) ignores extra commas, detects them by testing whether \verb+#1+
    is empty;
(2) this is a \cs{fi} when expanded, but doesn't count as a \cs{fi}
    when being skipped over when its surrounding condition is false.
    The real \cs{fi} won't be expanded, because it is parsed as the
    parameter terminator of \cs{processOptions@b}.
(3) needs \verb+#1#2+ instead of just \verb+#1+, so \TeX{} will ignore space
    tokens in front of \verb+#1+. As a side effect, when the option begins
    with \texttt{=}, the \texttt{=} will be put into \verb+#1+, so
    \cs{missingKey} can be reported.
(4) There are four different cases in which \cs{processOptions@b} can be
    invoked. The exact case is determined by how the macro parameter text
    separates parameters. The cases are: \emphsl{Normal case}:
    \verb+#1#2+ is the key, \verb+#3+ is the value, \verb+#4+ is \texttt{=,};
    \textsl{MissingArg case} (\texttt{=}$\langle\hbox{value}\rangle$ is
    missing, or $\langle\hbox{key}\rangle$ is missing, but
    \texttt{=}$\langle\hbox{value}\rangle$ is present):
    \verb+#1#2+ is $\langle\hbox{key}\rangle$\texttt{,} or
    \texttt{=}$\langle\hbox{value}\rangle$\texttt{,},
    \verb+#3+ and \verb+#4+ are empty;
    \textsl{Terminator case}: \verb+#1#2+ is \verb+\hfuzz,+,
    \verb+#3+ and \verb+#4+ are empty;
    \textsl{OnlySpace case}: \verb+#1+ is \verb+,+,
    \verb+#2+, \verb+#3+ and \verb+#4+ are empty.
(5) \cs{@gobble} removes the call of \cs{processOptions@a}
    at the end of the macro, so the iteration is finished.

\subsection{Default option sets}

Since there are 51 load options in the current \nproduct{magyar.ldf}, the user
should not be forced to know all of them. Reasonable defaults are provided
instead, so novice users can use the default of defaults
(\texttt{defaults=over-1.4}), without the need to know that there are
options, intermediate users can select one of the 5 defaults, and possibly
change a few options they don't like in their preferred default, and only
expert users will change options individually.

The number of bytes loaded were measured in a recent version of
\nproduct{magyar.ldf}, totalling 177\,353 bytes. Out of that $177$\,kB, 32\,417
bytes were used for initialization and providing the load option suport
framework, and declaring the options for the 5 defaults. After that, 138\,872
bytes were used for implementing features selected by the load options. In
the description below, the number of bytes skipped out of the feature bytes
are listed. (The smaller the number the more parts of \nproduct{magyar.ldf} is
processed at load time.)

The default sets are:
%
\begin{description}
\item[\tt =over-1.4] (not loaded 10\,720 bytes) This is the default among
  the defaults. Its main purpose is to make all documents with the previous
  version of \nproduct{magyar.ldf} (1.4) compilable with the new version,
  to provide emergency bugfixes to the incompatibility problems caused by
  the old version. It introduces a few essential typographical changes over
  the new version, which have only little impact on line and page boundaries;
  but it disables big, eye-catching changes. It makes most of new commands
  available, but doesn't turn new features on.
\item[\tt =compat-1.4] (not loaded 82\,890 bytes)
  Implements a compatibility mode with version 1.4 of \nproduct{magyar.ldf}.
  Documents compiled should look the same (but exact match not guaranteed),
  even if the compatible solution is not correct typograpically. It doesn't
  define new commands sucs as \cs{told} or \cs{emitdate}.
\item[\tt =safest] (not loaded 124\,679 bytes)
  Turns off all features, reverts to \LaTeX{} and \nproduct{Babel} defaults
  in every respect. It is useful only for debugging purposes: if a document
  doesn't compile, but it compiles with
  \texttt{defaults=safest}, individual options can be turned on one-by-one
  to see which of them causes the compatibility problem.
\item[\tt =prettiest] (not loaded 1\,221 bytes)
  It turns on all new features, and tries to follow Hungarian typography in
  the prettiest, most advanced way. It is possible that compatibility
  problems will arise with other packages, although the author of
  \nproduct{magyar.ldf} doesn't know about such problems.
\item[\tt =hu-min] (not loaded 1\,317 bytes)
  Follows Hungarian typographical rules as much as possible. (The compliance
  is not full, of course, because some aspects are not implemented, thus they
  are not covered by load options, thus they cannot be controlled using
  defaults.) If typographical rules allow choice (for example, the first
  paragraph of a section may or may not be indented), the easiest and most
  compatible solution is chosen (e.g.\ accept the indentation defined by the
  document class).
\end{description}

\subsection{Skipping parts of the input file}

Since some code parts of \nproduct{magyar.ldf} can be disabled using load
options, it would be wise to skip them completely. The easiest way of
skipping part of \TeX{} code is wrapping it into
\verb+\ifnum\MyFeature<1 ... \fi+. But this kind of skipping will consume
hash memory for new control sequences skipped over, and it also requires that
the skipped part is nested with respect to \cs{if}\ldots{}s.
\nproduct{magyar.ldf} defines the following macro that does skipping without
these two flaws.
%
\begin{verbatim}
\@gobble\iftrue
\def\skiplong#1{\fi
  \bgroup% so ^} would close it
  \catcode\string`^13 \lccode\string`~=\string`^
  \lowercase{\let~\fi}%
  \catcode\string`\\14 % comment, save hash memory
  \catcode\string`$14
  \iffalse}
\@gobble\fi
\end{verbatim}
%
\noindent After that, code can be skipped with the construct
%
\begin{verbatim}
\ifnum\MyFeature<1 \skiplong\fi
  ...
  \@gobble
{^}
\end{verbatim}

\cs{lowercase} is needed in the implementation because
\verb+\let^\fi+ wouldn't work, because the catcode of \verb+^+ is already
assigned to be superscript when the definition of \cs{skiplong} was read.


\subsection{Detecting digits for the definite article}\label{pts:az}

\cs{ref}, \cs{pageref} and \cs{cite} generate numbers, which is often
prefixed by the definite article in Hungarian. The construct
\verb+the \ref{foo}+ works fine in English, but
the Hungarian definite article has two forms: ``a'' and ``az''. ``az'' must
be used if the following words (as pronounced) starts by a wovel, and ``a''
must be used for consonants. So there is a strong need for a macro that
generates the definite article for numbers automatically.
\nproduct{magyar.ldf} contains the macro \cs{az}, which prefixes its argument
by either \verb+a~+ or \verb+az~+. This kind of macro is unique to
\nproduct{magyar.ldf}, other \texttt{.ldf} files doen't seem to contain
solutions for similar problems.

Unfortunately, \cs{az} is not expandable, because it redefines the meaning of
several commands before processing its argument.
\cs{az} works by half-expanding its argument (expanding, of course, \cs{ref},
\cs{pageref} and \cs{cite}), ignoring braces and most control sequences,
non-digit and non-letter characters, changing \cs{romannu\allowbreak meral} to \cs{number}
(so the the ``x'' will become ``az~x'', but \verb+\az{\romannumeral+\texttt{\char32}\allowbreak
\verb+10}+
yields ``a~x''), looking for a number, a word or a single letter in the
beginning (in fact, ``az'' has to be emitted if the starting digit is ``5'',
and ``a'' has to be emitted if the starting digit is not ``1'' or ``5'').
For words, single letters and positive numbers not beginning with
``1'', the proper definite article depends on the first letter only.

For numbers starting with one, the definite article must be ``az'' if and
only if the number of digits is $3k+1$ for an integer $k$. For example,
the Hungarian words for $1$, $12$, $123$, $1000$ are ``egy'',
``tizenkett\H{o}'', ``sz\'azhuszonh\'arom'', ``ezer'', respectively, and
the definite forms are
``az~1'', ``a~12'', ``a~123'', ``az~1000'', respectively. So we have to
count the number of digits of a number.

It is not necessary to have 10 \cs{if} commands to test whether macro argument \verb+#1+ is a digit:
\verb+\ifnum1<1\string#1+\texttt{\char32} works almost always fine. The space at the end is important,
because it will terminate the second number of the \cs{ifnum} if \verb+#1+ is
a digit. The condition ($1<1$) is false if \verb+#1+ is a non-digit, and true
($1<10$, $1<11$ etc.) otherwise. \cs{string} cancels special the special
catcode \verb+#1+ might have. \verb+#1+ shouldn't be longer than a single
token, because the test makes \TeX{} process the extra tokens when \verb+#1+
contains a digit followed by the extra tokens.
If \verb+#1+ is \cs{if} or similar, the
test isn't skippable. The test works even if \verb+#1+ is empty.

The macro \cs{Az} is also defined that inserts a captitalized definite
article to be used at the beginning of the sentence. The macros \cs{aref},
\cs{Aref}, \cs{apageref}, \cs{Apageref}, \cs{acite} and \cs{Acite} are
combinations of \cs{az} and referencing commands, so for example
\verb+\aref{foo}+ is equivalent to \verb+\az{\ref{foo}}+.


\subsection{Counting the number of digits with multiple sentinels}

A ``sentinel'' is something which is placed to the end of a list so that a
conditional
iteration over the list stops at the sentinel. Subsection \ref{pts:options}
contains
\verb+\hfuzz,+, which is a sentinel for the option processing of the macro
\cs{processOptions@b}. A sentinel is usually a single token, but sometimes
multiple sentines has to be used in a row, when a macro processing them
needs multiple parameters.

As already mentioned in subsection \ref{pts:az},
the Hungarian definite article\,(\emph{a/az}) for a number depends on its
pronounciation.
% depends on the first letter of
%the word it precedes. If the word is a number, then its pronounciation
%has to be considered.
The rule is: ``az'' has to be emitted for numbers
starting with ``5'', and for numbers starting with ``1'' and having the
number of digits following ``1'' divisible by 3 (all other numbers should
be preceded by ``a''). \nproduct{magyar.ldf} thus contains a macro that
counts number of digits following it:

\begin{verbatim}
\def\digitthree#1{\digitthree@#1///\hbox$}%
\def\digitthree@#1#2#3{%
  \csname digitthree@%
  \ifnum9<1\string#1 \ifnum9<1\string#2 \ifnum9<1\string#3 %
  \else b\fi\else b\fi\else z\fi\endcsname}
\def\digitthree@z#1\hbox${z}%
\def\digitthree@b#1\hbox${}%
\message{1:\digitthree{} 100:\digitthree{23+}
  1000:\digitthree{456}}
\end{verbatim}

In this example the macro \cs{digitthree} expands to ``z'' if its argument
starts with digits of the multiple of 3. \verb+\hbox$+ is used as a sentinel
to skip everything after the last digit has been found. The sentinel must not
be present in the parameter itself. \verb+\hbox$+ makes no sense in \TeX{}, so
it is quite reasonable to assume that the parameter doesn't contain this.
\nproduct{magyar.ldf} uses \cs{hfuzz} and \cs{vfuzz} when only a single token
is allowed, because these two unexpandable tokens are quite rare.
The three consecutive slashes in the example are three sentinels, so
\cs{digitthree@} has always enough arguments.
% The
%construct \verb+\ifnum9<1\string#1+\texttt{\char32} tests whether \verb+#1+
%is a digit.
%It works unless \verb+#1+ contains more than one tokens, so for
%example \verb+\digitthree{1{2x}}+ doesn't work as expected.

The test doesn't work if the parameter of \cs{digitthree} contains braces,
for example \verb+\digitthree{1{2x}}+ would look for the undefined control
sequence \cs{digitthree@x}.

In the example the \cs{csname} trick was used to avoid \cs{expandafter} in
the nested \cs{if}s.

See the definition of \cs{@@magyar@az@set} in \nproduct{magyar.ldf} for using
three multi-character sentines in the same macro.


\subsection{The definite article in front of roman
numbers}\label{pts:hunnewlabel}

\cs{az} in \nproduct{magyar.ldf} (see in subsection \ref{pts:az}) works
differently for \verb+\az{x}+ and \verb+\az{\romannumeral 10}+, but how
should it distinguish when \cs{romannumeral} has already been expanded by
the time \cs{az} is called? There is no general solution to the problem, but
\nproduct{magyar.ldf} addresses the case when \verb+\az{\ref{my-part}}+ is
called, having label \texttt{my-part} pointing to a \cs{part}, when
\verb+\def\thepart{\@Roman+\allowbreak\verb+\c@part}+ is active. (This is so with the standard
\nproduct{book.cls}). \cs{ref} gets the part number from the
\verb+\newlabel{my-part}{{x}{42}}+
command written to the \texttt{.aux} in the previous run of \LaTeX{}.
\cs{label}, which has emitted this \cs{newlabel} has already expanded
\cs{romannumeral} in the previous run, a long time before our \cs{ref} is
called.

To make the definite article work in this special case, \nproduct{magyar.ldf}
redefines \cs{label} so it writes \cs{hunnewlabel} to the \texttt{.aux} file
in addition to \cs{newlabel}. The arguments of \cs{hunnewlabel} are
pre-expanded when \verb+\let\romannumeral\num+\allowbreak\verb+ber+
is in effect. This solution
also works when \cs{pageref} refers to a roman page number. Making the page
number expanded in the right time is rather tricky. \LaTeX{}
\cs{protected@write} says \verb+\let\thepage\relax+, which prevents expansion
in the following \cs{edef}, so \cs{thepage} is expanded only when the page is
shipped out, and \cs{c@page} contains the right page number. What we want is
half-expanding \cs{thepage}, so it gets expanded to \verb+\@roman\c@page+,
and \cs{@roman} gets expanded to \cs{number} (!), but the expansion of
\cs{number}\cs{c@page} is postponed until the page is shipped out. This can
be accomplished by defining \verb+\def\romannumeral{\noexpand\number}+
\hskip0pt plus10pt
before
calling \cs{protected@write}. Actually, \nproduct{magyar.ldf} itself expands
the page number once, so
three \cs{noexpands} are needed in front of \cs{number}.

Redefining \cs{label} (so it emits \cs{hunnewlabel}) also raises a problem.
Some packages loaded later might also override \cs{label}, for example
\nproduct{hyperref.sty} loads \nproduct{nameref.sty} \cs{AtBeginDocument},
which overrides \cs{label}. \nproduct{magyar.ldf} recognises the new
definition when the Hungarian language is activated -- which is done after
the \cs{AtBeginDocument} hooks are run (see subsection
\ref{pts:preamblecmds}), so \cs{hunnewlabel} works fine with
\nproduct{hyperref.sty}.

\subsection{Removing all braces}

Removing all braces from a token list is required by \cs{az} command
(that inserts the \emph{a/az} definite article). \cs{az} can find the first
letter of its argument more easily if the argument doesn't contain braces.

\begin{verbatim}
\@gobble\iftrue
\def\removebraces@stop#1#2\fi{#1}%
\def\removebraces#1{%
  \ifx\hfuzz#1\removebraces@stop\fi
  \expandafter\removebraces\expandafter{%
  \ifcat{\noexpand#1\hfuzz\iffalse}\fi\expandafter
    \removebraces\else\hfuzz}\removebraces@nob{#1}\fi}
\def\removebraces@nob#1#2{#2% #2 is \fi
  \ifx\hfuzz#1\hfuzz\expandafter\@firstoftwo
    \expandafter\removebraces\fi\removebraces@nobone#1}
\def\removebraces@nobone#1{\noexpand#1\removebraces}
\message{R:\removebraces {{foo}{{}{b}{{{{a\fi}}}}r}}\hfuzz;}
\end{verbatim}

The \cs{removebraces} macro defined above removes all braces and
spaces (recursively) from the tokens following it, till the first
\cs{hfuzz}. The tokens may not contain a \cs{hfuzz} inside braces, but they
may contain expandable material, even with unbalanced conditionals, because
those are left unexpanded by the \cs{noexpand} in \cs{removebraces@nobone}.
The most
important trick here is the \verb+\ifcat{\noexpand#1+ construct, which is
true if \verb+#1+ starts with a brace, and yields \verb+#1+ with its first
brace stripped. \verb+\iffalse}\fi+ is needed so that the macro definition
is nested with respect to braces. The usage of \cs{@firstoftwo} is also
worth mentioning: it is used to change the \cs{removebraces@nobone} token
following the \cs{if} to \cs{removebraces}.

\subsection{Changing \cs{catcode}s safely}\label{pts:catcodes}

\cs{makeatletter} is equivalent to \verb+\catcode 64 12+ on ASCII systems,
which chan\-ges the category code of character having code 64 to 12 (letter).
It is possible to specify the character \texttt{@} without knowing its
character code: \verb+\catcode`@12+. Wherever \TeX{} looks for a number
(after \cs{catcode}, \cs{romannumeral}, \cs{number} and \cs{ifnum} etc.),
it accepts a decimal number, an octal number prefixed by \texttt{'}, a
hexadecimal number with digits \texttt{0-9A-F} prefixed by \texttt{"}, an
internal counter (such as \cs{linepenalty}), a \cs{count} register (such as
\cs{count42} or \cs{@listdepth}) or a character prefixed by \texttt{\string`}.
The character can be specified as a character token, or as a
single-character control sequence. It is wise to specify \verb+{+, \verb+}+,
\verb+%+ and space as \texttt{\string\{}, \texttt{\string\}},
\texttt{\string\%} and \cs{\char32}, respectively, so the whole construct
would be properly nested with respect to braces, and the \verb+%+ and space
tokens won't be ignored.

However, many \nproduct{Babel} language modules (\texttt{.ldf} files)
make the character \texttt{\string`}
active (i.e.\ \cs{catcode} 13), so the definition of \texttt{\string`} gets
expanded in \verb+\catcode`@12+. The expansion can be prevented by
\cs{noexpand}, but \verb+\noexpand`+ yields \texttt{\string`}$_{13}$, which
is wrong, because \texttt{\string`}$_{12}$ is needed, and moreover,
will be expanded in the second run, because \TeX{} is looking for a number.
Fortunately,
\cs{string\string`} solves the problem, because \cs{string} changes the
\cs{catcode} of the following character token to 12 (other) or 10 (space)
(and, if a
control sequence follows, \cs{string} converts it to a series of character
tokens with \cs{catcode} other or space). Thus, the most perfect definition of
\cs{makeatletter} is
\cs{catcode\string\string\string`\string\@11\char32},
which doesn't rely on the previous \cs{catcode} of \texttt{`} or \texttt{@}.
The space at the end of the definition is needed so \TeX{} knows that the
number 11 won't be followed by subsequent digits. Of course, the definition
works only when the characters \texttt{catcodestring} have \cs{catcode}
letter, \verb+\+ is an escape character (\cs{catcode} 0), and space is a
space (\cs{catcode} 10). These are resonable assumptions, because none of
standard \LaTeX{} packages change them.

% The following example shows that the
%expansion cannot be prevented by \cs{noexpand}:
%\begin{verbatim}
%\catcode``13
%\def`#1{64 }
%\catcode\noexpand`+2 % close brace
%@ % ! Too many }'s.
%\end{verbatim}

The \LaTeX{} kernel's definition of \cs{makeatletter} is
\verb+\catcode`\@11\relax+, having \cs{relax} instead of space, which is
equally good to mark the end of a number. This definition doesn't need
\cs{string}, because by the time it is read, the \cs{catcode} of
\texttt{\string`} is guaranteed to be 12 (other).

\nproduct{magyar.ldf} saves the \cs{catcode} of
\texttt{\string` ! \string& + - = | ; : ' " ? /} in the beginning, changes them
to other, and restores them just before \cs{endinput}. This is needed in case
some other \texttt{.ldf}s have been loaded (e.g.\
\verb+\usepackage[french,+\allowbreak\verb+magyar]{babel}+),
which have redefined some \cs{catcode}s. For example, \nproduct{french.ldf}
activates \texttt{! ? ; :}.

It is also a good idea not to change \cs{catcode}s until
\verb+\begin{docu+\allowbreak\verb+ment}+ (not even in \cs{AtBeginDocument}), because other
packages to be loaded may depend on the old, unchanged \cs{catcode}s.
\nproduct{Babel}, unfortunately, activates a character immediately when a
shorthand is defined in a \texttt{.ldf} file, so this can raise strange
compatiblity issues -- part of which can be resolved by loading most of the
packages before \nproduct{Babel}. \nproduct{magyar.ldf} solves the problem by
not touching the \cs{catcode} of its own shorthands at the time of definition,
but calls \cs{bbl@activate} in \cs{extrasmagyar}, and \cs{bbl@deactivate} in
\cs{noextrasmagyar}. This is a local and temporary solution only, future
versions of \nproduct{Babel} are expected to postpone character activation as
far as \cs{@preamblecmds} (see also in subsection \ref{pts:preamblecmds}).

\subsection{Shorthands}

A shorthand is an active character defined by an \texttt{.ldf} file with the
\cs{declare@\allowbreak shorthand} command provided by \nproduct{Babel}.
In this sense, all active punctuation characters (see in subsection
\ref{pts:punctuation}) are shorthands. But the most important shorthand in
\nproduct{magyar.ldf} is \texttt{\string`}$_{13}$. (Most \texttt{.ldf} files
choose that character to be main shorthand, but some files such as
\nproduct{germanb.ldf} choose \texttt{\string"}$_{13}$.) The use of
Hungarian shorthands can be disabled by the \texttt{active=} load option, and
the shorthand character is controlled by the \texttt{activeprefix=} load
option, with the default being \texttt{\string`}$_{13}$.
\nproduct{magyar.ldf} even provides the \cs{shu\string`} command, which is a
longer version of \texttt{\string`}$_{13}$, but without the possibly dangerous
\cs{catcode} change.
Each shorthand is an
active character, which raises compatiblity problems (see more in subsection
\ref{pts:catcodes}). \nproduct{magyar.ldf}
tries as hard as possible avoid problems, but all effort is vanity if
another \texttt{.ldf} file is loaded which activates the same shorthand the
unsafe default way.

For the user a shorthand is a control sequence without a backslash. So a
shorthand is a command that can be typed and read quickly.
\nproduct{germanb.sty} provides \texttt{\string"a} to be equivalent to
\verb+\"a+, saving a keypress for every accented German letter.
\nproduct{magyar.ldf} doesn't provide this save, because the letters
\texttt{o} and \texttt{u} have 3 accented forms, and introducing different
letters for them would lead to confusion. Hungarian \LaTeX{} authors are
encouranged to use the \texttt{latin2} encoding to type accented letters as a
single character.

But the shorthand does an important job concerning (unaccented) long double
consonants, for example \texttt{\string`tty} is an abbreviation for
\verb+t\nobreak\discretio+\allowbreak\verb+nary{y-}{}+\allowbreak\verb+{}ty\nobreak\hskip\z@skip+.
See the reason why this is needed in subsection \ref{pts:longdouble}. It
should be noted that shorthands are implemented as \TeX{} macros, so
\texttt{\string`\char32\csbrace{t}ty} and \texttt{\string`tty} are treated
equivalently.

The shorthand functionality of \nproduct{magyar.ldf} for non-letters are
inspired by \nproduct{ukraineb.ldf}, which contains many of those.
\texttt{\string`=} and \texttt{\string`-}
stand for a hyphen that separates words, so both words are automatically
hyphenated by \TeX{} (the implementation is
\verb+\leavevmode\nobreak-\hskip\z@skip+); \texttt{\string`-} in math mode
stands for a space character following a delimiter
(\verb+\mskip2.4mu plus3.6mu minus1.8+\allowbreak\texttt{mu}) that will magically be exactly as
wide as if a space was inserted outside math mode, because the implicit
\verb+\mskip0.6mu+ after the delimiter is already subtracted;
\texttt{\string`--} emits \verb+\,--\,+, to be used between author names in
Hungarian bibliographies; \texttt{\string`|} emits a hyphen that will be
repeated in the beginning of the next line if the line is broken there
(\verb+\leavevmode\nobreak-\discretionary{}+\allowbreak\verb+{-}{}\nobreak\hskip\z@skip+), to
be used with words having (e.g.\ % important %hyphens
``n\'atrium\leavevmode
\nobreak-\nobreak\discretionary{}{-}{}\nobreak\hskip0pt klorid'') important hyphens;
\texttt{\string`\string_}
inserts a discretionary hyphen with automatic hyphenation enabled at both
sides; \texttt{\string`\string<} inserts a french opening guillemot even if
the ligature \texttt{\string<\string<} is missing from the current font;
\texttt{\string`\string>} inserts its pair; \texttt{\string`\string"} is
equivalent to \cs{allowbreak} with hyphenation enabled at both sides
(implementation: \cs{hskip}\cs{z@skip}); \texttt{\string`\string~} inserts a
hyphen that doesn't form ligatures when repeated
(implementation: \verb+\textormath{\leavevmode\hbox{-}}{-}+).

\subsection{Inserting code to \cs{@preamblecmds}}\label{pts:preamblecmds}

\nproduct{Babel} calls \cs{selectlanguage} to set the default language
\cs{AtBeginDocument}, which is too early in general. Suppose that the default
language redefines some \cs{catcode}s to be used with active characters. All
packages that are loaded after the default language is activated, will contain
characters with unexpected and invalid catcodes. For example, if
\nproduct{hyperref.sty} is loaded after \nproduct{magyar.ldf}, the
\cs{AtBeginDocument} entries of \nproduct{hyperref.sty} contain
\verb+\RequirePackage{nameref}+, which is executed \textsl{after} the entry
\verb+\selectlanguage{magyar}+ of \nproduct{babel.sty}, so
\nproduct{nameref.sty} will be loaded with wrong catcodes, so it won't work.

The solution to this is to postpone the activation of the default language
after the \cs{AtBeginDocument} hooks. This is accomplished by
\nproduct{magyar.ldf} by appending to \cs{@preamblecmds}, which is executed
by the \LaTeX{} kernel in \cs{document} after the \cs{AtBeginDocument} hooks.
But what about the call to \cs{selectlanguage} call inserted to
\cs{AtBeginDocument} by \nproduct{babel.def}? It becomes a no-op, fortunately,
because \nproduct{magyar.ldf} modifies \cs{selectlanguage} to do nothing if
the name of the language (\cs{languagename}) hasn't changed -- and exactly
this is the case when activating the default language. Of course,
\cs{@preamblecmds} has to force the change even with unchanged
\cs{languagename}, so it calls \cs{select@language} (notice the at-sign).

So \nproduct{magyar.ldf} adds \cs{select@language} to \cs{@preamblecmds},
and it also runs \verb+\pagestyle{headings}+ for the relevant document
classes, so \cs{ps@headings} will be executed once more, and the Hungarian
version of the headings, as defined by \nproduct{magyar.ldf}
will get a chance to be installed.


\subsection{Displaying theorem titles}

In English, theorem titles are displayed as ``Theorem 1'', but Hungarian
requires ``1.\ t\'etel.''. To apply the changes, the \cs{@begintheorem} and
\cs{@opargbegintheo\allowbreak rem} macros are redefined each time the Hungarian
language is activated. However, if \nproduct{theorem.sty} or
\nproduct{ntheorem.sty} is loaded, the changes have to be embedded into a
theorem style. The chosen name for the style is \texttt{magyar-plain}. It is
activated by default when \nproduct{magyar.ldf} is loaded, so theorem titles
will come out right unless the user calls \cs{theoremstyle}. When
\nproduct{amsthm.sty} is loaded, \nproduct{magyar.ldf} redefines the macros
\cs{thmhead} and \cs{swappedhead} so both of them will emit the title
properly.

\subsection{Extra symbols \cs{paragraph} titles and description items}

Hungarian typography requires a separator character different from a dot
to be inserted after the \cs{paragraph} title, so the English paragraph start
``\textbf{title}\enskip text'' should be something like
``\textbf{title}\enskip\raise.5ex\hbox{\font\f=msam10 at1.3ex \f\char7}\enskip
text''. \nproduct{magyar.ldf} provides several pre-defined title separation
symbols, selected by the load option \texttt{postpara=};
\texttt{postsubpara=} controls \cs{subparagraph}s and
\texttt{postdescription=} controls \cs{item}s in the description environment.

\nproduct{magyar.ldf} redefines \cs{paragraph} in a really ugly way when
\texttt{postpara=} is active, so that no extra horizontal space is inserted
after the title, but the title ends by the separation symbol. The default
definition of \cs{paragraph} is based on \cs{@startsection}, whose \verb+#5+
is a negative skip, which means a positive horizontal skip after the title.
This is changed to $-1$\,sp by \nproduct{magyar.ldf} to avoid the skip, and
an optional argument is always passed to the original
\cs{paragraph} so the title will be
typeset with the separator.
% %WF ettől a megoldástól kicsit félek, hisz a \paragraph-nak van
% %saját opcionális paramétere, ami így problémát okoz! sőt tán futási
% %hibát is.
% Nem okoz hibát, mert ha az én \paragraph-om kap opcionális paramétert
% (vagy csillagot), akkor azt adja át, értelemszerűen. Kérlek, küldj mintát!

\subsection{Forcing indentation after section titles}

Hungarian typography allows the first paragraph following the section title
to be either indented or unindented, so \nproduct{magyar.ldf} provides the
load option \texttt{afterindent=} to control this. \LaTeX{} calculates the
value of the boolean variable \cs{if@afterindent} from the signedness of a
parameter of \cs{@startsection}, and later uses that boolean to insert or
omit the indentation. The value of the boolean is froced to true by
\nproduct{magyar.ldf} with the simple definition
\verb+\let\@afterindent+\allowbreak\verb+false\@afterindenttrue+.

\subsection{The decimal comma}

The dot character is defined as \emph{ordinary} by default, so decimal real
numbers can be typed simply as \verb+$-12.34$+. In Hungarian, however, the
decimal point is denoted by a comma instead of a dot, but typing
\verb+$-12,34$+ yields ``$-12,34$'' with too much space after the comma,
because the comma is punctiation rather than an ordinary character.
\verb+$-12{,}34$+ yields ``$-12{,}34$'', which is correct, but
\nproduct{magyar.ldf} provides two mechanism to save the two keypresses of
the curly braces around the comma.
The \cs{HuComma}
macro below inserts an ordinary comma if it is followed by a digit, and
an operator comma otherwise:
%
\begin{verbatim}
\edef\hucomma@lowa#1#2 #3#4 #5#6\hfuzz{%
  \noexpand\ifnum9<1#5 \noexpand\if#1t\noexpand\if#3c% (1)
  \noexpand\mathord\noexpand\fi\noexpand\fi\noexpand\fi\mathchar
  \ifnum\mathcode`,="8000 "613B \else\the\mathcode`, \space\fi}
\def\hucomma@lowb{\expandafter\hucomma@lowa
  \meaning\reserved@a/ / /\hfuzz}%
\DeclareRobustCommand\HuComma
  {\futurelet\reserved@a\hucomma@lowb}
\end{verbatim}
%
These macros were inspired by the solution proposed to the comma problem by
Donald Aresenau. In line (1) \cs{hucomma@lowa} tests whether the
\cs{meaning} of the following character is ``the character
$\langle\hbox{digit}\rangle$. A \cs{meaning} is always at least three words,
but it may be more (e.g.\ ``math shift character \$''). Only ``the
character'' starts with letters ``t'' and ``c''. \cs{edef} is needed above
so the \cs{mathchar} emitted doesn't depend on \cs{mathcode} changes after
the definition of \cs{HuComma}.

Then the comma character can be redefined to be \cs{HuComma}:
% %WF to be HELYETT by (?) 
% szerintem `by' rosszabb.
%
\begin{verbatim}
\expandafter\addto\csname \expandafter\ifx\csname mathoptions@on
  \endcsname\relax check@mathfonts\else mathoptions@on\fi
  \endcsname{\catcode`,12 \mathcode`,"8000
  \begingroup\lccode`~`,\lowercase{\endgroup\def~}{\HuComma}}
\end{verbatim}
%
With these definitions, the formula
  ``$F_{i}(x,y)=y^i+1{,}3x,\ x,y \in A,\ i=1,\ 2,\allowbreak 3,\ \ldots$''
can be typed simply as
\verb~$F_{i}(x,y)=y^i+1,3x,\ x,y \in A,~\allowbreak\verb~\ i=1,\ ~\allowbreak\verb+2,\ 3,\ldots$+,
if \cs{\char32} is breakable (such as in \nproduct{nath.sty}).
% %WF ezt nem értem, nem azt kéne írni $i=1,2,3,\ldots$ helyett, hogy
% %WF $i=1, 2, 3,\dots$? A példa így írva nem jó, szövegközi módban nem
% %WF használunk \qquad-ot, javaslatom:
% %WF $F_{i}(x,y)=y^i+1,3x$, $x,y\in A$, $i=1, 2, 3,\dots$.  
% Igen, köszönöm.
%
% %WF ki akartam próbálni a mathhucomma opciót, de nem működött sem a
% %WF mathhucomma=fix, sem a mathhucomma=define, sem a prittiest-tel!
% Nekem működik


The definitions are appended to \cs{mathoptions@on} when \nproduct{nath.sty}
is loaded, and \cs{check@mathfonts} when \nproduct{nath.sty} is missing. The
appropriate macro is run just before \cs{everymath} by \LaTeX{}. Redefining
the \cs{catcode} and \cs{mathcode} this way   ensures that the proper comma
is used inside math mode -- unless the whole math formula is a macro argument
with already assigned \cs{catcode}s. Also not the smart use of
\cs{begingroup}, \cs{lccode}, \cs{lowercase} and \cs{endgroup} to modify the
active meaning of a character without actually activating it.
\verb+\catcode`,13+ before \verb+\def,+ wouldn't help here anyway if the
whole construct is embedded into a macro definition, because \cs{catcode}
wouldn't be able to change an already assigned catcode.

\nproduct{frenchb.ldf} provides the commands \cs{DecimalMathComma} and
\cs{StandardMath\allowbreak Comma} to change the \cs{mathcode} of the comma. However, the
smart comma based on \cs{HuComma} act correctly without the user needing to
be aware of curly braces or redefinitions.

The solution above can be activated with the loading option
\texttt{mathhucomma=\allowbreak fix}. An alternative approach doesn't change
\cs{mathcode}s, but introduces a special math mode in which the dot appears
as a comma only when the Hungarian language is active. Thus the
printout of \verb+\MathReal{-12.34}+ depends on the current \nproduct{Babel}
language. The definition of \cs{MathReal} in \nproduct{magyar.ldf} is similar
to:

\begin{verbatim}
\def\mathreal@lowa#1{\ensuremath{\mathreal@lowb#1%
  \@gobble.}}
\def\mathreal@lowb#1.{%
  #1\@secondoftwo\@gobble% (1)
  {\mathchar"013B \mathreal@lowb}}% comma
\DeclareRobustCommand\MathReal{\ensuremath}%
{\catcode`\ 11\relax\addto\extrasmagyar{%
\babel@save\MathReal %
\let\MathReal \mathreal@lowa}}
\end{verbatim}

The argument of \cs{MathReal} must contain the dot to be changed literally,
outside braces. There is a little macro wizardry in the implementation that
stops calling \cs{mathreal@lowb} infinitely.
\cs{mathreal@lowa} terminates its argument by a sentinel \verb+\@gobble.+,
so \verb+#1+ of \cs{mathreal@lowb} will end by \cs{@gobble}, which
will gobble \cs{@secondoftwo}, so the \cs{@gobble} in line (1) will take
effect, which stops the recursion.

\cs{MathReal} is going to be extended in the future so it will handle
phyisical units following the number properly, and it will also insert thin
spaces after each three digits. This feature has arlready been implemented in
\nproduct{frenchb.ldf}.

\subsection{Parsing dates}\label{pts:stripdot}

There are many correct ways to write dates in Hungarian, and
\nproduct{magyar.ldf} provides the \cs{emitdate} command that can generate
all of these formats. But doing the reverse is a little more interesting.
Let's suppose we have a Gregorian date consisting of a year (4 or 2 digits),
a month (a number or a name) and a day-of-month in some standard format.
% in a token list. %The task is to define
We need the command \cs{parsedate} that will
detect the format, split the date into fields, and call \cs{fixdate}:
\begin{verbatim}
\def\fixdate#1#2#3{%
  \@tempcnta#1 \ifnum#1<50 \advance\@tempcnta2000 \fi
  \ifnum\@tempcnta<100 \advance\@tempcnta1900 \fi
  \typeout{found year=(\@tempcnta) month=(#2) day=(#3)}}
\end{verbatim}

Many dates have an optional dot at the end. Since that dot doesn't carry
useful information, we should remove it first. The
\cs{stripdot} command defined below expands to its argument with the trailing
dot removed. \cs{stripdot} works only if the argument doesn't contain
the token \cs{relax}. \cs{relax} is not special, any other token would have
worked.
\begin{verbatim}
\def\stripdot#1{\expandafter\stripdot@lowb\stripdot@lowa
  #1\relax.\relax}%
\def\stripdot@lowa#1.\relax{#1\relax}%
\def\stripdot@lowb#1\relax#2\relax{#1}%
\end{verbatim}

The definition of \cs{parsedate} is the following:
\begin{verbatim}
\def\parsedate#1{%
  \begingroup
    \def\today{\the\year-\the\month-\the\day}% ISO format
    \let\protect\string
    \let\'\@firstofone% remove accects from Hungarian month names
    \let~\space% change `2003.~okt' to `2003. okt'
    \edef\re@b{\def\noexpand\re@b{#1}}%
  \expandafter\endgroup\re@b
  \edef\re@b{\expandafter\stripdot\expandafter{\re@b}}%
  \let\re@a\@empty \expandafter\parsedate@a\re@b!--!\hfuzz
  \ifx\re@a\@empty \expandafter\parsedate@f\re@b!//:!\hfuzz \fi
  \ifx\re@a\@empty \expandafter\parsedate@b\re@b!//!\hfuzz \fi
  \ifx\re@a\@empty \expandafter\parsedate@c\re@b!..!\hfuzz \fi
  \ifx\re@a\@empty \expandafter\parsedate@d\re@b!. xyz !\hfuzz \fi
  \ifx\re@a\@empty \expandafter\parsedate@e\re@b!xyz , !\hfuzz \fi
  \ifx\re@a\@empty \errmessage{Unrecognised date: \re@b}%
  \else \re@a% call \fixdate
  \fi}
\end{verbatim}

\cs{parsedate} first does some generic cleanup, and puts the resulting date
into \cs{re@b}. \cs{endgroup} cancels the redefinition of \cs{today} etc.,
but \cs{re@b} is expanded first, which defines itself, so the value of
\cs{re@b} will be retained after \cs{endgroup}.
% We have already seen this trick in \ref{pts:endgroup}.
After that, the trailing dot is stripped, and
then various \cs{parsedate@}$\cdots$ commands are run. If one command
recognises the date format, it puts a call to \cs{fixdate} into \cs{re@a},
which will be called at the end of \cs{parsedate}. The strange strings like
\verb+!//:!\hfuzz+ are sentinels.

The idiom \verb+\expandafter\endgroup\re@b+ is an important trick to expand
a macro before the current group completes (and changes are undone). This
extra macro usually contains definitions of other control sequences whose
meaning are about to be retained after the end of the group. An alternative
would be to inject such a definition using \cs{aftergroup}, but it only
accepts a single token, so it would be very painful to make a macro
definition with spaces and braces survive this way.
% Dat: MetaPost needs explicit save 

The individual \cs{parsedate@}$\cdots$ commands are the following:
\begin{verbatim}
\def\parsedate@a#1-#2-#3!#4\hfuzz{% ISO date: YYYY-MM-DD
  \ifx\hfuzz#4\hfuzz\else \ifnum1<1\string#1\relax
  \ifnum1<1\string#2\relax \ifnum1<1\string#3\relax
  \def\re@a{\fixdate{#1}{#2}{#3}}%
  \fi\fi\fi\fi}
\def\parsedate@b#1/#2/#3!#4\hfuzz{% LaTeX date: YYYY/MM/DD
  \ifx\hfuzz#4\hfuzz\else \ifnum1<1\string#1\relax
  \ifnum1<1\string#2\relax \ifnum1<1\string#3\relax
  \def\re@a{\fixdate{#1}{#2}{#3}}%
  \fi\fi\fi\fi}
\def\parsedate@c#1.#2.#3!#4\hfuzz{% English date: YYYY.DD.MM
  \ifx\hfuzz#4\hfuzz\else \ifnum1<1\string#1\relax
  \ifnum1<1\string#2\relax \ifnum1<1\string#3\relax
  \def\re@a{\fixdate{#1}{#3}{#2}}%
  \fi\fi\fi\fi}
% vvv English and Hungarian month names
\def\mon@jan{1} \def\mon@feb{2} \def\mon@mar{3} \def\mon@apr{4}
\def\mon@maj{5} \def\mon@may{5} \def\mon@jun{6} \def\mon@jul{7}
\def\mon@aug{8} \def\mon@sze{9} \def\mon@sep{9} \def\mon@okt{10}
\def\mon@oct{10} \def\mon@nov{11} \def\mon@dec{12}
\def\parsedate@d#1. #2#3#4#5 #6!#7\hfuzz{% {2003. oktober 25}
  \ifx\hfuzz#7\hfuzz\else
    % now: {#1}=={2003}, {#2#3#4#5}=={oktober}, {#6}=={25}
    \ifnum1<1\string#1\relax \ifnum1<1\string#6\relax
      \lowercase{%
        \expandafter\ifx\csname mon@#2#3#4\endcsname\relax\else
        \edef\re@a{\noexpand\fixdate{\number#1}{%
          \csname mon@#2#3#4\endcsname}{\number#6}}\fi}%
  \fi\fi\fi}
\def\parsedate@e#1#2#3#4 #5, #6!#7\hfuzz{% {October 25, 2003}
  \ifx\hfuzz#7\hfuzz\else
    \ifnum1<1\string#5\relax \ifnum1<1\string#6\relax
      \lowercase{%
        \expandafter\ifx\csname mon@#1#2#3\endcsname\relax\else
        \edef\re@a{\noexpand\fixdate{\number#6}{%
          \csname mon@#1#2#3\endcsname}{\number#5}}\fi}%
  \fi\fi\fi}
\def\parsedate@f#1/#2/#3:#4!#5\hfuzz{% LaTeX default \today
  % YYYY/MM/DD:XX:YY
  \ifx\hfuzz#5\hfuzz\else \ifnum1<1\string#1\relax
  \ifnum1<1\string#2\relax \ifnum1<1\string#3\relax
  \def\re@a{\fixdate{#1}{#2}{#3}}%
  \fi\fi\fi\fi}
\end{verbatim}
\vskip0pt plus 30pt \hrule height 0pt % Dat: avoid `Underfull \hbox'

This implementation of date parsing isn't error-proof. If something weird
is passed to \cs{parsedate}, it may produce surprising \TeX{} errors.
However, \cs{parse\allowbreak date} can distinguish between different formats
of correct input.

\subsection{Setting up french spacing}

Hungarian typography requires \cs{frenchspacing} turned on,
but most \LaTeX{} users don't seem to follow this requirement.
\nproduct{Babel} provides the \cs{bbl@frenchspa\allowbreak cing} command, which turns
french spacing on if it was off. The \texttt{frenchspacing=} load option
of \nproduct{magyar.ldf} controls how Hungarian text should behave.
For the sake of symmetry, \nproduct{magyar.ldf} provides
\cs{@@magyar@antifrenchspacing}, % too,
which -- contrary to the
typographical requirement -- turns french spacing off:
%
\begin{verbatim}
\def\@@magyar@antifrenchspacing{%
  \ifnum\the\sfcode`\.=\@m
    \nonfrenchspacing
    \let\@@magyar@nonfrenchspacing\frenchspacing
  \else \let\@@magyar@nonfrenchspacing\relax \fi}
\let\@@magyar@@nonantifrenchspacing\frenchspacing
\addto\extrasmagyar{\@@magyar@antifrenchspacing}
\addto\noextrasmagyar{\@@magyar@nonantifrenchspacing}
\end{verbatim}

\subsection{\nproduct{varioref.sty} fixes}\label{pts:varioref}

The \texttt{magyar} load option of \nproduct{varioref.sty} (2001/09/04 v1.3c)
is buggy, because it uses the never defined \cs{aza} command for adding
definite articles, and it also calls \cs{AtBeginDocument} too late, producing
a \LaTeX{} error each time the Hungarian language is activated.
\nproduct{magyar.ldf} contains the correct definitions for the
language-specific text reference macros, such as \cs{reftextlabelrange}, and
also contains ugly fixup code to remove the wrong macros inserted by
\nproduct{varioref.sty}. A patch has been sent recently to the author of
\nproduct{varioref.sty}.

Some of these text reference macros use the \cs{az} and the \cs{told} commands
defined by \nproduct{magyar.ldf}.

\subsection{Removing the full stop after section titles in AMS classes}

AMS document classes always append a full stop after section titles, which is
strictly forbidden in Hungarian typography. The solution is to remove the
tokens \verb+\@addpunct.+ from the definition of \cs{@sect} (and also from
\cs{NR@sect} in case \nproduct{nameref.sty} has also been loaded). But this
simple idea is quite complicated to program, and the result is ugly:
%
\begin{verbatim}
\expandafter\amssect@fixa\@sect[][][][][][][][]%
  \global\@nobreaktrue\@xsect\hfuzz\@sect
\expandafter\amssect@fixa\@sect[][][][][][][][]%
  \global\@nobreaktrue\@xsect\hfuzz\NR@sect% with nameref.sty
\long\def\amssect@fixa#1\global\@nobreaktrue\@xsect#2\hfuzz#3{%
  \ifx\hfuzz#2\hfuzz\else\amssect@fixb#3\fi}% fix if found
\def\amssect@fixb#1{% #1 is \@sect or \NR@sect
  \expandafter\let\csname amssect@saved\string#1\endcsname#1%
  \edef#1{\noexpand\expandafter\noexpand\amssect@low\expandafter
    \noexpand\csname amssect@saved\string#1\endcsname}%
  \let\@svsechd\@empty% prevent Undefinded \cs
  \long\def\amssect@low##1\global\@nobreaktrue{##1%
    \expandafter\def\expandafter\@svsechd\expandafter{%
      \expandafter\let\expandafter\@addpunct\expandafter\@gobble
      \@svsechd}%
    \global\@nobreaktrue}}
\end{verbatim}
%
\noindent This detects AMS classes by the
presence of \verb+\global\@nobreaktrue\@xsect+ in the definition of
\cs{@sect}, and adds code just before \cs{@xsect}. The code added prepends
\verb+\let\@addpunct\@gobble+ to the definition of \cs{@svsechd}.
\cs{@svsechd} is later called by \cs{@xsect}, which calls \cs{@addpunct}, but
by that time \cs{@addpunct} %\texttt{.}
is a no-op. The application of this fix
is controlled by the \texttt{amspostsectiondot=} load option.

\subsection{Reduced math skips}

Investigations in \cite{bwfinal} have shown that the following settings
produce the desired space in Hungarian math mode:
%
\begin{verbatim}
\thickmuskip 4mu plus  2mu minus4mu % LaTeX: 5mu plus5mu
\medmuskip   2mu plus1.5mu minus2mu % LaTeX: 4mu plus2mu minus4mu
\thinmuskip  3mu % LaTeX: ditto
\end{verbatim}
%
\noindent Notice that $\hbox{\cs{medmuskip}}<\hbox{\cs{thinmuskip}}$.
These settings can be selected in \nproduct{magyar.ldf} with the load option
\texttt{mathmuskips=}. The difference between the original and the reduced
spacing:
$$\hbox{$
\thickmuskip 5mu plus5mu
\medmuskip   4mu plus2mu minus4mu
\thinmuskip  3mu
a+b-c/d*y\circ x=z$}\quad\quad\hbox{$
\thickmuskip 4mu plus  2mu minus4mu
\medmuskip   2mu plus1.5mu minus2mu
\thinmuskip  3mu
a+b-c/d*y\circ x=z$}$$

\subsection{Breaking a long inline math formula}

Hungarian typography requires that a binary relation or operator
(e.g.\ in $
1+\nobreak\discretionary{}{\hbox{\(+\)}}{}
2=\nobreak\discretionary{}{\hbox{\(=\)}}{}
3+\nobreak\discretionary{}{\hbox{\(+\)}}{}
4)$ must be
repeated in the next line if an inline math formula is broken there. This can be accomplished
for the equation sign by substituting
\verb/=\nobreak\discretionary{}{\hbox{\(=\)}}{}/ for \verb/=/ in math
formulas. The long inline formula delimiters \cs{(} and \cs{)} are used
because the catcode of the \verb+$+ would be wrong if \nproduct{nath.sty} was
loaded after \nproduct{magyar.ldf}. \cs{nobreak} is necessary, so \TeX{}
itself won't break the line after the ``$=$''.

The \texttt{mathbrk=} load option of \nproduct{magyar.ldf} controls whether
the operators and relations should be redefined. If so, the operators
$+$, $-$, $*$ (as well as 37 operators available as control sequences)
and the relations $<$, $>$, $=$, $:$
(as well as 43 relations available as control sequences) are modified so 
they get repeated at the beginning of the line. The \cs{cdot} and the
\cs{slash} operators are also modified, because Hungarian typography disallows
breaking the line around them.

\subsection{Restarting footnote numbering on each page}

Although \verb+\usepackage[perpage]{footmisc}+ and
\nproduct{footnpag.sty} provide these features, \nproduct{magyar.ldf} allows
normal arabic footnote and page-restarting asterisk-footnotes to be
intermixed. It is common in Hungarian article collections to have the notes
of the author numbered in arabic (by \cs{footnote}), and the footnotes of
the editor added with asterisks (by \cs{editorfootnote}). The first four
editorial footnotes on a page are marked with
\textsuperscript{*},
\textsuperscript{**},
\textsuperscript{***},
and \textsuperscript{\dag}.
% and -- to avoid the many stars -- a numbering is started from \textsuperscript{*4}.
\nproduct{magyar.ldf} also inserts proper additional space
between the footnote mark and the footnote text, and the footnote facility
is fully customizable with the \cs{footnotestyle} command.

The basic idea behind the implementation of pagewise numbering is creating a
\cs{label} for each footnote, and whenever the \cs{pageref} for that label
shows a different page, resetting the counter to zero. This clobbering
can be automated by abusing the \cs{cl@footnote} hook. Each time
\cs{stepcounter} advances a counter, the corresponding \cs{cl@...} hook is
called, which usually resets other counters (for example, advancing the
chapter counter resets the section counter). But arbitrary code can be
executed after the automatic \verb+\stepcounter{footnote}+ by appending that
code to the macro \cs{cl@footnote}.

The famous problem of creating a macro that will expand to $n$ asterisks is
proposed in chapter D of the \TeX{}book (\cite{texbook}). David Kastrup has provided a
brilliant solution to the problem in \cite{macro-virt}:
\verb+\expandafter\mtostar\romannumeral\number+$n$\allowbreak\verb+000A+, where \cs{mtostar}
transforms \texttt{m}s to asterisks:
\verb+\def\mtostar#1{\if#1m*\ex+\allowbreak\verb+pand+\allowbreak\verb+after+\allowbreak\verb+\mtostar\fi}+.
This solution is used in \nproduct{magyar.ldf}.

\nproduct{magyar.ldf} provides the following command to insert footnotes into
section titles, so neither the table of contents, nor the page headings will
be affected:
\begin{verbatim}
\def\headingfootnote{%
  \ifx\protect\@typeset@protect\expandafter\footnote
  \else\expandafter\@gobble\fi
\end{verbatim}

\subsection{Class-specific modifications}

\nproduct{magyar.ldf} does some modifications based on the current document
class (using the \cs{@ifclassloaded} \LaTeX{} command). Only the standard
classes \nproduct{article.cls}, \nproduct{report.cls}, \nproduct{book.cls}
and \nproduct{letter.cls} are supported now. The visual appearance
of the \cs{part} and \cs{chapter} commands are changed, and the page headers
are also modified. For \nproduct{book.cls}, part numbering is spelled out, so
``Part 1'' becomes ``Els\H{o} r\'esz'' (meaning ``Part One'') if the load
option \texttt{partnumber=Huordinal} is active. The command
\cs{ps@headings} has to be executed again to install its changed heading
macros. This is called after \cs{AtBeginDocument} hooks from
\cs{@preamblecmds}, after the default language has been activated
(see in subsection \ref{pts:preamblecmds}).

The typographically correct
customization of \nproduct{letter.cls} is under development.

\subsection{Spelling out numerals and ordinals}

The \cs{@hunumeral} and \cs{@huordinal} macros defined in
\nproduct{magyar.ldf} can spell out integers between $-9999$ and $9999$.
\cs{@Hunumeral} and \cs{@Huordinal} are the capitalized versions of these
macros.  For example, \verb+\@huordinal{2004}+ yields ``k\'ete\-zer-negyedik''
(meaning: two thousand and fourth), and \verb+\@Hunumeral{2004}+ yields
``K\'etezer-n\'egy'' (meaning: Two thousand and four). All these macros
are fully expandable, so they can be used for \cs{part} numbering:
\verb+\def\thepart{\@Hu+\allowbreak\verb+ordinal\c@part}+, or more simply:
\verb+\def\thepart{\Huordinal{part}}+.

The most important implementation issue is the method to retrieve the last
digit of a number in an expandable construct. If the number is between 
$0$ and $9999$, the following macro solves the problem:
%
\begin{verbatim}
\def\LastDigitOf#1{\expandafter\lastdigit@a\number#1;}%
\def\lastdigit@a#1;{% #1 in 0..9999
  \ifnum#1<10 #1\else\ifnum#1<100 \lastdigit@b00#1%
  \else\ifnum#1<1000 \lastdigit@b0#1\else\lastdigit@b#1\fi
\def\lastdigit@b#1#2#3#4{#4}
\end{verbatim}

\subsection{Suffix generation}

The Hungarian language doesn't have prepositions for representing relations
in space and time, but it has suffixes to be appended to the end of the word
for the same purpose. For example, an English maths text might contain
``It follows from (1)'', in which ``from (1)'' can be typed as
\verb+from (\ref{eq1})+. The \LaTeX{} referencing scheme guarantees that the
text above will come out right, even if the order of equations is changed in
the document. But in Hungarian, the suffix standing in place of ``from''
has two forms: \emph{-b\'ol/-b\H{o}l}, depending on the vowel harmony of the
pronounciation of \verb+\ref{eq1}+. So there is a need for automatic suffix
generation. \nproduct{magyar.ldf} provides the command \cs{told}, with which
the Hungarian version of ``from (1)'' can be typed as
\verb/\told(\ref{eq1})+bol{}/, which will generate ``(1)-b\H{o}l'',
% %WF \verb/(\told\ref{eq1})+bol{}/ LEMARADT A ZÁRÓJEL!!
% Kösz, javítva.
``(2)-b\H{o}l'', but ``(3)-b\'ol''.

\cs{told} knows about 20 different suffixes, and $4\cdot 20$ suffix
combinations (such as \verb/\told3+adik+ra{}/, meaning: to the third).
Only the last number is considered of references containing multiple numbers.
Roman numbers are recognised properly in references with the help of
\cs{hunnewlabel} (see in subsection \ref{pts:hunnewlabel}) -- this is
implemented similarly as with \cs{az}. Suffix generation is supported only
for integers and Hungarian document structure names (see in subsection
\ref{pts:refstruc}), because writing a generic suffix generator that doesn't
need a database is quite a difficult task, and definitely won't give
Hungarian \LaTeX{} users much
more comfort beyond the current \cs{told} implementation.

Although most Hungarian suffixes has 1, 2 or 3 forms,\footnote{Of course,
suffixes with only one form are not supported by \cs{told}.}
numbers can be classified into 23 paradigm classes, so that the paradigm
class uniquely determines the correct form of all known suffixes. The reason
why there are so many classes, is because the letter ``v'' of the
\emph{-val/-vel} suffix must be also changed to the last letter of the number
if that letter is a consonant. So, essentially each final digit has a
class, and there are classes for the powers of 10, and some of the numbers
$20$, $30$ \ldots $90$ also have their own classes. Adding up all these, the
final number 23 is reasonable. So it is true that the suffix of a number
depends on the last nonzero digit, and the number of trailing zeroes.

The implementation of \cs{told} is suprisingly long and ugly, full of
recursive macros that parse the input; and doesn't contain bright new ideas
not found elsewhere in \nproduct{magyar.ldf}.
The curious \TeX{} hacker should study \cs{az} instead, because it is shorter
and it trick density is much higher.

\subsection{Warning messages}

\nproduct{magyar.ldf} has a unique feature that it displays warning messages
(called ``suggestions'') at load time to notify the user that they are using
\nproduct{magyar.ldf} in a possibly wrong way. If they are not
disabled by the \texttt{suggestions=} load option, are following suggestions
displayed on the terminal during the \cs{AtBeginDocument} hook:

\begin{itemize}

\item the user forgot to load \verb+\usepackage{t1enc}+ -- so words with
accented letters won't by hyphenated automatically;

\item the user forgot to load \verb+\usepackage[latin2]{inputenc}+, or the
input encoding chosen is not \texttt{latin2}, \texttt{cp1250} or
\texttt{utf8} -- so there is a high chance that accented characters disappear
or come out wrong;

\item the Hungarian hyphenation patterns requested were not found --
\nproduct{magyar.ldf} tries using the other 2 possible Hungarian patterns, if
they are available;

\item \cs{def}\cs{magyarOptions} or
\cs{PassOptionsToPackage}\verb+{...}{magyar.ldf}+ was specified too late --
late options can be detected, but they have no effect, since options do their
work while \nproduct{magyar.ldf} is being \textsl{loaded};

\item the buggy \nproduct{varioref.sty} has been loaded as
\verb+\usepackage[magyar]{varioref}+ -- this happens until the patch is
integrated to \nproduct{varioref.sty}, the current version is so buggy that
it displays an untracable \LaTeX{} error each time the Hungarian language is
activated (see in subsection \ref{pts:varioref}).

\end{itemize}

\section{Miscellaneous tricks}

First we introduce some
common expansion tool macros defined by \LaTeX{}:
\begin{verbatim}
\def\@empty{}
\long\def\@gobble#1{}
\long\def\@gobbletwo#1#2{}
\long\def\@firstofone#1{#1}
\long\def\@firstoftwo#1#2{#1}
\long\def\@secondoftwo#1#2{#2}
\end{verbatim}

\cs{@firstofone} differs from \cs{@empty}, because it may not be followed
by \verb+}+, it ignores spaces in front of its argument, and it
removes at most one pair of braces around its argument. All of these
properties are consequences of the macro expansion rules described in
chapter 20 of The \TeX{}book (\cite{texbook}).

This section contains \TeX{} macro and typesetting tricks not tightly related
to the Hungarian language.

\subsection{The factorial sign in math mode}

\def\factorial{\mathchar"5021\mathopen{}\mathinner{}}

\nproduct{nath.sty} contains a smartest definition of the factorial
operator, so $(a+b){\factorial}/a\factorial b\factorial+c\factorial\cdot
d\factorial$, with proper spacing can be typed as
\verb|$(a+b){!}/a!b!+c!\cdot d!$|. The only place where braces were needed is
before the slash. \nproduct{magyar.ldf} adapts the definition:
%
\begin{verbatim}
\def\factorial{\mathchar"5021\mathopen{}\mathinner{}}
\expandafter\addto\csname \expandafter\ifx
  \csname mathoptions@on\endcsname\relax% detect nath.sty
  check@mathfonts\else mathoptions@on\fi\endcsname{%
  \catcode`!12 \mathcode`!"8000
  \begingroup\lccode`~`!\lowercase{\endgroup\def~}{\factorial}}
\end{verbatim}

\subsection{Including the structure name in references}\label{pts:refstruc}

Texts like ``in subsection~5.6'' are usually typed as
\verb+in subsection~\ref{that}+. But it would be nice if \LaTeX{} would be
able to guess that the place \verb+\ref{that}+ points to is actually a
subsection. The structure depth can be deduced by counting the dots in the
reference: a subsection has one dot (in an article), and a subsubsection has
two dots.
\nproduct{magyar.ldf} provides the \cs{refstruc} command which has a smarter
detection scheme: it changes all roman and arabic numbers to one (\texttt{1},
\texttt{i} or \texttt{I}) in the
reference, and compares the result with the tokens generated by
\cs{thechapter}, \cs{thesection} etc., with \cs{c@chapter} etc. set to $1$
temporarily. This should work in most cases, although it cannot refer to
equations, tables or figures. In Hungarian text, the Hungarian structure
names are emitted, and other texts the original, English control
sequence names are printed. \cs{refstruc} supports the definite article and
suffixes, so for example \verb/\Az{\refstruc{that+tol}}/ may emit
``az 1.\ fejezett\H{o}l'' (meaning: from chapter 1).

The full implemenatation is quite long, and is not included here, but the
macro that changes all roman and arabic numbers to one is presented:
%
\begin{verbatim}
\def\NumbersToOne#1{\nonumbers@a#1\hfuzz}
\def\nonumbers@skipa#1\nonumbers@s{#1\nonumbers@a}
\def\nonumbers@a#1{% change first digit
  \ifx#1\hfuzz \expandafter\@gobble
  \else\if1<1\string#11\else\if\noexpand#1mi\else\if\noexpand#1di%
  \else\if\noexpand#1ci\else\if\noexpand#1li\else\if\noexpand#1xi%
  \else\if\noexpand#1vi\else\if\noexpand#1ii\else\if\noexpand#1MI%
  \else\if\noexpand#1DI\else\if\noexpand#1CI\else\if\noexpand#1LI%
  \else\if\noexpand#1XI\else\if\noexpand#1VI\else\if\noexpand#1II%
  \else\noexpand#1\nonumbers@skipa
  \fi\fi\fi\fi\fi\fi\fi \fi\fi\fi\fi\fi\fi\fi\fi\fi \nonumbers@s}
\def\nonumbers@s#1{% gobble next digits
  \ifx#1\hfuzz \expandafter\@gobble
  \else\if1<1\string#1\else\if\noexpand#1m\else\if\noexpand#1d%
  \else\if\noexpand#1c\else\if\noexpand#1l\else\if\noexpand#1x%
  \else\if\noexpand#1v\else\if\noexpand#1i\else\if\noexpand#1M%
  \else\if\noexpand#1D\else\if\noexpand#1C\else\if\noexpand#1L%
  \else\if\noexpand#1X\else\if\noexpand#1V\else\if\noexpand#1I%
  \else\noexpand#1\nonumbers@skipa
  \fi\fi\fi\fi\fi\fi\fi \fi\fi\fi\fi\fi\fi\fi\fi\fi \nonumbers@s}
\end{verbatim}

\subsection{Enabling long page numbers}

If the with of a page number is longer than \cs{@pnumwidth} in the table of
contents, \LaTeX{} emits an ``Overfull \cs{hbox}'' warning. This can be got
rid of by changing \cs{@dottedtocline} defined in the \LaTeX{} kernel. The
line
%
\begin{verbatim}
\hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
\end{verbatim}
%
\noindent should be changed to
%
\begin{verbatim}
\setbox\@tempboxa\hbox{\normalfont \normalcolor #5}%
\ifdim\wd\@tempboxa<\@pnumwidth\setbox\@tempboxa
  \hb@xt@\@pnumwidth{\hfil\unhbox\@tempboxa}\fi
\box\@tempboxa
\end{verbatim}

Although this change isn't related to the Hungarian language,
\nproduct{magyar.ldf} can be asked to do it with the \texttt{dottedtocline=}
load option.

\subsection{Removing AMS warnings from \cs{listoftables}}

Some AMS document classes (such as \nproduct{amsart.cls}) produce an
``Overfull \cs{hbox}'' warning for each
line in the \cs{listoftables} and \cs{listoffigure}. This can be fixed by
changing \verb+\@tocline{0}{3pt plus 2pt}{0pt}{}{}{}+
to       \verb+\@tocline{0+\allowbreak\verb+}{3pt plus 2pt}{0pt}{}{\parindent}{}+ in
\cs{l@table} and \cs{l@figure} defined by the classes. The
following code does the change:
%
\begin{verbatim}
\ifnum 0<%
  \expandafter\ifx\csname setTrue\endcsname\relax\else1\fi
  \expandafter\ifx\csname allowttyhyphens\endcsname\relax\else1\fi
\space
  \def\amsfix#1#2#3#4#5#6#7\vfuzz{%
    \def\reserved@a{#6}%
    \ifx\@tocline#2\ifx\reserved@a\@empty%
      \def#1{\@tocline{#3}{#4}{#5}{\parindent}{}}%
    \fi\fi}
  \expandafter\amsfix\expandafter\l@table \l@table ,,,,,,,\vfuzz
  \expandafter\amsfix\expandafter\l@figure\l@figure,,,,,,,\vfuzz
\fi
\end{verbatim}
%
Control sequences \cs{setTrue} or \cs{allowttyhyphens} are defined by each of
the AMS document classes, so their presence indicates that one of those
classes are loaded. The logical or operation using \cs{ifx}s nested to the
\cs{ifnum} test is also worth noting.

% Dat: easy trick removed to conserve space
%\subsection{Undefining a control sequence}
%
%\verb+\let\foo\@undefined+
%
%This only works when \cs{@undefined} is undefined, which is so in \LaTeX{}.
%In the examples of this article,
%the character \texttt{@} is allowed to be part of control
%sequences (because it has \cs{catcode} 12 (letter)). This is the
%default behaviour in \LaTeX{} class and package files, but not in documents.
%The \LaTeX{} \cs{makeatletter} command can be used in documents to
%change the \cs{catcode} of \texttt{@} to letter.

% Dat: easy trick removed to conserve space
%\subsection{Testing whether a control sequence is defined}
%
%The test can be accomplished by
%\verb+\ifx\csname foo\endcsname\relax ...\fi+, as it is implemented in
%\cs{@ifunde\allowbreak fined} of the \LaTeX{} kernel, or \cs{ifx}\cs{foo}\cs{@unde\allowbreak fined}, but
%this depends on the definedness of \cs{@undefined}. It is important to know
%that \verb+\csname foo\endcsname+ does a \verb+\let\foo\relax+ if \cs{foo}
%was undefined.

% Dat: removed, because had at other places
%\subsection{Changing the definition of an active character}
%\verb+\begingroup\lccode`~`!\lowercase{\endgroup\def~}{\foo}+

% Dat: easy trick removed to conserve space
%\subsection{Detecting a short argument}
%\begin{verbatim}
%% vvv Wizadry: length(#1) < 2, use macro arg to remove braces
%\expandafter\ifx\expandafter\@empty\@gobble#1\@empty\@empty
%% vvv Wizadry: length(#1) = 1, use macro arg to remove braces
%\expandafter\ifx\expandafter\@empty\@gobble#1\@empty\@gobble.%
%\end{verbatim}

% Dat: easy trick removed to conserve space
%\subsection{Equality order}
%
%\verb+\ifx\hfuzz#1+ is better than
%\verb+\ifx#1\hfuzz+ is wrong, because it is true if \verb+#1+ begins with
%the same two tokens. The correct solution is:
%\verb+\ifx\hfuzz#1+, which has a side effect: if \verb+#1+ begins with
%\cs{hfuzz}, that token will be discarded, but other tokens will be emitted.

% \subsection{Robust commands}

\subsection{Conditionally discarding the rest of the file}

The na\"ive solution \verb+\ifskiprest\endinput+$\P$\verb+\fi+ yields the \TeX{} error
message ``\cs{end} occurred when \cs{iftrue} in line $n$ was incomplete''
if there is a line break at the $\P$ sign. Without the line break, the na\"ive
solution works perfectly, because \cs{endinput} stops reading the current file
\textsl{after} the current line, so the \cs{fi} also gets evaluated.

% vvv Dat: \expandafter is superfluous:
%But in the following solution \cs{expandafter} evaluates the
%\cs{endinput} primitive
%before \cs{fi}. \cs{endinput} 
%\begin{verbatim}
%\newif\ifskiprest
%...
%\ifskiprest \expandafter\endinput\fi
%\end{verbatim}

It is possible to do some action before \cs{endinput}:
%
\begin{verbatim}
\expandafter\ifx\csname ver@foo.sty\endcsname\relax
  \endinput \errmessage{I am incompatible with foo.sty}\fi
\end{verbatim}

All the action above must be put after \cs{endinput} without a line break.
The \verb+\csname fi\endcsname+ construct closes the \cs{ifx} when the
condition is true, but is invisible when the condition is false, and
\TeX{} is skipping tokens.

The \cs{@ifpackageloaded} macro of the \LaTeX{} kernel implements the
conditional stop with a different trick. The following two constructs are
equivalent: \verb+\@ifpackageloaded{foo}{\endinput\errmessage{I+ \verb+am incompatible with+\ \allowbreak
\verb+foo.sty}}{}+ and
%
\begin{verbatim}
\expandafter\ifx\csname ver@foo.sty\endcsname\relax
      \expandafter\@gobble
\else \expandafter\@firstoftwo \fi
{\endinput
\errmessage{I am incompatible with foo.sty}}
\end{verbatim}
%
\noindent In the trick above, \cs{errmessage} isn't in the same line as \cs{endinput}.
This isn't a problem, because by the time \cs{endinput} is evaluated by
\TeX{}'s stomach, \cs{errmessage} has been read from the file, and it is
already on the input stack. \cs{endinput} doesn't discard the input stack,
it just prevents more lines to be read from the current file.

\subsection{Typesetting text verbatim}

\cs{catcode}s are assigned when \TeX{}'s eyes read the next
character from the current line. Thus a \cs{catcode} command affects all
subsequent characters of the current line, as well as the following lines.
But once a category code has been assigned, it won't be affected by
\cs{catcode} commands. For example,
\verb+\@firstofone{\cat+\allowbreak\verb+code`A 14 AAA}+
makes \texttt{A} a comment starter character, but it emits three
\texttt{A}s, because the category code of the three \texttt{A}s has already
been assigned by the time \cs{catcode} is evaluated. The reason why the
\cs{verb} command of the \LaTeX{} kernel cannot be part of a macro argument
is the same: \cs{verb} changes the \cs{catcode} of most characters to other,
but these changes have no effect inside a macro argument, because the
argument has been read from the input file by the time \cs{catcode} can take
effect.

A verbatim macro can be based on the \cs{meaning} primitive instead of
changing \cs{catcode}s, so this macro can be a part of macro arguments,
but \TeX{}'s eyes has destroyed some information such as comments and the
exact number of successive spaces by the time \cs{meaning} is
expanded. For example, these definitions are from \nproduct{binhex.dtx}:

\begin{verbatim}
\def\verbatize#1{\begingroup
  \toks0{#1}\edef\next{\the\toks0}%
  \dimen0\the\fontdimen2\font  \fontdimen2\font=0pt
  \expandafter\stripit \meaning\next
  \fontdimen2\font=\dimen0 \endgroup}
\def\next{}
\expandafter\def\expandafter\stripit\meaning\next{}
\end{verbatim}

\subsection{Stopping the iteration}

Let's suppose we need a macro that capitalizes all ``a'' and ``b''
till the first ``.'':

\begin{verbatim}
\def\ucab#1{%
  \if\noexpand#1.\expandafter\@gobble
  \else\if\noexpand#1aA%
  \else\if\noexpand#1bB%
  \else\noexpand#1%
  \fi\fi\fi\ucab}
\message{\ucab abc.abc} % -> ABcabc
\end{verbatim}

\cs{noexpand} prevents expansion of \verb+#1+ in case it is an expandable
control sequence such as \cs{the} or a macro. If \cs{if} is changed to
\cs{ifx}, then not only the character codes, but the category codes would be
compared.

The trick that stops the iteration
here is that \cs{expandafter} expands the first \cs{else} that
will remove everything up to the last \cs{ucab}. Then comes \cs{@gobble},
which removes \cs{ucab}, thus the iteration is stopped.

The construct
doesn't work when \verb+#1+ had braces around it, or it is \cs{if...},
\cs{else} or \cs{fi}. Also, spaces will be ignored because of macro
expansion.

But what if we'd like to capitalize only the \textsl{first} ``a'' or ``b''?
Then we would need \verb+\expandafter\expandafter\expandafter\@gobble+
after ``A'', and 7 \cs{expandafter}s after ``B''. But
\cs{expandafter} can be completely avoided using a different approach,
based on macro arguments:

\begin{verbatim}
\def\helpif#1#2{#1\@firstoftwo}
\def\ucabs#1{%
   \if\noexpand#1.\helpif\fi\@secondoftwo{}
  {\if\noexpand#1a\helpif\fi\@secondoftwo{A}
  {\if\noexpand#1b\helpif\fi\@secondoftwo{B}
  {\noexpand#1\ucabs}}}%
}\message{\ucabs cbbas} % -> cBbas
\end{verbatim}

It is not possible to move \cs{fi} into the definition of \cs{helpif},
because then \TeX{} won't see that \cs{fi} when it is skipping the whole
\cs{if} \ldots{} \cs{helpif}. With a small rearrangement we can get rid of
\cs{@secondoftwo}:

\begin{verbatim}
\@gobble{\iftrue\iftrue} % \def\helpjf... contains 2*\fi
\def\helpjf#1\fi{#1\expandafter\@firstoftwo
  \else\expandafter\@secondoftwo\fi}
\def\ucabj#1{%
   \helpjf\if\noexpand#1.\fi{}
  {\helpjf\if\noexpand#1a\fi{A}
  {\helpjf\if\noexpand#1b\fi{B}
  {\noexpand#1\ucabs}}}%
}\message{\ucabj cdabs} % -> cdAbs
\end{verbatim}

The line containing \cs{@gobble} above is needed so that \verb+\def\helpjf+
can be put inside \cs{iffalse} \ldots{} \cs{fi}, and \TeX{}'s \cs{fi} count
won't decrease when seeing the two \cs{fi} tokens in the definition of
\cs{helpjf}.

\subsection{Appending tokens to a macro}

\TeX{} doesn't provide primitives for modifying to expansion text of a macro,
but it is possible to define a new macro with the contents of the old one and
some new tokens. For example, \hskip0pt minus1pt
\verb+\expandafter\def\expandafter\foo+\allowbreak\verb+\expandafter{\foo+\allowbreak
\verb+\iffalse$}+
appends the two tokens \verb+\iffalse$+ to the macro \cs{foo}. Three
\cs{expa\allowbreak ndafter}s were used to make the old \cs{foo} only expanded once. None
of the above tokens were expanded, fortunately. Any tokens can be
appended this way, if they are nested with respect to braces. But care has to
be taken with doubling \verb+#+s:
%
\begin{verbatim}
\def\AppendTo#1#2{\expandafter\def\expandafter
  #1\expandafter{#1#2}}
\def\foo{} \AppendTo\foo{#}
\end{verbatim}
%
yields the \TeX{} error ``Illegal parameter number in definition of
\cs{foo}''. This can be solved by using token list registers, who double
their hashmarks when being expanded in an \cs{edef}:
%
\begin{verbatim}
\def\AppendTo#1#2{\begingroup
  \expandafter\toks\expandafter0\expandafter{\foo#2}%
  \global\edef#1{\the\toks0}\endgroup}
\def\foo{} \AppendTo\foo{#x}
\show\foo % \foo=macro:-> ##x
\end{verbatim}

Note that \verb+#+s has to be properly formulated when a macro is defined,
and it is \cs{def} who eats half of \verb+#+s (and converts \verb+#1+ etc.\
to special, inaccessible tokens), but \cs{edef} doesn't convert
\verb+#+$_{6}$ to special tokens if it comes from a token list register. The
disadvantage of the second definition of \cs{AppendTo} that it must be
\cs{global}. (In fact, there is a much longer solution that manually doubles
the \verb+#+s.) The \cs{addto} command of \nproduct{Babel} and the \cs{vref@addto}
command of \nproduct{varioref.sty} are \cs{global}, similarly to this solution.

\subsection{Processing arbitrary package options}

\LaTeX{} packages may can the standard commands \cs{DeclareOption}, \cs{Execute\allowbreak Option} and
\cs{Pro\allowbreak cessOptions} to access package options passed to them,
and these commands work fine when there is a finite fixed set of options. The
\cs{Declare\allowbreak Op\allowbreak tion*} command can be used to declare arbitrary options:
%
\begin{verbatim}
%\DeclareOption{10pt}{\typeout{got ten-pt}} % (1)
\DeclareOption*{\typeout{got=(\CurrentOption)}}
\ProcessOptions  % in file foo.sty
\end{verbatim}
%
\noindent When that \texttt{foo.sty} is loaded as
\verb+\usepackage[,foo=bar,,no,]{foo}+, two lines will be printed:
\texttt{got=(foo=bar)} and \texttt{got=no}. The optional argument of
\cs{usepack\allowbreak age} may contain spaces and/or a single newline around commas and
at the ends. Class options are passed to \cs{DeclareOption*}, so when
\verb+\documentclass[10pt]+\allowbreak\verb+{article}+ is active, \texttt{got=(10pt)} will not
appear, but when line (1) is uncommented, \texttt{got ten-pt} will appear.

There is an alternative, low-level way for accessing all the options at once:
\begin{verbatim}
\AtEndOfPackage{\let\@unprocessedoptions\relax}% prevent warning
\typeout{\csname opt@\@currname.\@currext\endcsname}
\end{verbatim}
%
\noindent This prints the full of option lists with extra spaces and newlines
removed, but commas, including superfluous ones, are kept intact.

\section{Beyond the current \nproduct{magyar.ldf}}

\subsection{Software related to Hungarian typesetting}\label{pts:downloads}

Although \nproduct{magyar.ldf} contains most of the functionality needed for
following the Hungarian typographic traditions, there are more utilities and
packages that help typesetting Hungarian texts. Most of these software,
including \nproduct{magyar.ldf} is
going to be available under the name \nproduct{Magyar\LaTeX} from the
URL %\myurl+
\texttt{http://}\allowbreak\verb+www.math.bme.hu/latex/+.

\begin{description}

\item[\nproduct{magyar.ldf}]
  The new Hungarian module for \nproduct{Babel}. Version 1.5 was written by
  P\'eter Szab\'o from the autumn of 2003.

\item[\nproduct{huhyph.tex} or \nproduct{huhyph3.tex}]
  The old (version 3) Hungarian hyphenation \cs{patter\allowbreak ns} for the T1
  encoding,
  written by Gyula Mayer in 1998. Part of most \TeX{} distributions.
  See more information in subsection
  \ref{pts:hyphenation}.

\item[\nproduct{huhyphc.tex}]
  The new version of the Hungarian hyphenation \cs{patterns} for the T1
  encoding, written by Gyula Mayer in 2002 (\cite{huhydok-en}). Part of most \TeX{}
  distributions. Hyphenates foreign compound words on the subword boundary,
  e.g.\ ``szin-kron''.
  See more information in subsection \ref{pts:hyphenation}.

\item[\nproduct{huhyphf.tex}]
  The new version of the Hungarian hyphenation \cs{patterns} for the T1
  encoding, written by Gyula Mayer in 2002 (\cite{huhydok-en}). Part of most \TeX{}
  distributions. Hyphenates foreign compound words phonetically,
  e.g.\ ``szink-ron''.
  See more information in subsection \ref{pts:hyphenation}.

\item[\nproduct{lafmtgen.pl}]
  An easy-to-use Perl script that can generete format files (\texttt{.fmt})
  containing all hyphenation patterns required by the specified \LaTeX{}
  document. Has some other features related to generating and installing
  format files. To be used with the UNIX
  \nproduct{te\TeX} distribution. It was written by P\'eter Szab\'o in 2003.

\item[\nproduct{huplain.bst}]
  \nproduct{BibTeX} style file for Hungarian
  bibliographies, based on \nproduct{plain.bst}. It encourages sharing the
  same \texttt{.bib} database between Hungarian and English documents.
  It follows the (simple) convention that the style of a bibliography depends
  on the language of the document containing the entry, not the language of
  the entry itself. It was written by P\'eter Szab\'o in 2003.

\item[\nproduct{husort.pl}]
  A drop-in replacement of \nproduct{makeindex} that follows the
  Hungarian standards of index sorting and typesetting.
  It is implemeneted as a Perl script.
  It was written by P\'eter Szab\'o in 2003.

\item[\nproduct{ccs\textunderscore extract.pl}]
  A Perl script that helps hyphenation of words containing long double
  Hungarian consonants. It finds all occurences of such words in the document
  and lets the user decide whether to insert \nproduct{magyar.ldf} shorthands
  for \cs{discretionary} breaks for long double consonants in each unique
  word. The program was written by P\'eter Szab\'o in 2003.

\def\xindy{\nproduct{X\r\i ndy}}

\item[\nproduct{magyar.xdy}]
  Hungarian style file for the \xindy{} index processing program. Implements
  the Hungarian sorting order and a Hungarian typesetting style. The
  implemented sorting order does not follow Hungarian rules as strictly and
  advancedly as \nproduct{husort.pl}.
  It was written by P\'eter Szab\'o in 2003.

\item[\nproduct{CM-Super}]
  The EC fonts in Type\,1 format in T1 and various other encodings. It is not
  part of \nproduct{Magyar\LaTeX}, but it is available from CTAN. It is
  useful for converting Hungarian text to PDF, so the generated PDF file will
  contain the EC fonts in Type\,1 format, and will be rendered quickly and
  nicely by \nproduct{Acrobat Reader}.
  % The fonts are not part of
  %\nproduct{Magyar\LaTeX}, but are freely available from CTAN.

\item[\nproduct{MagyarISpell}]
  The Hungarian language database of the \nproduct{ISpell} spell checker for
  UNIX. On \nproduct{Debian} systems it can be installed with the command
  \texttt{apt-get install ihungarian}. \nproduct{ISpell} has a \TeX{} mode,
  which skips control sequences and comments when checking \TeX{} source.
  (Unfortunately, the arguments of \verb+\begin{tabular}+ and many other
  non-textual elements of \LaTeX{} documents are not skipped.)
  \nproduct{ISpell} can be used interactively, but this method is not
  confortable, and incremental checking is not possible. \nproduct{ISpell}
  has an interprocess communication protocol, through which it can be
  integrated into text editors. For exaple, \nproduct{Emacs} has built-in
  \nproduct{ISpell} support, which can mark incorrect words visually.
  \nproduct{OpenOffice}, \nproduct{LyX}, editors in KDE and newer versions of
  \nproduct{Vim} can also use \nproduct{ISpell} for spell checking.
  \nproduct{MagyarISpell} works fine in these editors.
  It is not part of \nproduct{MagyarLaTeX}, but it is available for free.

  Note, however, that both the database and the stemmer of
  \nproduct{MagyarISpell} is far from perfect, but among the Hungarian spell
  checkers only this one
  works inside \nproduct{ISpell}, so only this can be easily integrated into
  editors.

\item[\nproduct{MSpell}]
  A commercial Hungarian spell checker with free \nproduct{Linux} download,
  developed by Morphologic (a company in Hungary that produces linguistic
  software). Doesn't have an interactive mode, but can replace
  \nproduct{ISpell} in inter-process communication mode. A shell script is
  provided that replaces the \texttt{ispell} command, so \nproduct{MSpell}
  can be integrated into text editors more easily.
  It is not part of \nproduct{Magyar\LaTeX}.

\item[\nproduct{HuSpell}]
  The successor of \nproduct{MagyarISpell}, based on a different spell
  checking architecture. It understands Hungarian much better than
  \nproduct{MagyarISpell}, but since it is not based on \nproduct{ISpell}, it
  is harder to integrate into text editors. For example, it is not available
  from the \nproduct{Emacs} spell checking menu, even if it is installed.
  It is not part of \nproduct{Magyar\LaTeX}, but it is freely available.

\end{description}

\subsection{Future work}

Some features are still missing from \nproduct{magyar.ldf}:
\nproduct{letter.cls} is not customized properly, the left indentation of the
nested list environments is also not customized; a macro that emits numbers
with groups of three digits separated is missing; \nproduct{layout.sty} and
many other packages don't have Hungarian captions yet; the shorthand
\texttt{\string`} is not disabled in math mode to give a chance to
\nproduct{nath.sty} to typeset $H_\mathrm{symm}$ with \verb+$H_{`symm}$+;
\cs{hunnewlabel} should store \texttt{table}, \texttt{figure} or
\texttt{equation}, so \cs{refstruc} should insert it; new fonts and/or
methods should be developed in place of \texttt{\string`tty}; Hungarian
typography needs a baseline grid, which is almost impossible to enforce in
\LaTeX{}; some proposed separation symbols after the \cs{paragraph} are not
available yet; section titles should not be larger than normal text; bold
fonts should be substituted for bold extended fonts, whenever available --
and never with an error or warning message; page numbers should be removed
from blank pages; the width of \cs{parindent} should be computed based on
\cs{textwidth}; the length of the last line of a paragraph should not be too
near to the right margin, especially if $\hbox{\cs{parindent}}=0$;
\cs{vskip}s above and below sections should be reduced; \cs{MathReal} should
be extended with physical units; providing the commands \cs{H} and \cs{.} for
OT1-encoded typewriter fonts; virtual fonts to support \cs{umlautlow} in T1
encoding; boldface in \verb+\begin{description}+ should be changed to
\cs{emph}; changing the values of some compile-time options in run-time;
the \cs{textqq} command should work both as a command and an environment;
\cs{told} should generate suffixes for month names.

Other features should be implemented outside \nproduct{magyar.ldf}, as
external programs. All of the programs in subsection \ref{pts:downloads} needs
improvements in some way.

\subsection{Conclusion}

An update \nproduct{magyar.ldf} that follows the Hungarian
typographical rules and works together with the most popular \LaTeX{}
packages without problems, has been awaited for many years. This new version
is ready, as a single file longer than anything else ever before,
and it is filled with many advanced features. Most of the
features adapt \LaTeX{} to the Hungarian typographical rules, but some of
them are just bugfixes to various external packages, including fixes to
design flaws and compatibility issues in \nproduct{Babel} itself. The
implementation of some features clearly show that \TeX{} macro programming is
an obscure and ineffective way of solving some of the language-related
problems. It is hoped that new versions of $\mathrm\Omega$, together with the new
version of \nproduct{Babel} will provide a framework in which
such problems can be addressed compactly and elegantly, without the
awareness of actual and possible compatibility glitches.

%\bibliography{../magyarldf-doc}
%\bibliographystyle{plain}
% OK: %WF Ez a TUGBoat-ban is megjelent, arra kéne hivatkozni:
\def\noopsort#1{} \def\printfirst#1#2{#1} \def\switchargs#1#2{#2#1}
\begin{thebibliography}{1}

\bibitem{bwfinal}
Gy{\"o}ngyi Bujdos{\'o} and Ferenc Wettl.
\newblock On the localization of {\TeX} in {Hungary}.
\newblock {\em TUGBoat}, 23(1):21--26, 2002.

\bibitem{macro-virt}
David Kastrup.
\newblock De ore leonis. {Macro} expansion for virtuosi.
\newblock In {\em EuroBacho{\TeX}}, May 2002.

\bibitem{texbook}
Donald~E. Knuth.
\newblock {\em The {{\TeX}book}}.
\newblock Addison--Wesley, 1984.

\bibitem{huhydok-en}
Gyula Mayer.
\newblock The {Hungarian} hyphenation module of {\TeX} and {\LaTeX}.
\newblock Unpublished article in Hungarian, 10~July 2002.

\bibitem{comp-word-hyph}
Petr Sojka.
\newblock Notes on compound word hyphenation in {\TeX}.
\newblock In {\em TUGboat Annual Meeting}, volume~16, 1995.

\end{thebibliography}


\end{document}
