Debian Codegraph @

texmf-dist/doc/latex/linop/linop.tex

raw
1 %% linop.sty
2 %% Copyright 2016 Johannes Weytjens
3 %
4 % This work may be distributed and/or modified under the
5 % conditions of the LaTeX Project Public License, either version 1.3
6 % of this license or (at your option) any later version.
7 % The latest version of this license is in
8 % http://www.latex-project.org/lppl.txt
9 % and version 1.3 or later is part of all distributions of LaTeX
10 % version 2005/12/01 or later.
11 %
12 % This work has the LPPL maintenance status `maintained'.
13 %
14 % The Current Maintainer of this work is Johannes Weytjens
15 %
16 % This work consists of the file linop.sty
17
18 \documentclass[10pt]{article}
19
20 % layout
21 \usepackage[T1]{fontenc}
22 \usepackage[utf8]{inputenc}
23 \usepackage[a4paper]{geometry}
24 \usepackage[english]{babel}
25 \usepackage[tracking=true,kerning=true,factor=1250]{microtype}
26 \usepackage[compact]{titlesec}
27 \usepackage{tocloft}
28 \usepackage[charter,expert]{mathdesign}
29 \usepackage[scaled=0.96]{XCharter}
30 \usepackage{linop}
31 \usepackage{parskip}
32 \usepackage{float}
33 \usepackage{xparse}
34 \usepackage{fancyvrb}
35 \usepackage{booktabs}
36 \usepackage{graphicx}
37 \usepackage{caption}
38 \usepackage{cprotect}
39 \usepackage[hang]{footmisc}
40
41 % math
42 \usepackage{bm}
43
44 % titlesec
45 \titleformat{\section}[hang]{\scshape\Large}{\thesection.}{1ex}{}
46 \titleformat{\subsection}[hang]{\scshape\large}{\thesubsection.}{0.5ex}{}
47 \titleformat{\subsubsection}[hang]{\scshape}{\thesubsubsection.}{0.25ex}{}
48
49 % tableofcontents
50 \setcounter{tocdepth}{1}
51 \renewcommand{\cfttoctitlefont}{\Large\scshape}
52 \renewcommand{\cftsecfont}{\scshape}
53 \renewcommand{\cftsecpagefont}{\large}
54
55 % footmisc
56 \setlength{\footnotemargin}{1em}
57
58 % distance between columns in a table
59 \setlength{\tabcolsep}{20pt}
60
61 % caption
62 \DeclareCaptionFormat{center}{{\centerline{#1#2}\\}#3}
63 \captionsetup{font={small},labelfont=sc,width=0.8\textwidth,format=center,labelsep=none,justification=justified}
64
65 % microtype
66 \SetTracking{encoding={*}, shape=sc}{0} % small caps are correctly typeset
67 % protrusion for footnotes
68 \DeclareMicrotypeSet{textandfootnote}{%
69 encoding = {OT1,T1},
70 family = {*},
71 size = {normalsize,footnotesize,small,large,Large,scriptsize},
72 font = {*}
73 }
74
75 % PDF (metadata)
76 \usepackage{hyperref}
77 \hypersetup{
78 pdfauthor = {Johannes Weytjens},
79 pdftitle = {The linop package v0.1},
80 pdfcreator = {LaTeX}
81 }
82
83 \title{The \texttt{linop} package v0.1}
84 \author{Johannes Weytjens \\ \href{[email protected]}{[email protected]}}
85
86 \begin{document}
87 \maketitle
88
89 \tableofcontents
90
91 \section{Introduction}
92 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.
93
94 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.
95
96 \begin{table}[ht]
97 \centering
98 \begin{tabular}{ll}
99 \verb|\hat{a}_{in}\hat{a}_{in}^{\dagger}| & $\hat{a}_{in}\hat{a}_{in}^{\dagger}$ \\
100 \verb|\op{a}{in}\hc{a}{in}| & $\op{a}{in}\hc{a}{in}$
101 \end{tabular}
102 \end{table}
103
104 Typesetting the \verb|\dagger| and a subscript simultaneously pushes the subscript down, this is no longer the case with the here defined macros.
105
106 \subsection{Required packages}
107 As these are simple macros, you only need the \texttt{xparse} package.
108
109 \newpage
110 \section{List of commands}
111 The two macros defined in this package are \verb|\op| and \verb|\hc| as well as their starred versions.
112
113 \begin{Verbatim}[commandchars=\&\"\!]
114 \op[&rmfamily&itshape"superscript spacing!&ttfamily]{&rmfamily&itshape"operator!&ttfamily}{&rmfamily&itshape"subscript!&ttfamily}{&rmfamily&itshape"superscript!&ttfamily}{&rmfamily&itshape"supersuperscript!&ttfamily}
115 \hc[&rmfamily&itshape"superscript spacing!&ttfamily]{&rmfamily&itshape"operator!&ttfamily}{&rmfamily&itshape"subscript!&ttfamily}{&rmfamily&itshape"superscript!&ttfamily}{&rmfamily&itshape"supersuperscript!&ttfamily}
116 \end{Verbatim}
117
118 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.
119
120 \begin{table}[H]
121 \centering
122 \begin{tabular}{ll}
123 \verb|\op{a}{in}{0}| & $\op{a}{in}{0}$ \\
124 \verb|\op{a}{}{(1)}{2}| & $\op{a}{}{(1)}{2}$ \\
125 \verb|\hc{b}{out}{0}| & $\hc{b}{out}{0}$ \\
126 \verb|\hc{b}{out}{}{2}| & $\hc{b}{out}{}{2}$
127 \end{tabular}
128 \end{table}
129
130 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.
131
132 \begin{table}[H]
133 \centering
134 \begin{tabular}{ll}
135 \verb|\op*{A}{in}{0}| & $\op*{A}{in}{0}$ \\
136 \verb|\hc*{ab}{out}| & $\hc*{ab}{out}$ \\
137 \verb|\hc*[\kern4pt]{\mathcal{L}}| & $\hc*[\kern4pt]{\mathcal{L}}$
138 \end{tabular}
139 \end{table}
140
141
142 \section{List of options}
143 \subsection{bold}
144 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.
145
146 \renewcommand{\linopstyle}{\mathbf}
147 \renewcommand{\linopstylewide}{\linopstyle}
148
149 \begin{table}[H]
150 \centering
151 \begin{tabular}{ll}
152 \verb|\op{a}{in}{0}| & $\op{a}{in}{0}$ \\
153 \verb|\hc{b}{out}| & $\hc{b}{out}$
154 \end{tabular}
155 \end{table}
156
157 \subsection{bmbold}
158 The \texttt{bmbold} option achieves the same effect as bold, but instead uses the bold math font provided by the \texttt{bm} package.
159
160 \renewcommand{\linopstyle}{\bm}
161
162 \begin{table}[H]
163 \centering
164 \begin{tabular}{ll}
165 \verb|\op{a}{in}{0}| & $\op{a}{in}{0}$ \\
166 \verb|\hc{b}{out}| & $\hc{b}{out}$
167 \end{tabular}
168 \end{table}
169
170 \subsection{nohat}
171 The option \texttt{nohat} typesets the operators without a \verb|\hat|. This also applies to the starred versions.
172
173 \renewcommand{\linopstyle}{}
174
175 \begin{table}[H]
176 \centering
177 \begin{tabular}{ll}
178 \verb|\op{a}{in}{0}| & $\op{a}{in}{0}$ \\
179 \verb|\hc{b}{out}| & $\hc{b}{out}$
180 \end{tabular}
181 \end{table}
182
183 \subsection{wide}
184
185 \renewcommand{\linopstyle}{\hat}
186 With the wide option, all operators will use \verb|\widehat|, regardless of whether you're using the starred or non starred versions.
187
188 \subsection{star}
189
190 \renewcommand{\linopconjugate}{*}
191
192 The \texttt{star} options typesets the Hermitian conjugate with a star instead of a dagger.
193
194 \begin{table}[H]
195 \centering
196 \begin{tabular}{ll}
197 \verb|\hc{b}{out}| & $\hc{b}{out}$
198 \end{tabular}
199 \end{table}
200
201
202
203 \subsection{compact}
204 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|.}.
205
206 \renewcommand{\linopconjugate}{\dagger}
207
208 \begin{table}[H]
209 \centering
210 \begin{tabular}{lll}
211 \verb|\op{a}{in}\hc{a}{in}| & $\op{a}{in}\hc{a}{in}$ & using \verb|\mathstrut| \\
212 \gdef\linopsubscript{}%
213 \gdef\linopsuperscript{\phantom{\dagger}}%
214 \gdef\linopsuperscripthc{}%
215 \verb|\op{a}{in}\hc{a}{in}| & $\op{a}{in}\hc{a}{in}$ & using \verb|\phantom{\dagger}|
216 \end{tabular}
217 \end{table}
218
219 \begin{figure}[H]
220 \centering
221 \includegraphics[scale=0.35]{compact}
222 \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}|.}
223 \end{figure}
224
225
226 \subsection{square}
227 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.
228
229 \DeclareDocumentCommand{\op}{s m O{} O{} O{}}{%
230 \IfBooleanTF#1%
231 {\linopstylewide{#2}_{\linopsubscript#3}^{\linopspacewide#4^{#5}\linopsuperscript}}
232 {\linopstyle{#2}_{\linopsubscript#3}^{#4^{#5}\linopsuperscript}}
233 }
234
235 \DeclareDocumentCommand{\hc}{s m O{} O{} O{}}{%
236 \IfBooleanTF#1%
237 {\linopstylewide{#2}_{\linopsubscript#3}^{\linopspacewide\linopconjugate#4^{#5}\linopsuperscripthc}}
238 {\linopstyle{#2}_{\linopsubscript#3}^{\linopconjugate#4^{#5}\linopsuperscripthc}}
239 }
240
241 \begin{table}[H]
242 \centering
243 \begin{tabular}{ll}
244 \verb|\op{a}[in][0]| & $\op{a}[in][0]$ \\
245 \verb|\hc{b}[out]| & $\hc{b}[out]$
246 \end{tabular}
247 \end{table}
248
249 \section{Advanced control}
250 All the options above are set by renewing some custom commands which are
251
252 \begin{table}[H]
253 \centering
254 \begin{tabular}{lll}
255 \toprule
256 command & default value & description \\
257 \midrule
258 \verb|\linopstyle| & \verb|\hat| & style of operators\\
259 \verb|\linopstylewide| & \verb|\widehat| & style of starred operators\\
260 \verb|\linopconjugate| & \verb|\dagger| & symbol used for Hermitian conjugate\\
261 \verb|\linopspacewide| & \verb|\>| & spacing in superscript of \verb|op*|\\
262 \verb|\linopspacewidehc| & \verb|\:| & spacing in superscript of \verb|hc*|\\
263 \verb|\linopsubscript| & \verb|\mathstrut| & equal spacing in subscript \\
264 \verb|\linopsuperscript| & \verb|\mathstrut| & equal spacing in superscript of \verb|op|\\
265 \verb|\linopsuperscripthc| & \verb|\mathstrut| & equal spacing in superscript of \verb|hc|\\
266 \bottomrule
267 \end{tabular}
268 \end{table}
269
270 These can be changed with \verb|\renewcommand| for even further control.
271
272 \end{document}