8

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}}{}
\newenvironment{exampletwo}{\setmathfont{Bradley Hand ITC}\setmainfont{Bradley Hand ITC}}{}

\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

David Carlisle
  • 757,742
tim-mccurrach
  • 181
  • 1
  • 1
  • 4
  • Thankyou, any ideas re: the original post? – tim-mccurrach Mar 07 '15 at 16:58
  • Sorry, I am no expert in xelatex stuff –  Mar 07 '15 at 17:18
  • 1
    you seem to be using unicode-math not mathspec, I retagged. – David Carlisle Mar 07 '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-mccurrach Mar 07 '15 at 21:20

1 Answers1

11

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

enter image description here

\documentclass{article}
\usepackage{fontspec,unicode-math}
\setmainfont{Arial}
\DeclareMathVersion{bhitc}
\setmathfont[version=normal]{Arial}
\setmathfont[version=bhitc]{Bradley Hand ITC}
\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}
David Carlisle
  • 757,742
  • 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-mccurrach Mar 07 '15 at 21:40
  • 1
    @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 07 '15 at 21:47
  • @Tim I found the fonts, so updated answer. – David Carlisle Mar 08 '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 01 '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 01 '17 at 13:16
  • Ahhh...The old, "it's not a bug, it's a feature!" argument. I've seen that before. – Steven B. Segletes Nov 01 '17 at 13:19
  • Well, duh, Massimo solved it, \setmathfont[range=\mathit]{Arial-Italic} at https://tex.stackexchange.com/questions/398895/using-two-different-math-fonts-with-lualatex – Steven B. Segletes Nov 01 '17 at 16:26