[XeTeX] Maths in XeLaTeX

Bruno Voisin bvoisin at mac.com
Wed Sep 8 19:04:52 CEST 2004


Those of us who use XeLaTeX and write maths have probably been faced 
with this problem: the default math fonts for LaTeX are Computer 
Modern, which do not mix well visually with the OS X fonts that XeTeX 
allows us to use (they look too thin in comparison -- and for my 
eyesight!).

A solution that I had been trying to implement for some time, 
unsuccessfully, is to let XeLaTeX replace the CM math fonts by the 
alternative commercial MathTime or Lucida or the free Fourier fonts, 
provided you have these fonts. That does not work out-of-the-box, first 
because LaTeX, even in maths, uses text fonts in several circumstances:

- for \mathrm, \mathbf and the like (assume, like me, you're a fluid 
dynamicist, you'll want to write, for example, \mathit{Re} for 
specifying the Reynolds number with properly spaced "R" and "e")

- for log-like functions \sin, \cos, etc.

and secondly because, for these text-in-maths fonts, LaTeX does not use 
the text fonts that you (the user) have specified (Hoefler, Optima, 
whatever); instead, it uses:

- by default Computer Modern, as specified in 
/usr/local/teTeX/share/texmf.tetex/tex/latex/base/fontmath.ltx:

	\DeclareSymbolFont{operators}   {OT1}{cmr} {m}{n}
	\SetSymbolFont{operators}{bold}{OT1}{cmr} {bx}{n}
	\DeclareSymbolFontAlphabet{\mathrm}    {operators}
	\DeclareMathAlphabet      {\mathbf}{OT1}{cmr}{bx}{n}
	\DeclareMathAlphabet      {\mathsf}{OT1}{cmss}{m}{n}
	\DeclareMathAlphabet      {\mathit}{OT1}{cmr}{m}{it}
	\DeclareMathAlphabet      {\mathtt}{OT1}{cmtt}{m}{n}
	\SetMathAlphabet\mathsf{bold}{OT1}{cmss}{bx}{n}
	\SetMathAlphabet\mathit{bold}{OT1}{cmr}{bx}{it}

- otherwise, if you have switched to Lucida, MathTime or Fourier, the 
respective text fonts as specified, for example, in 
/usr/local/teTeX/share/texmf.tetex/tex/latex/lucidabr/lucidabr.sty:

	\DeclareSymbolFont{operators}{\operator at encoding}{\rmdefault}{m}{n}
	\SetSymbolFont{operators}{bold}{\operator at encoding}{\rmdefault}{b}{n}
	\SetSymbolFont{operators}{normal}{\operator at encoding}{\rmdefault}{m}{n}
	\DeclareMathAlphabet\mathbf  \operator at encoding{\rmdefault}{b}{n}
	\DeclareMathAlphabet\mathrm  \operator at encoding{\rmdefault}{m}{n}
	\DeclareMathAlphabet\mathsf  \operator at encoding{\sfdefault}{m}{n}
	\DeclareMathAlphabet\mathit  \operator at encoding{\rmdefault}{m}{it}
	\DeclareMathAlphabet\mathtt  \operator at encoding{\ttdefault}{m}{n}
	\SetMathAlphabet{\mathbf}{bold}{\operator at encoding}{\rmdefault}{b}{n}
	\SetMathAlphabet{\mathsf}{bold}{\operator at encoding}{\sfdefault}{b}{n}
	\SetMathAlphabet{\mathrm}{bold}{\operator at encoding}{\rmdefault}{b}{n}
	\SetMathAlphabet{\mathit}{bold}{\operator at encoding}{\rmdefault}{b}{it}
	\SetMathAlphabet{\mathtt}{bold}{\operator at encoding}{\ttdefault}{b}{n}

The problem arises because the text fonts for Lucida, MathTime and 
Fourier are all known to LaTeX as re-encoded and possibly virtual 
fonts. Alas, XeLaTeX does not do (yet) virtual fonts, and can only 
reencode fonts which have undergone a not (yet) documented conversion 
process to OTF format (plus, conversion might be prohibited by font 
licensing).

Having done the above analysis, the solution is in fact obvious, but I 
just figured it out: after defining the OS X text fonts for the XeLaTeX 
document to compile, write:

	\SetSymbolFont{operators}{normal}{\encodingdefault}{\rmdefault}{m}{n}
	\SetSymbolFont{operators}{bold}  {\encodingdefault}{\rmdefault}{b}{n}
	\SetMathAlphabet{\mathrm}{normal}{\encodingdefault}{\rmdefault}{m}{n}
	\SetMathAlphabet{\mathbf}{normal}{\encodingdefault}{\rmdefault}{b}{n}
	\SetMathAlphabet{\mathit}{normal}{\encodingdefault}{\rmdefault}{m}{it}
	\SetMathAlphabet{\mathrm}{bold}  {\encodingdefault}{\rmdefault}{b}{n}
	\SetMathAlphabet{\mathit}{bold}  {\encodingdefault}{\rmdefault}{b}{it}

to coerce LaTeX into using these fonts for text in maths too (the above 
assumes the text fonts are available in bold/italic/bold italic, with 
obvious adaptations to other circumstances). The procedure is a rather 
quick fix, and most likely to leave some issues unsolved (like math 
accents), but it sort of works.

