5

I would like to use e.g. the calligraphic font from two different fonts conveniently in the same document.

For example in the snippet below, how can I load in parallel e.g. the calligraphic fonts from LatinModern and use it via a command like \symcallatin{ABC}?

I have already found some solutions that rely on switching the whole font e.g. using mathversion. But I would like to avoid this and instead have a dedicated command that allows to write certain symbols in a predefined font. How can this be achieved?

% !TeX TS-program = lualatex
\documentclass{standalone}
\usepackage{fontspec,unicode-math}

\setmathfont{TeX Gyre Pagella Math}
\setmathfont[range={cal,bfcal},StylisticSet=1]{XITS Math}

\begin{document}
    $\symcal{ABC}$ 
\end{document}
  • If you do \symscr you get the glyphs from Pagella Math. – egreg Jul 2 '18 at 10:42
  • @egreg Thanks for your reply. But isn't that (in general) a different font than the calligraphics from Pagella math? – bonanza Jul 2 '18 at 10:44
7
+50

Combining different fonts in Math mode was traditionally implemented with the \fam primitive. unicode-math does not use \fam by default for OTF fonts, but you can change that by manually loading the fonts into mathgroups. The additional fonts are not loaded by the unicode-math machinery, so range etc. is not available:

\documentclass{article}
\usepackage{unicode-math}
\setmathfont{XITS Math}
\ExplSyntaxOn
\makeatletter
\cs_new:Npn\definemathgroup#1#2#3#4{
  \fontspec_set_family:Nnn\l_my_math_font_family{SmallCapsFont={},ItalicFont={},BoldFont={},Script=Math,#3}{#4}
  \exp_args:Nc\new@mathgroup{\string#1}
  \::c\::n\::f\:::\new@symbolfont{\string#1}{TU}{\l_my_math_font_family}{\seriesdefault}{\shapedefault}
  \cs_new:Npn#1##1{#2{\fam\use:c{\string#1}##1}}
}
\makeatother
\ExplSyntaxOff
\definemathgroup\mathmyothercal\symcal{}{Latin Modern Math}
\definemathgroup\mathtgcal\symcal{}{Tex Gyre DejaVu Math}
\begin{document}
\[ABC=\symcal{ABC}=\mathtgcal{ABC}=\mathmyothercal{ABC}\]
\end{document}

enter image description here

In the command \definemathgroup the second parameter(always \symcal in the examples above) select the math alphabet. This can be replaced by the other \sym... commands from unicode-math to load other math alphabets, e.g. \smybb for blackbord bold, \symfrak, \symit, \symnormal, ...

  • Thanks, that looks really great! Could you add what needs to be changed in the case other than calligraphic fonts are desired (e.g. fraktur, blackboard, typewriter, upright, italic etc. )? – bonanza Jul 6 '18 at 8:44
  • @bonanza Just replace \symcal with the corresponding \sym.... A full list is to be found in the unicode-math documentation. – Marcel Krüger Jul 6 '18 at 8:58
  • Thanks, I thought its more complicated as I believed that the \fontspec_set_family: .... line only loads the script glyphs. – bonanza Jul 6 '18 at 8:59
  • 1
    @bonanza Probably because of Script=Math, but that does not mean to only load script glyphs, it indicates that the font is used for mathematical writing instead of text in latin script, arabic script, etc. – Marcel Krüger Jul 6 '18 at 9:12
  • 1
    I added a issue to unicode-math for this github.com/wspr/unicode-math/issues/481 – Ulrike Fischer Jul 7 '18 at 16:00

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.