Debian Codegraph @

texmf-dist/tex/latex/carlisle/slashed.sty

raw
1 %% slashed.sty: Produce the `Feynman slashed character' notation
2 %% beloved of High Energy Physicists.
3 %%
4 %% This is a standard LaTeX package, but as many physicists perversely
5 %% use use a plain TeX rather than a format designed for document
6 %% production, it runs under plain as well.
7 %% (Just say \input slashed.sty in that case
8 %% rather than \usepackage{slashed}).
9
10 %% This began life as me commenting in comp.text.tex
11 %% on some code posted by Ben Bullock, which was originally written by
12 %% Mike Wade.
13 %% In the ensuing newsgroup thread, P? Parker, Axel Thimm
14 %% and Maurizio Loreti and others made helpful comments
15 %%
16 %% David Carlisle
17 %%
18 %% Copyright 1997 David carlisle
19 %% This file may be distributed under the terms of the LPPL.
20 %% See 00readme.txt for details.
21
22 \ifx\ProvidesPackage\undefined
23 \catcode`\@=11
24 \else
25 \ProvidesPackage{slashed}
26 [1997/01/16 v0.01 Feynman Slashed Character Notation (DPC)]
27 \fi
28
29
30 %% Usage \slashed{p} \slashed{D} etc.
31
32 %% As \slashed may not put the / quite where you want, you can
33 %% customise it for certain arguments. After
34 %%
35 %% \declareslashed{}{/}{.1}{0}{D}
36 %%
37 %% Then any later use of \slashed{D} will have the / moved
38 %% to the right of centre by 0.1 of the width of `D'.
39 %%
40 %% The arguments to \declareslashed are:
41 %%
42 %% #1 A command to apply to the constructed character (for instance
43 %% \mathbin to re-make it into a binary relation). (It seems that
44 %% For the intended use as the Feynman notation it will only
45 %% ever be applied to `ordinary' symbols, and so #1 will be empty
46 %% but someone might find use for it.
47 %%
48 %% #2 The symbol to overprint. Normally / but you can try \not or |
49 %% (or \big/ or whatever) to get different effects.
50 %%
51 %% #3 The overprinted symbol is moved to the right by this fraction
52 %% of the width of the symbol #5.
53 %%
54 %% #4 The overprinted symbol is moved up by this fraction
55 %% of the width of the symbol #5.
56 %% (Note width not height, so #3 and #4 use the same units)
57 %%
58 %% #5 The symbol to which these customisations applies.
59
60
61 %% The basic guts of the macro just measures the specified character
62 %% and a / and arranges to put the centre of the / over the centre
63 %% of the character. (This, barring some TeX quibbles, was what the
64 %% orignally posted macro did.)
65
66 %% The first refinement is to call the macro via \mathpalette so
67 %% that it works correctly in subscripts, fractions etc.
68
69 %% Remaining problems.
70
71 %% The macro puts the middle of the slash through the
72 %% middle of the symbol, where `middle' is defined as the centre of the
73 %% bounding rectangles. However the eye doesn't necessarily work that
74 %% way, for instance $\sla D$ looks to have the slash too far to the
75 %% left to me. It is virtually impossible to do such micro positioning
76 %% automatically as it depends on the shape of the letters and the
77 %% personal judgement of the viewer, and \TeX\ does not have either of
78 %% these pieces of information. However one could do something like
79 %% the following which allows you to predefine offsets for certain
80 %% letters. The offsets are done relative to the size of the symbol
81 %% so they work OK in superscrips (or within the scope of a La\TeX\
82 %% size change).
83
84 %% Some characters just don't work with /. The computer modern math
85 %% italic f and / have about the same slope and whatever you do it
86 %% just looks horrible. So allow the use of an alternative character
87 %% (eg \not, which has a slightly different slope).
88
89 % #1 normally /
90 % #2 right shift
91 % #3 up shift
92 % #4 \displaystyle etc (added by \mathpalette)
93 % #5 symbol.
94 \def\sla@#1#2#3#4#5{{%
95 \setbox\z@\hbox{$\m@th#4#5$}%
96 \setbox\tw@\hbox{$\m@th#4#1$}%
97 \dimen4\wd\ifdim\wd\z@<\wd\tw@\tw@\else\z@\fi
98 \dimen@\ht\tw@
99 \advance\dimen@-\dp\tw@
100 \advance\dimen@-\ht\z@
101 \advance\dimen@\dp\z@
102 \divide\dimen@\tw@
103 \advance\dimen@-#3\ht\tw@
104 \advance\dimen@-#3\dp\tw@
105 \dimen@ii#2\wd\z@
106 \raise-\dimen@\hbox to\dimen4{%
107 \hss\kern\dimen@ii\box\tw@\kern-\dimen@ii\hss}%
108 \llap{\hbox to\dimen4{\hss\box\z@\hss}}}}
109
110 % Use offsets of 0 unless a command has been pre-defined
111 % with different offsets for this symbol.
112 \def\slashed#1{%
113 \expandafter\ifx\csname sla@\string#1\endcsname\relax
114 {\mathpalette{\sla@/00}{#1}}%
115 \else
116 \csname sla@\string#1\endcsname
117 \fi}
118
119 % #1 normally empty, can be \mathop etc
120 % #2 normally /
121 % #3 right shift
122 % #4 up shift
123 % #5 symbol
124 \def\declareslashed#1#2#3#4#5{%
125 \expandafter\def\csname sla@\string#5\endcsname{%
126 #1{\mathpalette{\sla@{#2}{#3}{#4}}{#5}}}}
127
128 \catcode`\@=12
129
130 %% Now some fine tuning, if you are not using Computer Modern
131 %% This is almost certainly wrong. You may think some of these are
132 %% wrong anyway.
133
134
135 \declareslashed{}{/}{.08}{0}{D}
136 \declareslashed{}{/}{.1}{0}{A}
137 \declareslashed{}{/}{0}{-.05}{k}
138 \declareslashed{}{/}{.1}{0}{\partial}
139 \declareslashed{}{\not}{-.6}{0}{f}
140
141 \endinput
142
143 ================================================================
144 % test file (plain TeX)
145 \input slashed.sty
146
147
148 $
149 \slashed{D} \slashed{p} \slashed{k} \slashed{r} \slashed{A}
150 \slashed{f}
151 \slashed{U} \slashed{\partial}
152 $
153
154 \bye
155
156 ================================================================
157 % and same again as LaTeX
158
159 \documentclass{article}
160 \usepackage{slashed}
161
162 \begin{document}
163
164 $
165 \slashed{D} \slashed{p} \slashed{k} \slashed{r} \slashed{A}
166 \slashed{f}
167 \slashed{U} \slashed{\partial}
168 $
169 \end{document}
170
171