]> mj.ucw.cz Git - ucwmac.git/blob - ucwmac.tex
A6, A7 dropped from ucwmac, please use ucw-paper
[ucwmac.git] / ucwmac.tex
1 % The UCW Macro Collection (a successor of mjmac.tex)
2 % Written by Martin Mares <mj@ucw.cz> in 2010 and placed into public domain
3 % -------------------------------------------------------------------------
4
5 %%% Prolog %%%
6
7 % We'll use internal macros of plain TeX
8 \catcode`@=11
9
10 %%% PDF output detection %%%
11
12 \newif\ifpdf
13 \pdffalse
14
15 \ifx\pdfoutput\undefined
16 \else\ifnum\pdfoutput>0
17         \pdftrue
18 \fi\fi
19
20 %%% Page size and margins %%%
21
22 % If you modify these registers, call \setuppage afterwards
23 \newdimen\pagewidth
24 \newdimen\pageheight
25 \newdimen\leftmargin
26 \newdimen\rightmargin
27 \newdimen\topmargin
28 \newdimen\bottommargin
29 \newdimen\evenpageshift
30
31 \def\setuppage{%
32         \hsize=\pagewidth
33         \advance\hsize by -\leftmargin
34         \advance\hsize by -\rightmargin
35         \vsize=\pageheight
36         \advance\vsize by -\topmargin
37         \advance\vsize by -\bottommargin
38         \hoffset=\leftmargin
39         \advance\hoffset by -1truein
40         \voffset=\topmargin
41         \advance\voffset by -1truein
42         \ifpdf
43                 \pdfpagewidth=\pagewidth
44                 \pdfpageheight=\pageheight
45         \fi
46 }
47
48 % Set multiple margins to the same value
49 \def\sethmargins#1{\leftmargin=#1\relax\rightmargin=#1\relax\evenpageshift=0pt\relax}
50 \def\setvmargins#1{\topmargin=#1\relax\bottommargin=#1\relax}
51 \def\setmargins#1{\sethmargins{#1}\setvmargins{#1}}
52
53 % Define inner/outer margin instead of left/right
54 \def\setinneroutermargin#1#2{\leftmargin#1\relax\rightmargin#2\relax\evenpageshift=\rightmargin\advance\evenpageshift by -\leftmargin}
55
56 % Use a predefined paper format, calls \setuppage automagically
57 \def\setpaper#1{%
58         \expandafter\let\expandafter\currentpaper\csname paper-#1\endcsname
59         \ifx\currentpaper\relax
60                 \errmessage{Undefined paper format #1}
61         \fi
62         \currentpaper
63 }
64
65 % Switch to landscape orientation, calls \setuppage automagically
66 \def\landscape{%
67         \dimen0=\pageheight
68         \pageheight=\pagewidth
69         \pagewidth=\dimen0
70         \setuppage
71 }
72
73 % Common paper sizes
74 \def\defpaper#1#2#3{\expandafter\def\csname paper-#1\endcsname{\pagewidth=#2\pageheight=#3\setuppage}}
75 \defpaper{a3}{297truemm}{420truemm}
76 \defpaper{a4}{210truemm}{297truemm}
77 \defpaper{a5}{148truemm}{210truemm}
78 \defpaper{letter}{8.5truein}{11truein}
79 \defpaper{legal}{8.5truein}{14truein}
80
81 % Default page parameters
82 \setmargins{1truein}
83 \setpaper{a4}
84
85 %%% Placing material at specified coordinates %%%
86
87 % Set all dimensions of a given box register to zero
88 \def\smashbox#1{\ht#1=0pt \dp#1=0pt \wd#1=0pt}
89 \def\smashedhbox#1{{\setbox0=\hbox{#1}\smashbox0\box0}}
90 \def\smashedvbox#1{{\setbox0=\vbox{#1}\smashbox0\box0}}
91
92 % Variants of \llap and \rlap working equally on both sides and/or vertically
93 \def\hlap#1{\hbox to 0pt{\hss #1\hss}}
94 \def\vlap#1{\vbox to 0pt{\vss #1\vss}}
95 \def\clap#1{\vlap{\hlap{#1}}}
96
97 % \placeat{right}{down}{hmaterial} places <hmaterial>, so that its
98 % reference point lies at the given position wrt. the current ref point
99 \long\def\placeat#1#2#3{\smashedhbox{\hskip #1\lower #2\hbox{#3}}}
100
101 % Like \vbox, but with reference point in the upper left corner
102 \def\vhang#1{\vtop{\hrule height 0pt\relax #1}}
103
104 % Like \vhang, but respecting interline skips
105 \def\vhanglines#1{\vtop{\hbox to 0pt{}#1}}
106
107 % Crosshair with reference point in its center
108 \def\crosshair#1{\clap{\vrule height 0.2pt width #1}\clap{\vrule height #1 width 0.2pt}}
109
110 %%% Output routine %%%
111
112 \newbox\pageunderlays
113 \newbox\pageoverlays
114 \newbox\commonunderlays
115 \newbox\commonoverlays
116
117 % In addition to the normal page contents, you can define page overlays
118 % and underlays, which are zero-size vboxes positioned absolutely in the
119 % front / in the back of the normal material. Also, there are global
120 % versions of both which are not reset after every page.
121 \def\addlay#1#2{\setbox#1=\vbox{\ifvbox#1\box#1\fi\smashedvbox{#2}}}
122 \def\pageunderlay{\addlay\pageunderlays}
123 \def\pageoverlay{\addlay\pageoverlays}
124 \def\commonunderlay{\addlay\commonoverlays}
125 \def\commonoverlay{\addlay\commonoverlays}
126
127 % Our variation on \plainoutput, which manages inner/outer margins and overlays
128 \output{\ucwoutput}
129 \def\ucwoutput{\wigglepage\shipout\vbox{%
130         \makeheadline
131         \ifvbox\commonunderlays\copy\commonunderlays\nointerlineskip\fi
132         \ifvbox\pageunderlays\box\pageunderlays\nointerlineskip\fi
133         \pagebody
134         \ifvbox\commonoverlays\vbox to 0pt{\vskip -\vsize\copy\commonoverlays}\fi
135         \ifvbox\pageoverlays\vbox to 0pt{\vskip -\vsize\box\pageoverlays}\fi
136         \makefootline
137 }\advancepageno
138 \ifnum\outputpenalty>-\@MM \else\dosupereject\fi}
139
140 \def\wigglepage{\ifodd\pageno\else\advance\hoffset by \evenpageshift\fi}
141
142 % Make it easier to redefine footline font (also, fix it so that OFS won't change it unless asked)
143 \let\footfont=\tenrm
144 \footline={\hss\footfont\folio\hss}
145
146 %%% Itemization %%%
147
148 % Default dimensions of itemized lists
149 \newdimen\itemindent            \itemindent=0.5in
150 \newdimen\itemnarrow            \itemnarrow=0.5in                       % make lines narrower by this amount
151 \newskip\itemmarkerskip         \itemmarkerskip=0.4em                   % between marker and the item
152 \newskip\preitemizeskip         \preitemizeskip=3pt plus 2pt minus 1pt  % before the list
153 \newskip\postitemizeskip        \postitemizeskip=3pt plus 2pt minus 1pt % after the list
154 \newskip\interitemskip          \interitemskip=2pt plus 1pt minus 0.5pt % between two items
155
156 % Analogues for nested lists
157 \newdimen\nesteditemindent      \nesteditemindent=0.25in
158 \newdimen\nesteditemnarrow      \nesteditemnarrow=0.25in
159 \newskip\prenesteditemizeskip   \prenesteditemizeskip=0pt
160 \newskip\postnesteditemizeskip  \postnesteditemizeskip=0pt
161
162 \newif\ifitems\itemsfalse
163 \newbox\itembox
164 \newcount\itemcount
165
166 \def\preitemize{
167         \ifitems
168                 \vskip\prenesteditemizeskip
169                 \advance\leftskip by \nesteditemindent
170                 \advance\rightskip by \nesteditemnarrow
171         \else
172                 \vskip\preitemizeskip
173                 \advance\leftskip by \itemindent
174                 \advance\rightskip by \itemnarrow
175         \fi
176         \parskip=\interitemskip
177 }
178
179 \def\postitemize{
180         \ifitems
181                 \vskip\postnesteditemizeskip
182         \else
183                 \vskip\postitemizeskip
184         \fi
185 }
186
187 \def\inititemize{\begingroup\preitemize\itemstrue\parindent=0pt}
188
189 \def\itemize#1{\inititemize\setbox\itembox\llap{#1\hskip\itemmarkerskip}%
190 \let\:=\singleitem}
191
192 \def\singleitem{\par\leavevmode\copy\itembox\ignorespaces}
193
194 \def\endlist{\par\endgroup\postitemize}
195
196 \def\ibull{\raise0.2ex\hbox{$\bullet$}} % Signs frequently used for \itemize
197 \def\idot{\raise0.2ex\hbox{$\cdot$}}
198 \def\istar{\raise0.2ex\hbox{$\ast$}}
199
200 \def\numlist#1{\inititemize\itemcount=0\let\:=\numbereditem
201 \let\itemnumbering=#1}
202
203 \def\numbereditem{\par\leavevmode\advance\itemcount by 1
204 \llap{\itemnumbering\hskip\itemmarkerskip}\ignorespaces}
205
206 \def\nnorm{\the\itemcount}
207 \def\ndotted{\nnorm.}
208 \def\nparen{\nnorm)}
209 \def\nroman{\romannumeral\itemcount}
210 \def\nromanp{\nroman)}
211 \def\nalpha{\count@=96\advance\count@ by\itemcount\char\count@)}
212 \def\nAlpha{\count@=64\advance\count@ by\itemcount\char\count@)}
213 \def\ngreek{$\ifcase\itemcount\or\alpha\or\beta\or\gamma\or\delta\or\epsilon\or
214 \zeta\or\eta\or\theta\or\iota\or\kappa\or\lambda\or\mu\or\nu\or\xi\or\pi\or\rho
215 \or\sigma\or\tau\or\upsilon\or\phi\or\chi\or\psi\or\omega\fi$)}
216
217 %%% Miscellanea %%%
218
219 % {\I italic} with automatic italic correction
220 \def\I{\it\aftergroup\/}
221
222 % A breakable dash, to be repeated on the next line
223 \def\={\discretionary{-}{-}{-}}
224
225 % Non-breakable identifiers
226 \def\<#1>{\leavevmode\hbox{\I #1}}
227
228 % A handy shortcut
229 \let\>=\noindent
230
231 % Variants of \centerline, \leftline and \rightline, which are compatible with
232 % verbatim environments and other catcode hacks
233 \def\cline{\bgroup\def\linet@mp{\aftergroup\box\aftergroup0\aftergroup\egroup\hss\bgroup\aftergroup\hss\aftergroup\egroup}\afterassignment\linet@mp\setbox0\hbox to \hsize}
234 \def\lline{\bgroup\def\linet@mp{\aftergroup\box\aftergroup0\aftergroup\egroup\bgroup\aftergroup\hss\aftergroup\egroup}\afterassignment\linet@mp\setbox0\hbox to \hsize}
235 \def\rline{\bgroup\def\linet@mp{\aftergroup\box\aftergroup0\aftergroup\egroup\hss\bgroup\aftergroup\egroup}\afterassignment\linet@mp\setbox0\hbox to \hsize}
236
237 %%% Epilog %%%
238
239 % Let's hide all internal macros
240 \catcode`@=12