1 % The UCW Macro Collection (a successor of mjmac.tex)
2 % Written by Martin Mares <mj@ucw.cz> in 2010--2018 and placed into public domain
3 % -------------------------------------------------------------------------------
7 % We'll use internal macros of plain TeX
10 \ifx\eTeXversion\undefined
11 \errmessage{ucwmac requires the e-TeX engine or its successor}
14 %%% PDF output detection %%%
19 \ifx\pdfoutput\undefined
20 \else\ifnum\pdfoutput>0
22 \pdfpkresolution=600 % Provide a reasonable default
25 %%% Page size and margins %%%
27 % If you modify these registers, call \setuppage afterwards
28 \ifx\luatexversion\undefined
29 % In LuaTeX, \pagewidth and \pageheight are primitive
36 \newdimen\bottommargin
37 \newdimen\evenpageshift
41 \advance\hsize by -\leftmargin
42 \advance\hsize by -\rightmargin
44 \advance\vsize by -\topmargin
45 \advance\vsize by -\bottommargin
47 \advance\hoffset by -1truein
49 \advance\voffset by -1truein
53 \ifx\luatexversion\undefined
54 \pdfpagewidth=\pagewidth
55 \pdfpageheight=\pageheight
60 % Set multiple margins to the same value
61 \def\sethmargins#1{\leftmargin=#1\relax\rightmargin=#1\relax\evenpageshift=0pt\relax}
62 \def\setvmargins#1{\topmargin=#1\relax\bottommargin=#1\relax}
63 \def\setmargins#1{\sethmargins{#1}\setvmargins{#1}}
65 % Define inner/outer margin instead of left/right
66 \def\setinneroutermargin#1#2{\leftmargin#1\relax\rightmargin#2\relax\evenpageshift=\rightmargin\advance\evenpageshift by -\leftmargin}
68 % Use a predefined paper format, calls \setuppage automagically
70 \expandafter\let\expandafter\currentpaper\csname paper-#1\endcsname
71 \ifx\currentpaper\relax
72 \errmessage{Undefined paper format #1}
77 % Switch to landscape orientation, calls \setuppage automagically
80 \pageheight=\pagewidth
86 \def\defpaper#1#2#3{\expandafter\def\csname paper-#1\endcsname{\pagewidth=#2\pageheight=#3\setuppage}}
87 \defpaper{a3}{297truemm}{420truemm}
88 \defpaper{a4}{210truemm}{297truemm}
89 \defpaper{a5}{148truemm}{210truemm}
90 \defpaper{letter}{8.5truein}{11truein}
91 \defpaper{legal}{8.5truein}{14truein}
93 % Default page parameters
97 %%% Placing material at specified coordinates %%%
99 % Set all dimensions of a given box register to zero
100 \def\smashbox#1{\ht#1=0pt \dp#1=0pt \wd#1=0pt}
101 \long\def\smashedhbox#1{{\setbox0=\hbox{#1}\smashbox0\box0}}
102 \long\def\smashedvbox#1{{\setbox0=\vbox{#1}\smashbox0\box0}}
104 % Variants of \llap and \rlap working equally on both sides and/or vertically
105 \def\hlap#1{\hbox to 0pt{\hss #1\hss}}
106 \def\vlap#1{\vbox to 0pt{\vss #1\vss}}
107 \def\clap#1{\vlap{\hlap{#1}}}
109 % \placeat{right}{down}{hmaterial} places <hmaterial>, so that its
110 % reference point lies at the given position wrt. the current ref point
111 \long\def\placeat#1#2#3{\smashedhbox{\hskip #1\lower #2\hbox{#3}}}
113 % Like \vbox, but with reference point in the upper left corner
114 \long\def\vhang#1{\vtop{\hrule height 0pt\relax #1}}
116 % Like \vhang, but respecting interline skips
117 \long\def\vhanglines#1{\vtop{\hbox to 0pt{}#1}}
119 % Crosshair with reference point in its center
120 \def\crosshair#1{\clap{\vrule height 0.2pt width #1}\clap{\vrule height #1 width 0.2pt}}
122 %%% Output routine %%%
124 \newbox\pageunderlays
126 \newbox\commonunderlays
127 \newbox\commonoverlays
129 % In addition to the normal page contents, you can define page overlays
130 % and underlays, which are zero-size vboxes positioned absolutely in the
131 % front / in the back of the normal material. Also, there are global
132 % versions of both which are not reset after every page.
133 \def\addlay#1#2{\setbox#1=\vbox{\ifvbox#1\box#1\fi\nointerlineskip\smashedvbox{#2}}}
134 \def\pageunderlay{\addlay\pageunderlays}
135 \def\pageoverlay{\addlay\pageoverlays}
136 \def\commonunderlay{\addlay\commonoverlays}
137 \def\commonoverlay{\addlay\commonoverlays}
139 % Our variation on \plainoutput, which manages inner/outer margins and overlays
141 \newdimen\pagebodydepth
142 \def\ucwoutput{\wigglepage\shipout\vbox{%
144 \ifvbox\commonunderlays\copy\commonunderlays\nointerlineskip\fi
145 \ifvbox\pageunderlays\box\pageunderlays\nointerlineskip\fi
147 \pagebodydepth=\prevdepth
149 \ifvbox\commonoverlays\vbox to 0pt{\vskip -\vsize\copy\commonoverlays\vss}\nointerlineskip\fi
150 \ifvbox\pageoverlays\vbox to 0pt{\vskip -\vsize\box\pageoverlays\vss}\nointerlineskip\fi
151 \prevdepth=\pagebodydepth
154 \ifnum\outputpenalty>-\@MM \else\dosupereject\fi}
156 \def\wigglepage{\ifodd\pageno\else\advance\hoffset by \evenpageshift\fi}
158 % Make it easier to redefine footline font (also, fix it so that OFS won't change it unless asked)
160 \footline={\hss\footfont\folio\hss}
164 % Default dimensions of itemized lists
165 \newdimen\itemindent \itemindent=0.5in
166 \newdimen\itemnarrow \itemnarrow=0.5in % make lines narrower by this amount
167 \newskip\itemmarkerskip \itemmarkerskip=0.4em % between marker and the item
168 \newskip\preitemizeskip \preitemizeskip=3pt plus 2pt minus 1pt % before the list
169 \newskip\postitemizeskip \postitemizeskip=3pt plus 2pt minus 1pt % after the list
170 \newskip\interitemskip \interitemskip=2pt plus 1pt minus 0.5pt % between two items
172 % Analogues for nested lists
173 \newdimen\nesteditemindent \nesteditemindent=0.25in
174 \newdimen\nesteditemnarrow \nesteditemnarrow=0.25in
175 \newskip\prenesteditemizeskip \prenesteditemizeskip=0pt
176 \newskip\postnesteditemizeskip \postnesteditemizeskip=0pt
178 \newif\ifitems\itemsfalse
184 \vskip\prenesteditemizeskip
185 \advance\leftskip by \nesteditemindent
186 \advance\rightskip by \nesteditemnarrow
188 \vskip\preitemizeskip
189 \advance\leftskip by \itemindent
190 \advance\rightskip by \itemnarrow
192 \parskip=\interitemskip
197 \vskip\postnesteditemizeskip
199 \vskip\postitemizeskip
203 \def\inititemize{\begingroup\preitemize\itemstrue\parindent=0pt}
205 \def\itemize#1{\inititemize\setbox\itembox\llap{#1\hskip\itemmarkerskip}%
208 \def\singleitem{\par\leavevmode\copy\itembox\ignorespaces}
210 \def\endlist{\par\endgroup\postitemize}
212 \def\ibull{\raise0.2ex\hbox{$\bullet$}} % Signs frequently used for \itemize
213 \def\idot{\raise0.2ex\hbox{$\cdot$}}
214 \def\istar{\raise0.2ex\hbox{$\ast$}}
216 \def\numlist#1{\inititemize\itemcount=0\let\:=\numbereditem
217 \let\itemnumbering=#1}
219 \def\numbereditem{\par\leavevmode\advance\itemcount by 1
220 \llap{\itemnumbering\hskip\itemmarkerskip}\ignorespaces}
222 \def\nnorm{\the\itemcount}
223 \def\ndotted{\nnorm.}
225 \def\nparenp{(\nnorm)}
226 \def\nroman{\romannumeral\itemcount}
227 \def\nromanp{\nroman)}
228 \def\nalpha{\count@=96\advance\count@ by\itemcount\char\count@)}
229 \def\nAlpha{\count@=64\advance\count@ by\itemcount\char\count@)}
230 \def\ngreek{$\ifcase\itemcount\or\alpha\or\beta\or\gamma\or\delta\or\epsilon\or
231 \zeta\or\eta\or\theta\or\iota\or\kappa\or\lambda\or\mu\or\nu\or\xi\or\pi\or\rho
232 \or\sigma\or\tau\or\upsilon\or\phi\or\chi\or\psi\or\omega\fi$)}
236 % {\I italic} with automatic italic correction
237 \def\I{\it\aftergroup\/}
239 % A breakable dash, to be repeated on the next line
240 \def\={\discretionary{-}{-}{-}}
242 % Non-breakable identifiers
243 \def\<#1>{\leavevmode\hbox{\I #1}}
248 % Variants of \centerline, \leftline and \rightline, which are compatible with
249 % verbatim environments and other catcode hacks
250 \def\cline{\bgroup\def\linet@mp{\aftergroup\box\aftergroup0\aftergroup\egroup\hss\bgroup\aftergroup\hss\aftergroup\egroup}\afterassignment\linet@mp\setbox0\hbox to \hsize}
251 \def\lline{\bgroup\def\linet@mp{\aftergroup\box\aftergroup0\aftergroup\egroup\bgroup\aftergroup\hss\aftergroup\egroup}\afterassignment\linet@mp\setbox0\hbox to \hsize}
252 \def\rline{\bgroup\def\linet@mp{\aftergroup\box\aftergroup0\aftergroup\egroup\hss\bgroup\aftergroup\egroup}\afterassignment\linet@mp\setbox0\hbox to \hsize}
256 % Let's hide all internal macros