11

I'm using a silly font inside an environment, so that the text inside looks quite different than the surrounding text. However, I am having trouble getting mathmode to look silly, but legible.

\documentclass{minimal}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmathfont{XITS Math}
\begin{document}
Normal text. $abc$.
\begingroup
\fontspec{Handwriting - Dakota}%
\setmathfont{Handwriting - Dakota}%
Silly text $abc$ or even just  $2 - 4 + \frac{2}{3} + x^2$
\endgroup
Normal text. $10-8=2$.
\end{document}

However, the $abc$ does not show up, probably because the font doesn't have the special scripts unicode-math is asking for. I just want to use fairly normal characters, no need for unicode input. On the other hand the mathspec package only allows a single font, I believe, so I'd have to have silly math in the whole document.

Some of the fonts are even a little sparser, I think. They have a hyphen, but $10-8$ does not include the minus sign, presumably because the font lacks such a symbol.

Is there some way to use the silly font for letters and digits (inside this environment), but fall back to a "real" font for any missing symbols?

2
  • I've checked for duplicates, but most of the answers don't seem applicable. The closest I've seen would suggest redefining every letter as an active catcode and switching math fonts... Dec 8 '11 at 23:38
  • Adding \setmathfont[range=\mathit]{XITS Math} in your environment will get you partway there – $abc$ turns up, but the minus signs are still missing. Dec 9 '11 at 1:01
12

Use range option; \mathit for the variable, \mathup for the digits (and other upright symbols of course):

\documentclass{minimal}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmathfont{XITS Math}
\begin{document}
Normal text. $abc$.
\begingroup
\fontspec{Handwriting - Dakota}%
\setmathfont[range={\mathit,\mathup}]{Handwriting - Dakota}%
Silly text $abc$ or even just  $2 - 4 + \frac{2}{3} + x^2$
\endgroup
Normal text. $10-8=2$.
\end{document}

You can even squeeze few more symbols out of it, by adding e.g.:

\setmathfont[range={`\+,`\<,`\>,`\=,`\{,`\},`\|,`\(,`\)}]{Handwriting - Dakota}
2
  • Is there an easy way to do this if one doesn't know for sure which glyphs are in the special font? (I know that one can look them up but it'd be easier if one could define a "base" font and an "overlay" font.) Dec 9 '11 at 8:07
  • I don't think so, this would require a font fallback mechanism but there isn't (might be possible to build such mechanism on top of luatex). Dec 9 '11 at 8:31

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.