2

When using the mathspec package, is it possible to have more than one math digits font in different places in the same document.

Mostly, I want the font for my math digits to be the same as my main text font, but at some places I use Eastern Arabic numerals within the math environment, so I want to be able to switch to a font that has these unicode characters. (Yes, I could choose a font that has these defined as my main text font, but that is not the optimal solution at the moment.)

Here is a minimal example, which helps explain what I am trying to do.

\documentclass[a4paper,12pt]{article}
\usepackage[MnSymbol]{mathspec}

\setmainfont[Mapping=tex-text]{Junicode}

\setmathsfont(Digits){Junicode} % XITS Math
\setmathsfont(Symbols){XITS Math}
\setmathsfont(Latin){Junicode}
\setmathrm{Junicode}

\def\offsetdigits#1{%
\xoffset{#1}0%
\xoffset{#1}1%
\xoffset{#1}2%
\xoffset{#1}3%
\xoffset{#1}4%
\xoffset{#1}5%
\xoffset{#1}6%
\xoffset{#1}7%
\xoffset{#1}8%
\xoffset{#1}9}
\def\xoffset#1#2{%
\XeTeXmathcodenum`#2=\numexpr\XeTeXmathcodenum`#2-`0+#1\relax}


\begin{document}

I want the digits in my math environment to be the same as those in my text, 
for example, 44{\textdegree} and $\frac{\pi}{\sin 44 \text{\textdegree}}$.

But at other points in the document, I want to be able to switch to a different 
font so that I can have some Eastern Arabic digits in the math environment; for 
example {\offsetdigits{"0660}$\frac{2}{5}$}. The numbers in this fraction will 
only appear if we switch Junicode with XITS Math in the \verb|\setmathsfont(Digits)
{Junicode}| line in the preamble. 

\end{document} 
3

Due to the many preamble-only restrictions customary in LaTeX(1), and for which mathspec is no exception(2), one can not just do a natural \setmathsfont{Digits}{xits-math.otf} at the desired location in the document body.

(1) for example, codeline 583 in File r: ltfssdcl.dtx Date: 2011/05/08 Version v3.0n of the Sources of LaTeX2e: \@onlypreamble\DeclareMathSymbol

(2) it contains also many \@onlypreamble, admittedly for the case at hand, those already in the kernel of LaTeX are the main obstacle to a quick, local soution.

mathspec has no interface for math versions, so some hacking is necessary.

\documentclass[a4paper,12pt]{article}
\usepackage[MnSymbol]{mathspec}

\setmainfont[Mapping=tex-text]{Junicode}

\makeatletter
\setmathsfont(Digits){xits-math.otf}     % temporary declaration
\edef\SavedFontName{\eu@Digitsmathsfont}
\makeatother

\setmathsfont(Digits){Junicode} 
\setmathsfont(Symbols){XITS Math}
\setmathsfont(Latin){Junicode}
\setmathrm{Junicode}

%%% \setmathsfont(Digits){Baskerville}   % testing at home 
%%% \setmathsfont(Symbols){xits-math.otf}

\makeatletter
\DeclareMathVersion{XITSdigits}
\SetSymbolFont{\eu@DigitsArabic@symfont}
        {XITSdigits} {EU1} {\SavedFontName} {m} {n}
\makeatother

\def\offsetdigits#1{%
\xoffset{#1}0%
\xoffset{#1}1%
\xoffset{#1}2%
\xoffset{#1}3%
\xoffset{#1}4%
\xoffset{#1}5%
\xoffset{#1}6%
\xoffset{#1}7%
\xoffset{#1}8%
\xoffset{#1}9}
\def\xoffset#1#2{%
\XeTeXmathcodenum`#2=\numexpr\XeTeXmathcodenum`#2-`0+#1\relax}

\begin{document}

I want the digits in my math environment to be the same as those in my text, 
for example, 44{\textdegree} and $\frac{\pi}{\sin 44 \text{\textdegree}}$.


\mathversion{XITSdigits}

But at other points in the document, I want to be able to switch to a different 
font so that I can have some Eastern Arabic digits in the math environment; for 
example {\offsetdigits{"0660}$\frac{2}{5}$}. The numbers in this fraction will 
only appear if we switch Junicode with XITS Math in the 
\verb|\setmathsfont(Digits){Junicode}| line in the preamble. 

\end{document} 

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.