# What is the right way to input prime with Unicode-math (LuaTeX backend)

I opened an issue about this in Unicode-math's github repository. However, I am not so sure it is actually a bug, or I just did something wrong.

Here is a minimal example,

\documentclass{article}

\usepackage{unicode-math}

\setmathfont[version=Asana]      {Asana Math}
\setmathfont[version=Cambria]    {Cambria Math}
\setmathfont[version=LatinModern]{Latin Modern Math}
\setmathfont[version=Minion]     {Minion Math}
\setmathfont[version=XITS]       {XITS Math}

\setlength{\parindent}{0pt}

\begin{document}
\fontsize{36}{36}\selectfont
Asana       \mathversion{Asana}       $\testprime$
Cambria     \mathversion{Cambria}     $\testprime$
LatinModern \mathversion{LatinModern} $\testprime$
Minion      \mathversion{Minion}      $\testprime$
XITS        \mathversion{XITS}        $\testprime$
\end{document}


It seems that the ASCII input was transformed into supscripts while \prime etc are not.

With Asana Math the ASCII version looks fine while the \prime version looks horrible. It looks like in Asana Math primes are designed as normal glyph, they need to be raised to supscripts to works well.

With Latin Modern Math, it looks horrible for both case. I think it is a font problem for LM case.

For other three fonts, the \prime looks good while using ASCII input they looks terrible. In these fonts, the primes seems to be designed as a supscripts glyph, and raising them even more does not looks good.

Is there anyway to modify the behavior of the ASCII input?

In addition, with Latin Modern Math, neither '''' or \qprime works, they all produce nothing. I thought '''' was supposed to use negative kern to fake the \qprime when it is not available.

Update: Thanks for both @KhaledHosny and @LeoLiu's answers. Now it seems to be more complicated. Using the old TeX way to typeset primes get the position right when both prime and subscripts are presented. However, to conform the Unicode standard, I think the fonts should design the primes as superscript glyphs, which means they will look really bad when raised in superscript position. Right now my temporary solution is to use \prime etc. and add a negative kern between primes and subscripts.

Update Thanks for @LeoLiu's answer, which worked fine for me before. Here is just an update for newer versions of unicode-math. The main change is that the prefix of unicode-math's internal macros is now __um instead of um.

\ExplSyntaxOn
\group_begin:
\char_set_catcode_active:N \'
\char_set_catcode_active:N \
\char_set_catcode_active:n {"2032}
\char_set_catcode_active:n {"2033}
\char_set_catcode_active:n {"2034}
\char_set_catcode_active:n {"2057}
\char_set_catcode_active:n {"2035}
\char_set_catcode_active:n {"2036}
\char_set_catcode_active:n {"2037}
\cs_gset:Nn \__um_define_prime_chars: {
\cs_set_eq:NN '        \__um_scan_prime:
\cs_set_eq:NN ^^^^2032 \__um_scan_prime:
\cs_set_eq:NN ^^^^2033 \__um_scan_dprime:
\cs_set_eq:NN ^^^^2034 \__um_scan_trprime:
\cs_set_eq:NN ^^^^2057 \__um_scan_qprime:
\cs_set_eq:NN         \__um_scan_backprime:
\cs_set_eq:NN ^^^^2035 \__um_scan_backprime:
\cs_set_eq:NN ^^^^2036 \__um_scan_backdprime:
\cs_set_eq:NN ^^^^2037 \__um_scan_backtrprime:
}
\group_end:
\ExplSyntaxOff


Also it seems that newer versions of CambriaMath and latest unicode-math together no longer need this fix. Though it is still needed for MinionMath.

In traditional TeX fonts, \prime is a big glyph like the one in Latin Modern Math or Asana Math. However, there isn't such a character in Unicode. Symbol U+2032 is used as prime, but it looks like $^\prime$ i.e. $'$ in TeX. That makes the problem.

As a Unicode math font, Cambria/Minion/XITS is correct. And \prime command should be unavailable then. It seems a bug. I don't think the maintainers of unicode-math can do much. Asana Math and Latin Modern Math fonts may be modified to coincide with Unicode standard; then unicode-math can produce consistent result.

Definition in Unicode: http://www.unicode.org/charts/PDF/U2000.pdf

A temporary fix for Cambria Math:

\documentclass{article}
\usepackage{unicode-math}
\setmathfont{Cambria Math}
\ExplSyntaxOn
\group_begin:
\char_set_catcode_active:N \'
\char_set_catcode_active:N \
\char_set_catcode_active:n {"2032}
\char_set_catcode_active:n {"2033}
\char_set_catcode_active:n {"2034}
\char_set_catcode_active:n {"2057}
\char_set_catcode_active:n {"2035}
\char_set_catcode_active:n {"2036}
\char_set_catcode_active:n {"2037}
\cs_gset:Nn \um_define_prime_chars: {
\cs_set_eq:NN '        \um_scan_prime:
\cs_set_eq:NN ^^^^2032 \um_scan_prime:
\cs_set_eq:NN ^^^^2033 \um_scan_dprime:
\cs_set_eq:NN ^^^^2034 \um_scan_trprime:
\cs_set_eq:NN ^^^^2057 \um_scan_qprime:
\cs_set_eq:NN         \um_scan_backprime:
\cs_set_eq:NN ^^^^2035 \um_scan_backprime:
\cs_set_eq:NN ^^^^2036 \um_scan_backdprime:
\cs_set_eq:NN ^^^^2037 \um_scan_backtrprime:
}
\group_end:
\ExplSyntaxOff

\begin{document}

$A' A'' A''' A''''$

\end{document}


• Can you do the same "fix" that you did for Cambria Math on a per-font basis (e.g. for use with \mathversion)? It seems to apply to the current math font now. Nov 27, 2013 at 8:12

You can either use f' or f^\prime, which is the proper way for inputting prime even if not using unicode-math. The fact that some fonts give superscripted prime with \prime is not something you should rely on. See Why isn't \prime automatically set to be a superscript? for the reason why old TeX fonts have such a big prime glyph (In OpenType math the issue is dealt with a bit differently, but some fonts still following the old practices).

• Now that I see the image (it was not sown when I wrote this answer), there is clearly a bug with the f' case. Oct 1, 2011 at 3:41
• Sorry to bring up an old topic, but it seems that the bug is still around. What's the recommended workaround? Jul 18, 2014 at 9:37