4

I would like to be able to combine font changing commands using unicode-math in a math environment. For instance, I define a symbol as being in an upright font, but I want a bold version of that upright symbol. I was thinking that \symbf{\symup{V}} would work, but it does not. There are the commands \symbfup and others to specify both font faces. How can I accomplish combining them? The actual use case is shown in the MWE below:

\documentclass{article}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Pagella Math}
\newcommand*{\velocity}{\symup{V}}
\newcommand*{\vectorsym}[1]{\symbf{#1}}
\begin{document}
$\velocity \quad \vectorsym{\velocity} \quad \symbfup{V}$
\end{document}
  • 1
    latex math font commands (both classical and unicode-math) are designed not to merge in this way, the intention is that you have a named command for each alphabet used. – David Carlisle Dec 13 '15 at 18:58
  • @DavidCarlisle So I need to define a special command to do what I want? OK that's fine. Thanks! – darthbith Dec 13 '15 at 19:05
  • I did have some thoughts about making the math font commands behave more like the text font ones so that \mathbf{\mathsf{X}} would give you a bold sans X. Maybe if I get some time to look at the code again over the Christmas break… – Will Robertson Dec 14 '15 at 2:31
6

As David Carlisle remarks in comments, math alphabet commands have never thought to behave “cumulatively”. Thus \symbf has no effect on something already affected by \symup. However, since your aim is to produce \symbf anyway (and \symbfup does nothing different from it), you can define \vectorsym to locally redefine \symup to be a no-op:

\documentclass{article}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Pagella Math}

\newcommand*{\velocity}{\symup{V}}

\ExplSyntaxOn
\NewDocumentCommand{\vectorsym}{m}
 {
  \group_begin:
  \cs_set_eq:NN \symup \use:n
  \symbf{#1}
  \group_end:
 }
\ExplSyntaxOff

\begin{document}
$\velocity \quad \vectorsym{\velocity} \quad \symbfup{V} \quad \vectorsym{x}$
\end{document}

enter image description here

  • Thank you! So the bold font makes things upright anyways? Then how would I achieve a bold italic math font? Do those characters have to exist in the font? I'm not sure what a use case for that would be, but now I'm curious :-) – darthbith Dec 14 '15 at 12:23
  • @darthbith \symbfit, IIRC – egreg Dec 14 '15 at 12:33
  • Well that's just too logical... thank you again! :-) – darthbith Dec 14 '15 at 14:09

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.