Debian Codegraph @

texmf-dist/source/latex/parskip/parskip.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: parskip.dtx
4 %% (C) Copyright 1989 H.Partl, TU Wien
5 %% (C) Copyright 2001 Robin Fairbairns
6 %% (C) Copyright 2018-2021 Frank Mittelbach
7 %
8 % It may be distributed and/or modified under the conditions of the
9 % LaTeX Project Public License (LPPL), either version 1.3c of this
10 % license or (at your option) any later version. The latest version
11 % of this license is in the file
12 %
13 % https://www.latex-project.org/lppl.txt
14 %
15 %
16 % The development version of the bundle can be found below
17 %
18 % https://github.com/FrankMittelbach/fmitex-parskip/
19 %
20 % for those people who are interested or want to report an issue.
21 %
22 %<*driver>
23 \documentclass{article}
24 \usepackage{doc,url}
25 \EnableCrossrefs
26 \CodelineIndex
27 \begin{document}
28 \DocInput{parskip.dtx}
29 \end{document}
30 %</driver>
31 %
32 % \fi
33 %
34 %
35 % \newcommand\option[1]{\texttt{#1}}
36 % \newcommand\cs[1]{\texttt{\bslash#1}}
37 % \newcommand\pkg[1]{\textsf{#1}}
38 %
39 % \title{The \texttt{parskip} package\thanks{This is a
40 % reimplementation of a package originally written by Hubert Partl
41 % in 1989 and later maintained by Robin Fairbairns.}}
42 % \author{Frank Mittelbach}
43 %
44 % \maketitle
45 %
46 % \begin{abstract}
47 % The \pkg{parskip} package helps in implementing paragraph layouts
48 % where the paragraphs are separated by a vertical space instead of
49 % (or in addition to) indenting them.
50 %
51 % The package can be used with any document class at any size. By
52 % default it produces the following paragraph layout: Zero
53 % \cs{parindent} and non-zero \cs{parskip}. The stretchable glue in
54 % \cs{parskip} helps \LaTeX{} in finding the best place for page
55 % breaks.
56 %
57 % \end{abstract}
58 %
59 % \section{Introduction}
60 %
61 % Many \LaTeX{} constructs are internally built by using the paragraph
62 % mechanism even if technically there aren't text paragraphs. In most
63 % such cases the \LaTeX{} code handles indentation and suppressed it
64 % if necessary. But unfortunately this is normally not done for
65 % \cs{parskip} (as that is zero in the default layouts) and thus
66 % changing it will result in vertical spaces in unexpected places.
67 %
68 % This package attempts to fix the spacing in table of contents
69 % structures, list environments, and around display headings that would
70 % get screwed up by a positive \cs{parskip} value.
71 %
72 % It is, however, is no more than quick fix; the `proper' way to
73 % achieve effects as far-reaching as this is to create a new class.
74 %
75 % \subsection{History}
76 %
77 % This file was originally developed by Hubert Partl in 1989 (i.e.,
78 % for \LaTeX\,2.09) to provide a somewhat crude solution to an
79 % existing problem in case no proper document class (back then called
80 % document style) support was available.
81 %
82 % About ten years later Robin Fairbairns picked up the orphaned
83 % package and his version was then the one available for \LaTeXe{}
84 % during the next 15\textsuperscript{+} years.
85 %
86 % Finally, while working on the next edition of the \LaTeX{} Companion
87 % the current author did a reimplementation, that added support for TOC
88 % data and heading structures. Also a few additional key/value options
89 % were added to make the package more useful. It still is and will
90 % remain an inferior choice compared to a properly designed document
91 % class. But it offers a starting point if nothing is around.
92 %
93 %
94 %
95 % \section{The user interface}
96 %
97 % The \pkg{parskip} package doesn't offer any document user commands
98 % and just needs loading with \cs{usepackage}.
99 %
100 %
101 % \subsection{Options to customize the package}\label{sec:options}
102 %
103 % All of the package options are implemented as key/value options.
104 % \begin{description}
105 % \item[\option{skip}]
106 % With the package option \texttt{skip} it is possible to explicitly
107 % specify the vertical space between paragraphs. If the option is
108 % not given (or given without a value) then \verb=.5\baselineskip=
109 % plus \texttt{2pt} of stretch is assumed.
110 % \item[\option{tocskip}]
111 % By default the \cs{parskip} is zero within \cs{tableofcontents}
112 % and similar lists, regardless of its value elsewhere. With the
113 % option \texttt{tocskip} it can be given a different value. If
114 % used without an explicit value you get the same \cs{parskip} as elsewhere
115 % within these lists.
116 % \item[\option{indent}]
117 % With the package option \texttt{indent} it is possible to explicitly set
118 % the paragraph indentation. Using this option without a value keeps the
119 % document class indentation unchanged, if it is specified with a
120 % value then that value is used. If the package is loaded without
121 % this option
122 % the indentation is set
123 % to zero.
124 % \item[\option{parfill}]
125 % With package option \texttt{parfill}, the package also adjusts
126 % \cs{parfillskip} to impose a minimum space at the end of
127 % the last line of a paragraph. If specified without a value then
128 % \texttt{30pt} are assumed, if a value is given that forms the minimum.
129 % \end{description}
130 %
131 %
132 % \section{Differences to the original package}
133 %
134 % If the package is used without any options or just with the option
135 % \option{parfill} it behaves like the earlier version, except that now
136 % the spacing around headings is also adjusted (not adding extra
137 % \cs{parskip}). If this is not desirable when processing an old
138 % document it can be avoided by explicitly
139 % requesting version \texttt{v1} as follows:
140 % \begin{quote}
141 % \verb/\usepackage{parskip}[=v1]/
142 % \end{quote}
143 % Of course, the new options, etc.\ are then also not available.
144 %
145 %
146 %
147 % \section{Sources, bugs and issues}
148 %
149 % The official production version is available from CTAN.
150 % The latest (development) sources are maintained at GitHub at:
151 % \begin{quote}
152 % \url{https://github.com/FrankMittelbach/fmitex-parskip}
153 % \end{quote}
154 % In case of problems with the package you can report them at
155 % \begin{quote}
156 % \url{https://github.com/FrankMittelbach/fmitex-parskip/issues}
157 % \end{quote}
158 % Please provide a minimal test example that can be run and doesn't
159 % use packages not in a standard \LaTeX{} distribution (and only those
160 % that are needed to show the issue).
161 %
162 % \StopEventually{}
163 %
164 %
165 %
166 %
167 % \section{The Implementation}
168 %
169 % \setcounter{StandardModuleDepth}{1} ^^A everything is inside a module
170 %
171 % \begin{macrocode}
172 %<*package>
173 % \end{macrocode}
174 %
175 % \subsection{The main implementation part}
176 %
177 %
178 % \begin{macrocode}
179 \NeedsTeXFormat{LaTeX2e}[2018-04-01]
180
181 \DeclareRelease {v1}{2001-04-09}{parskip-2001-04-09.sty}
182 \DeclareCurrentRelease{v2}{2018-08-24}
183 % \end{macrocode}
184 %
185 % \begin{macrocode}
186 \ProvidesPackage{parskip}[2021-03-14 v2.0h non-zero parskip adjustments]
187 % \end{macrocode}
188 %
189 %
190 %
191 % \subsubsection{Option handling}
192 %
193 % Here we define all option keys for use as package options:
194 % \begin{macrocode}
195 \RequirePackage{kvoptions}
196 \SetupKeyvalOptions{family=parskip,prefix=parskip@}
197 % \end{macrocode}
198 %
199 % The key \option{indent} defines the amount of indentation for each
200 % paragraph. If not given the indentation will be zero (default) and
201 % if given without a value then the outer value from the document
202 % class will get used, otherwise the given value is used.
203 % \begin{macrocode}
204 \DeclareStringOption[0pt]{indent}[\parindent]
205 % \end{macrocode}
206 %
207 % The key \option{parfill} defines a minimum amount of white space
208 % that should be left in the last line. By default the last line can
209 % get completely fill up. If given without a value the default (as
210 % before) is to require a minimum of \texttt{30pt}, otherwise the
211 % given value is used.
212 % \begin{macrocode}
213 \DeclareStringOption[0pt]{parfill}[30pt]
214 % \end{macrocode}
215 %
216 % The key \option{skip} defines the vertical separation between
217 % paragraphs. If not given the default (as before) is to use half a
218 % \cs{baselineskip} plus a stretch of \texttt{2pt} to add some
219 % flexibility. If given, one need to provide an explicit value which
220 % is then used as a separation (and it needs to contain any extra
221 % stretch if that is wanted, i.e., there is no extra stretch added
222 % in this case).
223 % \changes{v2.0f}{2020/06/15}{Allow \texttt{skip} key without value
224 % without a package error (gh/14)}
225 % \begin{macrocode}
226 \DeclareStringOption{skip}[]
227 % \end{macrocode}
228 %
229 % The key \option{tocskip} defines the vertical separation inside the lists
230 % \cs{tableofcontents}, \cs{listoffigures} and \cs{listoftables}. By
231 % default there is no extra separatation (i.e., \texttt{0pt}). If
232 % specified without a value the standard \cs{parskip} is used,
233 % otherwise the given value.
234 % \begin{macrocode}
235 \DeclareStringOption[0pt]{tocskip}[\parskip]
236 % \end{macrocode}
237 %
238 % Execute any package options:
239 % \begin{macrocode}
240 \ProcessKeyvalOptions*
241 % \end{macrocode}
242 %
243 % So now we can evaluate the given options and adjust the
244 % parameter settings:
245 % \begin{macrocode}
246 \ifx\parskip@skip\@empty
247 % \end{macrocode}
248 % If no \option{skip} was given (or it was empty) set \cs{parskip}
249 % to half of \verb=.5\baselineskip= plus \texttt{2pt} stretch. Stretch
250 % or shrink inside \cs{baselineskip} is ignored in this case.
251 % \begin{macrocode}
252 \parskip=.5\baselineskip plus 2pt\relax
253 \else
254 % \end{macrocode}
255 % Otherwise set it to the specified value:
256 % \changes{v2.0c}{2019/02/16}{Support calc by using \cs{setlength}
257 % for assignments}
258 % \begin{macrocode}
259 \setlength\parskip\parskip@skip
260 \fi
261 % \end{macrocode}
262 % Setting \cs{parfillskip} was suggested by Donald Arseneau at some
263 % point on comp.text.tex:
264 % \begin{macrocode}
265 \setlength\parfillskip\parskip@parfill
266 \advance\parfillskip 0pt plus 1fil\relax
267 % \end{macrocode}
268 % \cs{parindent} gets whatever was specified. If the key was given
269 % without an option this will essentially reassign the now ``current'' value.
270 % \begin{macrocode}
271 \setlength\parindent\parskip@indent
272 % \end{macrocode}
273 %
274 %
275 %
276 % \subsection{Handling document elements}
277 %
278 % Setting up a non-zero \cs{parskip} has some side-effects in document
279 % elements such as lists or headings etc. Here we try to keep these
280 % side-effects somewhat under control.
281 %
282 % We make use of the \pkg{etoolbox} package to do patching.
283 % \begin{macrocode}
284 \RequirePackage{etoolbox}
285 % \end{macrocode}
286 %
287 % \subsubsection{Lists}
288 %
289 % To accompany this, the vertical spacing in the list environments is changed
290 % to use the same as \cs{parskip} in all relevant places (for
291 % \cs{normalsize} only), i.e.
292 %\begin{verbatim}
293 % \parsep = \parskip
294 % \itemsep = \z@ % add nothing to \parskip between items
295 % \topsep = \z@ % add nothing to \parskip before first item
296 %\end{verbatim}
297 %
298 % However, if the user explicitly asked for a zero parskip (via the
299 % \option{skip} option) we
300 % shouldn't do this but rather keep the default list settings, so
301 % we better check for this.
302 %
303 % \begin{macrocode}
304 \ifdim \parskip > 0pt
305 % \end{macrocode}
306 %
307 % \begin{macrocode}
308 \def\@listI{\leftmargin\leftmargini
309 \topsep\z@ \parsep\parskip \itemsep\z@}
310 \let\@listi\@listI
311 \@listi
312 % \end{macrocode}
313 %
314 % \begin{macrocode}
315 \def\@listii{\leftmargin\leftmarginii
316 \labelwidth\leftmarginii\advance\labelwidth-\labelsep
317 \topsep\z@ \parsep\parskip \itemsep\z@}
318 % \end{macrocode}
319 %
320 % \begin{macrocode}
321 \def\@listiii{\leftmargin\leftmarginiii
322 \labelwidth\leftmarginiii\advance\labelwidth-\labelsep
323 \topsep\z@ \parsep\parskip \itemsep\z@}
324 %
325 % and finally ...
326 % \partopsep = \z@ % don't even add anything before first item (beyond
327 % % \parskip) even if the list is preceded by a blank line
328 \partopsep=\z@
329 \fi
330 % \end{macrocode}
331 %
332 %
333 % \subsubsection{TOCs and similar lists}
334 %
335 % Within a table of contents or a list of figures we don't want any
336 % additional vertical spacing just because the individual lines in
337 % such a list are implemented as one-line paragraphs. So we locally
338 % set the \cs{parskip} to zero by default. Should be really something that is
339 % done already in \LaTeX{}.
340 % \changes{v2.0e}{2020/05/19}{Fix space at start of \cs{@starttoc} (gh/12)}
341 % \begin{macrocode}
342 \patchcmd\@starttoc
343 {\begingroup \makeatletter}
344 {\begingroup \makeatletter
345 % \end{macrocode}
346 % Just setting \cs{parskip} to zero as it was done in the original
347 % version of the package, does not always work. If the list starts
348 % out with an ordinary paragraph (and not with \cs{addvspace} as it
349 % usually does) we will get a zero \cs{parskip} but the heading
350 % above assumes we get the normal \cs{parskip} and has therefore
351 % removed that amount from its own vertical skip. As long as the
352 % parskip value is not too large people didn't notice that heading
353 % and list moved closer to each other but if you use, say,
354 % \texttt{[skip=20pt]} you will even see an overlap.
355 %
356 % We therefore do the following: we look at the last skip, undo it
357 % and then issue a skip that is equal to \cs{parskip} +
358 % \cs{lastskip}.
359 % This way the skip seen by any following code has the right value
360 % which is important for \cs{addvspace} calulations. Only then we
361 % locally set \cs{parskip} to zero or rather to
362 % \cs{parskip@tocskip}, the parameter that the user can set through
363 % an option.
364 % \changes{v2.0e}{2020/05/19}{Add \texttt{tocskip} option}
365 % \begin{macrocode}
366 \skip@\lastskip
367 \advance\skip@\parskip
368 \vskip-\lastskip
369 \vskip\skip@
370 \parskip\parskip@tocskip}
371 {}{\typeout{Couldn't patch \string\@starttoc}}
372 % \end{macrocode}
373 %
374 %
375 %
376 %
377 % \subsubsection{Standard headings}
378 %
379 % For the same reason we don't want to see an additional \cs{parskip}
380 % being added before and after a display heading, so we subtract its
381 % value (in two places):
382 % \begin{macrocode}
383 \patchcmd\@startsection
384 {\addvspace\@tempskipa}
385 {\advance\@tempskipa-\parskip\addvspace\@tempskipa}
386 {}{\typeout{Couldn't patch \string\@startsection}}
387 % \end{macrocode}
388 %
389 % \begin{macrocode}
390 \patchcmd\@xsect
391 {\vskip\@tempskipa}
392 {\advance\@tempskipa-\parskip\vskip\@tempskipa}
393 {}{\typeout{Couldn't patch \string\@xsect}}
394 % \end{macrocode}
395 %
396 %
397 %
398 %
399 % \subsubsection{\pkg{titlesec} headings}
400 %
401 % If \pkg{titlesec} is used then headings are built using different
402 % commands and we have to cancel the \cs{parskip} there. The principle
403 % is the same. Of course, the patching should only happen if that
404 % package really got loaded, so we defer it to the start of the
405 % document and test for it:
406 % \begin{macrocode}
407 \AtBeginDocument{%
408 \ifx\ttl@straight@ii\@undefined\else % titlesec got loaded
409 \patchcmd\ttl@straight@ii
410 {\addvspace{\@tempskipa}}%
411 {\advance\@tempskipa-\parskip \addvspace\@tempskipa}%
412 {}{\typeout{Couldn't patch \string\ttl@straight@ii}}%
413 \patchcmd\ttl@straight@ii
414 {\vspace{\@tempskipb}}%
415 {\advance\@tempskipb-\parskip \vspace\@tempskipb}%
416 {}{\typeout{Couldn't patch \string\ttl@straight@ii}}%
417 \patchcmd\ttl@part@ii
418 {\vspace*{\@tempskipa}}%
419 {\advance\@tempskipa-\parskip \vspace*\@tempskipa}%
420 {}{\typeout{Couldn't patch \string\ttl@part@ii}}%
421 \patchcmd\ttl@part@ii
422 {\vspace{\@tempskipb}}%
423 {\advance\@tempskipb-\parskip \vspace\@tempskipb}%
424 {}{\typeout{Couldn't patch \string\ttl@part@ii}}%
425 \patchcmd\ttl@page@ii
426 {\vspace*{\@tempskipa}}%
427 {\advance\@tempskipa-\parskip \vspace*\@tempskipa}%
428 {}{\typeout{Couldn't patch \string\ttl@page@ii}}%
429 \patchcmd\ttl@page@ii
430 {\vspace{\@tempskipb}}%
431 {\advance\@tempskipb-\parskip \vspace\@tempskipb}%
432 {}{\typeout{Couldn't patch \string\ttl@page@ii}}%
433 \fi}
434 % \end{macrocode}
435 %
436 %
437 %
438 % \subsubsection{\pkg{amsthm} theorems}
439 %
440 % The \pkg{amsthm} package is one of the few packages that make an
441 % explicit correction for \cs{parskip} which isn't any longer adequate
442 % if this \pkg{parskip} package is loaded. We therefore remove that
443 % setting from the package if it was loaded.
444 % \changes{v2.0b}{2018/09/17}{Support \cs{amsthm} (sx/450551)}
445 % \begin{macrocode}
446 \AtBeginDocument{%
447 \ifx\deferred@thm@head\@undefined\else % amsthm got loaded
448 \patchcmd\deferred@thm@head
449 {\addvspace{-\parskip}}{}%
450 {}{\typeout{Couldn't patch \string\deferred@thm@head!}}%
451 \fi}
452 % \end{macrocode}
453 %
454 %
455 % \subsection{Closing shop}
456 %
457
458 % \begin{macrocode}
459 %<*package>
460 % \end{macrocode}
461 %
462 % \Finale
463 %
464 \endinput