Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In ordinary LaTeX, one can easily add new math alphabets by using \DeclareMathAlphabet. One is then able to use, say, cmsy, eus, and rsfs letters side-by-side. Unfortunately, there does not seem to be a similar mechanism in unicode-math, or at the very least \DeclareMathAlphabet doesn't do what it's supposed to do.

Question. How can I set up my own math alphabets in unicode-math?

Attempted workarounds

Since unicode-math has lots of math alphabets, one workaround might be to replace an unused alphabet with the desired one using \setmathfont[range=...->...]. This doesn't quite work right in my example:

\documentclass[12pt]{article}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}

\usepackage{unicode-math}

\scrollmode

\setmathfont{xits-math.otf}
\setmathfont[range={\mathscr,\mathbfscr},StylisticSet=0]{xits-math.otf}
\setmathfont[range={\mathcal,\mathbfcal},StylisticSet=1]{xits-math.otf}
\setmathfont[range={\mathtt->\mathcal}]{latinmodern-math.otf}

\begin{document}
\[
\begin{array}{c}
\mathcal{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} \\
\mathscr{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} \\
\mathtt{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}
\end{array}
\]

I suspect the problem is that the codepoints of the calligraphic letters in Unicode are not contiguous.

Using \mathversion seems to work better:

\documentclass[12pt]{article}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}

\usepackage{unicode-math}

\setmathfont{xits-math.otf}

\setmathfont[version=eucal]{latinmodern-math.otf}
\newcommand{\eucal}[1]{\mathchoice %
  {\mbox{\mathversion{eucal}$\displaystyle\mathscr{#1}$}} %
  {\mbox{\mathversion{eucal}$\mathscr{#1}$}} %
  {\mbox{\mathversion{eucal}$\scriptstyle\mathscr{#1}$}} %
  {\mbox{\mathversion{eucal}$\scriptscriptstyle\mathscr{#1}$}}}

\setmathfont[range={\mathcal,\mathbfcal},StylisticSet=1]{xits-math.otf}

\begin{document}
\[
\begin{array}{c}
\mathcal{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} \\
\mathscr{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} \\
\eucal{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}
\end{array}
\]
\end{document}

But this feels very inefficient.

share|improve this question
    
I've also been struggling with mixing multiple math fonts. Thanks to your workaround, I can now do $\lambda x' \mathother{\lambda x'}$, where \mathother is analogous to your \eucal. I have found no other way to do this and get all the symbols (Greek letters, primes, etc.) I need from all the fonts. –  Sean Leather Nov 26 '13 at 13:03
    
I'm glad you found it useful! If you find any points that could be improved, please let me know. –  Zhen Lin Nov 26 '13 at 13:42
add comment

1 Answer

up vote 5 down vote accepted

enter image description here

Actually DeclareMathAlphabet works fine, the problem is that the latin alphabet has been given mathcodes pointing at the math alphabet range in Unicode plane 1 (1Dxxx block) but the fonts are expecting the ASCII range.

unicode-math implements math alphabets by switching mathcodes (rather than changing the math fam) so the simplest thing to do is use \mathup to switch the mathcodes back to the ASCII range then use \mathfrak or eufrak or whatever to switch fam, as shown here.

\documentclass[12pt]{article}
\usepackage{amsfonts}
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text}

\DeclareMathAlphabet{\mathrsfs}{U}{rsfso}{m}{n}
\DeclareMathAlphabet{\euler}{U}{euf}{m}{n}

\usepackage{unicode-math}

\setmathfont{xits-math.otf}


\setmathfont[range={\mathcal,\mathbfcal},StylisticSet=1]{xits-math.otf}


\begin{document}

\[
\begin{array}{cc}
1&\mathup{\mathrsfs{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}} \\
2&\mathcal{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} \\
3&\mathscr{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} \\
4&\mathup{\euler{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}}
\end{array}
\]


\end{document}
share|improve this answer
    
Wonderful! Is there a way to adjust the scaling as well, à la the Scale option in fontspec? –  Zhen Lin Apr 4 at 21:27
    
@ZhenLin I'll look over the weekend, a bit late now (I just watched \tracingall to reverse engineer the above and it's a bit late for that tonight:-) –  David Carlisle Apr 4 at 21:43
    
I see! Thanks for the tremendous effort! I've hacked together something for scaling by modifying \DeclareFontShape. –  Zhen Lin Apr 4 at 21:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.