summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex3/xor/xo-grid.dtx
blob: b1d737358a79d26730501598b41009597046a8d6 (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
% \iffalse
%%
%% (C) Copyright 1999-2000 Frank Mittelbach, David Carlisle, Chris Rowley
%% All rights reserved.
%%
%% Not for general distribution. In its present form it is not allowed
%% to put this package onto CD or an archive without consulting the
%% the authors.
%% 
% \fi
%

%    \begin{macrocode}
\def\@tempa#1: #2.dtx,v #3 #4 #5 #6 #7${
  \ProvidesPackage{#2}[#4 #3 #5 #6]}
\@tempa$Id: xo-grid.dtx,v 1.3 2000/08/11 07:14:20 latex3 Exp $
%    \end{macrocode}
%
% Ignore white space in this package.
%    \begin{macrocode}
\IgnoreWhiteSpace
%    \end{macrocode}
%
% This package implements grid design on top of \LaTeXe{} by adding
% |\AlignToGrid| in various macros. Nothing else is really needed (or
% so I hope :-)
%
% So far this probably doesn't cover all structures that should, or
% could be handled automatically.
%
% \subsection{Headings}
%
%
% \begin{macro}{\headingsinkage}
%    This is a temporary register used to specify the amount of
%    sinkage a |\@startsection| heading is allowed if it falls at the
%    a column break. In a proper reimplementation of |\@startsection|
%    as a template, this should be individually specifiable rather
%    than being the same for all headings!
%    \begin{macrocode}
\newskip\headingsinkage
\headingsinkage=5pt plus 3pt minus 5pt
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@startsection}
%    \begin{macrocode}
\def\@startsection#1#2#3#4#5#6{%
  \if@noskipsec \leavevmode \fi
  \par
  \@tempskipa #4\relax
  \@afterindenttrue
  \ifdim \@tempskipa <\z@
    \@tempskipa -\@tempskipa \@afterindentfalse
  \fi
  \if@nobreak
    \everypar{}%
  \else
    \addpenalty\@secpenalty
    \addvspace\@tempskipa
%    \end{macrocode}
%    next lines are pretty horrible but we need something like this
%    here (only it could be be done better)
%    \begin{macrocode}
    \vskip-\headingsinkage
    \vskip\saved@topskip
    \vskip-\prevdepth
    \nointerlineskip
    \null
    \nobreak
    \vskip-\saved@topskip
    \vskip\headingsinkage
  \fi
  \@ifstar
    {\@ssect{#3}{#4}{#5}{#6}}%
    {\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}
%    \end{macrocode}
% \end{macro}
%
%
%
%
% \begin{macro}{\@sect}
%    Have to ensure that we don't get the heading itself aligned due
%    to a dangling |\AlignToGrid| from a previous structure, so we
%    issue a |\IgnoreAlignToGrid| early on. That's the only change for
%    this command.
%    \begin{macrocode}
\def\@sect#1#2#3#4#5#6[#7]#8{%
  \ifnum #2>\c@secnumdepth
    \let\@svsec\@empty
  \else
    \refstepcounter{#1}%
    \protected@edef\@svsec{\@seccntformat{#1}\relax}%
  \fi
  \@tempskipa #5\relax
  \IgnoreAlignToGrid
  \ifdim \@tempskipa>\z@
    \begingroup
      #6{%
        \@hangfrom{\hskip #3\relax\@svsec}%
          \interlinepenalty \@M #8\@@par}%
    \endgroup
    \csname #1mark\endcsname{#7}%
    \addcontentsline{toc}{#1}{%
      \ifnum #2>\c@secnumdepth \else
        \protect\numberline{\csname the#1\endcsname}%
      \fi
      #7}%
  \else
    \def\@svsechd{%
      #6{\hskip #3\relax
      \@svsec #8}%
      \csname #1mark\endcsname{#7}%
      \addcontentsline{toc}{#1}{%
        \ifnum #2>\c@secnumdepth \else
          \protect\numberline{\csname the#1\endcsname}%
        \fi
        #7}}%
  \fi
  \@xsect{#5}}
%    \end{macrocode}
% \end{macro}
%
%
%
%
% \begin{macro}{\@xsect}
%    Now after having typeset the heading we need to issue
%    |\ObeyAlignToGrid| and make sure that the first line of text gets
%    aligned again. And in addition we issue a |\AlignToGrid| inside
%    the |\everypar| to align the first text after the heading. Of
%    course that mean that we will generate a break point after this
%    line and thus might end up up with a heading and only a single
%    line afterwards.
%
%    This could be fixed by using a ``rspace'' structure as
%    implemented in \texttt{xo-or.sty} but this is not added at the
%    moment!
%    \begin{macrocode}
\def\@xsect#1{%
  \ObeyAlignToGrid
  \@tempskipa #1\relax
  \ifdim \@tempskipa>\z@
    \par \nobreak
    \vskip \@tempskipa
    \@afterheading
  \else
    \@nobreakfalse
    \global\@noskipsectrue
    \everypar{%
      \if@noskipsec
        \global\@noskipsecfalse
       {\setbox\z@\lastbox}%
        \clubpenalty\@M
        \AlignToGrid
        \begingroup \@svsechd \endgroup
        \unskip
        \@tempskipa #1\relax
        \hskip -\@tempskipa
      \else
        \clubpenalty \@clubpenalty
        \everypar{}%
      \fi}%
  \fi
  \ignorespaces}
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
% \begin{macro}{\@afterheading}
%    The other case where we have to add |\AlignToGrid| to the
%    |\everypar|.
%    \begin{macrocode}
\def\@afterheading{%
  \@nobreaktrue
  \everypar{%
    \if@nobreak
      \@nobreakfalse
      \clubpenalty \@M
      \if@afterindent \else
        {\setbox\z@\lastbox}%
      \fi
      \AlignToGrid
    \else
      \clubpenalty \@clubpenalty
      \everypar{}%
    \fi}}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{List structures}
%
% \begin{macro}{\@doendpe}
%    Handling of |\everypar| after a list strcture is already strange
%    and complicated; here we complicate it even more by adding
%    |\AlignToGrid| into its definition(s).
%    \begin{macrocode}
\def\@doendpe{\@endpetrue
     \def\par{\@restorepar
              \everypar{\everypar{}\AlignToGrid}\par\@endpefalse}%
     \everypar{{\setbox\z@\lastbox}\everypar{}\AlignToGrid\@endpefalse}%
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
% \begin{macro}{\endtrivlist}
%    And there is one case  in |\endtrivlist| in which |\@doendpe|
%    is skipped so we have to set |\everypar| manually
%    here.\footnote{Perhaps done in a wrong way, CHECK!}
%    \begin{macrocode}
\def\endtrivlist{%
  \if@inlabel
    \leavevmode
    \global \@inlabelfalse
  \fi
  \if@newlist
    \@noitemerr
    \global \@newlistfalse
  \fi
  \ifhmode\unskip \par\fi
  \if@noparlist
    \everypar{\everypar{}\AlignToGrid}
  \else
    \ifdim\lastskip >\z@
      \@tempskipa\lastskip \vskip -\lastskip
      \advance\@tempskipa\parskip \advance\@tempskipa -\@outerparskip
      \vskip\@tempskipa
    \fi
    \@endparenv
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Math}
%
% \begin{macro}{\displaymath}
% \begin{macro}{\enddisplaymath}
% \begin{macro}{\[}
% \begin{macro}{\]}
%    Math is a bit more complicated as with the standard definitions
%    we don't regain control after the display. So we change all the
%    definitions to use the |\@doendpe| method. This means we have to
%    redefine |\[| at al to be a ref to |\displaymath| not the other
%    way around as it was done in \texttt{latex.ltx}.
%    \begin{macrocode}
\def \displaymath {
   \relax\ifmmode
      \@badmath
   \else
      \ifvmode
         \nointerlineskip
         \makebox[.6\linewidth]%
      \fi
      $$%%$$ BRACE MATCH HACK
   \fi
}
\def \enddisplaymath {
   \relax\ifmmode
      \ifinner
         \@badmath
      \else
         $$%%$$ BRACE MATCH HACK
      \fi
   \else
      \@badmath
   \fi
%    \end{macrocode}
%    To gain control we end the paragraph and then invoke the |\end|
%    mechanism for dealing with par. This gives in certain situations
%    slightly different results compared working only with |$$|'s but
%    that's life.
%    \begin{macrocode}
   \par
   \@endpetrue % kill parindent if current paragraph continues
   \@ignoretrue
}
\def\[{\begin{displaymath}}
\def\]{\end{displaymath}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
%
% \begin{macro}{\endequation}
%    Same change for the end of an equation.
%    \begin{macrocode}
\def\endequation{\eqno \hbox{\@eqnnum}$$\par\@ignoretrue
   \@endpetrue % kill parindent if current paragraph continues
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\endeqnarray}
%    And again the same for the equation array structure.
%    \begin{macrocode}
\def\endeqnarray{%
      \@@eqncr
      \egroup
      \global\advance\c@equation\m@ne
   $$\par\@ignoretrue
   \@endpetrue % kill parindent if current paragraph continues
}
%    \end{macrocode}
% \end{macro}
%
% \endinput
\endinput
%
% $Log: xo-grid.dtx,v $
% Revision 1.3  2000/08/11 07:14:20  latex3
% added header
%
% Revision 1.2  2000/08/06 19:01:12  latex3
% fix \prevdepth situation before \@startsection
%
% Revision 1.1  2000/07/30 18:07:22  latex3
% Initial revision
%
%
%
%
%
%
%
% \begin{macro}{}
%    \begin{macrocode}
%    \end{macrocode}
% \end{macro}