Following this example I created a command to check, if the bold font is currently selected.

This definitely used to work with fontspec some time ago (with TeXlive2018, if pdf-metadata is to be trusted), but not anymore (just ran tlmgr on my TeXlive2020 installation), as the following MWE shows:

%!TEX program = lualatex

%-- Font setup
\setmainfont{XCharter} % <-- COMMENT THIS LINE!

%-- IfBold Command

%-- Define a command for K-theory


\section*{I like \K-Theory}
This is the regular \K.
\textbf{This is \IfBold{bold}{non-bold} text.}
This is \IfBold{bold}{non-bold} text.


Is this a newly introduced bug or am I missing something?

  • 2
    it is not a bug, it is a change in LaTeX, but I have no time now ... – Ulrike Fischer May 14 '20 at 9:33
  • 2
    the easiest for now is to add \DeclareFontSeriesDefault[sf]{bf}{b} and to test for b: \newcommand*{\my@test@bx}{b}, but I will discuss a more generic solution to test for "bold context". – Ulrike Fischer May 14 '20 at 12:40

I have added \IfFontSeriesContextTF to the set of NFSS commands in the kernel so that one can reliably determine the font series context even if, say in one font "bold" means semi-bold or ...

The first argument is either bf (am I typsetting in \bfseries?) or md(am I typsetting in `\mdseries?). It is an argument because one day there may be more series contexts available.

This is matching \DeclareFontSeriesDefault with which one can specify what "bold" means in \sffamilyand so forth.

The code will appear during the next days in a new upload of the latex-dev format and will appear officially in the fall release 2020.

For now you can use the code below in place of the one you had in your example (somewhat longer, I know). Once latex-dev is out all you need is the definition for \IfBold, i.e., one line and then use

lualatex-dev  myfile

to compile it.

%-- IfBold Command

  \expandafter\edef\csname ??def@ult\endcsname{\f@family}%

  \edef\reserved@a{\csname #1def@ult\endcsname}%
                \csname\requested@test@context series@#1\endcsname\f@series
                  \csname\requested@test@context def@ult\endcsname\f@series




The result is:

enter image description here

Happy Texing

Update 2020/05

An implementation of this is now added to the development format of LaTeX and can be tested with lualatex-dev etc. It will be available in the next main release in fall 2020.

  • Sorry for an unrelated comment here. I would be really grateful if you could take a look at this question: tex.stackexchange.com/q/546846 I think you, as a xparse developer can help. – antshar Jun 1 '20 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.