Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 % noindentafter.dtx
3 %<*identify>
4 %
5 % noindentafter -- purposefully prevention of paragraph indentation
6 %
7 %% ----------------------------------------------------------------------------
8 %%
9 %% Copyright (C) Michiel Helvensteijn, 2014-2021
10 %% Copyright (C) Falk Hanisch <[email protected]>, 2021-2021
11 %%
12 %% ----------------------------------------------------------------------------
13 %%
14 %% This work may be distributed and/or modified under the conditions of the
15 %% LaTeX Project Public License, version 1.3c of the license. The latest
16 %% version of this license is in
17 %% http://www.latex-project.org/lppl.txt
18 %% and version 1.3c or later is part of all distributions of
19 %% LaTeX version 2008-05-04 or later.
20 %%
21 %% This work has the LPPL maintenance status "author-maintained".
22 %%
23 %% The current maintainer and author of this work is Falk Hanisch.
24 %%
25 %% This work consists of the main source file README.md, LICENSE.md,
26 %% noindentafter.dtx and the derived documentation noindentafter.pdf
27 %%
28 %% ----------------------------------------------------------------------------
29 %%
30 %</identify>
31 % \fi
32 %
33 % \iffalse
34 %<*dtx>
35 \ifx\documentclass\undefined
36 \input docstrip.tex
37 \keepsilent
38
39 \preamble
40
41 noindentafter -- purposefully prevention of paragraph indentation
42
43 \endpreamble
44 \askforoverwritefalse
45 \usedir{tex/latex/noindentafter}
46 \generate{%
47 \usepreamble\defaultpreamble
48 \file{noindentafter.sty}{
49 \from{noindentafter.dtx}{package,identify}
50 \from{noindentafter.dtx}{package,body}
51 }
52 }
53 \else
54 \let\endbatchfile\relax
55 \fi
56 \endbatchfile
57 %</dtx>
58 % \fi
59 %
60 % \iffalse
61 %<*dtx|package&identify>
62 \NeedsTeXFormat{LaTeX2e}[2020-10-01]
63 %<*dtx>
64 \ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
65 \ProvidesFile{noindentafter.dtx}
66 %</dtx>
67 %<package&identify>\ProvidesPackage{noindentafter}
68 [2021-05-14 v1.00 purposefully prevention of paragraph indentation]
69 %</dtx|package&identify>
70 % \fi
71 %
72 % \iffalse
73 %<*dtx>
74 \documentclass[english,xindy]{tudscrdoc}
75 \KOMAoptions{parskip=false}
76 \usepackage{iftex}
77 \iftutex
78 \usepackage{fontspec}
79 \else
80 \usepackage[T1]{fontenc}
81 \fi
82 \usepackage{babel}
83 % normalized vskip for listings
84 \newlength\niavskip
85 \AtBeginDocument{%
86 \ifdim\parskip>\bigskipamount%
87 \setlength\niavskip{\parskip}%
88 \else%
89 \setlength\niavskip{\bigskipamount}%
90 \fi%
91 }
92 \newcommand*\nianormalizedvskip{\vskip\glueexpr\niavskip-\parskip\relax}
93 % listings style
94 \usepackage{xcolor}
95 \usepackage{quoting}
96 \usepackage{listings}
97 \lstset{%
98 inputencoding=utf8,extendedchars=true,%
99 literate=%
100 {ä}{{\"a}}1 {ö}{{\"o}}1 {ü}{{\"u}}1
101 {Ä}{{\"A}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1
102 {ß}{{\ss}}1 {~}{{\textasciitilde}}1
103 {»}{{\guillemetright}}1 {«}{{\guillemetleft}}1
104 }
105 \lstdefinestyle{noindentafter}{%
106 language=[LaTeX]tex,%
107 columns=flexible,%
108 frame=single,%
109 xleftmargin=\fboxsep,%
110 xrightmargin=\fboxsep,%
111 escapechar=§,%
112 aboveskip=\niavskip,%
113 belowskip=0pt,%
114 backgroundcolor=\color{yellow!10},%
115 basicstyle=\color{darkgray}\small\ttfamily,%
116 moretexcs=[2]{NoIndentAfterThis,NoIndentAfterCmd,NoIndentAfterEnv},%
117 texcsstyle=*\color{black},%
118 texcsstyle=*[2]\color{red}\bfseries,%
119 }
120 \lstnewenvironment{niaexample}[1][]{%
121 \lstset{style=noindentafter,#1}%
122 }{%
123 \nianormalizedvskip%
124 }
125 \makeatletter
126 % suppress overwriting warning
127 \providecommand*\filec@ntents@silent{%
128 \let\@latex@warning@no@line\@gobble%
129 }
130 % environment for listing and inclusion, unused guard <manual> necessary
131 \newenvironment{niashow}{%
132 \csuse{filecontents*}[force,nosearch,silent]{\jobname-lst.aux}%
133 }{%
134 \csuse{endfilecontents*}%
135 }%
136 \AfterEndEnvironment{niashow}{%
137 \begin{quoting}[rightmargin=0pt,vskip=0pt]
138 \lstinputlisting[style=noindentafter]{\jobname-lst.aux}%
139 \nianormalizedvskip%
140 \input{\jobname-lst.aux}%
141 \nianormalizedvskip%
142 \end{quoting}%
143 }
144 \newcommand*\niaagain[1][\relax]{%
145 #1%
146 \begin{quoting}[rightmargin=0pt,vskip=0pt]
147 \nianormalizedvskip%
148 \input{\jobname-lst.aux}%
149 \nianormalizedvskip%
150 \end{quoting}%
151 }
152 % TODO l3doc + l3build
153 \NewDocumentCommand\DescribeMacroExtended{m !o}{%
154 \ifhmode%
155 \vskip\niavskip%
156 \else%
157 \addpenalty{\@beginparpenalty}%
158 \addvspace{\niavskip}%
159 \fi%
160 \noindent%
161 \DescribeMacro{#1}%
162 \IfValueT{#2}{%
163 \expandafter\cs\expandafter{\expandafter\@gobble\string#1}#2%
164 \vskip\smallskipamount%
165 }%
166 \noindent\ignorespaces%
167 }
168 \makeatother
169
170 \usepackage{bookmark}
171 \usepackage[babel]{microtype}
172
173 \usepackage{noindentafter}
174 \NoIndentAfterEnv{niaexample}
175 \NoIndentAfterEnv{niashow}
176 \NoIndentAfterCmd{\niaagain}
177
178
179 %\EnableCrossrefs
180 \CodelineIndex
181 \RecordChanges
182 \GetFileInfo{noindentafter.dtx}
183
184
185
186 \begin{document}
187 \title{The package \pkg{noindentafter}}
188 \author{%
189 Michiel Helvensteijn (2014-2021)\\%
190 Falk Hanisch (2021--)\\%
191 \url{https://github.com/mrpiggi/noindentafter}\\%
192 \mailto{[email protected]}%
193 }
194 \date{\fileversion\nobreakspace(\filedate)}
195 \maketitle%
196 \begin{abstract}
197 \noindent
198 For certain environments---such as \env{itemize} or \env{theorem}---as
199 well as specific commands, indentation of the following paragraph is not
200 desired. It is of course possible to manually add \cs{noindent} to each
201 occurrence, but it is very easy to forget this at one point or another.
202 This package provides a few simple commands which can be used to patch
203 existing macros and environments in order to get rid of manually using
204 \cs{noindent} after these. Therefore, both packages \pkg{etoolbox} and
205 \pkg{xpatch} are required.
206 \end{abstract}
207 %\tableofcontents
208 \setcounter{secnumdepth}{0}
209 \DocInput{\filename}
210 \end{document}
211 % \fi
212 %
213 \changes{v0.0.1}{2013-08-02}{initial version by Michiel Helvensteijn}
214 \changes{v0.2.0}{2014-11-30}{new implementation, fixing a spacing issue}
215 \changes{v0.2.2}{2014-11-30}{fixed version number in the README}
216 \changes{v1.00}{2021-05-11}{new maintainer: Falk Hanisch}^^A
217 \changes{v1.00}{2021-05-14}{fix for \LaTeXe\ 2019-10-01 and later}
218
219
220
221 \section{Usage}
222
223 The package does not provide additional options and is used in the simplest way
224 possible:
225
226 \begin{niaexample}
227 \usepackage{noindentafter}
228 \end{niaexample}
229
230 In order to ensure a consistent layout throughout the document, it is
231 recommended---but not mandatory---to use the commands described below within
232 the preamble after loading package \pkg{noindentafter}.
233
234
235
236 \DescribeMacroExtended{\NoIndentAfterEnv}[\marg{environment}]
237 This is probably the most frequently needed functionality. After using this
238 command, any paragraph following such an \marg{environment} will remain
239 unindented. The example below shows the default output without the involvement
240 of \pkg{noindentafter}.
241
242 \begin{niashow}
243 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
244 vestibulum ut, placerat ac, adipiscing vitae, felis.
245
246 \begin{itemize}
247 \item First Item
248 \item Second Item
249 \end{itemize}
250
251 Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer
252 id, vulputate a, magna. Donec vehicula augue eu neque.
253
254 Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac
255 turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem.
256 \end{niashow}
257
258 Once \lstinline[style=noindentafter]|\NoIndentAfterEnv{itemize}| has been
259 executed, the output differs by the \emph{unintended} paragraph directly after
260 the \env{itemize} environment: \niaagain[\NoIndentAfterEnv{itemize}]
261
262 Note that using the \cs{NoIndentAfterEnv} command on an environment is not the
263 same as adding \cs{NoIndentAfterThis} to the end of it:^^A
264 \footnote{\cs{NoIndentAfterEnv} bypasses the group that surrounds environments}
265
266 \begin{niashow}
267 \newenvironment{mytestenv}{\itshape}{\NoIndentAfterThis}
268 \begin{mytestenv}
269 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
270 vestibulum ut, placerat ac, adipiscing vitae, felis.
271 \end{mytestenv}
272
273 Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer
274 id, vulputate a, magna. Donec vehicula augue eu neque.
275 \end{niashow}
276
277
278
279
280 \DescribeMacroExtended{\NoIndentAfterCmd}[\marg{command}]
281 By using \cs{NoIndentAfterCmd}, macros can be modified. There probably may not
282 be many situations where this is useful, but perhaps this one:
283
284 \begin{niashow}
285 Lorem ipsum dolor sit amet, consectetuer adipiscing elit:
286
287 \[ 1 + 1 = 2 \]
288
289 Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
290 dictum gravida mauris:
291
292 \NoIndentAfterCmd{\]}
293
294 \[ 2 + 2 = 4 \]
295
296 Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec
297 vehicula augue eu neque.
298 \end{niashow}
299
300
301
302 \DescribeMacroExtended{\NoIndentAfterThis}
303 Finally, this is the most primitive macro offered by the package. It forces a
304 paragraph break and suppresses indentation for whatever follows:
305
306 \begin{niashow}
307 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
308 vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
309 mauris. \NoIndentAfterThis Nam arcu libero, nonummy eget, consectetuer id,
310 vulputate a, magna. Donec vehicula augue eu neque.
311 \end{niashow}
312
313
314
315 \section{Acknowledgements}
316 This package resulted from \url{http://tex.stackexchange.com/q/112404} and the
317 excellent responses to it by \textsc{cgnieder} and \textsc{lockstep}. Although
318 it initially based on the proposed solution by \textsc{cgnieder}---as it was
319 simpler and more generally applicable---the answer by \textsc{lockstep} is
320 definitely worth reading.
321
322
323
324 \StopEventually{^^A
325 \cleardoublepage\PrintIndex^^A
326 \PrintChanges^^A
327 \PrintToDos^^A
328 }
329 %
330 % \iffalse
331 %</dtx>
332 %<*package&body>
333 % \fi
334 %
335 %^^A \cleardoublepage
336 %^^A \appendix
337 % \section{Implementation}
338 % The only required packages are \pkg{etoolbox} as well as \pkg{xpatch}.
339 % \begin{macrocode}
340 \RequirePackage{etoolbox}
341 \RequirePackage{xpatch}
342 % \end{macrocode}
343 %
344 % \begin{macro}{\nia@scan}
345 % This command implements the main principle behind this package. It checks
346 % whether it is followed by a paragraph. If so, the command \cs{par} is
347 % temporarily changed using \cs{everypar}, so that the following paragraph is
348 % not indented. Immediately afterwards, default paragraph behavior is restored
349 % with \cs{@restorepar} (from the \LaTeXe\ kernel).
350 % \begin{macrocode}
351 \newcommand*\nia@scan{%
352 \kernel@ifnextchar\par{%
353 \par%
354 \def\par{%
355 \everypar{\setbox\z@\lastbox\everypar{}}%
356 \@restorepar%
357 }%
358 }{}%
359 }
360 % \end{macrocode}
361 % \end{macro}^^A \nia@scan
362 %
363 % \begin{macro}{\nia@afterendenv}
364 % This command is used for hooking into the ending routine of an environment at
365 % the latest possible point after \cs{ignorespaces}. It is heavily inspired by
366 % David Carlisle\footnote{\url{https://tex.stackexchange.com/a/179034/38481}}
367 % and uses a delimited argument in order to apply \cs{nia@scan} last.
368 %
369 % It is invoked via hook \cs{AfterEndEnvironment} provided by \pkg{etoolbox}
370 % and leaves everything between its invocation and \cs{ignorespaces}|\fi| at
371 % the very end of \cs{end} unchanged---even additonal material given through
372 % the same hook---and finally executes \cs{nia@scan}.
373 % \begin{macrocode}
374 \newcommand*\nia@afterendenv{}
375 \def\nia@afterendenv#1\ignorespaces\fi{#1\ignorespaces\fi\nia@scan}
376 % \end{macrocode}
377 % \end{macro}^^A \nia@afterendenv
378 %
379 % \begin{macro}{\NoIndentAfterThis}
380 % \begin{macro}{\NoIndentAfterCmd}
381 % \begin{macro}{\NoIndentAfterEnv}
382 % These are finally the user-level commands to activate the funtionality of
383 % \pkg{noindetafter} for the given \marg{environment}/\marg{macro} as well as
384 % immediate execution.
385 % \begin{macrocode}
386 \newrobustcmd*\NoIndentAfterThis{\nia@scan\par}
387 \newcommand*\NoIndentAfterCmd[1]{%
388 \xapptocmd#1{\NoIndentAfterThis}{}{%
389 \PackageWarning{noindentafter}{%
390 Patching `\string#1' failed!\MessageBreak%
391 `\string\NoIndentAfterCmd{\string#1}' won't work%
392 }%
393 }%
394 }
395 \newcommand*\NoIndentAfterEnv[1]{\AfterEndEnvironment{#1}{\nia@afterendenv}}
396 % \end{macrocode}
397 % \end{macro}^^A \NoIndentAfterEnv
398 % \end{macro}^^A \NoIndentAfterCmd
399 % \end{macro}^^A \NoIndentAfterThis
400 %
401 % \iffalse
402 %</package&body>
403 % \fi
404 %
405 % \Finale
406 %
407 \endinput