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 % -------------------------------------------------------------------------------
7 % We'll use internal macros of plain TeX
10 %%% PDF output detection %%%
15 \ifx\pdfoutput\undefined
16 \else\ifnum\pdfoutput>0
18 \pdfpkresolution=600 % Provide a reasonable default
21 %%% Page size and margins %%%
23 % If you modify these registers, call \setuppage afterwards
29 \newdimen\bottommargin
30 \newdimen\evenpageshift
34 \advance\hsize by -\leftmargin
35 \advance\hsize by -\rightmargin
37 \advance\vsize by -\topmargin
38 \advance\vsize by -\bottommargin
40 \advance\hoffset by -1truein
42 \advance\voffset by -1truein
46 \pdfpagewidth=\pagewidth
47 \pdfpageheight=\pageheight
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}}
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}
59 % Use a predefined paper format, calls \setuppage automagically
61 \expandafter\let\expandafter\currentpaper\csname paper-#1\endcsname
62 \ifx\currentpaper\relax
63 \errmessage{Undefined paper format #1}
68 % Switch to landscape orientation, calls \setuppage automagically
71 \pageheight=\pagewidth
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}
84 % Default page parameters
88 %%% Placing material at specified coordinates %%%
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}}
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}}}
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}}}
104 % Like \vbox, but with reference point in the upper left corner
105 \long\def\vhang#1{\vtop{\hrule height 0pt\relax #1}}
107 % Like \vhang, but respecting interline skips
108 \long\def\vhanglines#1{\vtop{\hbox to 0pt{}#1}}
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}}
113 %%% Output routine %%%
115 \newbox\pageunderlays
117 \newbox\commonunderlays
118 \newbox\commonoverlays
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}
130 % Our variation on \plainoutput, which manages inner/outer margins and overlays
132 \newdimen\pagebodydepth
133 \def\ucwoutput{\wigglepage\shipout\vbox{%
135 \ifvbox\commonunderlays\copy\commonunderlays\nointerlineskip\fi
136 \ifvbox\pageunderlays\box\pageunderlays\nointerlineskip\fi
138 \pagebodydepth=\prevdepth
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
145 \ifnum\outputpenalty>-\@MM \else\dosupereject\fi}
147 \def\wigglepage{\ifodd\pageno\else\advance\hoffset by \evenpageshift\fi}
149 % Make it easier to redefine footline font (also, fix it so that OFS won't change it unless asked)
151 \footline={\hss\footfont\folio\hss}
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
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
169 \newif\ifitems\itemsfalse
175 \vskip\prenesteditemizeskip
176 \advance\leftskip by \nesteditemindent
177 \advance\rightskip by \nesteditemnarrow
179 \vskip\preitemizeskip
180 \advance\leftskip by \itemindent
181 \advance\rightskip by \itemnarrow
183 \parskip=\interitemskip
188 \vskip\postnesteditemizeskip
190 \vskip\postitemizeskip
194 \def\inititemize{\begingroup\preitemize\itemstrue\parindent=0pt}
196 \def\itemize#1{\inititemize\setbox\itembox\llap{#1\hskip\itemmarkerskip}%
199 \def\singleitem{\par\leavevmode\copy\itembox\ignorespaces}
201 \def\endlist{\par\endgroup\postitemize}
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$}}
207 \def\numlist#1{\inititemize\itemcount=0\let\:=\numbereditem
208 \let\itemnumbering=#1}
210 \def\numbereditem{\par\leavevmode\advance\itemcount by 1
211 \llap{\itemnumbering\hskip\itemmarkerskip}\ignorespaces}
213 \def\nnorm{\the\itemcount}
214 \def\ndotted{\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$)}
226 % {\I italic} with automatic italic correction
227 \def\I{\it\aftergroup\/}
229 % A breakable dash, to be repeated on the next line
230 \def\={\discretionary{-}{-}{-}}
232 % Non-breakable identifiers
233 \def\<#1>{\leavevmode\hbox{\I #1}}
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}
246 % Let's hide all internal macros