summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/linop/linop.tex
blob: 74316468962f40c93ff745559b93155158cce196 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
%% linop.sty
%% Copyright 2016 Johannes Weytjens
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Johannes Weytjens
%
% This work consists of the file linop.sty

\documentclass[10pt]{article}

% layout
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\usepackage[english]{babel}
\usepackage[tracking=true,kerning=true,factor=1250]{microtype}
\usepackage[compact]{titlesec}
\usepackage{tocloft}
\usepackage[charter,expert]{mathdesign}
\usepackage[scaled=0.96]{XCharter}
\usepackage{linop}
\usepackage{parskip}
\usepackage{float}
\usepackage{xparse}
\usepackage{fancyvrb}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{cprotect}
\usepackage[hang]{footmisc}

% math
\usepackage{bm}

% titlesec
\titleformat{\section}[hang]{\scshape\Large}{\thesection.}{1ex}{}
\titleformat{\subsection}[hang]{\scshape\large}{\thesubsection.}{0.5ex}{}
\titleformat{\subsubsection}[hang]{\scshape}{\thesubsubsection.}{0.25ex}{}

% tableofcontents
\setcounter{tocdepth}{1}
\renewcommand{\cfttoctitlefont}{\Large\scshape}
\renewcommand{\cftsecfont}{\scshape}
\renewcommand{\cftsecpagefont}{\large}

% footmisc
\setlength{\footnotemargin}{1em}

% distance between columns in a table
\setlength{\tabcolsep}{20pt}

