summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/simplewick/simplewick.dtx
blob: 1edd249491bc6d4002b1684ec54ee9db53c47127 (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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
%\iffalse
%<*package>
%%
%% ----
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public License
%% along with this program; if not, write to the Free Software
%% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
%% MA 02110-1301 USA
%%
%% This work consists of the files simplewick.dtx and simplewick.ins
%% and the derived file simplewick.sty.
%%
%% ----
%%
%% Original implementation of "contraction" adopted from thophys.sty by
%% Thorsten Ohl. Contractions below expressions ("bcontraction") and
%% stretching/shrinking fix "nomathglue" by Jindrich Kolorenc.
%%
%% ----
%%
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%</package>
%\fi
% \iffalse
% Doc-Source file to use with LaTeX2e
% \fi
% \iffalse
%<*driver>
\documentclass[11pt]{ltxdoc}
\usepackage{simplewick}

\CheckSum{171}
\changes{1.1}{2006/10/29}{First packed version}
\changes{1.2}{2007/08/09}{Improved spacing to cooperate better with operators (such as \cdot)}
\changes{1.2a}{2007/11/23}{License clarification}

\def\framed#1{
\hbox{\vrule width .02em\vbox{\hrule height .02em\vskip .5ex
\hbox{\hskip .5ex\vbox{\hbox{#1}}\hskip .5ex}
\vskip .5ex\hrule height .02em}\vrule width .02em}
}

\begin{document}
\DocInput{simplewick.dtx}
\end{document}
%</driver>
%\fi
%
%\title{Wick contractions in \LaTeX\ with |simplewick.sty|}
%\author{Jind\v rich Koloren\v c}
%\date{2006/10/29}
%\maketitle
%
%\noindent
%This is a manual accompanying the style file |simplewick.sty|
%providing macros |\acontraction| and |\bcontraction| to draw Wick
%contractions above and below expressions, respectively. The
%functionality is best illustrated by an example,
%$$
%\contraction{}{a}{{}^{\dagger}_i(t_1)a^{\dagger}_j(t_1)}{a}
%\relax%
%\contraction[2ex]{a^{\dagger}_i(t_1)}{a}{%
%{}^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)%
%a^{\dagger}_i(t_2)a^{\dagger}_j(t_2)a_j(t_2)}{a}
%\relax%
%\contraction[3ex]{a^{\dagger}_i(t_1)%
%a^{\dagger}_j(t_1)a_j(t_1)}{a}{{}_i(t_1)%
%a^{\dagger}_i(t_2)}{a}
%\relax%
%\bcontraction{a^{\dagger}_i(t_1)%
%a^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)}%
%{a}{{}^{\dagger}_i(t_2)a^{\dagger}_j(t_2)}{a}
%\relax%
%a^{\dagger}_i(t_1)a^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)
%a^{\dagger}_i(t_2)a^{\dagger}_j(t_2)a_j(t_2)a_i(t_2)\,.
%$$
%
%\section{Usage}
%The syntax will be explained on something simpler, however. The
%sequence
%\begin{verbatim}
%$$
%\contraction{}{A}{B}{C}
%\contraction[2ex]{A}{B}{C}{D}
%ABCD
%$$
%\end{verbatim}
%renders as
%$$
%\contraction{}{A}{B}{C}
%\contraction[2ex]{A}{B}{C}{D}
%ABCD\,.
%$$
%The parameters of the macro |\contraction[]{}{}{}{}| (which is a
%synonym for |\acontraction[]{}{}{}{}|) are as follows.
%\newbox\listlabelbox
%\begin{list}{$\triangleright$}{
%  \setlength{\topsep}{.6em}
%  \setlength{\itemsep}{.5ex}
%  \setlength{\parsep}{0pt}
%  \setbox\listlabelbox=\hbox{$\triangleright$}
%  \setlength{\labelwidth}{\wd\listlabelbox}
%  \setlength{\leftmargin}{1.5\parindent}
%}
%\item The first (optional) argument is the height of the
%contraction. When omitted (as in the first contraction above) it
%defaults to 1ex,
%\item the second argument contains the expression that lies before the
%contraction start,
%\item the third argument contains the expression, above which the
%start of the contraction is centered,
%\item the fourth argument is the
%part of the formula that is bridged by the contraction, and finally
%\item the contraction ends above the center of the last argument of
%the macro.
%\end{list}
%Note that the macro itself typesets only the contraction alone and rewinds
%back to allow for multiple contractions. Therefore, the expression to
%appear below the contraction(s) has to be repeated once more when you
%are finished with contractions themselves.
%
%I guess now it is the right time to move to that ``real life'' example
%from the beginning of this manual. Its source is
%\begin{verbatim}
%$$
%\contraction{}{a}{{}^{\dagger}_i(t_1)a^{\dagger}_j(t_1)}{a}
%%
%\contraction[2ex]{a^{\dagger}_i(t_1)}{a}{%
%{}^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)%
%a^{\dagger}_i(t_2)a^{\dagger}_j(t_2)a_j(t_2)}{a}
%%
%\contraction[3ex]{a^{\dagger}_i(t_1)%
%a^{\dagger}_j(t_1)a_j(t_1)}{a}{{}_i(t_1)%
%a^{\dagger}_i(t_2)}{a}
%%
%\bcontraction{a^{\dagger}_i(t_1)%
%a^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)}%
%{a}{{}^{\dagger}_i(t_2)a^{\dagger}_j(t_2)}{a}
%%
%a^{\dagger}_i(t_1)a^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)
%a^{\dagger}_i(t_2)a^{\dagger}_j(t_2)a_j(t_2)a_i(t_2)\,.
%$$
%\end{verbatim}
%
%
%\section{Contractions inside the text --- stretching and shrinking}
%The macro |\contraction| is prone to giving not entirely satisfactory
%results when the formula is under stress or tension, i.e., when \TeX\
%shrinks or stretches ``the glue'' from its natural width. When we try
%to squeeze the line
%\begin{verbatim}
%Contraction under stress
%$
%\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
%  \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
%=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
%$
%and with no stress
%$
%\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
%  \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
%=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
%$.
%\end{verbatim}
%into a narrow box, we get
%\vskip 1em
%\noindent
%\hbox to \textwidth{\hfil%
%\framed{%
%\vbox{\hsize=23.75em
%\noindent
%Contraction under stress
%$
%\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
%  \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
%=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
%$
%and with no stress
%$
%\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
%  \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
%=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
%$.
%}}\hfil}
%\vskip 1em
%\noindent
%This is not quite right since the contraction drawn on the first line
%is slightly too long, although its length is precisely the same as
%the length of the contraction on the second line --- they were entered
%via the same piece of code, after all. The style
%|simplewick.sty| offers a fix for this inconsistency in the form of
%the macro |\nomathglue{}| that prevents \TeX\ to shrink or stretch its
%argument. When used
%\begin{verbatim}
%Contraction under stress
%$
%\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
%  \nomathglue{%
%     \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)}
%=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
%$
%and with no stress
%$
%\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
%  \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
%=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
%$.
%\end{verbatim}
%the outcome should look precisely as we wanted.
%\vskip 1em
%\noindent
%\hbox to \textwidth{\hfil%
%\framed{%
%\vbox{\hsize=23.75em
%\noindent
%Contraction under stress
%$
%\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
%  \nomathglue{\bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)}
%=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
%$
%and with no stress
%$
%\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
%  \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
%=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
%$.
%}}\hfil}
%
%
%\section{Alternatives}
%An alternative method for typesetting Wick contractions with \LaTeX\ is a
%|wick.sty| by Taichiro Kugo, available at
%\begin{verbatim}
%http://www2.yukawa.kyoto-u.ac.jp/~kugo/index-e.html
%\end{verbatim}
%It is actually a more advanced solution than the one presented
%here (which is the reason why I call this package
%|simplewick|). Unfortunately, |wick.sty| seems to be somewhat
%conflicting with |amsmath| package. For example, I did not succeed to
%draw the |wick.sty| contractions above accented characters (such as
%those in the stretching examples above) when |amsmath| was
%loaded. Without |amsmath| it was just fine, however.
%
%
%\section{Credits}
%The package |simplewick.sty| is based on the code from |thophys.sty|
%by Thorsten Ohl that dates back to 1994. I only added the contractions
%below expressions (|\bcontraction|), the stretching/shrinking fix
%|\nomathglue| and this documentation. Contact information can be
%obtained by issuing a command |\simplewickcontact|.
%
%
%
%
%
%\StopEventually{}
%\section{The Code}
%    \begin{macrocode}
%<*simplewick.sty>
%    \end{macrocode}
%    \begin{macrocode}

