1

Consider the following code:

% !TeX program = xelatex
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsthm,amssymb,amsfonts}

% STIX Two font
\usepackage[math-style=ISO]{unicode-math}
\usepackage{xltxtra}
\setmainfont[Numbers=OldStyle]{STIX Two Text}
\setmathfont{STIX Two Math}

\begin{document}

\begin{tabular}{lll}
    text   & A = 1              & \textit{B = 0}          \\
    textbf & \textbf{A = 1}     & \textbf{\textit{B = 0}} \\
    math   & $A = 1$            & $\mathit{B = 0}$        \\
    mathbf & $\mathbf{A = 1}$   & $\mathbf{B = 0}$        \\
    symbf  & $\symbf{A = 1}$    & $\symbf{B = 0}$
\end{tabular}

\end{document}

Results:

enter image description here

As you can see, in a normal math environment (i.e. between $$), the numbers are of lining style (c.f. 3rd line). But if the numbers are in \mathbf or \mathit then they have the old style (c.f. 3rd line and 4th line), which is ugly for me. The reason is, I guess, that the STIX Two Math font does not have bold face or italic face.

I can use \symbf and \symit instead, but then my code will be invalid if e.g. I switch back to LaTeX (instead of XeLaTeX).

My question is: How to force \mathbf to use lining-style numbers? (Only numbers and not letters.)

Thank you very much in advance for your help!

1

One solution is to use \symbfup rather than \symbf. This gets you bold upright symbols, rather than ISO-style bold italic. That is probably what you wanted. (If you consistently want to use upright letters, consider setting math-style to something other than ISO.)

To answer the literal question you asked, you want to use \setmathrm from fontspec, which the unicode-math package includes. Give it the BoldFont= and BoldFeatures= options, as with \newfontfamily.

% !TeX program = xelatex
\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}

% STIX Two font
\usepackage[math-style=ISO]{unicode-math}
\setmainfont[Numbers=OldStyle]{STIX Two Text}
\setmathfont{STIX Two Math}
\setmathrm{STIX Two Text}[
  UprightFeatures={Numbers=OldStyle},
  BoldFont = STIX Two Text Bold,
  BoldFeatures={Numbers=Lining}]
\setboldmathrm{STIX Two Text Bold}[Numbers=Lining]

\begin{document}

\begin{tabular}{lll}
    text   & A = 1              & \textit{B = 0}          \\
    textbf & \textbf{A = 1}     & \textbf{\textit{B = 0}} \\
    math   & $A = 1$            & $\mathit{B = 0}$        \\
    mathbf & $\mathbf{A = 1}$   & $\mathbf{B = 0}$        \\
    symbf  & $\symbf{A = 1}$    & $\symbf{B = 0}$
\end{tabular}

\end{document}

Sample Text

I went ahead and set \setboldmathrm as well (the \mathrm font for bold-style math). You will get some harmless warning messages about how the font does not support uppercase numbers. You can suppress those by removing BoldFeatures={Numbers=Lining} and [Numbers=Lining].

I also removed a couple of packages you weren’t using for this example. Please note: you shouldn’t load inputenc in the TeX engines that support unicode-math, nor should you load amsfonts and amssymb if you are going to load an OpenType math font over them.

|improve this answer|||||
  • 1
    A detailed answer, with advice on good practice one should follow. This is a typical excellent answer that I expect. Since I cannot upvote twice, I found another answer (also excellent) from you to upvote. Thanks a lot! – Khue Sep 28 '18 at 7:05
  • @Khue Thanks. For future reference, you can upvote twice, once you get a little more karma, by awarding a bounty. – Davislor Sep 28 '18 at 7:19

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.