2

I'm trying to illustrate the difference between the various Unicode math fonts. Here's an example, which I find much too verbose:

\documentclass[border = 0.4 in]{standalone}
\usepackage{unicode-math}
\usepackage{xspace}

\DeclareDocumentCommand \numberset{m} {\ensuremath{\mathbb{#1}}\xspace}
\DeclareDocumentCommand \N{}          {\numberset{N}}
\DeclareDocumentCommand \Z{}          {\numberset{Z}}
\DeclareDocumentCommand \Q{}          {\numberset{Q}}
\DeclareDocumentCommand \R{}          {\numberset{R}}
\DeclareDocumentCommand \C{}          {\numberset{C}}
\DeclareDocumentCommand \H{}          {\numberset{H}}
\DeclareDocumentCommand \P{}          {\numberset{P}}

\begin{document}
\Large

\begin{tabular}{r c c c c c c c} 
  Latin Modern Math
  & \setmathfont{Latin Modern Math}\N
  & \setmathfont{Latin Modern Math}\Z
  & \setmathfont{Latin Modern Math}\Q
  & \setmathfont{Latin Modern Math}\R
  & \setmathfont{Latin Modern Math}\C
  & \setmathfont{Latin Modern Math}\H
  & \setmathfont{Latin Modern Math}\P \\

  \setmainfont{TeX Gyre Bonum}
  Tex Gyre Bonum Math
  & \setmathfont{TeX Gyre Bonum Math}\N
  & \setmathfont{TeX Gyre Bonum Math}\Z
  & \setmathfont{TeX Gyre Bonum Math}\Q
  & \setmathfont{TeX Gyre Bonum Math}\R
  & \setmathfont{TeX Gyre Bonum Math}\C
  & \setmathfont{TeX Gyre Bonum Math}\H
  & \setmathfont{TeX Gyre Bonum Math}\P \\

  \setmainfont{TeX Gyre Pagella}
  TeX Gyre Pagella Math
  & \setmathfont{TeX Gyre Pagella Math}\N
  & \setmathfont{TeX Gyre Pagella Math}\Z
  & \setmathfont{TeX Gyre Pagella Math}\Q
  & \setmathfont{TeX Gyre Pagella Math}\R
  & \setmathfont{TeX Gyre Pagella Math}\C
  & \setmathfont{TeX Gyre Pagella Math}\H
  & \setmathfont{TeX Gyre Pagella Math}\P \\

  % etc.     
\end{tabular}
\end{document}

enter image description here

I understand how to replace the repeated content with NewDocumentCommand. Instead, I'm looking for a way to modify the tabular environment to do this more directly: I want to change the math font for a row. Some of the solutions I've seen for changing the text font for a row don't work (at least for me) when it comes to math fonts and unicode-font.

1 Answer 1

2

Painfully slow:

\documentclass[border = 0.4 in]{standalone}
\usepackage{unicode-math}
\usepackage{array}

\NewDocumentCommand \numberset{m} {\mathbb{#1}}
\NewDocumentCommand \N{}          {\numberset{N}}
\NewDocumentCommand \Z{}          {\numberset{Z}}
\NewDocumentCommand \Q{}          {\numberset{Q}}
\NewDocumentCommand \R{}          {\numberset{R}}
\NewDocumentCommand \C{}          {\numberset{C}}
\NewDocumentCommand \Hq{}         {\numberset{H}}
\NewDocumentCommand \PP{}         {\numberset{P}}

\setmathfont[version=lmodern]{Latin Modern Math}
\setmathfont[version=bonum]{TeX Gyre Bonum Math}
\setmathfont[version=pagella]{TeX Gyre Pagella Math}
\setmathfont[version=schola]{TeX Gyre Schola Math}
\setmathfont[version=termes]{TeX Gyre Termes Math}
\setmathfont[version=xits]{XITS Math}
\setmathfont[version=asana]{Asana Math}

\newcolumntype{C}{>{\mathversion{\therowversion}$}c<{$}}
\newcommand{\rowfont}[2]{#1\gdef\therowversion{#2}}

\begin{document}

\begin{tabular}{l *{7}{C}}
\rowfont{Latin Modern Math}{lmodern}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{TeX Gyre Bonum}{bonum}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{TeX Gyre Pagella}{pagella}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{TeX Gyre Schola}{schola}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{TeX Gyre Termes}{termes}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{XITS}{xits}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{Asana}{asana}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\
\end{tabular}

\end{document}

Avoid \DeclareDocumentCommand unless you know what you're doing.

enter image description here

Much faster: define fonts and typeset the characters directly:

\documentclass[border = 0.4 in]{standalone}
\usepackage{fontspec}
\usepackage{array}

\newcommand{\C}{^^^^2102}
\newcommand{\Hq}{^^^^210d}
\newcommand{\N}{^^^^2115}
\newcommand{\PP}{^^^^2119}
\newcommand{\Q}{^^^^211a}
\newcommand{\R}{^^^^211d}
\newcommand{\Z}{^^^^2124}

\newfontfamily{\lmodern}{Latin Modern Math}
\newfontfamily{\bonum}{TeX Gyre Bonum Math}
\newfontfamily{\pagella}{TeX Gyre Pagella Math}
\newfontfamily{\schola}{TeX Gyre Schola Math}
\newfontfamily{\termes}{TeX Gyre Termes Math}
\newfontfamily{\xits}{XITS Math}
\newfontfamily{\asana}{Asana Math}

\newcolumntype{C}{>{\therowversion}c}
\newcommand{\rowfont}[2]{#1\gdef\therowversion{#2}}

\begin{document}

\begin{tabular}{l *{7}{C}}
\rowfont{Latin Modern Math}{\lmodern}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{TeX Gyre Bonum}{\bonum}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{TeX Gyre Pagella}{\pagella}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{TeX Gyre Schola}{\schola}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{TeX Gyre Termes}{\termes}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{XITS}{\xits}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\

\rowfont{Asana}{\asana}
 & \N & \Z & \Q & \R & \C & \Hq & \PP \\
\end{tabular}

\end{document}
2
  • Exactly what I was looking for — thank you! And it occurs to me that I can also just enter the Unicode characters directly (ℕ, ℝ, ℚ, ...) rather than use the ^^^^#### notation.
    – Derek
    Sep 18, 2016 at 14:14
  • @Derek I just didn't want to bother copying and pasting weird characters.
    – egreg
    Sep 18, 2016 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .