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