[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.

https://github.com/wspr/unicode-math
https://github.com/phst/lualatex-math

\documentclass{article}
\usepackage{unicode-math}

\ExplSyntaxOn\makeatletter
\DeclareDocumentCommand \UFsetmathfont { O{} m } {
  \um_init:
  \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
  \DeclareMathVersion{\l_um_mversion_tf}
  \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}
  \group_begin:
    \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}
  \group_end:
  \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
\um_mathmap_noparse: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
\um_assign_delcode_noparse: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
\um_mathmap_parse: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,
      Scale=1.00001,
      FontAdjustment={
        \fontdimen8\font= \um_get_fontparam:nn {43}
{FractionNumeratorDisplayStyleShiftUp}\relax
        \fontdimen9\font= \um_get_fontparam:nn {42}
{FractionNumeratorShiftUp}\relax
        \fontdimen10\font=\um_get_fontparam:nn {32}
{StackTopShiftUp}\relax
        \fontdimen11\font=\um_get_fontparam:nn {45}
{FractionDenominatorDisplayStyleShiftDown}\relax
        \fontdimen12\font=\um_get_fontparam:nn {44}
{FractionDenominatorShiftDown}\relax
        \fontdimen13\font=\um_get_fontparam:nn {21}
{SuperscriptShiftUp}\relax
        \fontdimen14\font=\um_get_fontparam:nn {21}
{SuperscriptShiftUp}\relax
        \fontdimen15\font=\um_get_fontparam:nn {22}
{SuperscriptShiftUpCramped}\relax
        \fontdimen16\font=\um_get_fontparam:nn {18}
{SubscriptShiftDown}\relax
        \fontdimen17\font=\um_get_fontparam:nn {18}
{SubscriptShiftDownWithSuperscript}\relax
        \fontdimen18\font=\um_get_fontparam:nn {24}
{SuperscriptBaselineDropMax}\relax
        \fontdimen19\font=\um_get_fontparam:nn {20}
{SubscriptBaselineDropMin}\relax
        \fontdimen20\font=0pt\relax % delim1 =
FractionDelimiterDisplaySize
        \fontdimen21\font=0pt\relax % delim2 = FractionDelimiterSize
        \fontdimen22\font=\um_get_fontparam:nn {15}
{AxisHeight}\relax
      }
    } {#2}
    \SetSymbolFont{symbols}{UFtest} %changed
      {\encodingdefault}{\zf at family}{\mddefault}{\updefault}
    \fontspec_select:xn {\l_um_font_keyval_tl,
      Scale=0.99999,
      FontAdjustment={
        \fontdimen8\font= \um_get_fontparam:nn {48}
{FractionRuleThickness}\relax
        \fontdimen9\font= \um_get_fontparam:nn {28}
{UpperLimitGapMin}\relax
        \fontdimen10\font=\um_get_fontparam:nn {30}
{LowerLimitGapMin}\relax
        \fontdimen11\font=\um_get_fontparam:nn {29}
{UpperLimitBaselineRiseMin}\relax
        \fontdimen12\font=\um_get_fontparam:nn {31}
{LowerLimitBaselineDropMin}\relax
        \fontdimen13\font=0pt\relax
      }
    } {#2}
    \SetSymbolFont{largesymbols}{UFtest} %changed
      {\encodingdefault}{\zf at family}{\mddefault}{\updefault}
  }
  \um_input_math_symbol_table:
  \um_remap_symbols:
  \um_setup_mathactives:
  \um_setup_accents:
  \um_setup_delcodes:
  \um_setup_alphabets:
  \ignorespaces
}
\ExplSyntaxOff\makeatletter

\setmathfont{Asana Math}
\UFsetmathfont{XITS Math}
\begin{document}
\mathversion{normal}

$a=b \int \sum $

\mathversion{UFtest}

$a=b \int \sum $
\end{document}

-- 
Ulrike Fischer 



More information about the XeTeX mailing list