LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Classic View

Use Proportional Font
Show Text Part by Default
Show All Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Vladimir Volovich <[log in to unmask]>
Sat, 14 Jun 1997 22:36:18 +0400
text/plain (175 lines)
% Hello, here is an example of
% macroses which redefine \uppercase to be `multilingually-clean' ;-)

\documentclass{article}

\makeatletter

% First, let's define macros to change `language':

\def\LangA{\begin@language
\language0
\uccode`a=`b
\end@language}

\def\LangB{\begin@language
\language1
\uccode`a=`c
\end@language}

\let\begin@language\relax \let\end@language\relax

% Now we redefine the \uppercase primitive
% (the case of \lowercase is analogous) ;-)

\let\orig@uppercase\uppercase \let\end@uppercase\relax

\def\uppercase#1{\protect\tmpe@uppercase{#1}}
\def\tmpe@uppercase#1{\edef\tmpd@uppercase{#1}%
  \expandafter\tmpa@uppercase\expandafter
  \begin@language\expandafter\end@language
  \tmpd@uppercase\begin@language\end@uppercase}
\def\tmpa@uppercase\begin@language#1\end@language
  #2\begin@language{#1\orig@uppercase{#2}%
  \futurelet\tmpb@uppercase\tmpc@uppercase}
\def\tmpc@uppercase{\ifx\tmpb@uppercase\end@uppercase
  \def\next{}\else\def\next{\tmpa@uppercase\begin@language}\fi\next}

\makeatother

\let\MakeUppercase\uppercase

\begin{document}

Here is a preliminary variant of macroses that redefine
\TeX's primitives \verb|\uppercase| and \verb|\lowercase|
in order to correctly handle multilingual arguments.
This means that, generally speaking, every language
may have it's own \verb|\lccode| and \verb|\uppercode|
settings (as well as \verb|\sfcode|, \verb|\mathcode|
and \verb|\delcode|).
And in my opinion the user should be allowed to set the values
of these registers (in a language-swithing macroses, such as
\verb|\selectlanguage| in \textsf{babel}).

If one wants to change \verb|\uccode| and \verb|\lccode| values
inside the argument of \verb|\uppercase|, the result would be
negative---especially if there are several language-switching
macroses. Moreover, any attempts to change the \verb|\uccode|
and \verb|\lccode| values inside the argument of \verb|\uppercase|
will have \textit{no effect at all} except redefining
of these values after exit from \verb|\uppercase|.

If one does not want to `touch' \TeX's primitives \verb|\uppercase|
and \verb|\lowercase|, there is a possibility to change
\LaTeX's macroses \verb|\MakeUppercase| and \verb|\MakeLowercase|
(namely, substitute the \verb|\uppercase| that is used
inside of \textit{these} macroses to the herein proposed macros).

Here is an example of using new \verb|\uppercase| macros.
Consider two languages, \verb|LangA| and \verb|LangB|,
that have \textit{conflicting} set of \verb|\uccode| and \verb|\lccode|
values. In the following (spurious) example we only suppose that,
e.~g., the uppercase variant of the letter \verb|a| in the
language \verb|LangA| is \verb|b|, and the uppercase variant
of the \textit{same} letter \verb|a| in the language \verb|LangB|
is \verb|c|.
With the new redefined \verb|uppercase|, the following text

\begin{verbatim}
\def\SomeText{Something that was put in a macro to save typing... }

\MakeUppercase{\LangA
Sample text in language A...
\SomeText
\LangB
And now sample text in language B...
\SomeText
\LangA
And we are again back to language A}
\end{verbatim}

\noindent will give us

\begin{quote}
\def\SomeText{Something that was put in a macro to save typing... }

\MakeUppercase{\LangA
Sample text in language A...
\SomeText
\LangB
And now sample text in language B...
\SomeText
\LangA
And we are again back to language A}
\end{quote}

\noindent
(note, that \verb|\MakeUppercase|, which is a \LaTeX's macros,
actually uses \verb|\uppercase|; so the same result would have been
obtained if we have used \verb|\uppercase| instead of
\verb|\MakeUppercase|).
As one can see, the \textit{same} letter \verb|a| transformed
to the \textit{different} letters, \verb|b| and \verb|c|,
according to the current language.

So, there is no need to be ``attached'' to the ``hard fixed''
values of \verb|\uccode| and \verb|\lccode| which are set in \LaTeX!
Of course, to get correct results after processing a multilingual
text, one needs to use only one language in one paragraph
(or explicitly set hyphenation for other-language-words
used in the same paragraph). But these redefined
\verb|\uppercase| and \verb|\lowercase| will work correctlly
even for multilingual arguments!
Unfortunately, \TeX\ does not use \verb|\lowercase| when
it breaks paragraphs into lines and searches for hyphenation
(it does this implicitly, i.~e.\ without a call to \verb|\lowercase|),
so it is impossible to meddle with this process \texttt{;-(}.

As you can see, this approach works even if the argument of
\verb|\uppercase| contains a ``hidden'' text (via macroses).
But of course, it is not a universal approach.
It fails when the language changing macroses are ``hidden''
in a group (via \verb|{...}| or \verb|\begingroup...\endgroup|).
But I think that in most cases user will be able to rewrite his text so
that all language switching will be done outside of groups.

These macros are useful also because \LaTeX\ uses \verb|\uppercase|
when it makes colontitles. So, it is possible to use
multilingual colontitles.

And now, how does it work.
The `corrected' macros changes the text like
\begin{verbatim}
   \uppercase{ [<text>] [<language change>] <text>
       [ <language change> <text> ... ] }
\end{verbatim}
(anything in square brackets is optional) to the following
\begin{verbatim}
   [\uppercase{<text>}] [<language change>]
      \uppercase{<text>} [ <language change> \uppercase{<text>} ... ],
\end{verbatim}
i.~e.\ it takes the language changing macroses out of the
\verb|\uppercase|
argument.
A language changing macroses are assumed here to have the following
form:
\begin{verbatim}
   \def<language>{\begin@language
       <changing of \language, \uccode, \lccode,
         \lefthypnenmin, \righthyphenmin, etc.>
       \end@language}
\end{verbatim}
This, of course, could be corrected to be used in \textsf{babel} system.

\vskip3\baselineskip
\hbox to\hsize{\hfill\vbox{%
\hbox{With best regards, Vladimir Volovich}
\hbox{e-mail: [log in to unmask]

\end{document}

--
With best regards,
                   Vladimir.

ATOM RSS1 RSS2