# \setmathsfont can be used only in preamble

Possibly related to

Roughly speaking, I would like to know if it is possible to change math font as freely as I can change text font by \fontspec.

It seems \setmathsfont form mathspec is powerful but can be used only in preamble. On the other hand \setmathfont from unicode-math can be used everywhere but it is not as powerful as \setmathsfont.

For instance, the following document does not compile

% !TEX program = XeLaTeX
% !TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{mathspec}
\begin{document}
$1+2=3$
\setmathsfont(Digits){Zapfino}
$1+2=3$
\end{document}


And the following document does compile.

% !TEX program = XeLaTeX
% !TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{unicode-math}
\begin{document}
$1+2=3$
\setmathfont[range=up/num]{Zapfino}
$1+2=3$
\end{document}


So my questions are

• Is \setmathfont an alternative to \setmathsfont?
• If so, what corresponds to \setmathsfont(Digits), \setmathsfont(Latin), and \setmathsfont(Greek)?
• Is it possible to use \setmathsfont within the document? Just like \setmathfont and \setmainfont.
• Or, is there any better way to break photomath? (see below)

# Motivation

I am currently making some arithmetic exercise such as

It turns out that my students use photomath to get the answer. The good news is that photomath does not recognize "ugly" fonts such as Zapfino.

But for demonstrating purpose, I want to use "pretty" font such as Latin Modern in the same document. So it would be nice if I can switch between "pretty" and "ugly" fonts.

• for the 2nd question see tex.stackexchange.com/questions/223421/… – touhami Dec 27 '15 at 9:23
• @touhami does not work (if I understood @David Carlisle's answer correctly.) It is \DeclareSymbolFont that is defined as \@latex@error {Can be used only in preamble}\@eha. Should I try @Joseph Wright♦'s answer instead? – Symbol 1 Dec 27 '15 at 9:35
• Imho in the long run unicode-math is the saner way to setup math. – Ulrike Fischer Dec 27 '15 at 11:10
• @UlrikeFischer I can take that :) I did not prefer either of them. – Symbol 1 Dec 28 '15 at 8:31