[XeTeX] fontspec & math(s)

Bruno Voisin bvoisin at mac.com
Thu Nov 18 09:46:50 CET 2004


Le 18 nov. 04, à 05:54, Will Robertson a écrit :

> If you put:
>
> \makeatletter
> \AtBeginDocument
>   {\DeclareSymbolFont{operators}\zf at enc\rmdefault\mddefault\updefault
>    \SetSymbolFont{operators}{bold}\zf at enc\rmdefault\bfdefault\updefault
>    \DeclareMathAlphabet\mathbf\zf at enc\rmdefault\bfdefault\updefault
>    \DeclareMathAlphabet\mathsf\zf at enc\sfdefault\mddefault\updefault
>    \DeclareMathAlphabet\mathit\zf at enc\rmdefault\mddefault\itdefault
>    \DeclareMathAlphabet\mathtt\zf at enc\ttdefault\mddefault\updefault
>    \SetMathAlphabet\mathsf{bold}\zf at enc\sfdefault\bfdefault\updefault
>    \SetMathAlphabet\mathit{bold}\zf at enc\rmdefault\bfdefault\itdefault}
> \makeatother
>
> in your preamble (AFTER you \usepackage{euler}, if you do), that's the  
> extent of my efforts. This requires you \setromanfont{} etc., in the  
> preamble, also.
>
> However, I get the wrong symbols when using \{ \}, so I must be  
> messing something up somewhere, and I haven't had time to work out  
> what's going wrong. Any suggestions?
>
> (Bruno's old posts on this subject were rather helpful, perhaps he can  
> comment further?)

Hi Will,

Presently I'm too busy to be able to undertake any TeX-related thing  
seriously. Thus I'm trying to refrain posting as much as possible,  
knowing that, after bringing up a question rapidly, I will have to call  
it quit before the question is solved or even formulated completely.  
(Looking at the OS X TeX list, you may guess that I've not really  
managed to adhere to these resolutions.)

About your question:

- I'm not sure \AtBeginDocument is required here, but it may cause no  
harm anyway.

- I think you could replace

	\DeclareSymbolFont{operators}\zf at enc\rmdefault\mddefault\updefault

by

	\SetSymbolFont{operators}{normal}\zf at enc\rmdefault\mddefault\updefault

But again the present line causes no harm, I think. Similarly the  
\DeclareMathAlphabet could be replaced by \SetMathAlphabet.

- You've forgotten \mathrm, for which you could add

	\DeclareMathAlphabet\mathrm\zf at enc\rmdefault\mddefault\updefault
	\SetMathAlphabet\mathrm{bold}\zf at enc\rmdefault\bfdefault\updefault

I think your problem is an encoding issue: the math fonts in TeX are  
assumed to have special encodings OML, OMS, OMX and even OT1. From  
/usr/local/teTeX/share/texmf.tetex/tex/latex/base/fontmath.ltx:

	\DeclareSymbolFont{operators}   {OT1}{cmr} {m}{n}
	\DeclareSymbolFont{letters}     {OML}{cmm} {m}{it}
	\DeclareSymbolFont{symbols}     {OMS}{cmsy}{m}{n}
	\DeclareSymbolFont{largesymbols}{OMX}{cmex}{m}{n}
	\SetSymbolFont{operators}{bold}{OT1}{cmr} {bx}{n}
	\SetSymbolFont{letters}  {bold}{OML}{cmm} {b}{it}
	\SetSymbolFont{symbols}  {bold}{OMS}{cmsy}{b}{n}
	\DeclareSymbolFontAlphabet{\mathrm}    {operators}
	\DeclareSymbolFontAlphabet{\mathnormal}{letters}
	\DeclareSymbolFontAlphabet{\mathcal}   {symbols}
	\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}

whereas in your code (and in mine too) the math fonts are assumed to  
have U encoding. This may mess up some character declarations,  
regarding in particular \{ and \}, equivalent to \lbrace and \rbrace in  
math mode, and \textbraceleft and \textbraceright in text mode.

In typical LaTeX straightforwardness ;~\, you find in  
/usr/local/teTeX/share/texmf.tetex/tex/latex/base/latex.ltx:

	\DeclareRobustCommand{\{}{\ifmmode\lbrace\else\textbraceleft\fi}
	\DeclareRobustCommand{\}}{\ifmmode\rbrace\else\textbraceright\fi}

Then, regarding math mode, in  
/usr/local/teTeX/share/texmf.tetex/tex/latex/base/fontmath.ltx you  
have:

	\DeclareMathDelimiter{\rbrace}
	   {\mathclose}{symbols}{"67}{largesymbols}{"09}
	\DeclareMathDelimiter{\lbrace}
	   {\mathopen}{symbols}{"66}{largesymbols}{"08}

