2

I'm using unicode-math (with XeLaTeX) to set my text and math fonts. However, using Garamond-math as a math font, I see the \prime symbol is too close to the letter:

enter image description here

I am trying to redefine the \prime command, and if possible I would like to remap ' in math mode so that it gives the correct spacing. However, the "usual" solution to redefine \prime, that is (MWE)

\documentclass{article}
\usepackage{unicode-math}
\setmathfont{Garamond-Math.otf}[StylisticSet={5,7,9}]
\let\originalprime\prime
\def\prime{\mkern3mu\originalprime\mkern-3}
\begin{document}

$f'(x)$

\end{document}

but this solution does not seem to work in this context. I also tried

\usepackage{newunicodechar}
\AtBeginDocument{\newunicodechar{′}{\mkern3mu\prime\mkern-3u}}

but again it had no effect.

2
  • As always you are more likely to get help if you provide full but minimal examples, not these sniplets, but something others can copy and test as is.
    – daleif
    Oct 10, 2022 at 13:53
  • It is most likely not the prime that is the main problem, but the italic f and its bounding box. In ConTeXt we can fix this on the fly, compare without fix and with fix.
    – mickep
    Oct 10, 2022 at 17:06

1 Answer 1

2

In unicode-math the command \prime is defined in terms of an internal function, which is used when f'(x) is processed. So redefining \prime does nothing, unless you do use it explicitly.

There is no interface for modifying the behavior, unfortunately. But the following works with the current version of unicode-math. However, due to accessing private functions, this is not guaranteed to remain stable in future releases.

\documentclass{article}
\usepackage{unicode-math}
\setmathfont{Garamond-Math.otf}[StylisticSet={5,7,9}]

\ExplSyntaxOn
\cs_set:Npn \__um_prime_single_mchar { \mkern2mu\Umathchar"0"0"2032\mkern-2mu~}
\cs_set:Npn \__um_prime_double_mchar { \mkern2mu\Umathchar"0"0"2033\mkern-2mu~}
\cs_set:Npn \__um_prime_triple_mchar { \mkern2mu\Umathchar"0"0"2034\mkern-2mu~}
\ExplSyntaxOff

\begin{document}

$f'(x)+f''(x)+f'''(x)$

$g'(x)+g''(x)+g'''(x)$

$h'(x)+h''(x)+h'''(x)$

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .