summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/finstrut/finstrut.sty
blob: 6f261c6181b9c50a23de33f3ffc7ecc56ea43ee8 (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
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{finstrut}[2011/03/14 v0.5 vmode final strut (DA/UL)]

%% Copyright (C) 2010 2011 Uwe Lueck, 
%% http://www.contact-ednotes.sty.de.vu 
%% -- author-maintained in the sense of LPPL below -- 
%%
%% This file can be redistributed and/or modified under 
%% the terms of the LaTeX Project Public License; either 
%% version 1.3c of the License, or any later version.
%% The latest version of this license is in
%%     http://www.latex-project.org/lppl.txt
%% We did our best to help you, but there is NO WARRANTY. 
%%
%% Please report bugs, problems, and suggestions via 
%% 
%%   http://www.contact-ednotes.sty.de.vu 
%%
%% % *** Another Introduction ***
%% % This is a variant of LaTeX's `\@finalstrut'
%% % that doesn't produce a spurious empty line 
%% % in vmode. In general, this deals with a 
%% % closing `\par' from users in footnotes, 
%% % the idea especially came from using the 
%% % 'lipsum' package.
%% % See `source2e.pdf' (`ltboxes.dtx') for the rationale 
%% % behind the original definition; it may imply 
%% % that the present suggestion is bad with 
%% % `p' columns in `tabular' etc.
%% % 
%% % With v0.4, the code essentially is Donald Arseneau's.
%% 
%% === Outline ===
%% v0.5 considers recommendations by Donald Arseneau. 
%% Some of them may break in applications that we do not 
%% know about, therefore they must be called by package 
%% options. Package Option |[full]| calls all of them.
%% %% 2011/03/14:
%% Package Option |[fullpar]| calls a variant of them 
%% where instead of testing for `hmode' vs.~`vmode', 
%% `vmode' is \emph{forced} by a `\par', saving some tokens.
%%
%% The choices shall not be checked at each invocation 
%% of `\@finalstrut', instead they are evaluated at the 
%% definition of `\@finalstrut', at the end of the package.
%% Choices are prepended to this definition by defining 
%% `\@tempe', `\@tempd', `\@tempc', and `\@tempb'.
%% 
%% === Options ===
%% According to `ltboxes.dtx', a `vmode' test once 
%% was introduced for \LaTeXe, but in 1994 removed again---it 
%% ``broke" in `p' columns. For this reason, v0.1 and v0.3 
%% used an `hmode' test instead. 
%% `ltboxes.dtx' does not tell exactly what code broke in 
%% exactly which situation. Bad. 
%% Brave users may dare the `vmode' test again by choosing 
%% package option |[v]|. It sets `\@tempe' for 
%% `\edef\@finalstrut'. The #1 argument of `\@tempe' is 
%% applied in `hmode', #2 in `vmode'---assuming we are not 
%% in `math' `mode' ...!? (TODO)%%%
%% %% <- !?? don't understand 2011/02/16 ->
%% %---While other conditionals 
%% % are disabled right before the latter, 
%% % we disable the mode test here:
\AtEndOfPackage{\def\@tempe#1#2{\noexpand\ifhmode#1\else#2\fi}}
\DeclareOption{v}{%
  \AtEndOfPackage{%
    \def\@tempe#1#2{\noexpand\ifvmode#2\else#1\fi}}}
%% Replacing the `hmode' or `vmode' test by \emph{forcing} `vmode'
%% (and then applying Donald Arseneau's suggestions for `vmode') 
%% seems just to save a few tokens. With v0.5, option |[par]| 
%% picks this idea.
\DeclareOption{par}{\AtEndOfPackage{\def\@tempe#1#2{\par#2}}}
%% |[argdelim]| appends a `\relax' to `\@finalstrut''s argument 
%% in case the box number is given as a string of digits 
%% (whereas `latex.ltx' only has `\strutbox' and 
%%  `\@arstrutbox' as arguments). 
%% This does not work when somebody tries (e.g.\@)
%% `\@finalstrut11 '. I.e., a ``multi-token" argument must 
%% be enclosed in braces indeed.
\AtEndOfPackage{\let\@tempd\@empty}
\DeclareOption{argdelim}{%
    \AtEndOfPackage{\def\@tempd{\relax}}}
%% %% v0.5 move \@tempc down
%% |[dptest]| caters for depth exceeeding the depth of the 
%% strut box and for negative depth. The test requires that 
%% a multi-token argument (see above) is enclosed in braces.
\AtEndOfPackage{\let\@tempc\@secondoftwo}
\DeclareOption{dptest}{%
  \AtEndOfPackage{%
    \def\@tempd{\relax}%
    \let\@tempc\@firstoftwo}}
%% |[full]| enables all of Donald Arseneau's suggestions:
\DeclareOption{full}{%
  \AtEndOfPackage{%
    \def\@tempe#1#2{\noexpand\ifvmode#2\else#1\fi}%
    \def\@tempd{\relax}%
    \let\@tempc\@firstoftwo
}}
%% |[fullpar]| enables all of Donald Arseneau's suggestions 
%% apart from replacing the `vmode' test by \emph{forcing}
%% `vmode', as with option |[par]|:
\DeclareOption{fullpar}{%
  \AtEndOfPackage{%
    \def\@tempe#1#2{\par#2}%
    \def\@tempd{\relax}%
    \let\@tempc\@firstoftwo
}}
%% |[show]| displays the definition of `\@finalstrut'
%% actually resulting: 
\AtEndOfPackage{\let\@tempb\relax}
\DeclareOption{show}{%
    \AtEndOfPackage{\def\@tempb{\show\@finalstrut}}}
%% Appending choices to the end-of-package hook:
\ProcessOptions
%% 
%% === Core Code ===
%% Now we append the `\edef' of `\@finalstrut' to the 
%% end-of-package hook 
%% (we must hurry so that nobody changes `\@tempe' etc.). 
%% |\dp@only| will be an abbreviation for invoking a strut rule; 
%% it will only be enabled after the `\edef':
\let\dp@only\relax
\AtEndOfPackage{%
  \begingroup
%% Some conditionals are disabled for the `\edef'.
    \let\ifdim\relax \let\else\relax \let\fi\relax
%% Actually, they will be restored by `\endgroup';
%% and in order to get the final `\@finalstrut'
%% outside the group, we ``emulate" its `\edef' 
%% by `\xdef'ing an alias `\@gtempa' of it etc. ...
    \xdef\@gtempa#1{%
      \unskip
      \@tempe{%                         %% \ifhmode/\ifvmode
          \noexpand\nobreak
          \vrule \dp@only #1\@tempd     %% maybe \relax
        }{%
%% Whereas v0.1 and v0.3 used `\kern' to get the bottom 
%% distance in `vmode', Donald Arseneau recommends `\hrule'
%% for the sake of bottom alignment with 'array.sty' 
%% (`b' type columns):
          \@tempc{%                     %% depth test or not 
            \ifdim\prevdepth<\dp#1\relax
                \ifdim\prevdepth>\z@
                    \kern -\prevdepth
                \fi
                \hrule \dp@only#1\relax
            \fi
          }{\hrule \dp@only #1\@tempd}% %% maybe \relax
        }%
    }
  \endgroup
  \let\@finalstrut\@gtempa
  \@tempb                               %% maybe \show
%% |\dp@only|
  \def\dp@only{\@width\z@ \@height\z@ \@depth\dp}
}
%%
%% === Example Result === %% 2011/02/17
%% Option |[fullpar]| amounts to 
%% \begin{verbatim}
%%   \def\@finalstrut#1{%
%%     \unskip\par
%%     \ifdim\prevdepth<\dp#1\relax
%%       \ifdim\prevdepth>\z@
%%         \kern -\prevdepth
%%       \fi
%%       \hrule \@width\z@ \@height\z@ \@depth\dp#1\relax
%%     \fi
%%   }
%% \end{verbatim}
%%
%% === Leaving ===
\endinput
%%
%% === VERSION HISTORY ===

v0.1   2010/12/20   very first 
v0.2   2011/02/09   redundancies removed -- still bad
       NOT DISTRIBUTED
v0.3   2011/02/11   code much reduced again (no \expandafter at all!); 
                    wrong comments replaced; \subsection
v0.4   2011/02/12   Donald Arseneau's full suggestions as options
v0.5   2011/02/12   first \@tempc line moved down
       2011/02/16   options [par] and [fullpar]
       2011/02/17   explaining \edef/\xdef
       2011/02/18   "emulate" \edef
       2011/03/14   some more text on v0.5