我想在数学环境中将所有大写字母/符号排版为粗体,将所有小写字母排版为斜体默认情况下。我想知道我该怎么做?
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
Var[aX+bY] = a^2Var[X] + 2ab Cov[X,Y] + b^2 Var[Y]
\]
\end{document}
答案1
我认为,只有X
和Y
应该加粗,而Var
和Cov
作为单词/运算符是直立的(“方差”和“协方差”的缩写)。在我看来,为和定义并使用和\X
是一个很好的折衷方案。\Y
\mathbf{X}
\mathbf{Y}
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\Var}{Var}
\DeclareMathOperator{\Cov}{Cov}
\newcommand*{\X}{\mathbf{X}}
\newcommand*{\Y}{\mathbf{Y}}
\begin{document}
\[
\Var[a\X+b\Y] = a^2\Var[\X] + 2ab \Cov[\X,\Y] + b^2 \Var[\Y]
\]
\end{document}
X
和Y
也可以在数学中默认设为粗体。那么粗体的原始大写字母可用作\orgX
和\orgY
:
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\Var}{Var}
\DeclareMathOperator{\Cov}{Cov}
\newcommand*{\MakeMathBold}[1]{%
\expandafter\MakeMathBoldAux\csname org#1\endcsname{#1}%
}
\newcommand*{\MakeMathBoldAux}[2]{%
\mathchardef#1=\the\mathcode`#2\relax
\begingroup
\lccode`~=`#2\relax
\lowercase{\endgroup
\def~{\mathbf{#1}}%
}%
\mathcode`#2="8000\relax
}
\MakeMathBold{X}
\MakeMathBold{Y}
\begin{document}
\[
\Var[aX+bY] = a^2\Var[X] + 2ab \Cov[X,Y] + b^2 \Var[Y]
\]
\end{document}
答案2
定义新的符号字体后,必须重新声明大写字母的数学代码。
\documentclass{article}
\usepackage{amsmath}
\DeclareSymbolFont{boldletters}{\encodingdefault}{\familydefault}{bx}{n}
\DeclareSymbolFontAlphabet{\mathbf}{boldletters}
\DeclareMathSymbol{A}{\mathalpha}{boldletters}{`A}
\DeclareMathSymbol{B}{\mathalpha}{boldletters}{`B}
\DeclareMathSymbol{C}{\mathalpha}{boldletters}{`C}
\DeclareMathSymbol{D}{\mathalpha}{boldletters}{`D}
\DeclareMathSymbol{E}{\mathalpha}{boldletters}{`E}
\DeclareMathSymbol{F}{\mathalpha}{boldletters}{`F}
\DeclareMathSymbol{G}{\mathalpha}{boldletters}{`G}
\DeclareMathSymbol{H}{\mathalpha}{boldletters}{`H}
\DeclareMathSymbol{I}{\mathalpha}{boldletters}{`I}
\DeclareMathSymbol{J}{\mathalpha}{boldletters}{`J}
\DeclareMathSymbol{K}{\mathalpha}{boldletters}{`K}
\DeclareMathSymbol{L}{\mathalpha}{boldletters}{`L}
\DeclareMathSymbol{M}{\mathalpha}{boldletters}{`M}
\DeclareMathSymbol{N}{\mathalpha}{boldletters}{`N}
\DeclareMathSymbol{O}{\mathalpha}{boldletters}{`O}
\DeclareMathSymbol{P}{\mathalpha}{boldletters}{`P}
\DeclareMathSymbol{Q}{\mathalpha}{boldletters}{`Q}
\DeclareMathSymbol{R}{\mathalpha}{boldletters}{`R}
\DeclareMathSymbol{S}{\mathalpha}{boldletters}{`S}
\DeclareMathSymbol{T}{\mathalpha}{boldletters}{`T}
\DeclareMathSymbol{U}{\mathalpha}{boldletters}{`U}
\DeclareMathSymbol{V}{\mathalpha}{boldletters}{`V}
\DeclareMathSymbol{W}{\mathalpha}{boldletters}{`W}
\DeclareMathSymbol{X}{\mathalpha}{boldletters}{`X}
\DeclareMathSymbol{Y}{\mathalpha}{boldletters}{`Y}
\DeclareMathSymbol{Z}{\mathalpha}{boldletters}{`Z}
\DeclareMathOperator{\Var}{Var}
\DeclareMathOperator{\Cov}{Cov}
\begin{document}
\[
\Var[aX+bY] = a^2\Var[X] + 2ab \Cov[X,Y] + b^2 \Var[Y]
\]
\end{document}
偶尔斜体大写字母可以用\mathnormal{A}