[XeTeX] How to mix math fonts?

Ulrik Vieth ulrik.vieth at arcor.de
Thu Jul 14 01:07:51 CEST 2011


On 07/13/2011 04:15 PM, Ulrike Fischer wrote:
>
> Did my version not work for you? I had no problems to compare your
> two fonts with it?

With a bit of hacking (mostly adjusting for unicode-math versions),
I managed to get it working, but I decided to generalize it a bit.

So here's the version I came up with, with takes a certain argument
to specify the name of the math version (instead of hard-wired UFtest).

\DeclareDocumentCommand \setmathfontversion { O{} mm } {
   \um_init:
   \csname S@\f at size\endcsname
   \tl_set:Nn \l_um_mversion_tf {#3}
   \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 {um_allsym}
     \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}{#3}
     {\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}{#3}
       {\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}{#3}
       {\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
}

With this version, I can even compare multiple fonts side-by-side:

\setmathfont[math-style=literal,bold-style=literal,
     vargreek-shape=unicode,SizeFeatures={
     {Size=-10, Colour=888888},
     {Size=10-, Colour=FF0000}}]{XITS Math}

\setmathfontversion[math-style=literal,bold-style=literal,
     vargreek-shape=unicode,SizeFeatures={
     {Size=-10, Colour=888888},
     {Size=10-, Colour=FF0000}}]{Asana Math}{asana}

\setmathfontversion[math-style=literal,bold-style=literal,
     vargreek-shape=unicode,SizeFeatures={
     {Size=-10, Colour=888888},
     {Size=10-, Colour=FF0000}}]{Cambria Math}{cambria}

\def\SYMB#1#2{\mathversion{#2}$\displaystyle #1$}

See the full source of my test file attached.

Regards, Ulrik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unimath-symbols-multi-fonts.ltx
Type: text/x-tex
Size: 8563 bytes
Desc: not available
URL: <http://tug.org/pipermail/xetex/attachments/20110714/dee293ba/attachment-0001.bin>


More information about the XeTeX mailing list