For text mode, if you're using the default, you find in  
/usr/local/teTeX/share/texmf.tetex/tex/latex/base/latex.ltx:

	\DeclareTextSymbolDefault{\textbraceleft}{OMS}
	\DeclareTextSymbolDefault{\textbraceright}{OMS}

and then in  
/usr/local/teTeX/share/texmf.tetex/tex/latex/base/omsenc.def:

	\DeclareTextSymbol{\textbraceleft}{OMS}{102}        % "66
	\DeclareTextSymbol{\textbraceright}{OMS}{103}       % "67

If you're using T1 encoding (through \usepackage[T1]{fontenc}), you  
find in /usr/local/teTeX/share/texmf.tetex/tex/latex/base/t1enc.def:

	\DeclareTextSymbol{\textbraceleft}{T1}{`\{}
	\DeclareTextSymbol{\textbraceright}{T1}{`\}}

What `\{ means I must confess I don't know. And if you're using LY1  
encoding (through \usepackage[LY1]{fontenc}), you find in  
/usr/local/teTeX/share/texmf.tetex/tex/latex/psnfssx/ly1enc.def:

	\DeclareTextSymbol{\textbraceleft}{LY1}     {123}
	\DeclareTextSymbol{\textbraceright}{LY1}    {125}

This means in any case that you may have to redefine some math  
characters. For example, in my case, using a combination of Hoefler  
Text and Lucida in maths, I've had to write:

	\DeclareMathSymbol{\geqslant}{\mathrel}{letters}{230}

to get the slanted >= character right in Lucida NewMath.

Here the code I've used (I haven't yet, due to time constraints,  
started to experiment with fontspec.sty):

	\DeclareFontFamily{U}{hoefmat}{}
	\DeclareFontShape{U}{hoefmat}{m}{n}
	  {<-> "Hoefler\space Text:mapping=tex-text;
	          Number\space Case=Upper\space Case\space Numbers
	       "}{}
	\DeclareFontShape{U}{hoefmat}{m}{it}
	  {<-> "Hoefler\space Text\space Italic:mapping=tex-text;
	          Smart\space Swashes=!Line\space Final\space Swashes,
	                              !Line\space Initial\space Swashes;
	          Number\space Case=Uppercase\space Numbers
	       "}{}
	\DeclareFontShape{U}{hoefmat}{b}{n}
	  {<-> "Hoefler\space Text\space Black:mapping=tex-text;
	          Number\space Case=Diphthong\space Ligatures
	       "}{}
	\DeclareFontShape{U}{hoefmat}{b}{it}
		  {<-> "Hoefler\space Text\space Black\space Italic:mapping=tex-text;
	          Smart\space Swashes=!Line\space Final\space Swashes,
	                              !Line\space Initial\space Swashes;
	          Number\space Case=Normal\space Vertical\space Position
	       "}{}
	\DeclareFontShape{U}{hoefmat}{bx}{n}
	  {<-> ssub * hoefmat/b/n}{}
	\DeclareFontShape{U}{hoefmat}{bx}{it}
	  {<-> ssub * hoefmat/b/it}{}
	\newcommand{\mtdefault}{hoefmat}

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

	\DeclareMathSymbol{\geqslant}{\mathrel}{letters}{230}

I've used a different font \mtdefault in maths, compared with  
\rmdefault in text, so that I could later, should the fancy take me,  
use Hoefler with oldstyle digits in text and modern digits in maths.

I feel a bit discouraged regarding the proper use of OS X fonts with  
maths in (La)TeX, there are so many things relying on the idiosyncrases  
of the CM/AMS fonts that I doubt anything automated could be devised  
for Xe(La)TeX. You only have to look at the number of manual work that  
had to be done in the packages mathtime.sty and lucidabr.sty to make it  
possible to use the MathTime and Lucida fonts, respectively, in maths  
instead of CM/AMS; the same applies to plain TeX, with the files  
mtmacs.tex and lcdplain.tex compared with plain.tex.

I am now inclined to think that nothing can really be done until a  
future (La)TeX based on Unicode from the ground up is finally released  
(LaTeX 3?), making it possible to use Unicode fonts having math symbols  
at the proper Unicode slots, to replace the current 7-bit-inspired  
mess. That supposes, of course, that these Unicode math fonts exist.  
Possibly the Mathematica fonts  
<http://www.mathmlcentral.com/characters/> and  
<http://support.wolfram.com/mathematica/systems/windows/general/ 
latestfonts.html> (can't say more, I still haven't upgraded my  
Mathematica 4 licence to version 5, and I have the impression the  
Mathematica 4 fonts were free but not the Mathematica 5 ones), or the  
STIX fonts <http://www.stixfonts.org/project.html> when they are  
finally released?

Sorry I can't help more,

Bruno



More information about the XeTeX mailing list