[XeTeX] How to mix math fonts?

Ulrike Fischer news3 at nililand.de
Wed Jul 6 10:03:55 CEST 2011

Am Wed, 6 Jul 2011 08:11:35 +0200 schrieb Mojca Miklavec:

> Hello,
> I would like to know how I can use unicode-math package for mixing
> multiple fonts. (I don't mean taking a few characters from one font
> and a few symbols from the other.) I would like to display one
> character from LM Math for example and the same one in XITS math next
> to each other, looping over "the whole" unicode range.
> I could use \setmathfont for each individual character, but then it
> takes ages to compile.

What you need is a new math version. But to quote the documentation
"LATEX’s concept of math ‘versions’ is not yet supported. The only
way to get bold maths is to add markup for it all. This is still an
area that requires investigation." 

You can try the following. I have a lot doubts that it will work
with complete equations (if e.g. spaces are correct) but as you want
only compare the glyphs it could work. 

I had to get the unicode-math from github (and for lualatex
lualatex-math) as the version on CTAN is not compatible with the
newest expl3. My new command  \UFsetmathfont is simply a hack of
\setmainfont with a new version name and the needed \SetSymbolFont's
instead of \DeclareSymbolFont, so if something breaks because of
line breaks or something similar check the original command.



\DeclareDocumentCommand \UFsetmathfont { O{} m } {
  \cs_if_exist:cF { S@ \f at size } { \calculate at math@sizes }
  \csname S@\f at size\endcsname
  \tl_set:Nn \l_um_mversion_tf {UFtest} %changed
  \tl_set:Nn \l_um_script_features_tl  {ScriptStyle}
  \tl_set:Nn \l_um_sscript_features_tl {ScriptScriptStyle}
  \tl_set:Nn \l_um_script_font_tl      {#2}
  \tl_set:Nn \l_um_sscript_font_tl     {#2}
  \keys_set:nn {unicode-math} {#1}
  \um_fontspec_select_font:n {#2}
    \fontfamily{\zf at family}\selectfont
    \fontspec_if_script:nTF {math}
      {\bool_gset_true:N  \l_um_ot_math_bool}
      {\bool_gset_false:N \l_um_ot_math_bool}
  \bool_if:NTF \l_um_init_bool {
    \tl_set:Nn \um_symfont_tl {operators}
    \msg_trace:nnx {unicode-math} {default-math-font} {#2}
    \cs_set_eq:NN \_um_sym:nnn \um_process_symbol_noparse:nnn
    \cs_set_eq:NN \um_set_mathalphabet_char:Nnn
    \cs_set_eq:NN \um_remap_symbol:nnn \um_remap_symbol_noparse:nnn
    \cs_set_eq:NN \um_maybe_init_alphabet:n \um_init_alphabet:n
    \cs_set_eq:NN \um_map_char_single:nn \um_map_char_noparse:nn
    \cs_set_eq:NN \um_assign_delcode:nn
    \int_incr:N \g_um_fam_int
    \tl_set:Nx \um_symfont_tl {um_fam\int_use:N\g_um_fam_int}
    \cs_set_eq:NN \_um_sym:nnn \um_process_symbol_parse:nnn
    \cs_set_eq:NN \um_set_mathalphabet_char:Nnn
    \cs_set_eq:NN \um_remap_symbol:nnn \um_remap_symbol_parse:nnn
    \cs_set_eq:NN \um_maybe_init_alphabet:n \use_none:n
    \cs_set_eq:NN \um_map_char_single:nn \um_map_char_parse:nn
    \cs_set_eq:NN \um_assign_delcode:nn \um_assign_delcode_parse:nn
  \SetSymbolFont{\um_symfont_tl}{UFtest} %changed
    {\encodingdefault}{\zf at family}{\mddefault}{\updefault}

  \bool_if:nT {\l_um_ot_math_bool &&
!\g_um_mainfont_already_set_bool} {
    \bool_set_true:N \g_um_mainfont_already_set_bool
    \dim_compare:nF { \fontdimen 10 \l_um_font == 0pt } {
      \DeclareMathSizes { \f at size } { \f at size }
      { \um_fontdimen_to_percent:nn{10}{\l_um_font}\dimexpr \f at size
pt\relax }
      { \um_fontdimen_to_percent:nn{11}{\l_um_font}\dimexpr \f at size
pt\relax }
    \fontspec_select:xn {\l_um_font_keyval_tl,
        \fontdimen8\font= \um_get_fontparam:nn {43}
        \fontdimen9\font= \um_get_fontparam:nn {42}
        \fontdimen10\font=\um_get_fontparam:nn {32}
        \fontdimen11\font=\um_get_fontparam:nn {45}
        \fontdimen12\font=\um_get_fontparam:nn {44}
        \fontdimen13\font=\um_get_fontparam:nn {21}
        \fontdimen14\font=\um_get_fontparam:nn {21}
        \fontdimen15\font=\um_get_fontparam:nn {22}
        \fontdimen16\font=\um_get_fontparam:nn {18}
        \fontdimen17\font=\um_get_fontparam:nn {18}
        \fontdimen18\font=\um_get_fontparam:nn {24}
        \fontdimen19\font=\um_get_fontparam:nn {20}
        \fontdimen20\font=0pt\relax % delim1 =
        \fontdimen21\font=0pt\relax % delim2 = FractionDelimiterSize
        \fontdimen22\font=\um_get_fontparam:nn {15}
    } {#2}
    \SetSymbolFont{symbols}{UFtest} %changed
      {\encodingdefault}{\zf at family}{\mddefault}{\updefault}
    \fontspec_select:xn {\l_um_font_keyval_tl,
        \fontdimen8\font= \um_get_fontparam:nn {48}
        \fontdimen9\font= \um_get_fontparam:nn {28}
        \fontdimen10\font=\um_get_fontparam:nn {30}
        \fontdimen11\font=\um_get_fontparam:nn {29}
        \fontdimen12\font=\um_get_fontparam:nn {31}
    } {#2}
    \SetSymbolFont{largesymbols}{UFtest} %changed
      {\encodingdefault}{\zf at family}{\mddefault}{\updefault}

\setmathfont{Asana Math}
\UFsetmathfont{XITS Math}

$a=b \int \sum $


$a=b \int \sum $

Ulrike Fischer 

More information about the XeTeX mailing list