summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/maybemath/maybemath.sty
blob: 0cbe49e8550d651993b9bf0cee0a650f564afcbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
\ProvidesPackage{maybemath}[2005/2/22]
\RequirePackage{amsmath}
\RequirePackage{bm}
%\RequirePackage{xspace}

%% A few commands for making math fonts bold, upright, italic
%% or sans-serif according to the context of surrounding text.
%% It is particularly useful for avoiding problems with math
%% boldness in section titles causing unwanted boldness
%% in e.g. the table of contents.
%%
%% Thanks to Viet-Trung Luu on comp.text.tex for providing 
%% the first steps to solving this problem.
%%
%% This material is subject to the LaTeX Project Public License. 
%% See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html
%% for the details of that license.
%%
%% Author: Andy Buckley <andy@insectnation.org>


%% Mode names for bold, ext-bold, italic and sans-serif contexts
\def\@boldname{b}%
\def\@boldexname{bx}%
\def\@italname{it}%
\def\@sfname{cmss}%


%% Use the bold symbol if reqd for math fonts
\DeclareRobustCommand{\maybebm}[1]{\ensuremath{%
    \ifx\f@series\@boldname%
        {{\bm{#1}}}%
    \else\ifx\f@series\@boldexname%
        {{\bm{#1}}}%
    \else%
        {{#1}}%
    \fi\fi%
}}

%% Use \mathrm if not in italic context
\DeclareRobustCommand{\mayberm}[1]{\ensuremath{%
  \ifx\f@shape\@italname%
    {#1}%
  \else%
    {\mathrm{#1}}%
  \fi%
}}

%% Use \mathit if in italic context
\DeclareRobustCommand{\maybeit}[1]{\ensuremath{%
  \ifx\f@shape\@italname%
    {\mathit{#1}}%
  \else%
    {#1}%
  \fi%
}}

%% Use \mathrm if not in italic context
%% and \mathit if in italic context
\DeclareRobustCommand{\maybeitrm}[1]{\ensuremath{%
  \ifx\f@shape\@italname%
    {\mathit{#1}}%
  \else%
    {\mathrm{#1}}%
  \fi%
}}

%% Maybe-italic subscript shifting
\DeclareRobustCommand{\maybeitsubscript}[1]{\ensuremath{%
  \ifx\f@shape\@italname%
    {\!\mspace{1mu}#1}%
  \else%
    {#1}%
  \fi%
}}

%% Maybe-sans font change
\DeclareRobustCommand{\maybesf}[1]{\ensuremath{%
  \ifx\f@family\@sfname%
    {\mathsf{#1}}%
  \else%
    {#1}%
  \fi%
}}

%% Convenience command for following bold and sans-serif contexts
\DeclareRobustCommand{\maybebmsf}[1]{%
  {\maybebm{\maybesf{#1}}}%
}

%% For reference purposes :-)
%\DeclareRobustCommand{\maybemath}{\texttt{maybemath}\xspace}