3

I want to typeset all capital letters/symbols to be bold and all small letter to be italics in math environment by default. I was wondering how can I do that?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
    Var[aX+bY] = a^2Var[X] + 2ab Cov[X,Y] + b^2 Var[Y]
\]
\end{document}
2

I think, only X and Y should b bold, whereas Var and Cov upright as words/operators (short for "variance" and "covariance"). Defining and using \X and \Y for \mathbf{X} and \mathbf{Y} is a good compromise IMHO.

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

Result

X and Y also could be make bold by default, when in math. Then the original uppercase letters for bold are available as \orgX and \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}
4
  • In this case \mathit{A} or \mathnormal{A} would not work.
    – egreg
    Aug 19 '15 at 16:13
  • @egreg Both \mathit{A} and \mathnormal{A} work in both cases, since A is never touched. In the first example, \mathsf{XY} works as expected, in the second example, \mathsf{\orgX\orgY} should be used. Aug 19 '15 at 16:21
  • The A was just for example. Anyway, you're missing \MakeMathBold{X} and \MakeMathBold{Y}.
    – egreg
    Aug 19 '15 at 16:43
  • @egreg Nice to have three complete different solutions in two answers: Pure macros, active characters in math mode, and the math font based solution from you. All three of them have different advantages and disadvantages. All of them can create normal uppercase letters: X, \orgX, \mathnormal{X}. Aug 19 '15 at 16:51
2

You have to redeclare the math code for the uppercase letters after defining a new symbol font.

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

The occasional italic uppercase letter can be obtained with \mathnormal{A}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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