summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/maybemath/maybemath.tex
blob: 54e7852c33b341c32994fe1172c4db60c66a0e40 (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
93
94
95
96
97
98
\documentclass[12pt]{article}
%\usepackage{setspace}
%\usepackage{booktabs}
\usepackage{maybemath, xspace}
\newcommand{\maybemath}{\texttt{maybemath}\xspace}

\author{Andy Buckley, \texttt{andy@insectnation.org}}
\title{The \maybemath package for \LaTeX}

\newcommand{\manifestsAs}{\ensuremath{\Rightarrow\quad}\xspace}
\newcommand{\texcommand}[1]{\texttt{\ensuremath{\backslash{}}{#1}}\xspace}
\newcommand{\texarg}[1]{\ensuremath{\!}\texttt{\{}\textit{#1}\texttt{\}}\xspace}
\newcommand{\maybebmName}{\texcommand{maybebm}}
\newcommand{\maybermName}{\texcommand{mayberm}}
\newcommand{\maybeitName}{\texcommand{maybeit}}
\newcommand{\maybeitrmName}{\texcommand{maybeitrm}}
\newcommand{\maybeitsubscriptName}{\texcommand{maybeitsubscript}}
\newcommand{\maybesfName}{\texcommand{maybesf}}
\newcommand{\maybebmsfName}{\texcommand{maybebmsf}}
\newcommand{\maybemathName}{\texcommand{maybemath}}

\begin{document}
\maketitle

The \maybemath package provides a set of commands for adjusting math-mode
typesetting to match the context of the surrounding paragraph. This includes
making the math-mode text bold, upright, forced italic or sans-serif according
to context, or any combination of these. It can be particularly useful when math
terms must appear in section headings, as this implies the same expression
appearing in several boldness contexts: the heading itself, the table of
contents and perhaps a page header or footer. Typically this has been resolved
manually by use of the optional second argument of the sectioning commands:
\maybemath provides a more seamless solution.

This package was developed in order to implement the \texttt{hepparticles}
package, used for typesetting high-energy physics particle names. 
% The commands are intended more for use in flexible macro definitions than 
% for direct use in documents, hence the command names are quite verbose.

The commands available are defined below. In general they may be nested and can
take arbitrarily large arguments within a single math expression. The term to
watch in the expressions below is the $x^3$:

\section{Bold contexts}
\begin{itemize}
\item For context-sensitive boldness use \maybebmName\texarg{expr}:\\
  {\verb|\dots foo bar, $x^2 + \maybebm{x^3} + \dotsb$|}\\ \manifestsAs {\dots foo bar, $x^2 + \maybebm{x^3} + \dotsb$}\\
  {\verb|\textbf{\dots foo bar, $x^2 + \maybebm{x^3} + \dotsb$}|}\\ \manifestsAs \textbf{\dots foo bar, $x^2 + \maybebm{x^3} + \dotsb$}
\end{itemize}


\section{Upright and italic contexts}
\begin{itemize}
\item For context-sensitive upright math typesetting use \maybermName\texarg{expr}:\\
  {\verb|\dots foo bar, $x^2 + \mayberm{x^3} + \dotsb$|}\\ \manifestsAs {\dots foo bar, $x^2 + \mayberm{x^3} + \dotsb$}\\
  {\verb|\textit{\dots foo bar, $x^2 + \mayberm{x^3} + \dotsb$}|}\\ \manifestsAs \textit{\dots foo bar, $x^2 + \mayberm{x^3} + \dotsb$}

\item Alternatively, to force \texcommand{mathit} in italic contexts use \maybeitName\texarg{expr}:\\
  {\verb|\dots foo bar, $x^2 + \maybeit{x^3} + \dotsb$|}\\ \manifestsAs {\dots foo bar, $x^2 + \maybeit{x^3} + \dotsb$}\\
  {\verb|\textit{\dots foo bar, $x^2 + \maybeit{x^3} + \dotsb$}|}\\ \manifestsAs \textit{\dots foo bar, $x^2 + \maybeit{x^3} + \dotsb$}

\item The functionality of both \maybermName and \maybeitName is combined for convenience in the command \maybeitrmName\texarg{expr}:\\
  {\verb|\dots foo bar, $x^2 + \maybeitrm{x^3} + \dotsb$|}\\ \manifestsAs {\dots foo bar, $x^2 + \maybeitrm{x^3} + \dotsb$}\\
  {\verb|\textit{\dots foo bar, $x^2 + \maybeitrm{x^3} + \dotsb$}|}\\ \manifestsAs \textit{\dots foo bar, $x^2 + \maybeitrm{x^3} + \dotsb$}

\item An extra command is available for adjusting the spacing of subscripts in italic contexts: they are shifted
      to the left if wrapped with the command \maybeitsubscriptName\texarg{expr}:\\
  {\verb|\dots foo bar, $\mayberm{B_d^0} \to \|\\\verb|\mayberm{B_\maybeitsubscript{d}^0}$|}\\ \manifestsAs {\dots foo bar, $\mayberm{B_d^0} \to \mayberm{B_\maybeitsubscript{d}^0}$}\\
  {\verb|\textit{\dots foo bar, $\mayberm{B_d^0} \to \|\\\verb|\mayberm{B_\maybeitsubscript{d}^0}$}|}\\ \manifestsAs \textit{\dots foo bar, $\mayberm{B_d^0} \to \mayberm{B_\maybeitsubscript{d}^0}$}\\
  I'm not aware if there are particular uses for this outside the pickinesses of particle-name typesetting but it \emph{may} be useful!
\end{itemize}


\section{Sans-serif contexts}
\begin{itemize}
\item For context-sensitive sans-serif math typesetting use \maybesfName\texarg{expr}:\\
  {\verb|\dots foo bar, $x^2 + \maybesf{x^3} + \dotsb$|}\\ \manifestsAs {\dots foo bar, $x^2 + \maybesf{x^3} + \dotsb$}\\
  {\verb|\textsf{\dots foo bar, $x^2 + \maybesf{x^3} + \dotsb$}|}\\ \manifestsAs \textsf{\dots foo bar, $x^2 + \maybesf{x^3} + \dotsb$}\\
  Note that there is no italic version of the sans-serif math font, so use of \maybesfName eliminates italic context handling.
\end{itemize}


\section{Combined contexts}
\begin{itemize}
\item For combined bold-and-sans-serif context handling, a \maybebmsfName\texarg{expr} command is provided:\\
  {\verb|\dots foo bar, $x^2 + \maybebmsf{x^3} + \dotsb$|}\\ \manifestsAs {\dots foo bar, $x^2 + \maybebmsf{x^3} + \dotsb$}\\
  {\verb|\textbf{\dots foo bar, $x^2 + \maybebmsf{x^3} + \dotsb$}|}\\ \manifestsAs \textbf{\dots foo bar, $x^2 + \maybebmsf{x^3} + \dotsb$}\\
  {\verb|\textsf{\dots foo bar, $x^2 + \maybebmsf{x^3} + \dotsb$}|}\\ \manifestsAs \textsf{\dots foo bar, $x^2 + \maybebmsf{x^3} + \dotsb$}\\
  {\verb|\textbf{\textsf{\dots foo bar, $x^2 + \maybebmsf{x^3} + \dotsb$}}|}\\ \manifestsAs \textbf{\textsf{\dots foo bar, $x^2 + \maybebmsf{x^3} + \dotsb$}}\\
  This is assumed to be the most commonly required combination of context-sensitive math typesetting: most other combinations can be achieved by nesting the primitive \maybemath commands.
\end{itemize}

%Finally, a \maybemathName command is provided for typesetting the name of the package:
%{\verb|\maybemath|} \manifestsAs \maybemath.\\

\noindent Any feedback is appreciated! Email to \texttt{andy@insectnation.org}, please.

\end{document}