[texhax] Upright digits in theorems
Uwe Lück
uwe.lueck at web.de
Thu Jun 8 23:35:44 CEST 2006
Sorry, contrary to my conviction my previously outgoing posting
didn't contain the attachment. (Oh, so often facts -- including
those that I have produced -- are contrary to my convictions.)
-- Uwe.
[And by mere accidence this has not been the second posting
lacking the attachment.]
At 23:32 06.06.06, Uwe Lück wrote:
>At 16:11 06.06.06, Alex Scorpan wrote:
> >What is the most elegant and robust way to arrange that digits and
> >such always display upright inside a theorem-like environment, when
> >the surrounding text is italic? This is for a rather large-scale
> >application.
>
>you can indeed replace 0 by \textup{0} etc. by TeX macros.
Attached is a demo .tex containing macros for these replacements.
A macro \UprightDigitsInEnv modifies an environment for them
after the environment has been defined.
This was more difficult than I expected. My first "multi-tasking"
package -- in a way. First, each of ten replacement processes
does its first move. During typesetting the environment, at
every digit the corresponding process does its next move.
This version doesn't "right" a digit within curly braces.
Some refinement could do this. And I would not bet that
I could find a refinement that also "rights" digits that appear
only after expansion. (The item labels in the demo exemplify
this.) Here your active characters approach would be superior
wrt this. Maybe for the latter approach it suffices to modify
\label and \ref such that the active digits just expand to their
"other" versions. I still think that the font approach is most
clean (see below for recalling).
Cheers,
Uwe.
>A /third/ approach: let \itshape etc. expand such that
>not standard italic/slanted fonts are used, rather your
>own variants where only letters are slanted (italic), not
>the digits. In this case I really rather guess, I only have
>a rough idea of METAFONT, I sometimes read .mf files,
>I would not be able to make .mf files that would be
>needed for this approach. -- Probably the most reliable
>approach -- e.g., the above second approach would have
>difficulties (hence at least not very elegant) with digits
>that only appear after expansion of some macros used
>by the author. -- I guess the most elegant solution for
>this third approach are the so-called "virtual fonts"
>-- someone else should advise on this.
-------------- next part --------------
% UprDigs.tex -- upright digits in theorem environments
% Uwe Lueck 2006/06/08 to texhax for Alex Scorpan.
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\documentclass[12pt]{article}
% \usepackage{trace}
\nofiles
% General macros:
\makeatletter
% Modifying some theorem environment #1,
% adding \uprightdigits on the left:
\newcommand*{\UprightDigitsInEnv}[1]{%
\expandafter\def
\csname#1\expandafter\expandafter\expandafter\endcsname
\expandafter\expandafter\expandafter {%
\expandafter\expandafter\expandafter \upright at digits
\csname#1\endcsname}}
\@onlypreamble\UprightDigitsInEnv
% What the added macro does:
\def\upright at digits{%
\let\env at considered\@currenvir
\let\envcontent\start at envcontent
\gather at envcontent}
\def\start at envcontent{%
\replace0\replace1\replace2\replace3\replace4
\replace5\replace6\replace7\replace8\replace9}
\long\def\gather at envcontent#1\end#2{%
\add at envcontent{#1}\def\env at found{#2}%
\ifx\env at found\env at considered
\expandafter\replacing
\else
\add at envcontent{\end{#2}}%
\expandafter\gather at envcontent
\fi}
\long\def\add at envcontent#1{%
\expandafter\def\expandafter\envcontent\expandafter{%
\envcontent#1}}
\def\replacing{%
\envcontent 0\@nil1\@nil2\@nil3\@nil4\@nil
5\@nil6\@nil7\@nil8\@nil9\@nil
\expandafter\end\expandafter{\env at considered}}
\def\replace#1{%
\long\def\@replace##1#1##2\@nil{%
\def\passed at by{##1}%
\ifx\@nnil##2\@nnil
\expandafter \passed at by
\else
\def\return at modified{%
\passed at by\textup{#1}\replace#1##2\@nil}%
\expandafter\return at modified
\fi}%
\@replace}
\makeatother
% Applying example:
\newtheorem{sthm}{Sample-Theorem}
\UprightDigitsInEnv{sthm}
\begin{document}
% \tracingmacros=1
\begin{sthm}
Two claims:
\begin{enumerate}
\item 7 by 6 equals 42.
\item 9 by 6 equals 54.
\end{enumerate}
\end{sthm}
\end{document}
More information about the texhax
mailing list