A while back, I asked about getting maths fonts to match the text fonts
specified by fontspec when using XeLaTeX, so at least for simple
mathematics where the symbols are all available there would be a perfect
match between text and inline equations.
Will Robertson helpfully replied with this suggestion:
> \documentclass[12pt]{article}
> \makeatletter
> \usepackage[no-math]{fontspec}
> \setmainfont{Adobe Garamond Pro}
> \DeclareSymbolFont{MRM}{EU1}{\zf@family}{m}{n}
> \DeclareSymbolFont{MIT}{EU1}{\zf@family}{m}{it}
> \DeclareMathSymbol{A}{\mathalpha}{MIT}{`\A}
> \DeclareMathSymbol{B}{\mathalpha}{MIT}{`\B}
> \DeclareMathSymbol{C}{\mathalpha}{MIT}{`\C}
> \DeclareMathSymbol{1}{\mathord}{MRM}{`\1}
> \DeclareMathSymbol{+}{\mathbin}{MRM}{`\+}
> \DeclareMathSymbol{=}{\mathrel}{MRM}{`\=}
> \begin{document}
> \noindent text: \textit{A+B}+1=\textit{C}\\
> math: $A+B+1=C$
> \end{document}
>
> Note that it looks like the spaces between symbols needs to be reduced
> for this font. Also, this technique only works for glyphs in the first
> 256 slots of the font, so you need to ask me for more code if you want
> to get this working for Greek symbols as well :)
If Will or anyone else reading this could elaborate on that last comment,
I'd be grateful, as a few key symbols such as the minus sign are indeed
past 255 in the font I'm using. It seems that adding
\DeclareMathSymbol{-}{\mathbin}{MRM}{"2212}
or any likely variation doesn't work in the latest versions of all the
software I'm using. Does this come from the general limitation in XeTeX
that \char can take 16-bit characters, but \mathchar only 8-bit?
If it's not currently possible to get this to work directly, is it at least
possible to define a \minussign macro or similar that can do the same
thing, perhaps by escaping to text mode where it does seem to be possible
to use 16-bit characters? This is a rare enough problem with my current
documents that such a workaround would be viable, though obviously I'd
prefer to just type '-' if there is a way it can be made to work.
Thanks,
Chris
>> Note that it looks like the spaces between symbols needs to be reduced
>> for this font. Also, this technique only works for glyphs in the first
>> 256 slots of the font, so you need to ask me for more code if you want
>> to get this working for Greek symbols as well :)
>
> If Will or anyone else reading this could elaborate on that last
> comment, I'd be grateful, as a few key symbols such as the minus sign
> are indeed past 255 in the font I'm using. It seems that adding
> \DeclareMathSymbol{-}{\mathbin}{MRM}{"2212}
> or any likely variation doesn't work in the latest versions of all the
> software I'm using. Does this come from the general limitation in XeTeX
> that \char can take 16-bit characters, but \mathchar only 8-bit?
Yes and no; the processing in LaTeX's \DeclareMathSymbol does not allow
character slots greater than 256. XeTeX provides \XeTeXmathcode and so
on to access the full range of unicode character slots (see
CTAN:info/xetexref for a bit more information about XeTeX math
settings).
> If it's not currently possible to get this to work directly, is it at
> least possible to define a \minussign macro or similar that can do the
> same thing, perhaps by escaping to text mode where it does seem to be
> possible to use 16-bit characters?
Here's the "proper" way to do it:
\documentclass[12pt]{article}
\makeatletter
\usepackage[no-math]{fontspec}
\setmainfont{Charis SIL}
\DeclareSymbolFont{MRM}{EU1}{\zf@family}{m}{n}
\begin{document}
\XeTeXmathcode`\-="2 \symMRM "2212 % minus sign
$A-B$
\end{document}
One of these days I really have to finish off unicode-math so this
stuff just works. You're not expected to have to set this stuff up
manually. The first number ("2) refers to the mathtype of the symbol,
see fntguide.pdf for a full listing. \symMRM is obviously the
SymbolFont defined earlier, and "2212 is the unicode slot of the
mathematical minus sign.
(You can use this XeTeXmathcode method exclusively instead of the
\DeclareMathSymbol method I showed earlier, actually.)
Hope this helps,
Will
>> Note that it looks like the spaces between symbols needs to be reduced
>> for this font. Also, this technique only works for glyphs in the first
>> 256 slots of the font, so you need to ask me for more code if you want
>> to get this working for Greek symbols as well :)
>
> If Will or anyone else reading this could elaborate on that last
> comment, I'd be grateful, as a few key symbols such as the minus sign
> are indeed past 255 in the font I'm using. It seems that adding
> \DeclareMathSymbol{-}{\mathbin}{MRM}{"2212}
> or any likely variation doesn't work in the latest versions of all the
> software I'm using. Does this come from the general limitation in XeTeX
> that \char can take 16-bit characters, but \mathchar only 8-bit?
Yes and no; the processing in LaTeX's \DeclareMathSymbol does not allow
character slots greater than 256. XeTeX provides \XeTeXmathcode and so
on to access the full range of unicode character slots (see
CTAN:info/xetexref for a bit more information about XeTeX math
settings).
> If it's not currently possible to get this to work directly, is it at
> least possible to define a \minussign macro or similar that can do the
> same thing, perhaps by escaping to text mode where it does seem to be
> possible to use 16-bit characters?
Here's the "proper" way to do it:
\documentclass[12pt]{article}
\makeatletter
\usepackage[no-math]{fontspec}
\setmainfont{Charis SIL}
\DeclareSymbolFont{MRM}{EU1}{\zf@family}{m}{n}