Debian Codegraph @

texmf-dist/tex/generic/ulem/ulem.sty

raw
1 %
2 % U L E M . S T Y [2019-11-18]
3 %
4 % The ulem package provides various types of underlining that can stretch
5 % between words and be broken across lines in LaTeX or plain TeX.
6 % In LaTeX ulem replaces italics with underlining in \em-phasized text.
7 % It is most suitable for simple text such as {\em ibid.} or \emph{\LaTeX:
8 % A Document Preparation System} that may need to be underlined in a
9 % manuscript submitted for publication. A declaration of \normalem (or
10 % the \usepackage option "normalem") restores the normal \em behavior.
11 %
12 % Full instructions appear in ulem.ltx (ulem.pdf). In summary:
13 %
14 % \uline{important} underlined text
15 % \uuline{urgent} double-underlined text
16 % \uwave{boat} wavy underline
17 % \sout{wrong} line drawn through word
18 % \xout{removed} marked over with //////.
19 % \dashuline{dashing} dash underline
20 % \dotuline{dotty} dotted underline
21 %
22 % {\em phasized\/} | In LaTeX, by default, these are underlined; use
23 % \emph{asized} | \normalem or [normalem] to restore italics
24 % \useunder{\uwave}{\bf}{\textbf}
25 % use wavy underline in place of bold face
26 % Use \markoverwith for defining new types of underlining.
27 %
28 % Copyright (c) 1989-2011 by Donald Arseneau (Vancouver, Canada; [email protected])
29 %
30 % This software may be freely transmitted, reproduced, or modified for any
31 % purpose provided that this copyright notice is left intact.
32 % (Small excerpts may be taken and used without any restriction.)
33 %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 % Defend against multiple loading.
36 \expandafter \ifx \csname UL@box\endcsname \relax \else
37 \immediate\write16{ulem.sty refuses to load twice. }\endinput \fi
38
39 % Set catcode of @ in case it isn't a "letter" already
40 \chardef\ULthickness\catcode\string`\@ % hold catcode temporarily
41 \catcode\string`\@=11
42
43 % \UL@protected = \protected, if available, else \relax
44
45 \begingroup
46 \global\expandafter\let\expandafter\UL@protected\csname protected\endcsname
47 \endgroup
48
49 \UL@protected\def\uline{\relax \ifmmode\expandafter\underline
50 \else \bgroup\expandafter\ULset\fi}
51
52 \newbox\UL@box
53 \newbox\UL@hyphenbox
54 \newskip\UL@skip
55 \newtoks\UL@hook
56 \newdimen\UL@height \UL@height=\maxdimen % flags being unused
57 \newcount\UL@pe
58
59 \UL@protected\def\UL@end *{\relax\relax}% something harmless but unique
60
61 % For regular underlines, set the depth based on the font, or retain
62 % the preset value, then start underlining.
63 \def\ULset{\UL@setULdepth
64 \def\UL@leadtype{\leaders \hrule \@height\UL@height \@depth\ULdepth}%
65 \ifmmode \ULdepth-4\p@ \fi
66 \UL@height-\ULdepth \advance\UL@height\ULthickness \ULon}
67
68 % Automatically set \ULdepth if it is to be automatic (flagged by \maxdimen)
69 \def\UL@setULdepth{\relax
70 \ifdim\ULdepth=\maxdimen % Set depth based on font, if not set already
71 \setbox\UL@box\hbox{{(j}}\ULdepth\dp\UL@box\advance\ULdepth.4\p@
72 % use setbox to support plain TeX
73 \fi}
74
75 % \ULon simply calls \UL@on (possibly \UL@on=\UL@onin) for text mode, but
76 % \UL@onmath if it is math mode.
77 \def\ULon{\ifmmode \expandafter\UL@onmath\else \expandafter\UL@on\fi}
78
79 % \UL@on sets the engine of underline running, and tells it
80 % where to stop. #1 = the relevant text.
81 \long\def\UL@on#1{\leavevmode\UL@ender \let\UL@on\UL@onin
82 \everymath{\UL@hrest}\everyvbox{\UL@hrest}\let\hskip\UL@hskip
83 \let\\\UL@cr \let\-\UL@dischyp \let\newline\UL@newline \let\ \UL@space
84 \def\hfil{\hskip\z@ plus1fil\relax}\def\hfill{\hskip\z@ plus1fill\relax}%
85 \def\hss{\hskip\z@ plus1filminus1fil\relax}\let\penalty\UL@penalty
86 \the\UL@hook
87 \UL@word\@empty#1\xdef\UL@spfactor{\the\spacefactor} \UL@end * }
88
89 % This is what \ULon does when it appears nested in an inner place.
90 \long\def\UL@onin#1{\leavevmode\UL@ender % when nested, do multiple underlining
91 \ifdim\ULdepth=\maxdimen\else
92 \UL@height\ULthickness \advance\ULdepth\thr@@\UL@height \advance\UL@height-\ULdepth
93 \fi
94 \setbox\UL@box\hbox{{#1}}%
95 \let\UL@start\relax\UL@putbox\egroup}
96 % \UL@putbox is disabled in inner mode, so re-enable it by changing \UL@start
97 % \UL@hrest is implicit due to \everyhbox. Double braces for \hbox are in
98 % lieu of \color@begin(end)group.
99
100 % This is what \ULon does in math mode.
101 \def\UL@onmath#1{\UL@ender\mathord{\UL@hrest\mathop{\kern\z@#1}\limits\sb
102 {\UL@leadtype\LA@hskip\p@ plus1fill}}\egroup}
103
104 \def\UL@unegroup{}
105 \gdef\UL@ender{}
106 % end-brace matching hack for when command is used as a font declaration:
107 \def\UL@swender{\ifnum`{=\z@\fi\aftergroup}\gdef\UL@ender{}}
108
109 % must expand to nothing outside the ifs for syntactical spaces to work.
110 % the \expandafters get rid of the \@empty inserted at the beg. of word
111 \long\def\UL@word#1 {\expandafter\UL@start#1 %
112 \expandafter\ifx\expandafter\UL@end#1\egroup\egroup
113 \unskip \unskip \unskip % remove extra leader at end
114 \spacefactor\UL@spfactor \let\UL@word\egroup
115 \else % not finished
116 \ifmmode\else \ifdim\lastskip=\z@\else % allow syntactical spaces
117 \global\UL@skip\lastskip \unskip
118 \UL@stop \UL@leaders
119 \fi\fi
120 \fi \UL@word\@empty}% \@empty preserves braces in param
121
122 % \UL@start: start of each chunk. It gives two levels of grouping.
123 % Each chunk is ended by \UL@stop. Local intermissions go like
124 % \UL@stop...\UL@start.
125 \def\UL@start{\setbox\UL@box\hbox\bgroup\everyhbox{\UL@hrest}%
126 % the following are to cope with stops (\ ,\- etc) within extra braces
127 \let\UL@start\@empty \def\UL@unegroup{\bgroup\bgroup}\let\UL@leadtype\@empty
128 \bgroup \kern-3sp\kern3sp % kerns so I can test for beginning of list
129 \if@ignore \global\@ignorefalse \ignorespaces \fi}
130
131 \def\UL@stop{\global\UL@pe\lastpenalty \unpenalty % penalty in \UL@pe
132 \ifnum\lastkern=\thr@@ \egroup\egroup % Nothing in hbox...but make sure:
133 \ifdim\wd\UL@box=\z@ \else \UL@putbox \fi % something in box so print it
134 \else \egroup\egroup \UL@putbox % something in box so print it
135 \fi \ifnum\UL@pe=\z@ \else \LA@penalty\UL@pe \fi % use penalty from inside box
136 \UL@unegroup}
137 % notice that a box with only a penalty in it is discarded, but the penalty
138 % is still used! This is so a series of discardable glues and penalties
139 % behaves properly.
140
141 \def\UL@putbox{\ifx\UL@start\@empty \else % not inner
142 \vrule\@width\z@ \LA@penalty\@M
143 {\UL@skip\wd\UL@box \UL@leaders \kern-\UL@skip}%
144 \box\UL@box
145 \fi}
146
147 % With interword leaders, give some overlap to avoid gaps caused by
148 % round-off errors in the printing program. Needs \unskip \unskip \unskip
149 % above. This version overlaps 1/300 inch, which looks good at high
150 % resolution, and will still work down to ~150 dpi. Change the value
151 % of \UL@pixel if necessary.
152
153 \newdimen\UL@pixel \UL@pixel=1in \divide\UL@pixel 300
154
155 \def\UL@leaders{{\LA@hskip-\UL@pixel \advance\UL@skip\tw@\UL@pixel
156 \UL@leadtype\LA@hskip\UL@skip \LA@hskip-\UL@pixel}}
157
158 % restore some things for inside math or \mbox
159 \def\UL@hrest{\let\ \LA@space \let\-\@empty \let\penalty\LA@penalty}
160
161 \let\LA@space\ %
162 \UL@protected\def\UL@space{\LA@space \global\UL@skip\lastskip \unskip \UL@reskip}%
163
164 % Hyphenation is done by explicit \discretionary. The overlapping melds
165 % with the running overlap because it *is* part of the running overlap:
166 % The word fragment is extended by the width of the hyphenation which is
167 % then overlapped by leaders. The discretionary may occupy this space
168 % if a break occurs; otherwise the next syllable gets doubly-overlapped
169 % (in registration) for a distance of the hyphen's width.
170 \UL@protected\def\UL@dischyp{\global\setbox\UL@hyphenbox\hbox
171 {\ifnum \hyphenchar\font<\z@ \string-\else \char\hyphenchar\font \fi}%
172 \kern\wd\UL@hyphenbox \LA@penalty\@M
173 \UL@stop \kern-\wd\UL@hyphenbox
174 \discretionary{\box\UL@hyphenbox}{}{}\UL@start}
175
176 \let\LA@penalty\penalty
177 \UL@protected\def\UL@penalty{\relax\ifhmode \afterassignment\UL@@penalty\count@
178 \else\LA@penalty\fi}
179 \def\UL@@penalty{\LA@penalty \ifnum\count@=\z@
180 \@ne \else \count@ \fi % zero penalty => no penalty, so use 1 instead.
181 \UL@stop \UL@start}
182
183 % The test \ifx\ \LA@space \else means we are neither in math mode nor an
184 % \mbox, so it is safe to stop the current \UL@box. \ , \- , and \penalty
185 % (= \linebreak or \nolinebreak) are common enough that they are restored
186 % directly (by \UL@hrest); \\, \newline, \hskip (= \hspace) are rare enough
187 % that the test is incorporated in their UL versions. This adds processing
188 % when they're used, but saves processing in \UL@hrest called by \everymath
189 % \everyvbox and \everyhbox.
190
191 \let\LA@hskip\hskip
192 \UL@protected\def\UL@hskip{\ifx\ \LA@space \LA@hskip \else
193 \afterassignment\UL@reskip \global\UL@skip \fi}
194
195 \def\UL@reskip{\UL@stop \UL@leaders \UL@start}
196
197 % Redefine \\ and \newline so the vertical space from \\[ ] is not lost
198 % and so the \hfil is not underlined! \\ and \newline do nothing if inside
199 % inner braces.
200
201 \UL@protected\def\UL@cr{\unskip \ifx\ \LA@space \let\UL@vad\@gobble
202 \else \UL@stop \unskip\unskip\unskip \let\UL@vad\vadjust \fi
203 \@ifstar{\UL@vad{\LA@penalty\@M}\UL@cra}\UL@cra}
204 \def\UL@cra{\@ifnextchar[\UL@crb\UL@newline}
205 \def\UL@crb[#1]{\UL@vad{\vskip#1}\UL@newline}
206
207 \UL@protected\def\UL@newline{\ifx\UL@start\@empty % (\UL@cr may have \UL@stop-ed already)
208 \unskip \ifx\ \LA@space \else \UL@stop \unskip\unskip\unskip \fi\fi
209 \LA@hskip \z@\@plus.0001fil\LA@penalty -\@M \UL@start}
210
211 % That concludes the basic underlining. To put various other objects
212 % (characters) under (or over) text we need to define \markoverwith
213 % to set the overlay material in a box, and use leaders of that box for
214 % overlaying the text. Here, the meaning of \UL@pixel is changed so
215 % that `pixel' size = box size. Note that we generally need \leaders
216 % (not \cleaders) for text, because an underline will be a patchwork
217 % of small \leaders, and the characters must stay in registration.
218 % However, we "hook" the leaders command so specific applications can
219 % reassign it (\let\ULleaders\xleaders or \let\ULleaders\cleaders).
220 %
221 \newbox\ULC@box
222 \let\ULleaders\leaders
223
224 \UL@protected\def\markoverwith#1{\leavevmode
225 \setbox\ULC@box\hbox{{#1}}\[email protected]\wd\ULC@box
226 \ifmmode \setbox\ULC@box\hbox{\raise1.4ex\box\ULC@box}%
227 \dp\[email protected]\ht\ULC@box\z@ \def\UL@leadtype{\cleaders\copy\ULC@box}%
228 \else
229 \def\UL@leadtype{\ULleaders\copy\ULC@box}%
230 \fi}
231
232 % Now define various special underlines. All the definitions go like
233 % \def \command {\bgroup \markoverwith{something} \ULon}
234
235 % For drawing a wavey underline instead of a straight one the command
236 % is \uwave (under-wave) which uses the wiggle from 6-pt lasy font:
237
238 \UL@protected\def\uwave{\leavevmode \bgroup
239 \ifdim \ULdepth=\maxdimen \ULdepth 3.5\p@
240 \else \advance\ULdepth2\p@
241 \fi \markoverwith{\lower\ULdepth\hbox{\sixly \char58}}\ULon}
242 \font\sixly=lasy6 % does not re-load if already loaded, so no memory drain.
243
244 % To draw a double underline under text, use \uuline{text}
245
246 \UL@protected\def\uuline{\leavevmode \bgroup
247 \UL@setULdepth
248 \ifx\UL@on\UL@onin \advance\ULdepth2.8\p@\fi
249 \markoverwith{\lower\ULdepth\hbox
250 {\kern-.03em\vbox{\hrule width.2em\kern1\p@\hrule}\kern-.03em}}%
251 \ULon}
252
253 % To draw a line through text instead of under it (strike out) do
254 % `under'-line with negative depth. Note that this one uses a real
255 % line, not characters, so there is no \markoverwith.
256
257 \UL@protected\def\sout{\leavevmode \bgroup \ULdepth=-.55ex \ULset}
258
259 % To mark //// over text instead of underlining (x-out)
260 %
261 \UL@protected\def\xout{\leavevmode \bgroup
262 \markoverwith{\hbox to.35em{\hss/\hss}}\ULon}
263
264 \UL@protected\def\dotuline{\leavevmode \bgroup
265 \UL@setULdepth
266 \ifx\UL@on\UL@onin \advance\ULdepth2\p@\fi
267 \markoverwith{\begingroup
268 %\advance\ULdepth0.08ex
269 \lower\ULdepth\hbox{\kern.06em .\kern.04em}%
270 \endgroup}%
271 \ULon}
272
273 \UL@protected\def\dashuline{\leavevmode \bgroup
274 \UL@setULdepth
275 \ifx\UL@on\UL@onin \advance\ULdepth2\p@\fi
276 \markoverwith{\kern.13em
277 \vtop{\kern\ULdepth \hrule width .3em}%
278 \kern.13em}\ULon}
279
280 % A command to declare that an underline command should be used in
281 % place of a particular font selection:
282 % \useunder {underline_command}{font_declaration}{font_command}
283 % e.g.: \useunder{\uuline}{\bfseries}{\textbf}
284 % \useunder{\uwave}{\bf}{}
285
286 \UL@protected\def\useunder#1#2#3{\relax
287 \ifx\relax#2\relax\else % declaration command given
288 \UL@protected\def#2{\def\@tempa{#1}\global\let\UL@ender\UL@swender
289 \expandafter\@tempa\expandafter{\ifnum\z@=\string`}\fi}%
290 \fi
291 \ifx\relax#3\relax\else % argumentative command
292 \UL@protected\def#3{#1}%
293 \fi}
294
295 \expandafter\ifx \csname @ifundefined\endcsname \relax
296
297 % Allow plain TeX to use ulem.sty:
298 \def\@height{height}
299 \def\@depth{depth}
300 \def\@width{width}
301 \def\@empty{}
302 \long\def\@gobble#1{}
303 \long\def\@firstoftwo#1#2{#1}%
304 \long\def\@secondoftwo#1#2{#2}%
305 % Do non-outer \newif with no visible \if's or \fi's when skipping
306 \csname newif\expandafter\endcsname \csname if@ignore\endcsname
307
308 \else
309
310 \let\LA@em\em \let\LA@emph\emph
311 \expandafter\let\expandafter\LA@Pem \csname em \endcsname
312 \expandafter\let\expandafter\LA@Pemph \csname emph \endcsname
313 \def\ULforem{\useunder{\uline}{\em}{\emph}}
314 \def\normalem{\let\em\LA@em \let\emph\LA@emph
315 \expandafter\let\csname em \endcsname\LA@Pem
316 \expandafter\let\csname emph \endcsname\LA@Pemph}
317 \ULforem % default is to use underlining for \em,
318
319 \fi
320
321 % Process LaTeX \package options; plain TeX skips this section
322
323 \expandafter\ifx\csname ProvidesPackage\endcsname \relax \else
324 \ProvidesPackage{ulem}[2019/11/18]
325 \DeclareOption{normalem}{\normalem}
326 \DeclareOption{ULforem}{\ULforem}
327 \DeclareOption{normalbf}{}
328 \DeclareOption{UWforbf}{\useunder{\uwave}{\bf}{\textbf}}
329 \ProcessOptions
330 %
331 \newcommand\UL@marpar[2][\ULmp@opt@arg]{\gdef\ULmp@opt@arg{#2}%
332 \ifx\ \LA@space \@latexerr{Marginpar lost}%
333 \else \UL@stop \LA@marginpar[#1]{#2}\UL@start \fi}
334 %
335 \AtBeginDocument{\let\LA@marginpar\marginpar}%
336 %
337 \addto@hook\UL@hook{\let\marginpar\UL@marpar}
338 \fi
339
340 \catcode`@=\ULthickness % Scratch meaning: restore catcode of @
341
342 \def\ULthickness{.4pt}% can change this with \renewcommand
343 \newdimen\ULdepth \ULdepth=\maxdimen
344 % "maxdimen" depth causes the depth to be set according to the font. You
345 % can change \ULdepth for a permanent setting or a special effect (\sout).
346
347 \endinput
348
349
350 % Previous bug-finders: Esther Hu (\hfill in plain); Lones Smith (\tt\-);
351 % Steve Anderson (\ooalign accents); Thanassi Protopapas ( { in tables).
352 % The bug finders' fee is now $0.00; it will double for each new bug found.
353 % Version (identified by year)
354 % 1994:
355 % Many changes! Notably: LaTeX2e options and \emph. Nesting works (somewhat).
356 % Behavior with inner braces is more consistent (not stripped). \useunder.
357 % Better underwave (using lasy6). Special underlines are not commented out.
358 % patch 1995: fix \UL@swender to work in {tabular}; make hyphenation join
359 % well; crude math support; eliminate \@clb
360 % 1996: use "\csname ProvidesPackage\endcsname", tidying.
361 % 1997: fix \\ when LaTeX changed; remove extra overlap in putbox.
362 % 2000: hook (and marginpar)
363 % 2004: Fix spacing in \uwave and \xout. \ULleaders hook.
364 % 2009: Accept \par in argument (\long)
365 % 2010: Include \dotuline and \dashuline, typeset documentation, add \UL@setULdepth
366 % 2011: Change \dimen@ to \UL@height
367 % 2012: Removed \let\par garbage
368 % 2017: Remove \makerobust
369 % 2019: Handle \ULdepth better. Some tweaks.
370 %
371 % Send problem reports to [email protected]
372 %
373 % test integrity:
374 % brackets: round, square, curly, angle: () [] {} <>
375 % backslash, slash, vertical, at, dollar, and: \ / | @ $ &
376 % hat, grave, acute (apostrophe), quote, tilde, under: ^ ` ' " ~ _