Debian Codegraph @

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

raw
1
2 %%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5%%%%%%%%%6
3 % Bundled source file for the NEEDSPACE package
4 %--------1---------2---------3---------4---------5---------6
5 % Please see the accompanying README for author,
6 % license, documentation and installation information
7 %%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5%%%%%%%%%6
8
9
10 %%%%%%%%%%%%%%%%%%%%
11 %% PACKAGE SOURCE %%
12 %%%%%%%%%%%%%%%%%%%%
13
14 \begin{filecontents*}[overwrite]{needspace.sty}
15
16 %% See needspace.dtx for Copyright and other information
17
18 \NeedsTeXFormat{LaTeX2e}
19 \ProvidesPackage{needspace}[2025/03/13 v1.3e reserve vertical space]
20
21 \newcommand{\needspace}[1]{%
22 \ifhmode \ifinner \@LRmoderr \else \par \fi \fi
23 \begingroup
24 \@tempskipb \lastskip
25 \vskip -\@tempskipb
26 \setlength\dimen@{#1}%
27 \advance\dimen@\@tempskipb
28 \vskip\z@\@plus\dimen@
29 \penalty -100
30 \vskip\z@\@plus -\dimen@
31 \vskip\dimen@
32 \penalty 9999%
33 \vskip -\dimen@
34 \vskip\@tempskipb % reinsert \lastskip
35 \endgroup
36 }
37
38 \newcommand\Needspace{%
39 \ifhmode \ifinner \@LRmoderr \else \par \fi \fi
40 \@tempskipb \lastskip
41 \vskip -\@tempskipb
42 \penalty-100
43 \begingroup
44 \@ifstar{\@sneedsp@}{\@needsp@}%
45 }
46
47 \newcommand\@sneedsp@[1]{%
48 \setlength\dimen@{#1}%
49 \advance\dimen@\@tempskipb
50 \dimen@ii\pagegoal \advance\dimen@ii-\pagetotal
51 \ifdim \dimen@>\dimen@ii
52 \break
53 \else
54 \vskip\@tempskipb % reinsert \lastskip
55 \fi
56 \endgroup
57 }
58
59 \newcommand\@needsp@[1]{%
60 \setlength\dimen@{#1}%
61 \advance\dimen@\@tempskipb
62 \dimen@ii\pagegoal \advance\dimen@ii-\pagetotal
63 \ifdim \dimen@>\dimen@ii
64 \ifdim \dimen@ii>\z@
65 \vfil
66 \fi
67 \break
68 \else
69 \vskip\@tempskipb % reinsert \lastskip
70 \fi
71 \endgroup
72 }
73
74 \end{filecontents*}
75 %%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5
76
77
78 % Conditionally compile the documentation & generate the .ins file:
79 \providecommand\documentationCompile{Y}
80 \makeatletter
81 \if\documentationCompile N
82 \expandafter\@@end
83 \fi
84
85
86 \begin{filecontents*}{needspace.ins}
87 %&latex
88 \def\documentationCompile{N}
89 \input needspace.dtx
90 \csname@@end\endcsname
91 \end{filecontents*}
92
93
94 %%%%%%%%%%%%%%%%%%%
95 %% DOCUMENTATION %%
96 %%%%%%%%%%%%%%%%%%%
97
98 \documentclass{ltxdoc}
99 \usepackage[it,medium]{titlesec}
100 \usepackage[T1]{fontenc}
101 \usepackage{microtype}
102 \usepackage{lmodern}
103 \usepackage[sc,osf]{mathpazo}
104 \linespread{1.1}
105 \frenchspacing
106
107 \usepackage{fancyvrb}
108
109 \usepackage[svgnames]{xcolor}
110 \usepackage[colorlinks,linktocpage]{hyperref}
111 \DeclareRobustCommand\pkg{\textsf}
112
113 \usepackage{needspace}
114 \GetFileInfo{needspace.sty}
115
116 \begin{document}
117
118 \title{The \pkg{needspace} package}
119 \author{%
120 Author: Peter Wilson, Herries Press\\
121 Maintainer: \LaTeX{} Project team\\
122 \url{https://github.com/LaTeX-Package-Repositories/herries-press}%
123 }
124 \date{\fileversion \qquad \filedate}
125
126 \maketitle
127
128 \section{Documentation}
129
130 This packages two commands, \cs{needspace} and \cs{Needspace}, for reserving
131 space to keep a certain amount of material from being split over a page break.
132 If there is not enough space, a \verb|\newpage| is automatically inserted.
133
134 The \cs{needspace}\meta{length} macro reserves an \emph{approximate}
135 amount of space \meta{length} for the material following to be kept on
136 the same page. The accuracy of its calculations depend on what
137 penalties are in effect, but is efficient and normally adequate. A
138 short page will be ragged bottom even if \cs{flushbottom} is in
139 effect.
140
141 \cs{Needspace}\marg{length} is less efficient but reserves the
142 requested space \meta{length} exactly. It should only be used between
143 paragraphs. Short pages that are produced by \cs{Needspace} will be
144 ragged bottom but short pages produced by \cs{Needspace*}\marg{length}
145 will be flush bottom if \cs{flushbottom} is in effect.
146
147 \section{Examples}
148
149 Here, we request that we need next five lines on a single page/column:
150 \begin{verbatim}
151 ... previous text.
152
153 \needspace{5\baselineskip}
154 The next five lines ...
155 \end{verbatim}
156
157 \newpage
158 \noindent
159 In this case, the space is reserved more accurately:
160 \begin{verbatim}
161 ... previous text.
162
163 \Needspace*{4\baselineskip}
164 The major principles are:
165 \begin{itemize}
166 \item ...
167 \end{verbatim}
168
169
170 \section*{Licence and copyright}
171
172 This work may be modified and/or distributed under the terms and
173 conditions of the \LaTeX\ Project Public
174 License\footnote{\url{http://www.latex-project.org/lppl.txt}},
175 version~1.3c or later (your choice). The current maintainer of this
176 work is the \LaTeX{} Project team.
177
178 \bigskip
179 \noindent
180 Copyright Peter Wilson, 1996--2003 \\
181 Copyright Will Robertson, 2010, 2013\\
182 Copyright LaTeX Project, 2025
183
184 \clearpage
185 \parindent=0pt
186
187 \section{Implementation}
188 \VerbatimInput{needspace.sty}
189
190 \end{document}