通过 \setmathfont 更改表格每行的数学字体

通过 \setmathfont 更改表格每行的数学字体

我试图说明各种 Unicode 数学字体之间的区别。下面是一个例子,我觉得它太冗长了:

\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}

在此处输入图片描述

我知道如何用 替换重复的内容NewDocumentCommand。相反,我正在寻找一种修改tabular环境的方法,以便更直接地执行此操作:我想更改一行的数学字体。我见过的一些用于更改一行的文本字体的解决方案在涉及数学字体和 时不起作用(至少对我来说)unicode-font

答案1

速度极慢:

\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}

避免 \DeclareDocumentCommand除非你知道自己在做什么。

在此处输入图片描述

更快:定义字体并直接排版字符:

\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}

相关内容