Debian Codegraph @

texmf-dist/doc/latex/soulpos/soulpos.tex

raw
1 %
2 % Copyright (C) 2012-2021 Javier Bezos http://www.texnia.com
3 %
4 % This file may be distributed and/or modified under the conditions of
5 % the MIT License. A version can be found at the end of this file.
6 %
7
8 \documentclass[a4paper,twocolumn]{article}
9
10 \title{Underlining (and more) with soulpos}
11 \author{Javier Bezos}
12 \date{2021-10-15}
13
14 \usepackage{tikz}
15 \usetikzlibrary{decorations.pathmorphing}
16
17 % \usepackage{soul}
18 \usepackage{soulpos}
19
20 \renewcommand{\ulpostolerance}{12}
21
22 \advance\textwidth16mm
23 \advance\oddsidemargin-8mm
24
25 \makeatletter
26 \newenvironment{desc}
27 {\vskip2ex
28 \hrule
29 \trivlist\item[]}
30 {\endtrivlist}
31 \makeatother
32
33 \begin{document}
34
35 \maketitle
36
37 This package just combines \textsf{soul} with the \texttt{savepos}
38 mechanism provided by the pdftex engine, so that you can create
39 (almost) arbitrary underlining and similar ``decorations'', including
40 rules, leaders and even pictures (\textsf{pgf}, \textsf{pstricks},
41 etc.). Unlike \textsf{soul} underlines, which are built by repeating small
42 elements, here each chunk of text to be underlined is a single
43 element.
44
45 The main drawback is obvious -- since it relies on \verb|\pdfsavepos|
46 two passes are necessary. Further, to prevent exhausting the hash
47 table, the auxiliary file containing the information about each
48 underline is read only when needed, which may impact performance
49 negatively.\footnote{Actually, two files are created, with extensions
50 \texttt{upa} and \texttt{upb}.}
51
52 Internally \textsf{soul} knows to some point where a break happens,
53 and this information may be used to set diferent styles depending on
54 the position.
55
56 This version (1.0) does almost no checking (e.g., to warn about the
57 need for a new run), which is left for a later release.
58
59 The package \textsf{soulutf8} is loaded if it (or \textsf{soul}) has
60 not been loaded before (note the UTF-8 encoding is not necessary for
61 \textsf{soulutf8} to work).
62
63 \section{Usage}
64
65 Underlining macros are defined much like in \textsf{soul}.
66
67 \begin{desc}
68 \verb|\ulposdef{<name>}[<options>]{<commands>}|
69 \end{desc}
70
71 Defines an underline as \verb|<commands>|, which is placed in a box of
72 width zero with either \verb|\llap| or \verb|\rlap|, as explained
73 below. Typically, \verb|<commands>| will contain a rule or leaders.
74 If the text spans more than one line, then there will be several
75 chunks to be undelined (one per line).
76
77 You can use the following macros in \verb|<commands>|.
78
79 \begin{desc}
80 \verb|\ulwidth|
81 \end{desc}
82
83 The width of the text block to be underlined. A basic underlining is:
84 \begin{verbatim}
85 \ulposdef{\uline}{\rule[-.8ex]{\ulwidth}{.5pt}}
86 \end{verbatim}
87
88 \begin{desc}
89 \verb|\ifulstarttype{<type>}{<true>}{<false>}|\qquad
90 \verb|\ifulendtype{<type>}{<true>}{<false>}|
91 \end{desc}
92
93 These tests can be used in \verb|<commands>|, to set different underlining
94 styles depending on where the current chunk begins or ends. Here
95 \verb|<type>| is: 0 if the very start or end of the underlined text, 1 if a
96 space, 2 if a discretionary hyphen and 3 if an explicit hyphen. See
97 an example below.
98
99 \begin{desc}
100 \verb|\ulstarttype|\qquad\verb|\ulendtype|
101 \end{desc}
102
103 Macros storing the values described above, so that you can use
104 \LaTeX{} conditionals (or \TeX{} ones). So, to check if the end is an
105 hyphen, test \verb|\ulendtype>1|.
106
107 \vskip2ex
108 \hrule
109 \vskip2ex
110
111 Valid keys/values in \verb|<options>| are:
112
113 \begin{description}
114 \item[\texttt{xoffset}]
115 This key provides a simple way to fix an unpleasant effect found in
116 many programs when colouring the text background -- the colour starts
117 and ends just at the edges of the first and last characters. Just set
118 the offset to a value larger than 0pt, as for example .1 em. This
119 value is added ($\times$2) to \verb|\ulwidth|, but no space is added
120 to the text (which can be done with the \verb|gap| key). Of course,
121 you can still do finer adjustments in the definition of the underline,
122 as shown in the samples below. You can use \verb|xoffset-start| and
123 \verb|xoffset-end| to set the corresponding values separately.
124
125 \item[\texttt{gap}] It is equivalent to the outer space in
126 \verb|\sodef|. This value is \textit{not} added to \verb|\ulwidth|.
127 You can use \verb|gap-start| and \verb|gap-end| to set the
128 corresponding values separately.
129
130 \item[\texttt{hyphens}] Sometimes excluding the hyphen from the
131 underlined text could make sense. Default is \verb|hyphens=include|
132 but you can set it to \verb|hyphens=exclude|.
133
134 \item[\texttt{overdraw}] By default underlines are drawn before the
135 text is typeset (with \verb|\rlap|), so that they are placed behind.
136 However, it can be drawn after (with \verb|\llap|), on top the text,
137 with \verb|overdraw| or, equivalently, \verb|overdraw=true| (default
138 is \verb|overdraw=false|).
139 \end{description}
140
141 \begin{desc}
142 \verb|\ulpostolerance|
143 \end{desc}
144
145 The current algorithm is based on changes of the $y$ coordinate of
146 savepos and therefore presumes a regular baseline. Any increasing or
147 decreasing of $y$ is considered a new chunk, but you can give a certain
148 tolerance with, for example:
149 \begin{verbatim}
150 \renewcommand{\ulpostolerance}{12}
151 \end{verbatim}
152
153 \section{Future work}
154
155 \begin{itemize}
156 \item Warnings.
157 \item In short documents, providing an option for using the aux file.
158 \item Redefinable macros.
159 \item \texttt{offset}, including edges at line breaks.
160 \item \texttt{.upb} is generated at the end of the run, so it might be
161 used by another program to generate the decorations. As of 1.0.
162 however, its syntax is likely to change and therefore unsupported.
163 \item Better manual.
164 \item Improved performance.
165 \item Fixing some issues in multicolumn text (it does not work if there
166 are just two lines, one at the left and the other at the right).
167 \item Some predefined ``decorations''.
168 \end{itemize}
169
170 \newcommand\ulpossample[1]{%
171 A single #1{word}. Now #1{a few words}. Longer:
172 #1{this text spans several lines, so that you can see the behaviour of
173 \textsf{soulpos} where there are line breaks}.\vskip2ex\hrule\vskip2ex}
174
175 \section{Examples}
176
177 % \def\ulpostolerance{-78}
178
179 \makeatletter
180 \expandafter\def\expandafter\verbatim@font\expandafter{%
181 \verbatim@font\small}
182 \makeatother
183
184 \begin{verbatim}
185 \ulposdef{\ulpgfA}{%
186 \raisebox{-.75ex}{%
187 \begin{tikzpicture}%
188 \clip (0,-1pt) rectangle (\ulwidth,1pt);
189 \draw[
190 color=black!40,
191 line width=.7pt,
192 decorate,
193 decoration=
194 {random steps,
195 segment length=1.5mm,
196 amplitude=.5pt}]
197 (0,0) -- +(\ulwidth+3pt,0);
198 \end{tikzpicture}}}
199 \end{verbatim}
200
201 \ulposdef\ulpgfA{%
202 \raisebox{-.75ex}{%
203 \begin{tikzpicture}%
204 \clip (0,-1pt) rectangle (\ulwidth,1pt);
205 \draw[
206 color=black!40,
207 line width=.7pt,
208 decorate,
209 decoration=
210 {random steps,segment length=1.5mm,amplitude=.5pt}]
211 (0,0) -- +(\ulwidth+3pt,0);
212 \end{tikzpicture}}}
213
214 \ulpossample\ulpgfA
215
216 \begin{verbatim}
217 \ulposdef{\ulpgfB}{%
218 \raisebox{-.75ex}{%
219 \begin{tikzpicture}%
220 \clip (0,-1pt) rectangle (\ulwidth,1pt);
221 \draw[color=black!40,
222 line width=.7pt,
223 decorate,
224 decoration=
225 {snake,
226 amplitude=.3pt,
227 segment length=1mm,}]
228 (0,0) -- +(\ulwidth+3pt,0);
229 \end{tikzpicture}}}
230 \end{verbatim}
231
232 \ulposdef\ulpgfB{%
233 \raisebox{-.75ex}{%
234 \begin{tikzpicture}%
235 \clip (0,-1pt) rectangle (\ulwidth,1pt);
236 \draw[color=black!40,
237 line width=.7pt,
238 decorate,
239 decoration=
240 {snake, amplitude=.3pt,segment length=1mm,}]
241 (0,0) -- +(\ulwidth+3pt,0);
242 \end{tikzpicture}}}
243
244 \ulpossample\ulpgfB
245
246 \begin{verbatim}
247 \ulposdef{\ulpgfC}[xoffset=.15em]{%
248 \ifulstarttype{0}%
249 {\def\arr{|}}%
250 {\def\arr{<}}%
251 \ifulendtype{0}%
252 {\edef\arr{\arr-|}}%
253 {\edef\arr{\arr->}}%
254 \raisebox{-.7ex}{%
255 \tikz
256 \draw[\arr,color=black!40,
257 line width=1pt]
258 (0,0) -- +(\ulwidth-1pt,0);}}
259 \end{verbatim}
260
261 \ulposdef\ulpgfC[xoffset=.15em]{%
262 \ifulstarttype{0}%
263 {\def\arr{|}}%
264 {\def\arr{<}}%
265 \ifulendtype{0}%
266 {\edef\arr{\arr-|}}%
267 {\edef\arr{\arr->}}%
268 \raisebox{-.7ex}{%
269 \tikz
270 \draw[\arr,color=black!40,
271 line width=1pt]
272 (0,0) -- +(\ulwidth-1pt,0);}}
273
274 \ulpossample\ulpgfC
275
276 \begin{verbatim}
277 \ulposdef{\ulbgdD}{%
278 \mbox{%
279 \color{black!30}%
280 \rule[-.8ex]{\ulwidth}{13pt}}}
281 \end{verbatim}
282
283 \ulposdef\ulbgdD{%
284 \mbox{%
285 \color{black!30}%
286 \rule[-.8ex]{\ulwidth}{13pt}}}
287
288 \ulpossample\ulbgdD
289
290 \begin{verbatim}
291 \ulposdef{\ulbgdE}[xoffset=.1em]{%
292 \mbox{%
293 \color{black!30}%
294 \rule[-.8ex]{\ulwidth}{13pt}}}
295 \end{verbatim}
296
297 \ulposdef\ulbgdE[xoffset=.1em]{%
298 \mbox{%
299 \color{black!30}%
300 \rule[-.8ex]{\ulwidth}{13pt}}}
301
302 \ulpossample\ulbgdE
303
304 \begin{verbatim}
305 \ulposdef{\uldash}{%
306 \makebox[\ulwidth]{%
307 \color{blue}%
308 \xleaders\hbox to.27em
309 {\hss\rule[-.8ex]{.18em}{.5pt}\hss}%
310 \hfill}}
311 \end{verbatim}
312
313 \ulposdef\uldash{%
314 \makebox[\ulwidth]{%
315 \color{blue}%
316 \xleaders\hbox to.27em{\hss\rule[-.8ex]{.18em}{.5pt}\hss}\hfill}}
317
318 \ulpossample\uldash
319
320 \begin{verbatim}
321 \ulposdef{\uldot}{%
322 \mbox{%
323 \raisebox{-.85ex}{%
324 \xleaders\hbox to.2em
325 {\hss\footnotesize.\hss}\hskip\ulwidth}}}
326 \end{verbatim}
327
328 \ulposdef\uldot{%
329 \mbox{%
330 \raisebox{-.85ex}{\xleaders\hbox to.2em{\hss\footnotesize.\hss}\hskip\ulwidth}}}
331
332 \ulpossample\uldot
333
334 \begin{verbatim}
335 \ulposdef{\ulflag}{%
336 \mbox{%
337 \color{red}\rule[-.85ex]{.25\ulwidth}{1.5pt}%
338 \color{yellow}\rule[-.85ex]{.5\ulwidth}{1.5pt}%
339 \color{red}\rule[-.85ex]{.25\ulwidth}{1.5pt}}}
340 \end{verbatim}
341
342 \ulposdef\ulflag{%
343 \mbox{%
344 \color{red}\rule[-.85ex]{.25\ulwidth}{1.5pt}%
345 \color{yellow}\rule[-.85ex]{.5\ulwidth}{1.5pt}%
346 \color{red}\rule[-.85ex]{.25\ulwidth}{1.5pt}}}
347
348 \ulpossample\ulflag
349
350 \end{document}
351
352 MIT License
353 -----------
354
355 Permission is hereby granted, free of charge, to any person obtaining a
356 copy of this software and associated documentation files (the
357 "Software"), to deal in the Software without restriction, including
358 without limitation the rights to use, copy, modify, merge, publish,
359 distribute, sublicense, and/or sell copies of the Software, and to
360 permit persons to whom the Software is furnished to do so, subject to
361 the following conditions:
362
363 The above copyright notice and this permission notice shall be included
364 in all copies or substantial portions of the Software.
365
366 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
367 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
368 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
369 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
370 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
371 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
372 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.