对称群的符号中,字母都是正体,输入对称群符号的时候需要多次使用 \mathrm
命令,非常繁琐。关于对称性群的符号,可以参看:
如何自定义一个 LaTeX 宏(不妨为 \sym
,接受一个参数,例如 \sym{p\bar{6}m2}
),该宏的作用类似于 \mathrm
,能够自动保持参数中的字母(a-z
)为正体(即 \mathrm{a}
等)同时能够正确解释其他 LaTeX 指令(至少能够保证上下标以及 \bar
命令被正确解释)?我自定义了下面的命令用于实现这里所描述的目的,本质上就是用 \mathrm
,所得结果并非所期望的。
\newcommand{\sym}[1]{\ensuremath{\mathrm{#1}}}
下面的 WME 用于说明期望的结果与实际结果之间的差异。
\documentclass[utf8,12pt]{ctexart}
\usepackage{amsmath,mathtools}
\usepackage{hyperref}
\newcommand{\sym}[1]{\ensuremath{\mathrm{#1}}}
\pagestyle{plain}
\begin{document}
\begin{tabular}{*{2}{c}}
\hline\hline
期望的结果 & 实际结果 \\
\hline
$\mathrm{p}2_{1}/\mathrm{b}11$ & $\sym{p2_{1}/b11}$ \\
\hline
$\mathrm{p}\bar{6}\mathrm{m}2$ & $\sym{p\bar{6}m2}$ \\
\hline\hline
\end{tabular}
\end{document}
能够自动保持参数中的字母(a-z)为正体(即\mathrm{a}
等)同时能够正确解释其他LaTeX
指令(至少能够保证上下标以及\bar
命令被正确解释)
但是对于\mathup
吞的参数,只要没有过于神秘的希腊字母、花体字母一类的在ams
框架下缺少的字体。这 似乎 是可行的。
\documentclass[fontset=fandol]{ctexart}
\usepackage{amsmath,amsfonts,amssymb}
\DeclareMathAlphabet{\mathup}{OT1}{\familydefault}{m}{n}
\begin{document}
\begin{tabular}{*{3}{c}}
\hline\hline
默认的效果 & 期望的结果 & 实际结果 \\
\hline
$p2_1/b11$ & $\mathrm{p}2_{1}/\mathrm{b}11$ & $\mathup{p2_1/b11}$ \\
\hline
$p\bar{6}m2$ & $\mathrm{p}\bar{6}\mathrm{m}2$ & $\mathup{p\bar{6}m2}$ \\
\hline
$x_1^n + \hat{y} - \sqrt{z}$ & $\mathrm{x}_1^{\mathrm{n}} + \hat{\mathrm{y}} - \sqrt{\mathrm{z}}$ & $\mathup{x_1^n + \hat{y} - \sqrt{z}}$ \\
\hline
$\sum_{n=1}^\infty \frac{1}{n^2}=\frac{\pi^2}{6}$ & $\mathrm{\sum_{n=1}^\infty \frac{1}{n^2}=\frac{\pi^2}{6}}$ & $\mathup{\sum_{n=1}^\infty \frac{1}{n^2}=\frac{\pi^2}{6}}$ \\
\hline\hline
\end{tabular}
\end{document}
@u55828 另外:
utf8
是错误选项。正确的名称为UTF8
,且在使用xelatex/lualatex
编译时,不需要显式写出,已经是默认值。