[latex3-commits] [git/LaTeX3-latex3-latex2e] develop: reimplementing \rmfamily \sffamily and \ttfamily and adding a hook (for platex) (7f149e5b)
Frank Mittelbach
frank.mittelbach at latex-project.org
Sun Jan 12 00:08:03 CET 2020
Repository : https://github.com/latex3/latex2e
On branch : develop
Link : https://github.com/latex3/latex2e/commit/7f149e5bf24d9b219e2c94b7a0964f28cf264eaf
>---------------------------------------------------------------
commit 7f149e5bf24d9b219e2c94b7a0964f28cf264eaf
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date: Sun Jan 12 00:08:03 2020 +0100
reimplementing \rmfamily \sffamily and \ttfamily and adding a hook (for platex)
>---------------------------------------------------------------
7f149e5bf24d9b219e2c94b7a0964f28cf264eaf
base/changes.txt | 6 +
base/ltfssini.dtx | 326 +++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 233 insertions(+), 99 deletions(-)
diff --git a/base/changes.txt b/base/changes.txt
index 31f547f5..686a62b4 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -4,6 +4,12 @@ completeness or accuracy and it contains some references to files that
are not part of the distribution.
=======================================================================
+2020-01-12 Frank Mittelbach <Frank.Mittelbach at latex-project.org>
+
+ * ltfssini.dtx (section{Custom series settings for main document families}):
+ Cleaning up the code for \rmfamily, \sffamily, \ttfamily and adding
+ hooks to support Japanese implementations.
+
2020-01-05 David Carlisle <David.Carlisle at latex-project.org>
* base/ltclass.dtx: Support more write streams for
diff --git a/base/ltfssini.dtx b/base/ltfssini.dtx
index fddd9f25..e948aa48 100644
--- a/base/ltfssini.dtx
+++ b/base/ltfssini.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment
%
-% Copyright (C) 1993-2019
+% Copyright (C) 1993-2020
% The LaTeX3 Project and any individual authors listed elsewhere
% in this file.
%
@@ -36,7 +36,7 @@
%
%
\ProvidesFile{ltfssini.dtx}
- [2019/12/17 v3.1e LaTeX Kernel (NFSS Initialisation)]
+ [2020/01/11 v3.1f LaTeX Kernel (NFSS Initialisation)]
% \iffalse
\documentclass{ltxdoc}
\begin{document}
@@ -449,80 +449,77 @@
% \begin{macro}{\rmfamily}
% Here are the document level commands for changing the main font
-% families.
-% \begin{macrocode}
-\DeclareRobustCommand\rmfamily{%
- \not at math@alphabet\rmfamily\mathrm
- % change the current series before changing the family
-% \end{macrocode}
+% families, or rather, here is a documented outline of the code,
+% the actual code is then streamlined and somewhat generalized.
+%\begin{verbatim}
+%\DeclareRobustCommand\rmfamily{%
+% \not at math@alphabet\rmfamily\mathrm
+%\end{verbatim}
% If families are changed then we have to do a bit more work.
% In the original NFSS implementation
% a family change kept encoding, series shape and size unchanged
% but now we can't any
% longer simply reuse the current series value. Instead we may have
% to change it from one family default to the next.
-% \begin{macrocode}
- \expand at font@defaults
-% \end{macrocode}
+%\begin{verbatim}
+% \expand at font@defaults
+%\end{verbatim}
% We have to do the testing while while the current family is still
% unchanged but we have to do the adjustment of the series after it
% got changed (because the new family might has different sets
% ofshapes available and we certainly don't want to see
% substituation going on. So we use \cs{target at series@value} to
% hold the target series (if any).
-% \begin{macrocode}
- \let\target at series@value\@empty
-% \end{macrocode}
+%\begin{verbatim}
+% \let\target at series@value\@empty
+%\end{verbatim}
% Thus, if the current family is the sans family
-% \begin{macrocode}
- \ifx\f at family\sfdef at ult
-% \end{macrocode}
+%\begin{verbatim}
+% \ifx\f at family\sfdef at ult
+%\end{verbatim}
% and if we using the medium series of the sans family
-% \begin{macrocode}
- \ifx\f at series\mdseries at sf
-% \end{macrocode}
+%\begin{verbatim}
+% \ifx\f at series\mdseries at sf
+%\end{verbatim}
% then lets switch to the medium series for the serif family
-% \begin{macrocode}
- \let\target at series@value\mdseries at rm
-% \end{macrocode}
+%\begin{verbatim}
+% \let\target at series@value\mdseries at rm
+%\end{verbatim}
% and if we use the bold series of the sans family switch to the
% bold default of the serif family:
-% \begin{macrocode}
- \else\ifx\f at series\bfseries at sf \let\target at series@value\bfseries at rm
-% \end{macrocode}
+%\begin{verbatim}
+% \else\ifx\f at series\bfseries at sf \let\target at series@value\bfseries at rm
+%\end{verbatim}
% However, the sans family may not have any specific defaults set,
% so we also compare with the overall defaults.
-% \begin{macrocode}
- \else\ifx\f at series\mddef at ult \let\target at series@value\mdseries at rm
- \else\ifx\f at series\bfdef at ult \let\target at series@value\bfseries at rm
-% \end{macrocode}
+%\begin{verbatim}
+% \else\ifx\f at series\mddef at ult \let\target at series@value\mdseries at rm
+% \else\ifx\f at series\bfdef at ult \let\target at series@value\bfseries at rm
+%\end{verbatim}
% If neither test was true we leave the series alone. This way a
% special manual setting such as \verb=\fontseries{lc}= is not
% undone if the family changes (of course there may not be any
% support for it in the new family but then the NFSS
% substitution kicks in and sorts it out).
-% \begin{macrocode}
- \fi\fi\fi\fi
+%\begin{verbatim}
+% \fi\fi\fi\fi
%
-% \end{macrocode}
+%\end{verbatim}
% We need to do the same if the current family is the typewriter family:
-% \begin{macrocode}
- \else\ifx\f at family\ttdef at ult
- \ifx\f at series\mdseries at tt \let\target at series@value\mdseries at rm
- \else\ifx\f at series\bfseries at tt \let\target at series@value\bfseries at rm
- \else\ifx\f at series\mddef at ult \let\target at series@value\mdseries at rm
- \else\ifx\f at series\bfdef at ult \let\target at series@value\bfseries at rm
- \fi\fi\fi\fi
-% \end{macrocode}
-%
-% \begin{macrocode}
- \fi\fi
-% \end{macrocode}
+%\begin{verbatim}
+% \else\ifx\f at family\ttdef at ult
+% \ifx\f at series\mdseries at tt \let\target at series@value\mdseries at rm
+% \else\ifx\f at series\bfseries at tt \let\target at series@value\bfseries at rm
+% \else\ifx\f at series\mddef at ult \let\target at series@value\mdseries at rm
+% \else\ifx\f at series\bfdef at ult \let\target at series@value\bfseries at rm
+% \fi\fi\fi\fi
+% \fi\fi
+%\end{verbatim}
% With these preparations for series out of the way we can now
% change the font family to \cs{rmdefault}.
-% \begin{macrocode}
- \fontfamily\rmdefault
-% \end{macrocode}
+%\begin{verbatim}
+% \fontfamily\rmdefault
+%\end{verbatim}
%
% If \cs{target at series@value} is still empty there is nothing more
% to do other than selecting the new family. However, if not then
@@ -533,82 +530,205 @@
% comparisons in \cs{fontseries} we need to make sure that the font
% family specifications are already loaded prior to calling
% \cs{fontseries}.
-% \begin{macrocode}
- \ifx\target at series@value\@empty \else
- \maybe at load@fontshape
-% \end{macrocode}
+%\begin{verbatim}
+% \ifx\target at series@value\@empty \else
+% \maybe at load@fontshape
+%\end{verbatim}
% Updating the series in this case means directly changing
% \cs{f at series} to the target value. We don't want to go through
% \cs{fontseries} because that would apply the mappings and then
% \texttt{bx + b} would keep \texttt{bx} instead of changing to
% \texttt{b} as desired.
% as
+%\begin{verbatim}
+% \let\f at series\target at series@value
+% \fi
+% \selectfont}
+%\end{verbatim}
+%
+% So now for the real definition: most of the code above gets
+% delegated to a helper command \cs{prepare at family@series at update}
+% so that the definition becomes again fairly short. In addition we
+% add a hook, mainly for our Japanese friends so that the code can
+% be extended prior to the call to \cs{selectfont}.
+%
+% \changes{v3.1f}{2020/01/11}{Streamlined implementation with hook}
% \begin{macrocode}
- \let\f at series\target at series@value
- \fi
- \selectfont}
+\DeclareRobustCommand\rmfamily{%
+ \not at math@alphabet\rmfamily\mathrm
+% \end{macrocode}
+% This holds all the code discussed above, first argument is the
+% meta family, i.e., \texttt{rm} in this case, and second argument
+% is the default family name, e.g., \texttt{cmr} indirectly
+% accessed via \cs{rmdefault}. This is calling \cs{fontfamily} and
+% if necessary \cs{fontseries} as outline above.
+% \begin{macrocode}
+ \prepare at family@series at update{rm}\rmdefault
+% \end{macrocode}
+% The comes the hook code (by default a no-op) and finally the call
+% to \cs{selectfont}.
+% \begin{macrocode}
+ \@rmfamilyhook
+ \selectfont}
% \end{macrocode}
%
% \begin{macro}{\sffamily}
% \begin{macro}{\ttfamily}
% The definitions for \cs{sffamily} and \cs{ttfamily} are similar,
% the differences are only in what font families get checked.
+% \changes{v3.1f}{2020/01/11}{Streamlined implementation with hook}
% \begin{macrocode}
\DeclareRobustCommand\sffamily{%
- \not at math@alphabet\sffamily\mathsf
- \expand at font@defaults
- \let\target at series@value\@empty
- \ifx\f at family\rmdef at ult
- \ifx\f at series\mdseries at rm \let\target at series@value\mdseries at sf
- \else\ifx\f at series\bfseries at rm \let\target at series@value\bfseries at sf
- \else\ifx\f at series\mddef at ult \let\target at series@value\mdseries at sf
- \else\ifx\f at series\bfdef at ult \let\target at series@value\bfseries at sf
- \fi\fi\fi\fi
- \else\ifx\f at family\ttdef at ult
- \ifx\f at series\mdseries at tt \let\target at series@value\mdseries at sf
- \else\ifx\f at series\bfseries at tt \let\target at series@value\bfseries at sf
- \else\ifx\f at series\mddef at ult \let\target at series@value\mdseries at sf
- \else\ifx\f at series\bfdef at ult \let\target at series@value\bfseries at sf
- \fi\fi\fi\fi
- \fi\fi
- \fontfamily\sfdefault
- \ifx\target at series@value\@empty \else
- \maybe at load@fontshape
- \let\f at series\target at series@value
- \fi
- \selectfont}
+ \not at math@alphabet\sffamily\mathsf
+ \prepare at family@series at update{sf}\sfdefault
+ \@sffamilyhook
+ \selectfont}
% \end{macrocode}
%
+% \changes{v3.1f}{2020/01/11}{Streamlined implementation with hook}
% \begin{macrocode}
\DeclareRobustCommand\ttfamily{%
- \not at math@alphabet\ttfamily\mathtt
- \expand at font@defaults
- \let\target at series@value\@empty
- \ifx\f at family\rmdef at ult
- \ifx\f at series\mdseries at rm \let\target at series@value\mdseries at tt
- \else\ifx\f at series\bfseries at rm \let\target at series@value\bfseries at tt
- \else\ifx\f at series\mddef at ult \let\target at series@value\mdseries at tt
- \else\ifx\f at series\bfdef at ult \let\target at series@value\bfseries at tt
- \fi\fi\fi\fi
- \else\ifx\f at family\sfdef at ult
- \ifx\f at series\mdseries at sf \let\target at series@value\mdseries at tt
- \else\ifx\f at series\bfseries at sf \let\target at series@value\bfseries at tt
- \else\ifx\f at series\mddef at ult \let\target at series@value\mdseries at tt
- \else\ifx\f at series\bfdef at ult \let\target at series@value\bfseries at tt
- \fi\fi\fi\fi
- \fi\fi
- \fontfamily\ttdefault
- \ifx\target at series@value\@empty \else
- \maybe at load@fontshape
- \let\f at series\target at series@value
- \fi
- \selectfont}
+ \not at math@alphabet\ttfamily\mathtt
+ \prepare at family@series at update{tt}\ttdefault
+ \@ttfamilyhook
+ \selectfont}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+%
+% \begin{macro}{\@rmfamilyhook}
+% \begin{macro}{\@sffamilyhook}
+% \begin{macro}{\@ttfamilyhook}
+% By default the hooks do nothing.
+% \begin{macrocode}
+\let\@rmfamilyhook\@empty
+\let\@sffamilyhook\@empty
+\let\@ttfamilyhook\@empty
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+
+
+
+% \begin{macro}{\prepare at family@series at update}
+% This is core command that prepares for the family update. The big
+% difference to the documented code above is that the nested
+% \cs{ifx} statements seem to be missing. Instead we loop through
+% an internal list that holds the names of the three meta
+% families. This approach allows us to extend the mechanism at a
+% later stage to allow for additional named meta families.
+%
+% \begin{macro}{\@meta at family@list}
+% Here is the current definition of that list:
+% \begin{macrocode}
+\def\@meta at family@list{\@elt{rm}\@elt{sf}\@elt{tt}}
% \end{macrocode}
% \end{macro}
+%
+% \begin{macrocode}
+\def\prepare at family@series at update#1#2{%
+ \expand at font@defaults
+% \end{macrocode}
+% We prepare for changing the current series. We have to find it
+% before changing the family as discussed above.
+% \begin{macrocode}
+ \let\target at series@value\@empty
+ \def\target at meta@family at value{#1}%
+% \end{macrocode}
+% To find it we loop over the meta family list with a suitable
+% definition of \cs{@elt}.
+% \begin{macrocode}
+ \let\@elt\update at series@target at value
+ \@meta at family@list
+ \let\@elt\relax
+% \end{macrocode}
+% That will figure out the correct series value to use without updating
+% it. Now we can change the family.
+% \begin{macrocode}
+ \fontfamily#2%
+% \end{macrocode}
+% After that we update the series. That code is again like the one
+% above.
+% \begin{macrocode}
+ \ifx\target at series@value\@empty
+ \else
+ \maybe at load@fontshape
+ \let\f at series\target at series@value
+ \fi
+}
+% \end{macrocode}
% \end{macro}
+%
+%
+%
+% \begin{macro}{\update at series@target at value}
+% In this macro used in the look you basically find the nested
+% \cs{ifx}s from the outline above. The only difference is that is
+% it is parameterized instead of being written out and only for one
+% block of tests because the code is called reatedly when looping
+% over the meta family list. From the list we get each meta family
+% name in turn.
+% \begin{macrocode}
+\def\update at series@target at value#1{%
+% \end{macrocode}
+% There is one additional test at the beginning, because the list
+% contains all meta families and we need to ignore the case where
+% current one from the list and target one are identical.
+% \begin{macrocode}
+ \def\@reserveda{#1}%
+ \ifx\target at meta@family at value\@reserveda % rm -> rm do nothing
+ \else
+% \end{macrocode}
+% We only ``do'' something if the current font family matches the
+% current meta family.
+% \begin{macrocode}
+ \expandafter\ifx\csname#1def at ult\endcsname\f at family
+% \end{macrocode}
+% If that's the case we know that this is the block that applies
+% (only one meta family can match). So to speed things up we
+% change \cs{@elt} so that the rest of the loop gets gobbled.
+% \begin{macrocode}
+ \let\@elt\@gobble
+% \end{macrocode}
+% Then we try to find the right new value for the series (as
+% explained above). The two macros defined first are only there
+% because we now need to use \cs{csname} and this way the code will
+% be a little faster.
+% \begin{macrocode}
+ \expandafter\let\expandafter\@reservedb
+ \csname mdseries@\target at meta@family at value\endcsname
+ \expandafter\let\expandafter\@reservedc
+ \csname bfseries@\target at meta@family at value\endcsname
+% \end{macrocode}
+% This here is now identical to the nested \cs{ifx} block from the
+% outline, except that it there appeared twice in
+% \cs{rmfamily}. This is now covered by looping and stopping the
+% loop when a match was found.
+% \begin{macrocode}
+ \expandafter\ifx\csname mdseries@#1\endcsname\f at series
+ \let\target at series@value\@reservedb
+ \else\expandafter\ifx\csname bfseries@#1\endcsname\f at series
+ \let\target at series@value\@reservedc
+ \else\ifx\f at series\mddef at ult \let\target at series@value\@reservedb
+ \else\ifx\f at series\bfdef at ult \let\target at series@value\@reservedc
+ \fi\fi\fi\fi
+ \fi
+ \fi
+}
+% \end{macrocode}
% \end{macro}
%
%
+%
+%
+%
+%
+%
+%
+%
% \begin{macro}{\init at series@setup}
% This is code to be run at begin document \ldots
% \begin{macrocode}
@@ -723,6 +843,14 @@
%<latexrelease>\DeclareRobustCommand\ttfamily
%<latexrelease> {\not at math@alphabet\ttfamily\mathtt
%<latexrelease> \fontfamily\ttdefault\selectfont}
+%<latexrelease>
+%<latexrelease>\let\@rmfamilyhook\@undefined
+%<latexrelease>\let\@sffamilyhook\@undefined
+%<latexrelease>\let\@ttfamilyhook\@undefined
+%<latexrelease>\let\@meta at family@list\@undefined
+%<latexrelease>\let\prepare at family@series at update\@undefined
+%<latexrelease>\let\update at series@target at value\@undefined
+%<latexrelease>
% \end{macrocode}
% This is always called in \cs{document} so don't make it undefined.
% \begin{macrocode}
More information about the latex3-commits
mailing list