summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/gmutils/gmmw.sty
blob: 46b8e41fa7d03bf5bd2303e057d74e5e0261c33a (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
%% 
%% \iffalse ^^A we skip the debug setting
\IfFileExists{\string~/bin/gen_and_xela}{\errorcontextlines=1000 }{}
%% \fi
%% ^^A $Id: TheUltimateMaster.gmd,v 0.352 2011/10/12 15:19:42 natror Exp natror $
%% This is file “gmmw.sty” generated with the DocStrip utility.
%% 
%%
%% The original source files were:
%%
%% gmutils/gmutils.gmd  (with options: `mw')
%%
%% 
%% Copyright ©  
%% by Grzegorz ‘Natror’ Murzynowski
%% natror (at) gmail (dot) com
%% 
%% This program is subject to the LaTeX Project Public License.
%% See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html
%% for the details of that license.
%%
%% LPPL status: "author-maintained".
%%
%% 
%% 
%% For documentation please refer to the file(s)
%% gmutils.{gmd,pdf}.
%% 
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gmmw}
    [2011/10/12 v0.996 improvements and workarounds to the MWCLS classes (GM)]


%%
%%
%%     ^^A\typeout{\unexpanded{#4}}%%
\RequirePackage{gmcommand}


\AtBeginDocument{% because we don't know when exactly \pk{hyperref} is
  % loaded and maybe after this package.
  \@ifpackageloaded{hyperref}{\newcounter{NoNumSecs}%
    \setcounter{NoNumSecs}{617}% to make |\ref|ing to an unnumbered section
    % visible (and funny?).
    \def\gmu@hyperrefstepcounter{\refstepcounter{NoNumSecs}}%
    \pdef\gmu@targetheading#1{%
      \hypertarget{#1}{#1}}}% end of then
  {\def\gmu@hyperrefstepcounter{}%
    \def\gmu@targetheading#1{#1}}% end of else
}% of |\AtBeginDocument|

\def\gmu@dontnumbersectionsoutofmainmatter{%
  \if@mainmatter\else \HeadingNumberedfalse \fi}
\def\gmu@clearpagesduetoopenright{%
  \if@openright\cleardoublepage\else \clearpage\fi}

\long\def\@ifnotmw#1#2{\gmu@ifundefined{mw@sectionxx}{#1}{#2}}

\@ifnotmw{}{%
\def\mw@sectionxx#1#2[#3]#4{%
  \edef\mw@HeadingLevel{\csname #1@level\endcsname
        \space}% space delimits level number!
  \ifHeadingNumbered
      \ifnum \mw@HeadingLevel>\c@secnumdepth \HeadingNumberedfalse \fi
      % \nostanza line below is in |\gmu@ifundefined| to make it work in classes
      % other than \pk{mwbk}\nostanza
      \gmu@ifundefined{if@mainmatter}{}{\gmu@dontnumbersectionsoutofmainmatter}
  \fi
%%   \ifHeadingNumbered
%%     \refstepcounter{#1}%
%%     \protected@edef\HeadingNumber{\csname the#1\endcsname\relax}%
%%   \else
%%     \let\HeadingNumber\@empty
%%   \fi
  \def\HeadingRHeadText{#2}%
  \def\HeadingTOCText{#3}%
  \def\HeadingText{#4}%
  \def\mw@HeadingType{#1}%
  \if\mw@HeadingBreakBefore
    \if@specialpage\else\thispagestyle{closing}\fi
    \gmu@ifundefined{if@openright}{}{\gmu@clearpagesduetoopenright}%
    \if\mw@HeadingBreakAfter
      \thispagestyle{blank}\else
      \thispagestyle{opening}\fi
       \global\@topnum\z@
  \fi% of |\if\mw@HeadingBreakBefore|
%%
  \ifHeadingNumbered
    \refstepcounter{#1}%
    \protected@edef\HeadingNumber{\csname the#1\endcsname\relax}%
  \else
    \let\HeadingNumber\@empty
    \gmu@hyperrefstepcounter % we step an auxiliary counter to make a
                            % hyperref's label/target.
  \fi% of |\ifHeadingNumbered|
%%
  \if\mw@HeadingRunIn
    \mw@runinheading
  \else
    \if\mw@HeadingWholeWidth
      \if@twocolumn
        \if\mw@HeadingBreakAfter
        \onecolumn
        \mw@normalheading
        \pagebreak\relax
              \if@twoside
                \null
                \thispagestyle{blank}%
                \newpage
              \fi% of |\if@twoside|
        \twocolumn
        \else
          \@topnewpage[\mw@normalheading]%
        \fi% of |\if\mw@HeadingBreakAfter|
      \else
        \mw@normalheading
        \if\mw@HeadingBreakAfter\pagebreak\relax\fi
      \fi% of |\if@twocolumn|
    \else
      \mw@normalheading
      \if\mw@HeadingBreakAfter\pagebreak\relax\fi
    \fi% of |\if\mw@HeadingWholeWidth|
  \fi% of |\if\mw@HeadingRunIn|
  }


\relaxen\SetSectionFormatting
\newcommand*\SetSectionFormatting[5][\empty]{%
  \ifx\empty#1\relax\else% empty (not |\empty|!) |#1| also launches |\else|.\HideDef
    \def\mw@HeadingRunIn{10}\def\mw@HeadingBreakBefore{10}%
    \def\mw@HeadingBreakAfter{10}\def\mw@HeadingWholeWidth{10}%
    \gmu@ifempty{#1}{}{\mw@processflags#1,\relax}% If |#1| is omitted,
    % the flags are left unchanged. If |#1| is given, even as [], the
    % flags are first cleared and then processed again.
  \fi
  \gmu@ifundefined{#2}{\@namedef{#2}{\mw@section{#2}}}{}%
  \mw@secdef{#2}{@preskip} {#3}{2 oblig.}%
  \mw@secdef{#2}{@head}    {#4}{3 oblig.}%
  \mw@secdef{#2}{@postskip}{#5}{4 oblig.}%
  \ifx\empty#1\relax
    \mw@secundef{#2@flags}{1 (optional)}%
  \else\mw@setflags{#2}% \ResumeDef
  \fi}

\def\mw@secdef#1#2#3#4{% ^^B
  \gmu@ifempty{#3}
    {\mw@secundef{#1#2}{#4}}
    {\@namedef{#1#2}{#3}}}

\def\mw@secundef#1#2{%
  \gmu@ifundefined{#1}{%
    \ClassError{mwcls/gm}{%
      command \bslash#1  undefined \MessageBreak
      after \bslash SetSectionFormatting!!!\MessageBreak}{%
      Provide the #2 argument of \bslash SetSectionFormatting.}}{}}

\def\addtoheading#1#2{%
    \n@melet{gmu@addtoheading@resa}{#1@head}%
    \edef\gmu@addtoheading@resa{\unexpanded{#2}\@xa\unexpanded{\gmu@addtoheading@resa}}%
    \n@melet{#1@head}{gmu@addtoheading@resa}%
}

}% of |\@ifnotmw|'s else.


\@ifnotmw{}{% We proceed only in \acro{MWCLS}.

\def\@afterheading{%
  \@nobreaktrue
  \xdef\gmu@prevsec{\mw@HeadingType}% added now
  \everypar{%
    \grelaxen\gmu@prevsec% added now. All the rest is original \LaTeX.
    \if@nobreak
    \@nobreakfalse
    \clubpenalty \@M
    \if@afterindent \else
    {\setbox\z@\lastbox}%
    \fi
    \else
    \clubpenalty \@clubpenalty
    \everypar{}%
    \fi}}

\def\gmu@checkaftersec{%
  \gmu@ifundefined{gmu@prevsec}{}{%
    \ifgmu@postsec% an additional switch that is true by default but
    % may be turned into an \cs{ifdim} in special
    % cases, see line \ref{gmu@postsec}.
    {\@xa\mw@getflags\@xa{\gmu@prevsec}%
      \glet\gmu@checkaftersec@resa\mw@HeadingBreakAfter}% \UnDef
    \if\mw@HeadingBreakBefore\def\gmu@checkaftersec@resa{11}\fi% if the
    % current heading inserts page break before itself, all the play
    % with vskips is irrelevant.
    \if\gmu@checkaftersec@resa\else
    \penalty10000\relax
    \skip\z@=\csname\gmu@prevsec @postskip\endcsname\relax
    \skip\tw@=\csname\mw@HeadingType @preskip\endcsname\relax
    \gmu@ifundefined{\mw@HeadingType @twoheadskip}{%
      \ifdim\skip\z@>\skip\tw@
      \vskip-\skip\z@% we strip off the post-skip of previous
      % header if it's bigger than current pre-skip
      \else
      \vskip-\skip\tw@% we strip off the current pre-skip otherwise
      \fi}{% But if the two-header-skip is defined, we put
      % \emph{it}
      \penalty10000
      \vskip-\skip\z@
      \penalty10000
      \vskip-\skip\tw@
      \penalty10000
      \vskip\csname\mw@HeadingType @twoheadskip\endcsname
      \relax}%
    \penalty10000
    \hrule height\z@\relax% to hide the last (un)skip before subsequent
    % \incs{addvspace}s. \ilrr
    \penalty10000
    \fi
    \fi
  }% of |\gmu@ifundefined{gmu@prevsec}| `else'.
}% of |\def\gmu@checkaftersec|.

\def\ParanoidPostsec{% \label{gmu@postsec} this version of
  % \inverb|\ifgmu@postsec| is intended for the special case of
  % sections may contain no normal text, as while \pk{gmdoc}ing.
  \def\ifgmu@postsec{% note this macro expands to an open \cs{if}.
    \skip\z@=\csname\gmu@prevsec @postskip\endcsname\relax
    \ifdim\lastskip=\skip\z@\relax% we play
    % with the vskips only if the last skip is the previous
    % heading's postskip (a~counter-example I~met while
    % \pk{gmdoc}ing).
  }}