% caption
\DeclareCaptionFormat{center}{{\centerline{#1#2}\\}#3}
\captionsetup{font={small},labelfont=sc,width=0.8\textwidth,format=center,labelsep=none,justification=justified}

% microtype
\SetTracking{encoding={*}, shape=sc}{0} % small caps are correctly typeset
% protrusion for footnotes
\DeclareMicrotypeSet{textandfootnote}{%
  encoding = {OT1,T1},
  family = {*},
  size = {normalsize,footnotesize,small,large,Large,scriptsize},
  font = {*}
}

% PDF (metadata)
\usepackage{hyperref}
\hypersetup{
    pdfauthor = {Johannes Weytjens},
    pdftitle = {The linop package v0.1},
    pdfcreator = {LaTeX}
}

\title{The \texttt{linop} package v0.1}
\author{Johannes Weytjens \\ \href{johannes.weytjens@nietsissimpel.org}{johannes.weytjens@nietsissimpel.org}}

\begin{document}
\maketitle

\tableofcontents

\section{Introduction}
There exist already many packages to help you typeset common and less common mathematical notation with ease. Yet, to the best of my knowledge, there does not yet exist a package that provides an easy way to typeset operators as they appear for example in many body physics, quantum (field) theory or linear algebra. The aim of this package is to provide two simple commands and many options to easily write operators in any of the ways they commonly appear.

Besides providing easy to use macros, this package also ensures consistent spacing for subscript and superscript. To illustrate this point, compare the normal way for typesetting operators with the macros provided by this package.

\begin{table}[ht]
	\centering
	\begin{tabular}{ll}
		\verb|\hat{a}_{in}\hat{a}_{in}^{\dagger}| & $\hat{a}_{in}\hat{a}_{in}^{\dagger}$ \\
		\verb|\op{a}{in}\hc{a}{in}| & $\op{a}{in}\hc{a}{in}$
	\end{tabular}
\end{table}

Typesetting the \verb|\dagger| and a subscript simultaneously pushes the subscript down, this is no longer the case with the here defined macros.

\subsection{Required packages}
As these are simple macros, you only need the \texttt{xparse} package.

\newpage
\section{List of commands}
The two macros defined in this package are \verb|\op| and \verb|\hc| as well as their starred versions.

\begin{Verbatim}[commandchars=\&\"\!]
	\op[&rmfamily&itshape"superscript spacing!&ttfamily]{&rmfamily&itshape"operator!&ttfamily}{&rmfamily&itshape"subscript!&ttfamily}{&rmfamily&itshape"superscript!&ttfamily}{&rmfamily&itshape"supersuperscript!&ttfamily}
	\hc[&rmfamily&itshape"superscript spacing!&ttfamily]{&rmfamily&itshape"operator!&ttfamily}{&rmfamily&itshape"subscript!&ttfamily}{&rmfamily&itshape"superscript!&ttfamily}{&rmfamily&itshape"supersuperscript!&ttfamily}
\end{Verbatim}

These macros typeset an operator and the Hermitian conjugate respectively. Only the \emph{operator} argument is mandatory, all other arguments can either be empty or be skipped entirely if no subscript or superscript is desired. The optional argument \emph{superscript spacing} only applies to the starred versions. Supersuperscripts are implemented to distinguish between e.g.\ the order in some expansion and the square of the operator.

\begin{table}[H]
	\centering
	\begin{tabular}{ll}
		\verb|\op{a}{in}{0}| & $\op{a}{in}{0}$ \\
		\verb|\op{a}{}{(1)}{2}| & $\op{a}{}{(1)}{2}$ \\
		\verb|\hc{b}{out}{0}| & $\hc{b}{out}{0}$ \\
		\verb|\hc{b}{out}{}{2}| & $\hc{b}{out}{}{2}$ 
	\end{tabular}
\end{table}

The defaults style is to typeset all operators with a hat. The none starred versions use \verb|\hat| and are only appropriate for single symbol operators. The starred version use \verb|\widehat| which scales with the width of the operator and can therefore be used for wider symbols. The \verb|\widehat| often overlaps with the superscripts however, so the starred version insert a \verb|\>| before the superscripts and a \verb|\:| for the Hermitian conjugate superscript. Controling the spacing of the superscript for individual operators can be done with the optional \emph{superscript spacing} argument.

\begin{table}[H]
	\centering
	\begin{tabular}{ll}
		\verb|\op*{A}{in}{0}| & $\op*{A}{in}{0}$ \\
		\verb|\hc*{ab}{out}| & $\hc*{ab}{out}$ \\
		\verb|\hc*[\kern4pt]{\mathcal{L}}| & $\hc*[\kern4pt]{\mathcal{L}}$ 
	\end{tabular}
\end{table}


\section{List of options}
\subsection{bold}
Some prefer to use bold letters for operators instead of hats. This can be achieved by using the \texttt{bold} option when loading the package. When using this option, the starred versions will produce the same result as the none starred versions.

\renewcommand{\linopstyle}{\mathbf}
\renewcommand{\linopstylewide}{\linopstyle}

\begin{table}[H]
	\centering
	\begin{tabular}{ll}
		\verb|\op{a}{in}{0}| & $\op{a}{in}{0}$ \\
		\verb|\hc{b}{out}| & $\hc{b}{out}$
	\end{tabular}
\end{table}

\subsection{bmbold}
The \texttt{bmbold} option achieves the same effect as bold, but instead uses the bold math font provided by the \texttt{bm} package.

\renewcommand{\linopstyle}{\bm}

\begin{table}[H]
	\centering
	\begin{tabular}{ll}
		\verb|\op{a}{in}{0}| & $\op{a}{in}{0}$ \\
		\verb|\hc{b}{out}| & $\hc{b}{out}$
	\end{tabular}
\end{table}

\subsection{nohat}
The option \texttt{nohat} typesets the operators without a \verb|\hat|. This also applies to the starred versions.

\renewcommand{\linopstyle}{}

\begin{table}[H]
	\centering
	\begin{tabular}{ll}
		\verb|\op{a}{in}{0}| & $\op{a}{in}{0}$ \\
		\verb|\hc{b}{out}| & $\hc{b}{out}$ 
	\end{tabular}
\end{table}

\subsection{wide}

\renewcommand{\linopstyle}{\hat}
With the wide option, all operators will use \verb|\widehat|, regardless of whether you're using the starred or non starred versions.

\subsection{star}

\renewcommand{\linopconjugate}{*}

The \texttt{star} options typesets the Hermitian conjugate with a star instead of a dagger.

\begin{table}[H]
	\centering
	\begin{tabular}{ll}
		\verb|\hc{b}{out}| & $\hc{b}{out}$
	\end{tabular}
\end{table}



\subsection{compact}
The consistent spacing is provided by using \verb|\mathstrut| in both the subscript and superscript. As the misalignment is caused by using a \verb|\dagger| in the superscript, the same effect can be achieved by using a \verb|\phantom{\dagger}| in the superscript of the non Hermitian conjugated operator. This turns out to be slightly more compact than using \verb|\mathstrut|, though the effect is minimal\cprotect\footnote{This is because \verb|\mathstrut| is defined as \verb|\def\mathstrut{\vphantom(}| and \verb|(| turns out be slightly larger than \verb|\dagger|.}.

\renewcommand{\linopconjugate}{\dagger}

\begin{table}[H]
	\centering
	\begin{tabular}{lll}
		\verb|\op{a}{in}\hc{a}{in}| & $\op{a}{in}\hc{a}{in}$ & using \verb|\mathstrut| \\
		\gdef\linopsubscript{}%
		\gdef\linopsuperscript{\phantom{\dagger}}%
		\gdef\linopsuperscripthc{}%
	 	\verb|\op{a}{in}\hc{a}{in}| & $\op{a}{in}\hc{a}{in}$ & using \verb|\phantom{\dagger}| 
	\end{tabular}
\end{table}

\begin{figure}[H]
	\centering
	\includegraphics[scale=0.35]{compact}	
	\cprotect\caption{Illustrating the difference between \verb|\mathstrut| and \verb|\phantom{\dagger}|. The light grey letters are the compact version that used \verb|\phantom{\dagger}|.}
\end{figure}


\subsection{square}
To help distinguish between the operator and the indices, the subscript and superscripts can be given in square brackets as well when using the \texttt{square} option.

\DeclareDocumentCommand{\op}{s m O{} O{} O{}}{%
        \IfBooleanTF#1%
        {\linopstylewide{#2}_{\linopsubscript#3}^{\linopspacewide#4^{#5}\linopsuperscript}}
        {\linopstyle{#2}_{\linopsubscript#3}^{#4^{#5}\linopsuperscript}}
}

\DeclareDocumentCommand{\hc}{s m O{} O{} O{}}{%
        \IfBooleanTF#1%
        {\linopstylewide{#2}_{\linopsubscript#3}^{\linopspacewide\linopconjugate#4^{#5}\linopsuperscripthc}}
        {\linopstyle{#2}_{\linopsubscript#3}^{\linopconjugate#4^{#5}\linopsuperscripthc}}
        }

\begin{table}[H]
	\centering
	\begin{tabular}{ll}
		\verb|\op{a}[in][0]| & $\op{a}[in][0]$ \\
		\verb|\hc{b}[out]| & $\hc{b}[out]$ 
	\end{tabular}
\end{table}

\section{Advanced control}
All the options above are set by renewing some custom commands which are

\begin{table}[H]
	\centering
	\begin{tabular}{lll}
		\toprule
		command & default value & description \\
		\midrule
		\verb|\linopstyle| & \verb|\hat| & style of operators\\
		\verb|\linopstylewide| & \verb|\widehat| & style of starred operators\\
		\verb|\linopconjugate| & \verb|\dagger| & symbol used for Hermitian conjugate\\
		\verb|\linopspacewide| & \verb|\>| & spacing in superscript of \verb|op*|\\
		\verb|\linopspacewidehc| & \verb|\:| & spacing in superscript of \verb|hc*|\\
		\verb|\linopsubscript| & \verb|\mathstrut| & equal spacing in subscript \\
		\verb|\linopsuperscript| & \verb|\mathstrut| & equal spacing in superscript of \verb|op|\\ 
		\verb|\linopsuperscripthc| & \verb|\mathstrut| & equal spacing in superscript of \verb|hc|\\
		\bottomrule
	\end{tabular}
\end{table}

These can be changed with \verb|\renewcommand| for even further control.
	
\end{document}