For example, to use Hoefler text with Lucida fonts you may write:

	\usepackage[T1]{fontenc}
	\usepackage{textcomp}
	\usepackage[lucidasmallscale]{lucidabr}

	\DeclareFontFamily{U}{hoefler}{}
	\DeclareFontShape{U}{hoefler}{m}{n}%
	  {<-> "Hoefler\space Text:%
	       "}{}
	\DeclareFontShape{U}{hoefler}{m}{it}%
	  {<-> "Hoefler\space Text\space Italic:%
	       "}{}
	\DeclareFontShape{U}{hoefler}{b}{n}%
	  {<-> "Hoefler\space Text\space Black:%
	       "}{}
	\DeclareFontShape{U}{hoefler}{bx}{n}%
	  {<-> ssub * hoefler/b/n}{}
	\DeclareFontShape{U}{hoefler}{b}{it}%
	  {<-> "Hoefler\space Text\space Black\space Italic:%
	       "}{}
	\DeclareFontShape{U}{hoefler}{bx}{it}%
	  {<-> ssub * hoefler/b/it}{}
	\DeclareFontShape{U}{hoefler}{m}{sc}%
	  {<-> "Hoefler\space Text:%
	       "}{}
	\renewcommand{\encodingdefault}{U}
	\renewcommand{\rmdefault}{hoefler}

	\SetSymbolFont{operators}{normal}{\encodingdefault}{\rmdefault}{m}{n}
	\SetSymbolFont{operators}{bold}  {\encodingdefault}{\rmdefault}{b}{n}
	\SetMathAlphabet{\mathrm}{normal}{\encodingdefault}{\rmdefault}{m}{n}
	\SetMathAlphabet{\mathbf}{normal}{\encodingdefault}{\rmdefault}{b}{n}
	\SetMathAlphabet{\mathit}{normal}{\encodingdefault}{\rmdefault}{m}{it}
	\SetMathAlphabet{\mathrm}{bold}  {\encodingdefault}{\rmdefault}{b}{n}
	\SetMathAlphabet{\mathit}{bold}  {\encodingdefault}{\rmdefault}{b}{it}

and if you want more sophisticated output like using old-style numbers 
for text and modern-style numbers for maths (I could not get old-style 
numbers to look fine in subscripts and superscripts):

	\usepackage[T1]{fontenc}
	\usepackage{textcomp}
	\usepackage[lucidasmallscale]{lucidabr}

	\DeclareFontFamily{U}{hoefler}{}
	\DeclareFontShape{U}{hoefler}{m}{n}%
	  {<-> "Hoefler\space Text:%
	       "}{}
	\DeclareFontShape{U}{hoefler}{m}{it}%
	  {<-> "Hoefler\space Text\space Italic:%
	       "}{}
	\DeclareFontShape{U}{hoefler}{b}{n}%
	  {<-> "Hoefler\space Text\space Black:%
	       "}{}
	\DeclareFontShape{U}{hoefler}{bx}{n}%
	  {<-> ssub * hoefler/b/n}{}
	\DeclareFontShape{U}{hoefler}{b}{it}%
	  {<-> "Hoefler\space Text\space Black\space Italic:%
	       "}{}
	\DeclareFontShape{U}{hoefler}{bx}{it}%
	  {<-> ssub * hoefler/b/it}{}
	\DeclareFontShape{U}{hoefler}{m}{sc}%
	  {<-> "Hoefler\space Text:%
	       "}{}
	\renewcommand{\encodingdefault}{U}
	\renewcommand{\rmdefault}{hoefler}

	\DeclareFontFamily{U}{hoefalt}{}
	\DeclareFontShape{U}{hoefalt}{m}{n}%
	  {<-> "Hoefler\space Text:%
	          Number\space Case=Upper\space Case\space Numbers%
	       "}{}
	\DeclareFontShape{U}{hoefalt}{m}{it}%
	  {<-> "Hoefler\space Text\space Italic:%
	          Number\space Case=Upper\space Case\space Numbers%
	       "}{}
	\DeclareFontShape{U}{hoefalt}{b}{n}%
	  {<-> "Hoefler\space Text\space Black:%
	          Number\space Case=Upper\space Case\space Numbers%
	       "}{}
	\DeclareFontShape{U}{hoefalt}{bx}{n}%
	  {<-> ssub * hoefalt/b/n}{}
	\DeclareFontShape{U}{hoefalt}{b}{it}%
	  {<-> "Hoefler\space Text\space Black\space Italic:%
	          Number\space Case=Upper\space Case\space Numbers%
	       "}{}
	\DeclareFontShape{U}{hoefalt}{bx}{it}%
	  {<-> ssub * hoefalt/b/it}{}

	\SetSymbolFont{operators}{normal}{\encodingdefault}{hoefalt}{m}{n}
	\SetSymbolFont{operators}{bold}  {\encodingdefault}{hoefalt}{b}{n}
	\SetMathAlphabet{\mathrm}{normal}{\encodingdefault}{hoefalt}{m}{n}
	\SetMathAlphabet{\mathbf}{normal}{\encodingdefault}{hoefalt}{b}{n}
	\SetMathAlphabet{\mathit}{normal}{\encodingdefault}{hoefalt}{m}{it}
	\SetMathAlphabet{\mathrm}{bold}  {\encodingdefault}{hoefalt}{b}{n}
	\SetMathAlphabet{\mathit}{bold}  {\encodingdefault}{hoefalt}{b}{it}

Example:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Image 1.pdf
Type: application/pdf
Size: 94345 bytes
Desc: not available
Url : http://tug.org/pipermail/xetex/attachments/20040908/1440d699/Image1-0001.pdf
-------------- next part --------------


The result is not optimal (the Hoefler and Lucida designs do not mix so 
well, and the x-heights are a bit different), but I find it better than 
the Hoefler/CM combination.

This is only for Lucida: I could not get MathTime and Fourier to work 
this way, because the corresponding math fonts are virtual by design, 
and there is nothing that I could think of to solve this for the 
moment.

Hope this may help others,

Bruno Voisin


More information about the XeTeX mailing list