\let\ifgmu@postsec\iftrue

\def\gmu@getaddvs#1\addvspace#2\gmu@getaddvs{%
  \toks\z@={#1}%
  \toks\tw@={#2}}

\def\gmu@setheading#1{%
  \@xa\gmu@getaddvs#1\gmu@getaddvs
  \edef#1{%
    \the\toks\z@\@nx\gmu@checkaftersec
    \@nx\addvspace\the\toks\tw@}}

\gmu@setheading\mw@normalheading
\gmu@setheading\mw@runinheading

\def\SetTwoheadSkip#1#2{\@namedef{#1@twoheadskip}{#2}}

}% of |\@ifnotmw|'s else.


\@ifnotmw{}{% We define this declaration only when in \pk{mwcls}.
\DeclareCommand\WPheadings{T{\chapter}}{%
  \SetSectionFormatting[breakbefore,wholewidth]
      {part}{\z@\@plus1fill}{}{\z@\@plus3fill}%
  %
  \gmuIfValueF{#1}{%
    \gmu@ifundefined{chapter}{}{%
      \SetSectionFormatting[breakbefore,wholewidth]
      {chapter}
      {66\p@}% |{67\p@}|% for Adventor/Schola 0,95.
      {\FormatHangHeading{\LARGE}}
      {27\p@\@plus0,2\p@\@minus1\p@}%
    }%
  }% of unless |#1|
  %
  \SetTwoheadSkip{section}{27\p@\@plus0,5\p@}%
  \SetSectionFormatting{section}
      {24\p@\@plus0,5\p@\@minus5\p@}%  ^^A {24\p@\@plus5\p@\@minus2\p@}
      {\FormatHangHeading {\Large}}
      {10\p@\@plus0,5\p@}% ed.\ Krajewska of ``Wiedza Powszechna'', as
      % we understand her, wants the skip between a~heading and text
      % to be rigid.
  %
  \SetTwoheadSkip{subsection}{11\p@\@plus0,5\p@\@minus1\p@}%
  \SetSectionFormatting{subsection}
      {19\p@\@plus0,4\p@\@minus6\p@}
      {\FormatHangHeading {\large}}% 12/14 pt
      {6\p@\@plus0,3\p@}% after-skip 6\,pt due to p.12, not to squeeze
      % the before-skip too much.
  %
  \SetTwoheadSkip{subsubsection}{10\p@\@plus1,75\p@\@minus1\p@}%
  \SetSectionFormatting{subsubsection}
      {10\p@\@plus0,2\p@\@minus1\p@}
      {\FormatHangHeading {\normalsize}}
      {3\p@\@plus0,1\p@}% those little skips should be smaller than
      % you calculate out of a~geometric progression, because the
      % interline skip enlarges them.
  %
  \SetSectionFormatting[runin]{paragraph}
      {7\p@\@plus0,15\p@\@minus1\p@}
      {\FormatRunInHeading{\normalsize}}
      {2\p@}%
  %
  \SetSectionFormatting[runin]{subparagraph}
      {4\p@\@plus1\p@\@minus0,5\p@}
      {\FormatRunInHeading{\normalsize}}
      {\z@}%
}% of |\WPheadings|
}% of |\@ifnotmw|

