1

I'm using xelatex and I'd like to use Cyrillic glyphs in math formulas just like ordinary glyphs. With the following code I have blanks instead of Cyrilli glyphs in the formula in the resulting PDF:

\documentclass{letter}
\usepackage{fontspec}
\setmainfont{Liberation Serif}
\setmathrm{Liberation Serif}
\begin{document}
Cyrillics: {абВ 0123456789} \it{абВ 0123456789}
$ abC = 1,234567890 = абВ = \sin {1,234567890 {абВ}_{абВ} } \Phi \alpha $
\end{document}

In the logfile it says

Missing character: There is no а in font cmmi10!
Missing character: There is no б in font cmmi10!
Missing character: There is no В in font cmmi10!
Missing character: There is no а in font cmmi7!
Missing character: There is no б in font cmmi7!
Missing character: There is no В in font cmmi7!

Using \mathit and the likes of it for every Cyrillics snippet is sort of a half-solution.

Is it possible to replace the 'Latin Modern' family in the configuration with, say, the 'CMU' ('Computer Modern Unicode') family, which has both Cyrillics and a decent glyphs' coverage? (My attempts to solve the problem with 'unicode-math' package produce the similar issue).

yury10578
  • 169
  • Welcome to Tex.SE. – Mico Mar 27 '20 at 19:54
  • I can’t reproduce your bug in my installation of TeX Live 2019. It should not be trying to load the cmm font family after you load fontspec. – Davislor Mar 28 '20 at 00:19
  • Text mode is one thing. On the maths mode side of things, the various math alphabets are defined in Latin, Greek, and Digits only. To define other glyphs as math symbols, you would have to define them similar to @egreg 's answer in https://tex.stackexchange.com/questions/201239/cant-get-unicode-symbols-in-math-mode – Cicada Mar 28 '20 at 02:46
  • @Davislor My installation is XeTeX 3.14159265-2.6-0.999991 (TeX Live 2019 on Slackware) kpathsea version 6.3.1 The TeXLive as a whole is from June 2019, I understand.

    How do I verify the installation?

    – yury10578 Mar 28 '20 at 04:43
  • @Cicada Unfortunately, the solution you mention doesn't work for me (maybe because it's for the 2014 version?):

    ! Undefined control sequence. \addmathletter ...alpha \csname sym\um_symfont_tl \endcsname #1\relax l.18 }

    ? ! Missing number, treated as zero.

    \sym l.18 }

    ?

    Do I

    – yury10578 Mar 28 '20 at 05:02
  • Does it work in LuaLaTeX? – Davislor Mar 28 '20 at 05:23
  • @Davislor No, fails in the same place - in the \int_step_inline:nnnn part

    Log messages look the same.

    – yury10578 Mar 28 '20 at 05:47
  • I've tried just now with older TeXLive (June 2018). It doesn't work correctly with my example ('cmm' still loads) or with unicode-math example cited here, either (\int_step_inline:nnnn fails). – yury10578 Mar 28 '20 at 06:16

2 Answers2

1

Without hyperref and polyglossia (some interaction occurring with them that I don't follow), I get this:

Cyrillic math

MWE

\documentclass[12pt]{article}

\usepackage{amsmath,amssymb}
\usepackage{unicode-math}
%\usepackage{polyglossia}
%\setdefaultlanguage{russian}
%\setotherlanguage{english}
%\newcommand\cyrillicfont{Noto Serif}

\setmainfont{Liberation Serif}
\setmathrm{Liberation Serif}

%\usepackage[russian]{hyperref}

\setmathfont{XITS Math}



%See: https://tex.stackexchange.com/questions/201239/cant-get-unicode-symbols-in-math-mode

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

\begin{document}
\[
(д+ф)^{2}=д^{2}+2дф+ф^{2}м
\]

\[
г л а м н я^{2^{i}}
\]

Inline math mode: $ abC = 1,234 = абВ = \sin ({1,67895 \times {абВ}_{абВ} }) \Phi \alpha $

xxx $а + ц ж + е$ xxx

\end{document}

Compiled with xelatex (miktex on windows):

This is XeTeX, Version 3.14159265-2.6-0.999992 (MiKTeX 2.9.7300 64-bit) entering extended mode (cyrillic_maths_egreg2a.tex LaTeX2e <2020-02-02> patch level 5 L3 programming layer <2020-03-06>

Cicada
  • 10,129
  • Thank you. It works, sort of, because there are actually two font faces in the output, XITS Math (latin, greek and numbers) and Liberation Serif (cyrillics).

    Could it be modified to use the 'setmainfont' face for latin, greek and numbers?

    – yury10578 Mar 28 '20 at 07:57
  • setmainfont is for text. Ask a separate question, to get more eyes on it. It sounds like the font is the issue: it will have to have cyrillic (for text) and all the math alphabets defined - to have a harmonious style. – Cicada Mar 28 '20 at 08:11
  • I mean could the \DeclareSymbolFont fragment use the same face as that which is set in \setmainfont also for latin, greek and numbers? – yury10578 Mar 28 '20 at 08:14
  • It remains a font issue. Ask a separate question. Note that: In text mode, one font for normal, one font for italic, one font for bold, one font for bold-italic. In each of these, there may (or may not) be Latin, Greek, Cyrillic, Armenian, and so on. In math mode (in Unicode), one font contains 13 Latin math alphabets, and 5 Greek ones, and there are 5 types of digits: see https://tex.stackexchange.com/questions/224144/is-there-any-sans-serif-font-that-fully-supports-unicode-math/411259 – Cicada Mar 28 '20 at 12:52
  • You are overcomplicating, I think. And I'd rather have an answer to my original question. Anyway, I was able to put together a fairly adequate solution finally -- with your help. Thanks. – yury10578 Mar 28 '20 at 14:53
0

What actually answers my own question fairly close is the approach to glyphs redefinition suggested by @Cicada (references in the code), combined with the 'mathfont' package (one click away from CTAN homepage). Works in OpenOffice's TexMaths addon, too.

\documentclass{letter}
\usepackage{mathfont}
\setmainfont{Liberation Serif}
\mathfont{Liberation Serif}
% The glyphs redefinition code by https://tex.stackexchange.com/users/182648/cicada
% as posted at https://tex.stackexchange.com/a/534590/210048
% See also: https://tex.stackexchange.com/questions/201239/cant-get-unicode-symbols-in-math-mode
\DeclareSymbolFont{cyrletters}{\encodingdefault}{\familydefault}{m}{it}
\newcommand{\makecyrmathletter}[1]{%
  \begingroup\lccode`a=#1\lowercase{\endgroup
  \Umathcode`a}="0 \csname symcyrletters\endcsname\space #1
}
\count255="409
\loop\ifnum\count255<"44F
  \advance\count255 by 1
  \makecyrmathletter{\count255}
\repeat
\begin{document}
Text: {\it{abC}} = 1,234567890 = {\it{абВ}\footnotesize{абВ}} = {sin} 1,234567890 \, {Φ} {\it{α}}
Math: $ abC = 1,234567890 = {абВ}_{абВ} = \sin {1,234567890} \, \Phi \, \alpha $
\end{document}

enter image description here

UPDATED: Even better is to use 'mathspec' package, which doesn't conflict with 'amsmath', as does 'mathfont'. In the same sample code substitute

\usepackage{mathfont}
\setmainfont{Liberation Serif}
\mathfont{Liberation Serif}

with

\usepackage{amsmath}
\usepackage{mathspec}
\setmainfont{Liberation Serif}
\setallmainfonts{Liberation Serif}
yury10578
  • 169