[latex3-commits] [git/LaTeX3-latex3-latex2e] gh336: fix for #336 (including a fix to the code for #293) (5346aae8)
Frank Mittelbach
frank.mittelbach at latex-project.org
Tue May 19 19:44:08 CEST 2020
Repository : https://github.com/latex3/latex2e
On branch : gh336
Link : https://github.com/latex3/latex2e/commit/5346aae878ece8dcb7bbe03a033018429b6ea404
>---------------------------------------------------------------
commit 5346aae878ece8dcb7bbe03a033018429b6ea404
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date: Tue May 19 19:44:08 2020 +0200
fix for #336
(including a fix to the code for #293)
>---------------------------------------------------------------
5346aae878ece8dcb7bbe03a033018429b6ea404
base/changes.txt | 6 +
base/doc/ltnews32.tex | 45 ++++--
base/ltfssaxes.dtx | 13 +-
base/ltfssini.dtx | 159 ++++++++++++++++++++-
base/testfiles/github-0336.lvt | 41 ++++++
.../{github-0022b.tlg => github-0336.tlg} | 18 ++-
.../tlb-latexrelease-rollback-003-often.luatex.tlg | 4 +
.../tlb-latexrelease-rollback-003-often.tlg | 4 +
.../tlb-latexrelease-rollback-003-often.xetex.tlg | 4 +
base/testfiles/tlb-rollback-004-often.luatex.tlg | 2 +
base/testfiles/tlb-rollback-004-often.tlg | 2 +
base/testfiles/tlb-rollback-004-often.xetex.tlg | 2 +
12 files changed, 283 insertions(+), 17 deletions(-)
diff --git a/base/changes.txt b/base/changes.txt
index 540decc6..f14ff1dd 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -6,6 +6,12 @@ completeness or accuracy and it contains some references to files that
are not part of the distribution.
================================================================================
+2020-05-19 Frank Mittelbach <Frank.Mittelbach at latex-project.org>
+
+ * ltfssini.dtx (section{Custom series settings for main document families}):
+ Added \IfFontSeriesContextTF so that it is possible to reliably
+ detect the current font series context (gh/335)
+
2020-05-15 Frank Mittelbach <Frank.Mittelbach at latex-project.org>
* ltdefns.dtx (subsection{Initex initialisations}):
diff --git a/base/doc/ltnews32.tex b/base/doc/ltnews32.tex
index 24185efc..df908d7d 100644
--- a/base/doc/ltnews32.tex
+++ b/base/doc/ltnews32.tex
@@ -303,9 +303,9 @@ method was improved to cover additional edge cases.
If a font family was set up with fairly unusual font series defaults,
e.g.,
\begin{verbatim}
-\renewcommand\ttdefault{lmvtt}
-\DeclareFontSeriesDefault[tt]{md}{lm}
-\DeclareFontSeriesDefault[tt]{bf}{bm}
+ \renewcommand\ttdefault{lmvtt}
+ \DeclareFontSeriesDefault[tt]{md}{lm}
+ \DeclareFontSeriesDefault[tt]{bf}{bm}
\end{verbatim}
then a switch between the main document families, e.g.,
\verb=\ttfamily...\rmfamily= did not always correctly continued
@@ -316,6 +316,35 @@ been corrected.
\githubissue{291}
+\subsection{Checking the current font series context}
+
+Sometimes it is necessary to define commands that act differently when
+used in bold context (e.g., inside \cs{textbf}. Now that it is
+possible in \LaTeX{} to specify different \enquote{\texttt{bf}}
+defaults based for each of the three meta families (\texttt{rm},
+\texttt{sf} and \texttt{tt}) via \cs{DeclareFontSeriesDefault}, it is
+not any longer easy to answer the question \enquote{am I typsetting in
+ a bold context?}. To help with this problem a new command was provided:
+\begin{quote}
+ \cs{IfFontSeriesContextTF}\Arg{context}\\
+ \hspace*{4em} \Arg{true code}\Arg{false code}
+\end{quote}
+The \meta{context} can be either \texttt{bf} (bold) or \texttt{md}
+(medium) and depending on whether or not the current font is
+recognized as being selected through \cs{bfseries} or \cs{mdseries}
+the \meta{true code} or \meta{false code} is executed.
+As an example
+\begin{verbatim}
+\usepackage{bm} % (bold math)
+\newcommand\vbeta{\IfFontSeriesContextTF{bf}%
+ {\ensuremath{\bm{\beta}}}%
+ {\ensuremath{\beta}}}
+\end{verbatim}
+This way you can write \cs{vbeta}\texttt{-isotopes} and if used in a
+heading it comes out in a bolder version.
+%
+\githubissue{336}
+
\subsection{Avoid spurious package option warning}
@@ -385,17 +414,17 @@ commands where defective as they are testing for \enquote{equal or
We have therefore introduced three new CamelCase commands as the
official interface for such tests
-\begin{flushleft}
+\begin{quote}
\cs{IfFormatAtLeastTF}\Arg{date}\\
\hspace*{4em} \Arg{true code}\Arg{false code}
-\end{flushleft}
+\end{quote}
and for package and class tests
-\begin{flushleft}
+\begin{quote}
\cs{IfClassAtLeastTF}\Arg{class name}\Arg{date}\\
\hspace*{4em} \Arg{true code}\Arg{false code} \\
\cs{IfPackageAtLeastTF}\Arg{package name}\Arg{date}\\
\hspace*{4em} \Arg{true code}\Arg{false code}
-\end{flushleft}
+\end{quote}
For compatibility reasons the legacy commands remain available, but we
suggest to replace them over time and use the new interfaces in new
code.
@@ -476,7 +505,7 @@ either add \texttt{\detokenize{>{$}...<{$}}} for such columns or
remove the \texttt{\$} signs in the cells. Alternatively, you can roll
back to the old version by loading \pkg{array} with
\begin{verbatim}
-\usepackage{array}[=v2.4]
+ \usepackage{array}[=v2.4]
\end{verbatim}
in such documents.
%
diff --git a/base/ltfssaxes.dtx b/base/ltfssaxes.dtx
index 13f743c8..08a0ff1b 100644
--- a/base/ltfssaxes.dtx
+++ b/base/ltfssaxes.dtx
@@ -35,7 +35,7 @@
%
%
\ProvidesFile{ltfssaxes.dtx}
- [2020/03/02 v1.0e LaTeX Kernel (NFSS Axes handing)]
+ [2020/05/19 v1.0f LaTeX Kernel (NFSS Axes handing)]
% \iffalse
\documentclass{ltxdoc}
\begin{document}
@@ -881,7 +881,16 @@
,ulm,elm,lm,slm,mm,sbm,bm,ebm,ubm,muc,mec,mc,msc,msx,mx,mex,mux,{}{},#1,}%
\edef\in@@{\the\series at check@toks}%
\ifx\in@@\@empty
- \def#2{#1}%
+% \end{macrocode}
+% The default definition for \cs{bfdefault} etc is actually
+% \texttt{b\cs{@empty}} so that we can detect if the user has
+% changed the default. However that means a) the above test will
+% definitely fail (maybe something to change) and b) we better use
+% \cs{edef} on the next line to get rid of it as otherwise the test
+% against \verb=#2= (e.g. \cs{bfdef at ult}) will fail in other places.
+% \changes{v1.0e}{2020/05/19}{Need to use \cs{edef} (gh/336)}
+% \begin{macrocode}
+ \edef#2{#1}%
\else
\edef#2{\expandafter\series at drop@one at m #1m\series at drop@one at m}%
\fi
diff --git a/base/ltfssini.dtx b/base/ltfssini.dtx
index 02f697bc..95202537 100644
--- a/base/ltfssini.dtx
+++ b/base/ltfssini.dtx
@@ -36,7 +36,7 @@
%
%
\ProvidesFile{ltfssini.dtx}
- [2020/04/13 v3.1n LaTeX Kernel (NFSS Initialisation)]
+ [2020/05/19 v3.2a LaTeX Kernel (NFSS Initialisation)]
% \iffalse
\documentclass{ltxdoc}
\begin{document}
@@ -1070,9 +1070,166 @@
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
+%
+%
+%
+% \begin{macro}{\IfFontSeriesContextTF}
+%
+% With the ability for \cs{bfseries} or \cs{mdseries} to be mapped
+% to different NFSS axis values it becomes important to have the
+% ability to determine the current context as we can no longer look
+% at \cs{f at series} to answer a question such as ``am I currently
+% typsetting in a bold typeface?''
+%
+% This is provided by the test \cs{IfFontSeriesContextTF}. It takes
+% three arguments:
+% \begin{itemize}
+% \item
+% The context we try to check (either \texttt{bf} for bold or
+% \texttt{md} for medium, i.e., the same that can go into the
+% first mandatory argument of \cs{DeclareFontSeriesDefault}),
+%
+% \item
+% what to do if we are in this context (true case) and
+%
+% \item
+% what to do if we are not (false case).
+% \end{itemize}
+% This allows you to define commands like \cs{IfBold}, e.g.,
+%\begin{verbatim}
+% \newcommand\IfBold[2]{\IfSeriesContextTF{bf}{#1}{#2}}
+%\end{verbatim}
+% and then do
+%\begin{verbatim}
+% This is \IfBold{bold}{non-bold} text.
+%\end{verbatim}
+% and get the appropriate result.
+%
+% \changes{v3.2a}{2020/05/19}{Macros added (gh/335)}
+% \begin{macrocode}
+%</2ekernel>
+%<*2ekernel|latexrelease>
+%<latexrelease>\IncludeInRelease{2020/10/01}%
+%<latexrelease> {\IfFontSeriesContext}{Font series context}%
+\DeclareRobustCommand\IfFontSeriesContextTF[1]{%
+ \expand at font@defaults
+% \end{macrocode}
+% In the beginning we haven't found the context we are loking for.
+% \begin{macrocode}
+ \@font at series@contextfalse
+% \end{macrocode}
+% We store the requested context away for use in the tests.
+% \begin{macrocode}
+ \def\requested at test@context{#1}%
+% \end{macrocode}
+% The next definition is there to ensure that get a final match
+% during testing
+% even if the current family is non of the meta families
+% (\texttt{rm}, \texttt{sf} or \texttt{tt}). This will then
+% basically tests if the current font family matches the overall default.
+% \begin{macrocode}
+ \expandafter\edef\csname ??def at ult\endcsname{\f at family}%
+% \end{macrocode}
+% Then we run through the meta family list (currently containing
+% just the three values) followed by the artifical meta family
+% \texttt{??} and test each of them in turn using
+% \cs{test at font@series at context} as the testing command.
+% \begin{macrocode}
+ \let\@elt\test at font@series at context
+ \@meta at family@list
+ \@elt{??}%
+ \let\@elt\relax
+% \end{macrocode}
+% Following that we evaluate the status of
+% \cs{if at font@series at context} to determine which of the remaining
+% arguments (true/false case) we have to execute.
+% \begin{macrocode}
+ \if at font@series at context
+ \expandafter\@firstoftwo
+ \else
+ \expandafter\@secondoftwo
+ \fi
+}
+% \end{macrocode}
+% \end{macro}
+
+
+% \begin{macro}{\test at font@series at context}
+% This tests the context (stored in \cs{requested at test@context})
+% and updates the bookean if the right context is found.
+% \begin{macrocode}
+\def\test at font@series at context#1{%
+% \end{macrocode}
+% First task is to figure out whether the current family matches
+% \cs{rmfamily}, \cs{sffamily}, etc.\ so in \cs{reserved at a} we
+% store the value of \cs{rmdef at ult} (or whatever the given meta
+% family is) and compare that to \cs{f at family}.
+% \begin{macrocode}
+ \edef\reserved at a{\csname #1def at ult\endcsname}%
+ \ifx\f at family\reserved at a
+% \end{macrocode}
+% If they match we have found the right meta family so we don't
+% need to test any of the remaining meta family and therefore
+% change \cs{@elt} to \cs{@gobble}.
+% \begin{macrocode}
+ \let\@elt\@gobble
+% \end{macrocode}
+% Now we have to test if \cs{f at series} matches the requested
+% context (e.g., whether \cs{bfseries at rm} has that value if the
+% current meta family is \texttt{rm} and we are looking for the
+% \texttt{bf} context).
+% \begin{macrocode}
+ \expandafter\ifx
+ \csname\requested at test@context series@#1\endcsname\f at series
+% \end{macrocode}
+% If yes we change the boolean and are done.
+% \begin{macrocode}
+ \@font at series@contexttrue
+% \end{macrocode}
+% If not then maybe the reason is that nothing special was set up
+% for that meta family so we also check now check if \cs{f at series}
+% matches the overall default (e.g., \cs{bfdef at ult} if we are
+% looking for the bold context). If that matches we change the boolean.
+% \begin{macrocode}
+ \else
+ \expandafter\ifx
+ \csname\requested at test@context def at ult\endcsname\f at series
+ \@font at series@contexttrue
+ \fi\fi\fi
+}
+% \end{macrocode}
+% \end{macro}
+
+
+% \begin{macro}{\if at font@series at context}
+% The boolean to signal if we found the requested font series context.
+% \begin{macrocode}
+\newif\if at font@series at context
+% \end{macrocode}
+% \end{macro}
+%
%
+% \begin{macrocode}
+%</2ekernel|latexrelease>
+%<latexrelease>\EndIncludeInRelease
+% \end{macrocode}
%
+% \begin{macrocode}
+%<latexrelease>\IncludeInRelease{0000/00/00}%
+%<latexrelease> {\IfFontSeriesContext}{Font series context}%
+%<latexrelease>
+%<latexrelease>\let\IfFontSeriesContextTF\@undefined
+%<latexrelease>\let\test at font@series at context\@undefined
+%<latexrelease>\let\if at font@series at context\@undefined
+%<latexrelease>\let\@font at series@contexttrue\@undefined
+%<latexrelease>\let\@font at series@contextfalse\@undefined
+%<latexrelease>\EndIncludeInRelease
+%<*2ekernel>
+% \end{macrocode}
+
+
+
%
% \section{Supporting nested emphasis}
%
diff --git a/base/testfiles/github-0336.lvt b/base/testfiles/github-0336.lvt
new file mode 100644
index 00000000..c5b06bb8
--- /dev/null
+++ b/base/testfiles/github-0336.lvt
@@ -0,0 +1,41 @@
+\documentclass{article}
+
+
+\DeclareFontShape{OT1}{cmr}{funny}{n}{%
+ <10>cmtt10%
+ }{}
+
+\DeclareFontSeriesDefault[rm]{bf}{funny}
+\DeclareFontSeriesDefault {bf}{b}
+
+\input{test2e}
+
+\START
+
+\newcommand\IfBold[2]{\IfFontSeriesContextTF{bf}
+ {#1\typeout{#1 \the\font}}{#2\typeout{#2 \the\font}}}
+
+\begin{document}
+
+Some regular \textbf{some bold} and non-bold again.
+
+\textbf{This is \IfBold{bold}{non-bold} text.}
+This is \IfBold{bold}{non-bold} text.
+
+\sffamily
+
+\textbf{This is \IfBold{bold}{non-bold} text.}
+This is \IfBold{bold}{non-bold} text.
+
+\ttfamily
+
+\textbf{This is \IfBold{bold}{non-bold} text.}
+This is \IfBold{bold}{non-bold} text.
+
+\fontencoding{T1}\fontfamily{lmr}\selectfont
+
+\textbf{This is \IfBold{bold}{non-bold} text.}
+This is \IfBold{bold}{non-bold} text.
+
+
+\END
diff --git a/base/testfiles/github-0022b.tlg b/base/testfiles/github-0336.tlg
similarity index 67%
copy from base/testfiles/github-0022b.tlg
copy to base/testfiles/github-0336.tlg
index c70d7419..7e72ff76 100644
--- a/base/testfiles/github-0022b.tlg
+++ b/base/testfiles/github-0336.tlg
@@ -1,10 +1,6 @@
This is a generated file for the LaTeX2e validation system.
Don't change this file in any respect.
-(github-0022b-1.sty
-Package github-0022b-1 with option X
-) (github-0022b-2.sty
-Do something
-) (github-0022b.aux)
+(github-0336.aux)
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line ....
LaTeX Font Info: ... okay on input line ....
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line ....
@@ -19,4 +15,14 @@ LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line ....
LaTeX Font Info: ... okay on input line ....
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line ....
LaTeX Font Info: ... okay on input line ....
-success!
+bold \OT1/cmr/funny/n/10
+non-bold \OT1/cmr/m/n/10
+bold \OT1/cmss/bx/n/10
+non-bold \OT1/cmss/m/n/10
+LaTeX Font Info: Font shape `OT1/cmtt/bx/n' in size <10> not available
+(Font) Font shape `OT1/cmtt/m/n' tried instead on input line ...
+bold \OT1/cmtt/m/n/10
+non-bold \OT1/cmtt/m/n/10
+LaTeX Font Info: Trying to load font information for T1+lmr on input line ....
+bold \T1/lmr/b/n/10
+non-bold \T1/lmr/m/n/10
diff --git a/base/testfiles/tlb-latexrelease-rollback-003-often.luatex.tlg b/base/testfiles/tlb-latexrelease-rollback-003-often.luatex.tlg
index 15e77976..0c6114aa 100644
--- a/base/testfiles/tlb-latexrelease-rollback-003-often.luatex.tlg
+++ b/base/testfiles/tlb-latexrelease-rollback-003-often.luatex.tlg
@@ -229,6 +229,8 @@ LaTeX Info: Redefining \mdseries on input line ....
LaTeX Info: Redefining \rmfamily on input line ....
LaTeX Info: Redefining \sffamily on input line ....
LaTeX Info: Redefining \ttfamily on input line ....
+Skipping: [....-..-..] Font series context on input line ....
+Applying: [....-..-..] Font series context on input line ....
Skipping: [....-..-..] Nested emph on input line ....
Skipping: [....-..-..] Nested emph on input line ....
Applying: [....-..-..] Nested emph on input line ....
@@ -618,6 +620,8 @@ LaTeX Info: Redefining \mdseries on input line ....
LaTeX Info: Redefining \rmfamily on input line ....
LaTeX Info: Redefining \sffamily on input line ....
LaTeX Info: Redefining \ttfamily on input line ....
+Skipping: [....-..-..] Font series context on input line ....
+Applying: [....-..-..] Font series context on input line ....
Skipping: [....-..-..] Nested emph on input line ....
Applying: [....-..-..] Nested emph on input line ....
LaTeX Info: Redefining \em on input line ....
diff --git a/base/testfiles/tlb-latexrelease-rollback-003-often.tlg b/base/testfiles/tlb-latexrelease-rollback-003-often.tlg
index 56278df4..5fb3a504 100644
--- a/base/testfiles/tlb-latexrelease-rollback-003-often.tlg
+++ b/base/testfiles/tlb-latexrelease-rollback-003-often.tlg
@@ -227,6 +227,8 @@ LaTeX Info: Redefining \mdseries on input line ....
LaTeX Info: Redefining \rmfamily on input line ....
LaTeX Info: Redefining \sffamily on input line ....
LaTeX Info: Redefining \ttfamily on input line ....
+Skipping: [....-..-..] Font series context on input line ....
+Applying: [....-..-..] Font series context on input line ....
Skipping: [....-..-..] Nested emph on input line ....
Skipping: [....-..-..] Nested emph on input line ....
Applying: [....-..-..] Nested emph on input line ....
@@ -610,6 +612,8 @@ LaTeX Info: Redefining \mdseries on input line ....
LaTeX Info: Redefining \rmfamily on input line ....
LaTeX Info: Redefining \sffamily on input line ....
LaTeX Info: Redefining \ttfamily on input line ....
+Skipping: [....-..-..] Font series context on input line ....
+Applying: [....-..-..] Font series context on input line ....
Skipping: [....-..-..] Nested emph on input line ....
Applying: [....-..-..] Nested emph on input line ....
LaTeX Info: Redefining \em on input line ....
diff --git a/base/testfiles/tlb-latexrelease-rollback-003-often.xetex.tlg b/base/testfiles/tlb-latexrelease-rollback-003-often.xetex.tlg
index 192ce3fa..312c4028 100644
--- a/base/testfiles/tlb-latexrelease-rollback-003-often.xetex.tlg
+++ b/base/testfiles/tlb-latexrelease-rollback-003-often.xetex.tlg
@@ -227,6 +227,8 @@ LaTeX Info: Redefining \mdseries on input line ....
LaTeX Info: Redefining \rmfamily on input line ....
LaTeX Info: Redefining \sffamily on input line ....
LaTeX Info: Redefining \ttfamily on input line ....
+Skipping: [....-..-..] Font series context on input line ....
+Applying: [....-..-..] Font series context on input line ....
Skipping: [....-..-..] Nested emph on input line ....
Skipping: [....-..-..] Nested emph on input line ....
Applying: [....-..-..] Nested emph on input line ....
@@ -619,6 +621,8 @@ LaTeX Info: Redefining \mdseries on input line ....
LaTeX Info: Redefining \rmfamily on input line ....
LaTeX Info: Redefining \sffamily on input line ....
LaTeX Info: Redefining \ttfamily on input line ....
+Skipping: [....-..-..] Font series context on input line ....
+Applying: [....-..-..] Font series context on input line ....
Skipping: [....-..-..] Nested emph on input line ....
Applying: [....-..-..] Nested emph on input line ....
LaTeX Info: Redefining \em on input line ....
diff --git a/base/testfiles/tlb-rollback-004-often.luatex.tlg b/base/testfiles/tlb-rollback-004-often.luatex.tlg
index 676bd0f6..efdf9902 100644
--- a/base/testfiles/tlb-rollback-004-often.luatex.tlg
+++ b/base/testfiles/tlb-rollback-004-often.luatex.tlg
@@ -327,6 +327,8 @@ LaTeX Info: Redefining \rmfamily on input line ....
LaTeX Info: Redefining \sffamily on input line ....
LaTeX Info: Redefining \ttfamily on input line ....
Already applied: [....-..-..] Custom series on input line ....
+Skipping: [....-..-..] Font series context on input line ....
+Applying: [....-..-..] Font series context on input line ....
Applying: [....-..-..] Nested emph on input line ....
LaTeX Info: Redefining \emreset on input line ....
LaTeX Info: Redefining \em on input line ....
diff --git a/base/testfiles/tlb-rollback-004-often.tlg b/base/testfiles/tlb-rollback-004-often.tlg
index 3f750b7a..66e679db 100644
--- a/base/testfiles/tlb-rollback-004-often.tlg
+++ b/base/testfiles/tlb-rollback-004-often.tlg
@@ -325,6 +325,8 @@ LaTeX Info: Redefining \rmfamily on input line ....
LaTeX Info: Redefining \sffamily on input line ....
LaTeX Info: Redefining \ttfamily on input line ....
Already applied: [....-..-..] Custom series on input line ....
+Skipping: [....-..-..] Font series context on input line ....
+Applying: [....-..-..] Font series context on input line ....
Applying: [....-..-..] Nested emph on input line ....
LaTeX Info: Redefining \emreset on input line ....
LaTeX Info: Redefining \em on input line ....
diff --git a/base/testfiles/tlb-rollback-004-often.xetex.tlg b/base/testfiles/tlb-rollback-004-often.xetex.tlg
index 9a2832bc..328dd37b 100644
--- a/base/testfiles/tlb-rollback-004-often.xetex.tlg
+++ b/base/testfiles/tlb-rollback-004-often.xetex.tlg
@@ -325,6 +325,8 @@ LaTeX Info: Redefining \rmfamily on input line ....
LaTeX Info: Redefining \sffamily on input line ....
LaTeX Info: Redefining \ttfamily on input line ....
Already applied: [....-..-..] Custom series on input line ....
+Skipping: [....-..-..] Font series context on input line ....
+Applying: [....-..-..] Font series context on input line ....
Applying: [....-..-..] Nested emph on input line ....
LaTeX Info: Redefining \emreset on input line ....
LaTeX Info: Redefining \em on input line ....
More information about the latex3-commits
mailing list.