Using mathspec \setmathfont with \newenvironment

I would like to change back and forth between two fonts. But I would like these two fonts to affect both normal text, as well as the digits and letters in maths mode. Something like this should work fine...

\documentclass{minimal}
\usepackage{unicode-math}

\newenvironment{example}{\setmathfont{Arial}\setmainfont{Arial}}{}

\begin{document}
\begin{example}  Prove the 33 is a factor of $2^{55}+1$ \end{example}\\
\begin{exampletwo}
First note 33 that $2^{55}+1 &=(2^5)^{11}+1$
\end{exampletwo}
\item
\end{document}


The problem comes when I try to use something like \cdots, since the fonts I'm using don't have full maths support. I have got round this by using mathspec and something like

 \setmathfont(Digits,Latin){Bradley Hand ITC}


so all the symbols remain as the default font. But I can't get \setmathfont with the mathspec package to work in the \newenvironment command.

Any help greatly appreciated.

Many Thanks

• Thankyou, any ideas re: the original post? – Tim Mar 7 '15 at 16:58
• Sorry, I am no expert in xelatex stuff – user31729 Mar 7 '15 at 17:18
• you seem to be using unicode-math not mathspec, I retagged. – David Carlisle Mar 7 '15 at 21:15
• Sorry for the confusion. The code post, is an almost working example of what I want. The only way I know to do what I want (change the Latin and Digits, but leave the symbols unchanged), would be using mathspec, but when I change from unicode-math to mathspec I can't get the \newenvironment to work. – Tim Mar 7 '15 at 21:20

You want to do the font declarations in the preamble, and just switch math versions in the environments.

\documentclass{article}
\usepackage{fontspec,unicode-math}
\setmainfont{Arial}
\DeclareMathVersion{bhitc}
\setmathfont[version=normal]{Arial}
\newenvironment{example}{\mathversion{normal}}{}
\newenvironment{exampletwo}{\mathversion{bhitc}}{}

\begin{document}
\begin{example}  Prove the 33 is a factor of $2^{55}+1$ \end{example}\\
\begin{exampletwo}
First note 33 that $2^{55}+1 =(2^5)^{11}+1$
\end{exampletwo}

\end{document}

• When I try and use symbols not supported in these fonts (such as \cdots) I get a square. Is there a way to do the above, but so that only the Digits and Latin are changed? – Tim Mar 7 '15 at 21:40
• @Tim probably is, but you'd have to undo a lot of what unicode-math does, it takes the line that it really wants to use one unicode font for the whole thing. xetex actually allows 256 fonts per math list (up from 16 in classic tex) but I'm not sure there is an existing high level interface to that. – David Carlisle Mar 7 '15 at 21:47
• @Tim I found the fonts, so updated answer. – David Carlisle Mar 8 '15 at 14:49
• Why, if I include alphabetic letters in the Arial math (example environment), are they presented as Latin Modern? – Steven B. Segletes Nov 1 '17 at 12:11
• @StevenB.Segletes must be a feature, related to this warning from unicode-math/fontspec * Font 'Arial' does not contain script 'Math'. * 'Latin' script used instead. – David Carlisle Nov 1 '17 at 13:16