5

Changing Math Fonts with luaotfload in Plain LuaTeX

Without a major exposition on all the options tried, here is the short of it:

Using Tex Live 2013, LuaTeX, plain.fmt and luaotfload.sty, (luaotfload-tool version 2.2, database version 2.204), on both Mac OS X and Windows7, the following TeX does not set the new math fonts properly.

% this works with ConTeXt's LuaTeX-Plain perfectly, except
% that *all* text is rendered in italic, (but that is a 
% problem for another time -- still better than this).
%
\input luaotfload.sty
\font\lmromr   =
    {latinmodernmathregular:mode=base;script=math} at 14pt
\font\lmromi   = 
    {latinmodernmathregular:mode=base;script=math}  at 14pt
\font\lmromsr  = 
    {LatinModernMath-Regular:mode=base;script=math;ssty=0} at 12pt
\font\lmromsi  = 
    {LatinModernMath-Regular:mode=base;script=math;ssty=0} at 12pt
\font\lmromssr = 
    {LatinModernMath-Regular:mode=base;script=math;ssty=1} at 10pt
\font\lmromssi = 
    {LatinModernMath-Regular:mode=base;script=math;ssty=1} at 10pt

\textfont0 = \lmromr  
\scriptfont0 = \lmromsr
\scriptscriptfont0 = \lmromssr
\textfont1 = \lmromi
\scriptfont1 = \lmromsi
\scriptscriptfont1 = \lmromssi
\textfont2 = \lmromr
\scriptfont2 = \lmromsr
\scriptscriptfont2 = \lmromssr
\textfont3 = \lmromr
\scriptfont3 = \lmromsr
\scriptscriptfont3 = \lmromssr

\TeX's “hello world” display math:
$$
x = {{b\pm\sqrt{b^{2} - 4ac}}\over{2ac}}
$$
Or some inline: $0 = ax^{2} + bx + c$, or
$\sqrt{a\over b}$ 
({\tt\$\\sqrt\{a\\over b\}\$}),
$\sin({\alpha\over\theta})$
({\tt\$\\sin(\{\\alpha\\over\\theta\}}).

\bye

All text is upright, and no symbols are displayed. Clearly my fault, but have no idea how to fix it or what fonts to use, or which font features to select other than the above.

Main reference: Khaled Hosny. Picked up ideas from some other searches, but no solutions. And no, I'm not interested to hear how easy LaTeX or ConTeXt or XeTeX is =).

Wish somebody makes a {plain-luatex} tag.

3
  • 1
    You have also to change almost all of the math codes. – egreg May 17 '14 at 17:42
  • 1
    See this gist for help. Notice the comment on LuaTeX (+ssty0, 1 and 2 instead of just 0 and 1). – morbusg May 22 '14 at 14:48
  • I don't understand why you need to load OTF math fonts for math. Note that you can combine OTF text fonts with Type1 math fonts: they are loaded by amstex.tex (for example) by default. – wipet May 24 '14 at 7:56
5

Because of the encoding difference between Unicode and TeX, you would need to write (almost) all of the mathematical mode definitions. Just to support your minimal, one would need (at least):

\def\mathfont{TeXGyreBonumMath-Regular:script=math} % just to make it more obvious
\font\math="\mathfont;+ssty=0" at 14pt
\font\maths="\mathfont;+ssty=1" at .7\fontdimen6\math
\font\mathss="\mathfont;+ssty=2" at .5\fontdimen6\math
\textfont0=\math \scriptfont0=\maths \scriptscriptfont0=\mathss
\fam0

\Umathchardef\pm="2"0"00B1
\def\sqrt{\Uradical"0"221A }
\Umathcodenum`a="1D44E
\Umathcodenum`b="1D44F
\Umathcodenum`c="1D450
\Umathcodenum`x="1D465
\Umathcode`\/="0"0"2215
\Umathcode`\+="2"0"2B
\Umathcode`\=="3"0"3D
\Umathcharnumdef\alpha="1D6FC
\Umathcharnumdef\theta="1D703

\newtoks\mathtttoks\mathtttoks={%
  \Umathcodenum`a="1D68A
  \Umathcodenum`b="1D68B }
\def\tt{\the\mathtttoks}

$$
  x = { b\pm\sqrt{b^2 - 4ac} \over 2ac }
$$
Or some inline: $0 = ax^2 + bx + c$, or $\sqrt{a/b}$
$\tt\sqrt{a/b}$

\bye

enter image description here

I have written some of these (not all, and there's some needless stuff there, too) in a gist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.