[Tex/LaTex] \prime gives “Undefined control sequence” in xelatex with unicode-math

symbolsunicode-mathxetex

I cannot seem to be able to create a prime (') in any custom font. This, for example

\documentclass{article}
\usepackage{unicode-math, polyglossia}
\setmainfont{Times New Roman}
\setmathfont[range=\mathit/{latin,Latin}]{timesi.ttf}
\begin{document}
  Hello, I want A-prime: 
  $$A^\prime.$$
\end{document}

gives "Undefined control sequence [ $$A^\prime]" error. I've tried A', A\prime, A^\prime, none works. Without the \setmathfont command, xelatex works fine, outputting the expected A' in the standard CM font. I found this: What is the right way to input prime with Unicode-math (LuaTeX backend) from 3 years ago, but they are concerned about the correct placement of prime, whereas for my example xelatex won't even recognise such command exists. I'd sure be grateful for any pointers.

Best Answer

It seems that there are appearing bugs in unicode-math.

Here's a workaround: load the prime from a math font after loading the fonts. By the way, it's necessary to call \setmathfont with the original font after any others to set the correct “fontdimens”.

\documentclass{scrartcl}
\usepackage{unicode-math,polyglossia}
\setmainfont{Gentium}
\setmathfont[range=\mathit/{latin,Latin}]{Gentium Italic}
\setmathfont[range={"2032}]{TeX Gyre Pagella Math}
\setmathfont[range={\int}]{Latin Modern Math}
\begin{document}
Hello, I want A-prime: \[ A^\prime \textrm{ or } x' \]
\end{document}

enter image description here

I used TeX Gyre Pagella Math because it looks better in my example, with Latin Modern Math you only need

\setmathfont[range=\mathit/{latin,Latin}]{Gentium Italic}
\setmathfont[range={"2032}]{Latin Modern Math}