# Can't get unicode symbols in math mode

I am trying for about a week to launch unicode-math package with XeLaTeX and got nothing. PDF is created well but all Cyrillic symbols in math mode are skipped. I tried using different math fonts - no progress at all. In log file, I found low-level error:

Missing character: There is no [cyrillic letter from input] in font cmmi12!


But all fonts used in document are Unicode ones.

Here is a file I want to be processed well (of course it is UTF-8).

\documentclass[12pt]{book}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=modern]{russian}
\setotherlanguage{english}
\defaultfontfeatures{Ligatures={TeX}}
\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}

\usepackage{amsmath, amssymb}
\usepackage[russian]{hyperref}

\usepackage{unicode-math}
\setmathfont{Latin Modern Math}

\frenchspacing

\begin{document}
Просто буквы % Plain letters
$$Память: M_{доп}(n) = \Theta(N)$$ % Memory: M_add(n) = \Theta(n)
\end{document}


• What makes you think there are glyphs in Latin Modern Math for Cyrillic chars? – Joseph Wright Sep 15 '14 at 11:34
• @JosephWright Actually i am trying fonts that are mentioned in unicode-math doc as Unicode-compatible ones. I also tried xits-math and don't succeed as well. – Lapshin Dmitry Sep 15 '14 at 11:43
• I think you slightly miss my point. Unicode fonts don't have every Unicode glyph in them, they have a subset but in predictable slots. In the case of a math mode font, this means defined 'mathematical meaning' glyphs. That I know of there are not such math mode slots for Cyrillic letters: one is expected to use Roman chars for maths. As such, it's entirely unsurprising that you don't get all of the text appearing in your output. – Joseph Wright Sep 15 '14 at 11:46
• Now that this question is resolved, could you adjust the title of this question to be more specific please? It won't archive well in its current form. – Will Robertson Sep 15 '14 at 12:53
• @WillRobertson changed. Actually, now I took in the problem and understand, why it should be called like this. – Lapshin Dmitry Sep 15 '14 at 16:22

This is not a problem of cyrillic math characters; if the text were English, the correct input would be

Letters only
$\text{Memory: } M_{\textup{add}}(n) = \Theta(N)$


because Память and доп are not math. The difference becomes clear when comparing this with the output of

$Memory: M_{add}(n) = \Theta(N)$


The bottom formula is clearly wrong. Textual subscripts are not math variables, so they should be typeset in the normal text font (upright), thus either \textnormal or \textup (the latter is shorter). Of course, you can define your own command for them.

Here's the complete example:

\documentclass[12pt]{book}

\usepackage{amsmath,amssymb}
\usepackage{unicode-math}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=modern]{russian}
\setotherlanguage{english}

\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}

\usepackage{color}
\usepackage{minted}
\usepackage[russian]{hyperref}

\setmathfont{Latin Modern Math}

\frenchspacing

\begin{document}

Просто буквы % Plain letters
$\text{Память: } M_{\textnormal{доп}}(n) = \Theta(N)$
\end{document}


It would be a different problem if you wanted to use a cyrillic letter as a math variable, but your case is not this one.

If you need cyrillic letters as math variables, here's a way to set them up:

\documentclass[12pt]{book}

\usepackage{amsmath,amssymb}
\usepackage{unicode-math}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=modern]{russian}
\setotherlanguage{english}

\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}

\usepackage[russian]{hyperref}

\setmathfont{Latin Modern Math}

\DeclareSymbolFont{cyrletters}{\encodingdefault}{\familydefault}{m}{it}
\newcommand{\makecyrmathletter}[1]{%
\begingroup\lccodea=#1\lowercase{\endgroup
\Umathcodea}="0 \csname symcyrletters\endcsname\space #1
}
\count255="409
\loop\ifnum\count255<"44F
\makecyrmathletter{\count255}
\repeat

\begin{document}
$(д+ф)^{2}=д^{2}+2дф+ф^{2}$
\end{document}


• I would use M_{\mathrm{add}}(n) instead of \textup to avoid that the index can change along with the surrounding textfont (e.g. if this is in bold). For the "Memory:" it depends on the meaning. – Ulrike Fischer Sep 15 '14 at 13:05
• @UlrikeFischer The choice between \mathrm and \textup is subjective; the safest is, in my opinion, \textnormal, but having a formula in a boldface context should be quite rare (that is, never). Using a personal command reliefs from the burden. The word “Memory” instead should inherit the font from the context. – egreg Sep 15 '14 at 13:10
• Good solution, but not for my problem --- i really need cyrillic as part of math. Still, great thanks! – Lapshin Dmitry Sep 15 '14 at 16:16
• @LapshinDmitry I've added the method for defining the letters as math (italic) variables. If you don't want italics, change the {it} into {n}. – egreg Sep 15 '14 at 17:15
• @LapshinDmitry If you don't say what are your needs, it's just guessing. – egreg Sep 15 '14 at 17:48

There has been some discussion about Cyrillic in math but the issue is still open: https://github.com/wspr/unicode-math/issues/29

As Joseph mentioned you need fonts with the glyph. In case of math (if you don't switch to a text font with \text{..}) you also need to set mathcodes. E.g.;

\documentclass[12pt]{book}
\usepackage{unicode-math}
\setmainfont{Arial Unicode MS} %for text
\setmathfont[]{xits-math.otf}
\ExplSyntaxOn
\makeatletter
\Umathcode  #1="\mathchar@type\mathalpha \csname sym\um_symfont_tl\endcsname #1\relax
}
\int_step_inline:nnnn {1024}{1}{1154}{
}
\ExplSyntaxOff

\begin{document}
Просто буквы % Plain letters
$$Память: M_{доп}(n) = \Theta(N)$$ % Memory: M_add(n) = \Theta(n)
\end{document}


(The \Umathcode line is copied and adapted from an old message in the xetex list and I don't what the quoting sign at the begin is doing there ...)

• The " is the hexadecimal prefix, as usual. – egreg Sep 15 '14 at 12:34
• @egreg: Yes I suspected this. But is seems not to make a difference if it is there or not. OK. Looking at it \mathchar@type\mathalpha is 7 and so "7=7. – Ulrike Fischer Sep 15 '14 at 12:50
• Since math types are from 0 to 7 it really doesn't make any difference. – egreg Sep 15 '14 at 12:53
• Exactly the result I wanted. Thanks a lot. I know that non-math text shouldn't be at math-mode, but I need cyrillic, and I got it. – Lapshin Dmitry Sep 15 '14 at 16:16