\@ifnotmw{% we are not in \pk{mwcls} and want to
  % handle \pk{mwcls}-like sectionings i.e., those written with two
  % optionals.
  \def\gmu@secini{gm@la}%
  \Store@Macros{%
    \partmark \chaptermark \sectionmark \subsectionmark
    \subsubsectionmark \paragraphmark}%
  % \Define\gmu@secxx
  \def\gmu@secxx#1#2[#3]#4{%
    \ifx\gmu@secstar\@empty
    % \nostanza a~tiny little trick to allow
      % a~special version of the heading just to the running head.
      \@namedef{#1mark}##1{% we redefine \cs{\<sec>mark} to gobble its
        % argument and to launch the stored true marking command on the
        % appropriate argument.
        \storedcsname{#1mark}{#2}%
        \Restore@MacroSt{#1mark}% after we've done what we
        % wanted we restore original |\#1mark|.\ilrr
      }%
      \def\gmu@secstar{[#3]}% if |\gmu@secstar|
    % is empty, which means the sectioning command was written
    % starless, we pass the `true' sectioning command |#3| as the
    % optional argument. Otherwise the sectioning command was written
    % with star so the `true' s.c.\ takes no optional.
    \fi
    \@xa\@xa\csname\gmu@secini#1\endcsname
    \gmu@secstar{#4}}%
}{% we are in \pk{mwcls} and want to reverse MW's optionals order
  % i.e., if there's just one optional, it should go both to toc and to
  % running head.
  \def\gmu@secini{gm@mw}%
  %
  \let\gmu@secmarkh\@gobble% in \pk{mwcls} there's no need to make
  % tricks for special version to running headings.
  % \Define\gmu@secxx
  \def\gmu@secxx#1#2[#3]#4{%
    \@xa\@xa\csname\gmu@secini#1\endcsname
    \gmu@secstar[#2][#3]{#4}}%
}

\def\gmu@sec#1{\@dblarg{\gmu@secx{#1}}}
\def\gmu@secx#1[#2]{%
  \@ifnextchar[{\gmu@secxx{#1}{#2}}{\gmu@secxx{#1}{#2}[#2]}}% if

\def\gmu@straightensec#1{% the parameter is for the command's name.
  \gmu@ifundefined{#1}{}{% we don't change the ontological status of the
    % command because someone may test it.
    \n@melet{\gmu@secini#1}{#1}%
    \@namedef{#1}{%
      \gmu@ifstar{\def\gmu@secstar{*}\gmu@sec{#1}}{%
        \def\gmu@secstar{}\gmu@sec{#1}}}}%
}%

\let\do\gmu@straightensec
\do{part}\do{chapter}\do{section}\do{subsection}\do{subsubsection}
\@ifnotmw{}{\do{paragraph}}% this `straightening' of

\endinput
%%
%% End of file `gmmw.sty'.