Debian Codegraph @

texmf-dist/source/latex/simplewick/simplewick.dtx

raw
1 %\iffalse
2 %<*package>
3 %%
4 %% ----
5 %%
6 %% This program is free software; you can redistribute it and/or modify
7 %% it under the terms of the GNU General Public License as published by
8 %% the Free Software Foundation; either version 2 of the License, or
9 %% (at your option) any later version.
10 %%
11 %% This program is distributed in the hope that it will be useful,
12 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
13 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 %% GNU General Public License for more details.
15 %%
16 %% You should have received a copy of the GNU General Public License
17 %% along with this program; if not, write to the Free Software
18 %% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 %% MA 02110-1301 USA
20 %%
21 %% This work consists of the files simplewick.dtx and simplewick.ins
22 %% and the derived file simplewick.sty.
23 %%
24 %% ----
25 %%
26 %% Original implementation of "contraction" adopted from thophys.sty by
27 %% Thorsten Ohl. Contractions below expressions ("bcontraction") and
28 %% stretching/shrinking fix "nomathglue" by Jindrich Kolorenc.
29 %%
30 %% ----
31 %%
32 %% \CharacterTable
33 %% {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
34 %% 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
35 %% Digits \0\1\2\3\4\5\6\7\8\9
36 %% Exclamation \! Double quote \" Hash (number) \#
37 %% Dollar \$ Percent \% Ampersand \&
38 %% Acute accent \' Left paren \( Right paren \)
39 %% Asterisk \* Plus \+ Comma \,
40 %% Minus \- Point \. Solidus \/
41 %% Colon \: Semicolon \; Less than \<
42 %% Equals \= Greater than \> Question mark \?
43 %% Commercial at \@ Left bracket \[ Backslash \\
44 %% Right bracket \] Circumflex \^ Underscore \_
45 %% Grave accent \` Left brace \{ Vertical bar \|
46 %% Right brace \} Tilde \~}
47 %</package>
48 %\fi
49 % \iffalse
50 % Doc-Source file to use with LaTeX2e
51 % \fi
52 % \iffalse
53 %<*driver>
54 \documentclass[11pt]{ltxdoc}
55 \usepackage{simplewick}
56
57 \CheckSum{171}
58 \changes{1.1}{2006/10/29}{First packed version}
59 \changes{1.2}{2007/08/09}{Improved spacing to cooperate better with operators (such as \cdot)}
60 \changes{1.2a}{2007/11/23}{License clarification}
61
62 \def\framed#1{
63 \hbox{\vrule width .02em\vbox{\hrule height .02em\vskip .5ex
64 \hbox{\hskip .5ex\vbox{\hbox{#1}}\hskip .5ex}
65 \vskip .5ex\hrule height .02em}\vrule width .02em}
66 }
67
68 \begin{document}
69 \DocInput{simplewick.dtx}
70 \end{document}
71 %</driver>
72 %\fi
73 %
74 %\title{Wick contractions in \LaTeX\ with |simplewick.sty|}
75 %\author{Jind\v rich Koloren\v c}
76 %\date{2006/10/29}
77 %\maketitle
78 %
79 %\noindent
80 %This is a manual accompanying the style file |simplewick.sty|
81 %providing macros |\acontraction| and |\bcontraction| to draw Wick
82 %contractions above and below expressions, respectively. The
83 %functionality is best illustrated by an example,
84 %$$
85 %\contraction{}{a}{{}^{\dagger}_i(t_1)a^{\dagger}_j(t_1)}{a}
86 %\relax%
87 %\contraction[2ex]{a^{\dagger}_i(t_1)}{a}{%
88 %{}^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)%
89 %a^{\dagger}_i(t_2)a^{\dagger}_j(t_2)a_j(t_2)}{a}
90 %\relax%
91 %\contraction[3ex]{a^{\dagger}_i(t_1)%
92 %a^{\dagger}_j(t_1)a_j(t_1)}{a}{{}_i(t_1)%
93 %a^{\dagger}_i(t_2)}{a}
94 %\relax%
95 %\bcontraction{a^{\dagger}_i(t_1)%
96 %a^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)}%
97 %{a}{{}^{\dagger}_i(t_2)a^{\dagger}_j(t_2)}{a}
98 %\relax%
99 %a^{\dagger}_i(t_1)a^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)
100 %a^{\dagger}_i(t_2)a^{\dagger}_j(t_2)a_j(t_2)a_i(t_2)\,.
101 %$$
102 %
103 %\section{Usage}
104 %The syntax will be explained on something simpler, however. The
105 %sequence
106 %\begin{verbatim}
107 %$$
108 %\contraction{}{A}{B}{C}
109 %\contraction[2ex]{A}{B}{C}{D}
110 %ABCD
111 %$$
112 %\end{verbatim}
113 %renders as
114 %$$
115 %\contraction{}{A}{B}{C}
116 %\contraction[2ex]{A}{B}{C}{D}
117 %ABCD\,.
118 %$$
119 %The parameters of the macro |\contraction[]{}{}{}{}| (which is a
120 %synonym for |\acontraction[]{}{}{}{}|) are as follows.
121 %\newbox\listlabelbox
122 %\begin{list}{$\triangleright$}{
123 % \setlength{\topsep}{.6em}
124 % \setlength{\itemsep}{.5ex}
125 % \setlength{\parsep}{0pt}
126 % \setbox\listlabelbox=\hbox{$\triangleright$}
127 % \setlength{\labelwidth}{\wd\listlabelbox}
128 % \setlength{\leftmargin}{1.5\parindent}
129 %}
130 %\item The first (optional) argument is the height of the
131 %contraction. When omitted (as in the first contraction above) it
132 %defaults to 1ex,
133 %\item the second argument contains the expression that lies before the
134 %contraction start,
135 %\item the third argument contains the expression, above which the
136 %start of the contraction is centered,
137 %\item the fourth argument is the
138 %part of the formula that is bridged by the contraction, and finally
139 %\item the contraction ends above the center of the last argument of
140 %the macro.
141 %\end{list}
142 %Note that the macro itself typesets only the contraction alone and rewinds
143 %back to allow for multiple contractions. Therefore, the expression to
144 %appear below the contraction(s) has to be repeated once more when you
145 %are finished with contractions themselves.
146 %
147 %I guess now it is the right time to move to that ``real life'' example
148 %from the beginning of this manual. Its source is
149 %\begin{verbatim}
150 %$$
151 %\contraction{}{a}{{}^{\dagger}_i(t_1)a^{\dagger}_j(t_1)}{a}
152 %%
153 %\contraction[2ex]{a^{\dagger}_i(t_1)}{a}{%
154 %{}^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)%
155 %a^{\dagger}_i(t_2)a^{\dagger}_j(t_2)a_j(t_2)}{a}
156 %%
157 %\contraction[3ex]{a^{\dagger}_i(t_1)%
158 %a^{\dagger}_j(t_1)a_j(t_1)}{a}{{}_i(t_1)%
159 %a^{\dagger}_i(t_2)}{a}
160 %%
161 %\bcontraction{a^{\dagger}_i(t_1)%
162 %a^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)}%
163 %{a}{{}^{\dagger}_i(t_2)a^{\dagger}_j(t_2)}{a}
164 %%
165 %a^{\dagger}_i(t_1)a^{\dagger}_j(t_1)a_j(t_1)a_i(t_1)
166 %a^{\dagger}_i(t_2)a^{\dagger}_j(t_2)a_j(t_2)a_i(t_2)\,.
167 %$$
168 %\end{verbatim}
169 %
170 %
171 %\section{Contractions inside the text --- stretching and shrinking}
172 %The macro |\contraction| is prone to giving not entirely satisfactory
173 %results when the formula is under stress or tension, i.e., when \TeX\
174 %shrinks or stretches ``the glue'' from its natural width. When we try
175 %to squeeze the line
176 %\begin{verbatim}
177 %Contraction under stress
178 %$
179 %\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
180 % \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
181 %=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
182 %$
183 %and with no stress
184 %$
185 %\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
186 % \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
187 %=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
188 %$.
189 %\end{verbatim}
190 %into a narrow box, we get
191 %\vskip 1em
192 %\noindent
193 %\hbox to \textwidth{\hfil%
194 %\framed{%
195 %\vbox{\hsize=23.75em
196 %\noindent
197 %Contraction under stress
198 %$
199 %\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
200 % \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
201 %=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
202 %$
203 %and with no stress
204 %$
205 %\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
206 % \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
207 %=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
208 %$.
209 %}}\hfil}
210 %\vskip 1em
211 %\noindent
212 %This is not quite right since the contraction drawn on the first line
213 %is slightly too long, although its length is precisely the same as
214 %the length of the contraction on the second line --- they were entered
215 %via the same piece of code, after all. The style
216 %|simplewick.sty| offers a fix for this inconsistency in the form of
217 %the macro |\nomathglue{}| that prevents \TeX\ to shrink or stretch its
218 %argument. When used
219 %\begin{verbatim}
220 %Contraction under stress
221 %$
222 %\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
223 % \nomathglue{%
224 % \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)}
225 %=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
226 %$
227 %and with no stress
228 %$
229 %\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
230 % \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
231 %=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
232 %$.
233 %\end{verbatim}
234 %the outcome should look precisely as we wanted.
235 %\vskip 1em
236 %\noindent
237 %\hbox to \textwidth{\hfil%
238 %\framed{%
239 %\vbox{\hsize=23.75em
240 %\noindent
241 %Contraction under stress
242 %$
243 %\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
244 % \nomathglue{\bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)}
245 %=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
246 %$
247 %and with no stress
248 %$
249 %\contraction{}{\bar G}{{}_1(\mathbf{q}_1)\>\>{}}{\bar G}
250 % \bar G_1(\mathbf{q}_1)\>\>{}\bar G_2(\mathbf{q}_2)
251 %=\bar\chi_{12}(\mathbf{q}_1-\mathbf{q}_2)
252 %$.
253 %}}\hfil}
254 %
255 %
256 %\section{Alternatives}
257 %An alternative method for typesetting Wick contractions with \LaTeX\ is a
258 %|wick.sty| by Taichiro Kugo, available at
259 %\begin{verbatim}
260 %http://www2.yukawa.kyoto-u.ac.jp/~kugo/index-e.html
261 %\end{verbatim}
262 %It is actually a more advanced solution than the one presented
263 %here (which is the reason why I call this package
264 %|simplewick|). Unfortunately, |wick.sty| seems to be somewhat
265 %conflicting with |amsmath| package. For example, I did not succeed to
266 %draw the |wick.sty| contractions above accented characters (such as
267 %those in the stretching examples above) when |amsmath| was
268 %loaded. Without |amsmath| it was just fine, however.
269 %
270 %
271 %\section{Credits}
272 %The package |simplewick.sty| is based on the code from |thophys.sty|
273 %by Thorsten Ohl that dates back to 1994. I only added the contractions
274 %below expressions (|\bcontraction|), the stretching/shrinking fix
275 %|\nomathglue| and this documentation. Contact information can be
276 %obtained by issuing a command |\simplewickcontact|.
277 %
278 %
279 %
280 %
281 %
282 %\StopEventually{}
283 %\section{The Code}
284 % \begin{macrocode}
285 %<*simplewick.sty>
286 % \end{macrocode}
287 % \begin{macrocode}
288
289 \def\fileversion{v1.2a}
290 \def\filedate{2007/11/23}
291 \ProvidesPackage{simplewick}[\filedate\space\fileversion]
292 \typeout{Package: simplewick \fileversion\space (\filedate)}
293
294 \makeatletter
295
296 % ----
297 % definition of several boxes we will use
298 % ----
299 \newbox\swb@xone
300 \newbox\swb@xtwo
301 \newbox\swb@xthree
302 \newbox\swb@xfour
303 \newdimen\swdimen@ne
304 \newdimen\swdimentw@
305
306 % ----
307 % contraction above the expression
308 % ----
309 \newcommand{\acontraction}[5][1ex]{%
310 \mathchoice
311 {\acontraction@\displaystyle{#2}{#3}{#4}{#5}{#1}}%
312 {\acontraction@\textstyle{#2}{#3}{#4}{#5}{#1}}%
313 {\acontraction@\scriptstyle{#2}{#3}{#4}{#5}{#1}}%
314 {\acontraction@\scriptscriptstyle{#2}{#3}{#4}{#5}{#1}}}%
315 \newcommand{\acontraction@}[6]{%
316 \setbox\swb@xone=\hbox{${}#1{}#2{}$}%
317 \setbox\swb@xtwo=\hbox{${}#1{}#3{}$}%
318 \setbox\swb@xthree=\hbox{${}#1{}#4{}$}%
319 \setbox\swb@xfour=\hbox{${}#1{}#5{}$}%
320 \swdimen@ne=\wd\swb@xtwo%
321 \advance\swdimen@ne by \wd\swb@xfour%
322 \divide\swdimen@ne by 2%
323 \advance\swdimen@ne by \wd\swb@xthree%
324 \vbox{%
325 \hbox to 0pt{%
326 \kern \wd\swb@xone%
327 \kern 0.5\wd\swb@xtwo%
328 \acontraction@@{\swdimen@ne}{#6}%
329 \hss}%
330 \vskip 0.5ex% how far above the line starts
331 \vskip\ht\swb@xtwo}}
332 \newcommand{\acontracted}[5][1ex]{%
333 \acontraction[#1]{#2}{#3}{#4}{#5}\ensuremath{#2#3#4#5}}
334 \newcommand{\acontraction@@}[3][0.05em]{%
335 % the 1st parameter (explicitly inserted) is the width
336 % of the contraction line
337 \hbox{%
338 \vrule width #1 height 0pt depth #3%
339 \vrule width #2 height 0pt depth #1%
340 \vrule width #1 height 0pt depth #3%
341 \relax}}
342 % compatibility with the previous version
343 \let\contraction\acontraction
344
345 % ----
346 % contraction below the expression
347 % ----
348 \newcommand{\bcontraction}[5][1ex]{%
349 \mathchoice
350 {\bcontraction@\displaystyle{#2}{#3}{#4}{#5}{#1}}%
351 {\bcontraction@\textstyle{#2}{#3}{#4}{#5}{#1}}%
352 {\bcontraction@\scriptstyle{#2}{#3}{#4}{#5}{#1}}%
353 {\bcontraction@\scriptscriptstyle{#2}{#3}{#4}{#5}{#1}}}%
354 \newcommand{\bcontraction@}[6]{%
355 \setbox\swb@xone=\hbox{${}#1{}#2{}$}%
356 \setbox\swb@xtwo=\hbox{${}#1{}#3{}$}%
357 \setbox\swb@xthree=\hbox{${}#1{}#4{}$}%
358 \setbox\swb@xfour=\hbox{${}#1{}#5{}$}%
359 \swdimen@ne=\wd\swb@xtwo%
360 \advance\swdimen@ne by \wd\swb@xfour%
361 \divide\swdimen@ne by 2%
362 \advance\swdimen@ne by \wd\swb@xthree%
363 \lower 0.5ex \vbox{%
364 \hbox to 0pt{%
365 \kern \wd\swb@xone%
366 \kern 0.5\wd\swb@xtwo%
367 \bcontraction@@{\swdimen@ne}{#6}%
368 \hss}%
369 }}
370 \newcommand{\bcontracted}[5][1ex]{%
371 \bcontraction[#1]{#2}{#3}{#4}{#5}\ensuremath{#2#3#4#5}}
372 \newcommand{\bcontraction@@}[3][0.05em]{%
373 % the 1st parameter (explicitly inserted) is the width
374 % of the contraction line
375 \hbox{%
376 \swdimentw@=#3
377 \advance\swdimentw@ by -#1
378 \vrule width #1 height 0pt depth #3%
379 \lower\swdimentw@\hbox{\vrule width #2 height 0pt depth #1}%
380 \vrule width #1 height 0pt depth #3%
381 \relax}}
382
383 \makeatother
384
385 % ----
386 % macro to switch off shrinking/stretching in mathmode
387 % (consult TeXbook, page 168, to see where the numbers came from)
388 % ----
389 \newcommand\nomathglue[1]{
390 \begingroup
391 \thinmuskip=3mu \medmuskip=4mu \thickmuskip=5mu
392 #1
393 \endgroup
394 }
395
396 % ----
397 % obfuscated contact info
398 % ----
399 \newcommand\simplewickcontact{%
400 {\tt {k}{o}{l}{o}{r}{e}{n}{c}{\tt @}{f}{z}{u}{.}{c}{z}}%
401 }
402
403 % \end{macrocode}
404 % \begin{macrocode}
405 %</simplewick.sty>
406 % \end{macrocode}
407 %\Finale
408 \endinput