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 % -------------------------------------------------------------------------
7 % We'll use internal macros of plain TeX
10 %%% PDF output detection %%%
15 \ifx\pdfoutput\undefined
16 \else\ifnum\pdfoutput>0
20 %%% Page size and margins %%%
22 % If you modify these registers, call \setuppage afterwards
28 \newdimen\bottommargin
29 \newdimen\evenpageshift
33 \advance\hsize by -\leftmargin
34 \advance\hsize by -\rightmargin
36 \advance\vsize by -\topmargin
37 \advance\vsize by -\bottommargin
39 \advance\hoffset by -1truein
41 \advance\voffset by -1truein
43 \pdfpagewidth=\pagewidth
44 \pdfpageheight=\pageheight
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}}
53 % Define inner/outer margin instead of left/right
54 \def\setinneroutermargin#1#2{\sethmargins{#1}{#2}\evenpageshift=\rightmargin\advance\evenpageshift by -\leftmargin}
56 % Use a predefined paper format, calls \setuppage automagically
58 \expandafter\let\expandafter\currentpaper\csname paper-#1\endcsname
59 \ifx\currentpaper\relax
60 \errmessage{Undefined paper format #1}
65 % Switch to landscape orientation, calls \setuppage automagically
68 \pageheight=\pagewidth
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{a6}{105truemm}{148truemm}
79 \defpaper{letter}{8.5truein}{11truein}
80 \defpaper{legal}{8.5truein}{14truein}
82 % Default page parameters
86 %%% Placing material at specified coordinates %%%
88 % Set all dimensions of a given box register to zero
89 \def\smashbox#1{\ht#1=0pt \dp#1=0pt \wd#1=0pt}
90 \def\smashedhbox#1{{\setbox0=\hbox{#1}\smashbox0\box0}}
91 \def\smashedvbox#1{{\setbox0=\vbox{#1}\smashbox0\box0}}
93 % Variants of \llap and \rlap working equally on both sides and/or vertically
94 \def\hlap#1{\hbox to 0pt{\hss #1\hss}}
95 \def\vlap#1{\vbox to 0pt{\vss #1\vss}}
96 \def\clap#1{\vlap{\hlap{#1}}}
98 % \placeat{right}{down}{hmaterial} places <hmaterial>, so that its
99 % reference point lies at the given position wrt. the current ref point
100 \long\def\placeat#1#2#3{\smashedhbox{\hskip #1\lower #2\hbox{#3}}}
102 % Like \vbox, but with reference point in the upper left corner
103 \def\vhang#1{\vtop{\hrule height 0pt\relax #1}}
105 % Like \vhang, but respecting interline skips
106 \def\vhanglines#1{\vtop{\hbox to 0pt{}#1}}
108 % Crosshair with reference point in its center
109 \def\crosshair#1{\clap{\vrule height 0.2pt width #1}\clap{\vrule height #1 width 0.2pt}}
111 %%% Output routine %%%
113 \newbox\pageunderlays
115 \newbox\commonunderlays
116 \newbox\commonoverlays
118 % In addition to the normal page contents, you can define page overlays
119 % and underlays, which are zero-size vboxes positioned absolutely in the
120 % front / in the back of the normal material. Also, there are global
121 % versions of both which are not reset after every page.
122 \def\addlay#1#2{\setbox#1=\vbox{\ifvbox#1\box#1\fi\smashedvbox{#2}}}
123 \def\pageunderlay{\addlay\pageunderlays}
124 \def\pageoverlay{\addlay\pageoverlays}
125 \def\commonunderlay{\addlay\commonoverlays}
126 \def\commonoverlay{\addlay\commonoverlays}
128 % Our variation on \plainoutput, which manages inner/outer margins and overlays
130 \def\ucwoutput{\wigglepage\shipout\vbox{%
132 \ifvbox\commonunderlays\copy\commonunderlays\nointerlineskip\fi
133 \ifvbox\pageunderlays\box\pageunderlays\nointerlineskip\fi
135 \ifvbox\commonoverlays\vbox to 0pt{\vskip -\vsize\copy\commonoverlays}\fi
136 \ifvbox\pageoverlays\vbox to 0pt{\vskip -\vsize\box\pageoverlays}\fi
139 \ifnum\outputpenalty>-\@MM \else\dosupereject\fi}
141 \def\wigglepage{\ifodd\pageno\else\advance\hoffset by \evenpageshift\fi}
145 % Default dimensions of itemized lists
146 \newdimen\itemindent \itemindent=0.5in
147 \newdimen\itemnarrow \itemnarrow=0.5in % make lines narrower by this amount
148 \newskip\itemmarkerskip \itemmarkerskip=0.4em % between marker and the item
149 \newskip\preitemizeskip \preitemizeskip=3pt plus 2pt minus 1pt % before the list
150 \newskip\postitemizeskip \postitemizeskip=3pt plus 2pt minus 1pt % after the list
151 \newskip\interitemskip \interitemskip=2pt plus 1pt minus 0.5pt % between two items
153 % Analogues for nested lists
154 \newdimen\nesteditemindent \nesteditemindent=0.25in
155 \newdimen\nesteditemnarrow \nesteditemnarrow=0.25in
156 \newskip\prenesteditemizeskip \prenesteditemizeskip=0pt
157 \newskip\postnesteditemizeskip \postnesteditemizeskip=0pt
159 \newif\ifitems\itemsfalse
165 \vskip\prenesteditemizeskip
166 \advance\leftskip by \nesteditemindent
167 \advance\rightskip by \nesteditemnarrow
169 \vskip\preitemizeskip
170 \advance\leftskip by \itemindent
171 \advance\rightskip by \itemnarrow
173 \parskip=\interitemskip
178 \vskip\postnesteditemizeskip
180 \vskip\postitemizeskip
184 \def\inititemize{\begingroup\preitemize\itemstrue\parindent=0pt}
186 \def\itemize#1{\inititemize\setbox\itembox\llap{#1\hskip\itemmarkerskip}%
189 \def\singleitem{\par\leavevmode\copy\itembox\ignorespaces}
191 \def\endlist{\par\endgroup\postitemize}
193 \def\ibull{\raise0.2ex\hbox{$\bullet$}} % Signs frequently used for \itemize
194 \def\idot{\raise0.2ex\hbox{$\cdot$}}
195 \def\istar{\raise0.2ex\hbox{$\ast$}}
197 \def\numlist#1{\inititemize\itemcount=0\let\:=\numbereditem
198 \let\itemnumbering=#1}
200 \def\numbereditem{\par\leavevmode\advance\itemcount by 1
201 \llap{\itemnumbering\hskip\itemmarkerskip}\ignorespaces}
203 \def\nnorm{\the\itemcount}
204 \def\ndotted{\nnorm.}
206 \def\nroman{\romannumeral\itemcount}
207 \def\nromanp{\nroman)}
208 \def\nalpha{\count@=96\advance\count@ by\itemcount\char\count@)}
209 \def\nAlpha{\count@=64\advance\count@ by\itemcount\char\count@)}
210 \def\ngreek{$\ifcase\itemcount\or\alpha\or\beta\or\gamma\or\delta\or\epsilon\or
211 \zeta\or\eta\or\theta\or\iota\or\kappa\or\lambda\or\mu\or\nu\or\xi\or\pi\or\rho
212 \or\sigma\or\tau\or\upsilon\or\phi\or\chi\or\psi\or\omega\fi$)}
214 %%% Verbatim typesetting %%%
216 % New \frenchspacing, which doesn't leave unwanted spaces in text.
217 \def\frenchsp@cing{\sfcode`\.\@m \sfcode`\?\@m \sfcode`\!\@m%
218 \sfcode`\:\@m \sfcode`\;\@m \sfcode`\,\@m}
220 % Typesetting of one verbatim word
225 \def\make@ther#1{\catcode`#1=12\relax}
226 \def\setverb@tim{\tt\frenchsp@cing\catcode`\`=13\catcode`\'=13\n@ligs%
227 \let\do=\make@ther\dospecials\obeyspaces\showsp@ces}
231 \gdef\n@ligs{\def`{\relax\lq}\def'{\relax\rq}}}
234 \global\chardef\sp@ce=32
235 \gdef\showsp@ces{\ifshowspaces\let =\sp@ce\fi}
238 \catcode124=\active % Make | active
239 \def\ttst@rt{\begingroup\setverb@tim\let|=\endgroup}
242 % Typesetting of verbatim block (enclosed in balanced {}'s)
245 \newskip\verblineglue
246 \newskip\verbleftskip
247 \newskip\verbrightskip
249 \verbglue=3pt plus 1pt minus 0.3pt
250 \verblineglue=0pt plus 1.5pt
252 \verbrightskip=0pt plus 1fil
264 \ifdim\v@rbspace>0pt \vskip\v@rbspace \fi
265 \line{\hskip\verbleftskip \vrule\box0\vrule \hskip\verbrightskip}
268 \advance\v@rbspace by 0.3\baselineskip %FIXME
273 \def\v@rbend{\par\egroup\endgroup\vskip\verbglue}
274 \def\v@rbl{\ifnum\verbcnt>0\{\fi\global\advance\verbcnt by 1\relax}
275 \def\v@rbr{\ifnum\verbcnt>1\}\else\v@rbend\fi\global\advance\verbcnt by -1\relax}
277 \def\v@rbparams{\setverb@tim\raggedbottom
280 \catcode124=12\setupt@bs\vskip\verbglue\defb@x\obeylines}
282 \def\startb@x{\setbox0=\hbox\bgroup}
283 \def\defb@x{\def\par{\egroup\verbship\startb@x}}
285 {\catcode`\^^I=\active
286 \gdef\setupt@bs{\catcode`\^^I=\active
287 \setbox0=\hbox{\tt\ }\tabwidth=\wd0\multiply\tabwidth by \tabsize%FIXME!!!
288 \def^^I{\egroup\t@b=\wd0\divide\t@b by \tabwidth%
289 \multiply\t@b by \tabwidth%
290 \advance\t@b by \tabwidth\advance\t@b by -\wd0\startb@x\box0\hbox to \t@b{}}%
294 \catcode`[=1\catcode`]=2\catcode123=\active\catcode125=\active
295 \gdef\verbatim[\begingroup\v@rbparams\catcode123=\active\catcode125=\active%
296 \let{=\v@rbl\let}=\v@rbr\chardef\{=123\chardef\}=125\verblocaldefs\startb@x%
299 % Input file verbatim
301 \def\verbinput#1{\begingroup\v@rbparams\verblocaldefs\input #1\endgroup}
305 % Let's hide all internal macros