\def\fileversion{v1.2a}
\def\filedate{2007/11/23}
\ProvidesPackage{simplewick}[\filedate\space\fileversion]
\typeout{Package: simplewick \fileversion\space (\filedate)}

\makeatletter

% ----
% definition of several boxes we will use
% ----
\newbox\swb@xone
\newbox\swb@xtwo
\newbox\swb@xthree
\newbox\swb@xfour
\newdimen\swdimen@ne
\newdimen\swdimentw@

% ----
% contraction above the expression
% ----
\newcommand{\acontraction}[5][1ex]{%
  \mathchoice
    {\acontraction@\displaystyle{#2}{#3}{#4}{#5}{#1}}%
    {\acontraction@\textstyle{#2}{#3}{#4}{#5}{#1}}%
    {\acontraction@\scriptstyle{#2}{#3}{#4}{#5}{#1}}%
    {\acontraction@\scriptscriptstyle{#2}{#3}{#4}{#5}{#1}}}%
\newcommand{\acontraction@}[6]{%
  \setbox\swb@xone=\hbox{${}#1{}#2{}$}%
  \setbox\swb@xtwo=\hbox{${}#1{}#3{}$}%
  \setbox\swb@xthree=\hbox{${}#1{}#4{}$}%
  \setbox\swb@xfour=\hbox{${}#1{}#5{}$}%
  \swdimen@ne=\wd\swb@xtwo%
  \advance\swdimen@ne by \wd\swb@xfour%
  \divide\swdimen@ne by 2%
  \advance\swdimen@ne by \wd\swb@xthree%
  \vbox{%
    \hbox to 0pt{%
      \kern \wd\swb@xone%
      \kern 0.5\wd\swb@xtwo%
      \acontraction@@{\swdimen@ne}{#6}%
      \hss}%
    \vskip 0.5ex%  how far above the line starts
    \vskip\ht\swb@xtwo}}
\newcommand{\acontracted}[5][1ex]{%
  \acontraction[#1]{#2}{#3}{#4}{#5}\ensuremath{#2#3#4#5}}
\newcommand{\acontraction@@}[3][0.05em]{%
% the 1st parameter (explicitly inserted) is the width
% of the contraction line
  \hbox{%
    \vrule width #1 height 0pt depth #3%
    \vrule width #2 height 0pt depth #1%
    \vrule width #1 height 0pt depth #3%
    \relax}}
% compatibility with the previous version
\let\contraction\acontraction

% ----
% contraction below the expression
% ----
\newcommand{\bcontraction}[5][1ex]{%
  \mathchoice
    {\bcontraction@\displaystyle{#2}{#3}{#4}{#5}{#1}}%
    {\bcontraction@\textstyle{#2}{#3}{#4}{#5}{#1}}%
    {\bcontraction@\scriptstyle{#2}{#3}{#4}{#5}{#1}}%
    {\bcontraction@\scriptscriptstyle{#2}{#3}{#4}{#5}{#1}}}%
\newcommand{\bcontraction@}[6]{%
  \setbox\swb@xone=\hbox{${}#1{}#2{}$}%
  \setbox\swb@xtwo=\hbox{${}#1{}#3{}$}%
  \setbox\swb@xthree=\hbox{${}#1{}#4{}$}%
  \setbox\swb@xfour=\hbox{${}#1{}#5{}$}%
  \swdimen@ne=\wd\swb@xtwo%
  \advance\swdimen@ne by \wd\swb@xfour%
  \divide\swdimen@ne by 2%
  \advance\swdimen@ne by \wd\swb@xthree%
  \lower 0.5ex \vbox{%
    \hbox to 0pt{%
      \kern \wd\swb@xone%
      \kern 0.5\wd\swb@xtwo%
      \bcontraction@@{\swdimen@ne}{#6}%
      \hss}%
    }}
\newcommand{\bcontracted}[5][1ex]{%
  \bcontraction[#1]{#2}{#3}{#4}{#5}\ensuremath{#2#3#4#5}}
\newcommand{\bcontraction@@}[3][0.05em]{%
% the 1st parameter (explicitly inserted) is the width
% of the contraction line
  \hbox{%
    \swdimentw@=#3
    \advance\swdimentw@ by -#1
    \vrule width #1 height 0pt depth #3%
    \lower\swdimentw@\hbox{\vrule width #2 height 0pt depth #1}%
    \vrule width #1 height 0pt depth #3%
    \relax}}

\makeatother

% ----
% macro to switch off shrinking/stretching in mathmode
% (consult TeXbook, page 168, to see where the numbers came from)
% ----
\newcommand\nomathglue[1]{
\begingroup
\thinmuskip=3mu \medmuskip=4mu \thickmuskip=5mu
#1
\endgroup
}

% ----
% obfuscated contact info
% ----
\newcommand\simplewickcontact{%
{\tt {k}{o}{l}{o}{r}{e}{n}{c}{\tt @}{f}{z}{u}{.}{c}{z}}%
}

%    \end{macrocode}
%    \begin{macrocode}
%</simplewick.sty>
%    \end{macrocode}
%\Finale
\endinput