| 1 |
% \iffalse meta-comment |
| 2 |
% ====================================================================== |
| 3 |
% setspaceenhanced.dtx |
| 4 |
% Copyright © 2008–2024 Markus Kohm |
| 5 |
% |
| 6 |
% This work is a KOMA-Script spin-off. For the original sources of |
| 7 |
% KOMA-Script's `float.hak' see file `scrhack.dtx' in the KOMA-Script |
| 8 |
% sources at <https://sourceforge.net/p/koma-script/code/>. |
| 9 |
% |
| 10 |
% Development is taking place as part of `scrhack' at |
| 11 |
% <https://github.com/komascript/third-party-enhancements>. New issues |
| 12 |
% should be reported there as well as known issues can be found. |
| 13 |
% |
| 14 |
% This work may be distributed and/or modified under the conditions of |
| 15 |
% the LaTeX Project Public License, version 1.3c of the license. |
| 16 |
% The latest 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 LaTeX |
| 19 |
% version 2005/12/01 or later and of this work. |
| 20 |
% |
| 21 |
% The Current Maintainer and author of this work is Markus Kohm. |
| 22 |
% |
| 23 |
% This work consists of the file `setspaceenhanced.dtx' and `README.md'. |
| 24 |
% |
| 25 |
% The recommended way to install `setspaceenhanced' is to use |
| 26 |
% the package manager of your TeX distribution. |
| 27 |
% ====================================================================== |
| 28 |
% |
| 29 |
%<*dtx> |
| 30 |
\ifx\ProvidesExplFile\undefined\def\ProvidesExplFile#1#2#3#4{}\fi |
| 31 |
\ProvidesExplFile{setspaceenhanced.dtx} |
| 32 |
%</dtx> |
| 33 |
%<*dtx|package> |
| 34 |
%<package>\ProvidesExplPackage{setspaceenhanced} |
| 35 |
{2024-11-12}{1.04} |
| 36 |
{% |
| 37 |
%<*dtx> |
| 38 |
sources and unpack driver of |
| 39 |
%</dtx> |
| 40 |
improved setspace package% |
| 41 |
} |
| 42 |
%</dtx|package> |
| 43 |
%<*dtx> |
| 44 |
\ifx\documentclass\undefined |
| 45 |
\input docstrip.tex |
| 46 |
\generate{% |
| 47 |
\file{setspaceenhanced.sty}{% |
| 48 |
\from{setspaceenhanced.dtx}{package}% |
| 49 |
}% |
| 50 |
}% |
| 51 |
\else |
| 52 |
\let\endbatchfile\ExplSyntaxOff |
| 53 |
\fi |
| 54 |
\endbatchfile |
| 55 |
\documentclass[ngerman,USenglish]{koma-script-source-doc} |
| 56 |
\NewDocElement[% |
| 57 |
macrolike = true, |
| 58 |
toplevel = true, |
| 59 |
idxtype = \textit{const.}, |
| 60 |
idxgroup = Constants, |
| 61 |
printtype = \textit{const.}, |
| 62 |
]{Constant}{Constant} |
| 63 |
\NewDocElement[% |
| 64 |
macrolike = true, |
| 65 |
toplevel = true, |
| 66 |
idxtype = \textit{var.}, |
| 67 |
idxgroup = Variable, |
| 68 |
printtype = \textit{var.}, |
| 69 |
]{Variable}{Variable} |
| 70 |
\usepackage{babel} |
| 71 |
\usepackage{csquotes} |
| 72 |
\usepackage[style=alphabetic]{biblatex} |
| 73 |
\begin{filecontents}[force]{\jobname.bib} |
| 74 |
@online{pkg:setspace, |
| 75 |
author={David Carlisle and Erica Harris and Geoffrey Tobin and |
| 76 |
Robin Fairbairns}, |
| 77 |
title={\pkg*{setspace} --- Set space between lines}, |
| 78 |
version={6.7b}, |
| 79 |
date={2022-12-04}, |
| 80 |
url={https://ctan.org/pkg/setspace}, |
| 81 |
urldate={2023-07-25}, |
| 82 |
note={Provides support for setting the spacing between lines in a |
| 83 |
document. Package options include \opt{singlespacing}, |
| 84 |
\opt{onehalfspacing}, and \opt{doublespacing}. Alternatively |
| 85 |
the spacing can be changed as required with the |
| 86 |
\cs{singlespacing}, \cs{onehalfspacing}, and |
| 87 |
\cs{doublespacing} commands. Other size spacings also |
| 88 |
available.}, |
| 89 |
} |
| 90 |
@manual{pkg:setspace:manual, |
| 91 |
author={Geoffrey Tobin and Robin Fairbairns}, |
| 92 |
date={2022-12-04}, |
| 93 |
title={The \pkg*{setspace} Package}, |
| 94 |
url={https://ctan.org/tex-archive/macros/latex/contrib/setspace}, |
| 95 |
urldate={2023-07-25}, |
| 96 |
abstract={}, |
| 97 |
} |
| 98 |
@online{pkg:scrlfile, |
| 99 |
author = {Markus Kohm}, |
| 100 |
version = {3.41}, |
| 101 |
date = {2023-07-07}, |
| 102 |
title = {\pkg*{scrlfile} – Installation control (not only) for |
| 103 |
\KOMAScript{} packages}, |
| 104 |
url = {https://ctan.org/pkg/scrlfile}, |
| 105 |
urldate = {2023-07-19}, |
| 106 |
note = {The package provides hooks for the execution of commands before |
| 107 |
or after loading files, classes or packages independent from the |
| 108 |
\LaTeX{} kernel version.}, |
| 109 |
} |
| 110 |
@online{pkg:koma-script, |
| 111 |
author={Markus Kohm}, |
| 112 |
version={3.41}, |
| 113 |
date={2023-07-07}, |
| 114 |
title={{\KOMAScript} --- A bundle of versatile classes and packages}, |
| 115 |
url={https://ctan.org/pkg/koma-script}, |
| 116 |
urldate={2023-07-14}, |
| 117 |
note={The \KOMAScript{} bundle provides replacements for the \pkg*{article}, |
| 118 |
\pkg*{report}, and \pkg*{book} classes with emphasis on typography and |
| 119 |
versatility. There is also a letter class.}, |
| 120 |
} |
| 121 |
@manual{pkg:koma-script:manual:de, |
| 122 |
author={Markus Kohm}, |
| 123 |
date={2023-06-16}, |
| 124 |
title={{\KOMAScript}}, |
| 125 |
subtitle={Die Anleitung}, |
| 126 |
url={http://mirrors.ctan.org/macros/latex/contrib/koma-script/scrguide-de.pdf}, |
| 127 |
urldate={2023-07-04}, |
| 128 |
} |
| 129 |
@manual{pkg:koma-script:manual:en, |
| 130 |
author={Markus Kohm}, |
| 131 |
date={2023-06-16}, |
| 132 |
title={{\KOMAScript}}, |
| 133 |
subtitle={The Guide}, |
| 134 |
url={http://mirrors.ctan.org/macros/latex/contrib/koma-script/scrguide-en.pdf}, |
| 135 |
urldate={2023-07-14}, |
| 136 |
} |
| 137 |
@article{latexnews35, |
| 138 |
author={{The {\LaTeX} Project Team}}, |
| 139 |
shortauthor={TLT}, |
| 140 |
year={2022}, |
| 141 |
month={6}, |
| 142 |
title={Issue 35}, |
| 143 |
journal={{\LaTeX} News}, |
| 144 |
url={http://mirrors.ctan.org/macros/latex/base/ltnews35.pdf}, |
| 145 |
urldate={2023-07-14}, |
| 146 |
} |
| 147 |
\end{filecontents} |
| 148 |
\addbibresource{\jobname.bib} |
| 149 |
\setcounter{StandardModuleDepth}{2} |
| 150 |
\begin{document} |
| 151 |
\nocite{pkg:setspace,pkg:koma-script} |
| 152 |
\DocInput{setspaceenhanced.dtx} |
| 153 |
\end{document} |
| 154 |
%</dtx> |
| 155 |
%\fi |
| 156 |
% |
| 157 |
% \changes{v0.1}{2023/06/01}{new \KOMAScript{} spin-off} |
| 158 |
% \changes{v1.0}{2023/08/04}{release} |
| 159 |
% |
| 160 |
% \GetFileInfo{setspaceenhanced.dtx} |
| 161 |
% \title{Improving ``\pkg{setspace}''} |
| 162 |
% \author{\href{mailto:[email protected]}{Markus Kohm}\thanks{Repository and |
| 163 |
% bug reports: |
| 164 |
% \url{https://github.com/komascript/third-party-enhancements}}} |
| 165 |
% \date{Version \filedate{} \fileversion} |
| 166 |
% \maketitle |
| 167 |
% \begin{abstract} |
| 168 |
% Package \pkg*{setspaceenhanced} has started as hack module of the |
| 169 |
% \KOMAScript{} package \pkg*{scrhack} years ago to fix an issue when using |
| 170 |
% package \pkg{setspace} with other document font sizes than 10\,pt, 11\,pt |
| 171 |
% or 12\,pt. This became necessary because package \pkg{setspace} originally |
| 172 |
% only supported these three font sizes and loading the package with a |
| 173 |
% floating point definition of \cs{@ptsize} even resulted in errors. These |
| 174 |
% two issues has been fixed some years ago. Now, \pkg{setspace} uses a |
| 175 |
% static factor for all font sizes but 10\,pt, 11\,pt, or |
| 176 |
% 12\,pt. |
| 177 |
% |
| 178 |
% Additionally, if you change font size inside the document |
| 179 |
% \pkg{setspace} still uses the stretch factor of the document font size |
| 180 |
% instead of using a proper stretch factor for the new font size. |
| 181 |
% |
| 182 |
% Package \pkg*{setspaceenhanced} provides improvements for all these |
| 183 |
% limitations and also some additional enhancements. |
| 184 |
% \end{abstract} |
| 185 |
% |
| 186 |
% \tableofcontents |
| 187 |
% |
| 188 |
%\iffalse |
| 189 |
%<*doc> |
| 190 |
%\fi |
| 191 |
\section{Why should I use this package instead of |
| 192 |
\texorpdfstring{\pkg{setpace}}{setspace} at least if I use a \KOMAScript{} |
| 193 |
class or \KOMAScript{} package \texorpdfstring{\pkg{scrextend}}{scrextend} |
| 194 |
or a similar package?} |
| 195 |
\label{sec:whywithkomascript} |
| 196 |
|
| 197 |
From 2006 \href{https://www.ctan.org/pkg/koma-script}{\KOMAScript} classes and |
| 198 |
\KOMAScript{} package \pkg{scrextend} provide option \opt{fontsize} for |
| 199 |
setting document font sizes not limited to 10\,pt, 11\,pt, or 12\,pt. Using |
| 200 |
this option is also not limited to integer font sizes but also supports |
| 201 |
floating point sizes like 11.5\,pt. To support such font sizes, the |
| 202 |
specification of macro \cs{@ptsize} has been changed to be no longer either 0, |
| 203 |
1 or 2 but to be the font size minus 10 in pt. |
| 204 |
|
| 205 |
By the way, e.g., Ivan Valbusa's package \pkg{fontsize} adopted this existing |
| 206 |
definition of \cs{@ptsize} from \KOMAScript{} by using most of the font size |
| 207 |
code of \KOMAScript. |
| 208 |
|
| 209 |
Unfortunately package \pkg{setspace} provides stretch factors for individual |
| 210 |
font sizes only for 10\,pt, 11\,pt or 12\,pt. For all sizes between these |
| 211 |
size, it uses the factor of the down rounded integer. For all sizes below |
| 212 |
10\,pt or 11\,pt it uses a static value, 1.25 for \cs{onehalfspacing} and |
| 213 |
1.667 for \cs{doublespacing}. Package \pkg*{setspaceenhanced} uses for |
| 214 |
\cs{onehalfspacing} and \cs{doublespacing} a calculation of the stretch factor |
| 215 |
depending on the selected baseline skip and font size. With this, every font |
| 216 |
size is supported. |
| 217 |
|
| 218 |
But that's just the tip of the iceberg and even comparatively |
| 219 |
unimportant. Much more important are the reasons in the following section, |
| 220 |
which also apply when using a \KOMAScript{} class or the \KOMAScript{} package |
| 221 |
\pkg{scrextend} or a similar package. |
| 222 |
|
| 223 |
|
| 224 |
\section{Why should I use this package instead of |
| 225 |
\texorpdfstring{\pkg{setpace}}{setspace} independent from using a |
| 226 |
\KOMAScript{} class or \KOMAScript{} package |
| 227 |
\texorpdfstring{\pkg{scrextend}}{scrextend} or similar packages?} |
| 228 |
\label{sec:whywithoutkomascript} |
| 229 |
|
| 230 |
\pkg{setspace} does not care for the \cs{baselineskip} selected by |
| 231 |
\cs{fontsize}. Instead it sets the stretch factor always depending on the |
| 232 |
document font size. And using \cs{singlespacing}, \cs{onehalfspacing} or |
| 233 |
\cs{doublespacing} or even \cs{setstretch}\SpecialCommandIndex{\setstretch} |
| 234 |
after switching the font size using \cs{fontsize} instead of \cs{Huge}, |
| 235 |
\cs{huge}, \cs{LARGE}, \cs{Large}, \cs{large}, \cs{normalsize}, \cs{small}, |
| 236 |
\cs{footnotesize}, \cs{scriptsize}, \cs{tiny}, or another command defined |
| 237 |
using \cs{@setsize}, reactivates the last used such font size commd. So using |
| 238 |
something like |
| 239 |
\begin{verbatim} |
| 240 |
\normalsize\fontsize{5pt}{7pt}\selectfont\onehalfspacing |
| 241 |
\end{verbatim} |
| 242 |
result in \cs{normalsize} with onehalfspacing, not 5\,pt with onehalfspacing! |
| 243 |
|
| 244 |
Package \pkg*{setspaceenhanced} uses for |
| 245 |
\cs{onehalfspacing} and \cs{doublespacing} a calculation of the stretch factor |
| 246 |
depending on the selected baseline skip and font size. So using something like |
| 247 |
\begin{verbatim} |
| 248 |
\normalsize\fontsize{5pt}{7pt}\onehalfspacing |
| 249 |
\end{verbatim} |
| 250 |
will not set the stretch factor based on \cs{normalsize} but based on font |
| 251 |
size 5\,pt with baseline skip 7\,pt. So this results in real onehalfspacing |
| 252 |
of the 5\,pt font. |
| 253 |
|
| 254 |
In other words: Package \pkg*{setspaceenhanced} uses a completely different |
| 255 |
definition of \cs{onehalfspacing} and \cs{doublespacing}. It always uses |
| 256 |
\cs{f@size} and \cs{f@baselineskip} to calculate a factor resulting in real |
| 257 |
onehalfspacing and doublespacing. This also means, if you use one of these |
| 258 |
commands after changing the font size, a new stretch factor is calculated |
| 259 |
depending on the current font size without changing the font size. |
| 260 |
|
| 261 |
\section{How to use |
| 262 |
\texorpdfstring{\pkg*{setspaceenhanced}}{setspaceenhanced}?} |
| 263 |
\label{sec:howtouse} |
| 264 |
|
| 265 |
In the document preamble of your document you just can replace |
| 266 |
\begin{verbatim} |
| 267 |
\usepackage{setspace} |
| 268 |
\end{verbatim} |
| 269 |
by |
| 270 |
\begin{verbatim} |
| 271 |
\usepackage{setspaceenhanced} |
| 272 |
\end{verbatim} |
| 273 |
to load package \pkg*{setspaceenhanced}. This does still also load package |
| 274 |
\pkg{setspace} but additionally replaces several commands of \pkg{setspace} to |
| 275 |
avoid the issues shown in \autoref{sec:whywithkomascript} and |
| 276 |
\autoref{sec:whywithoutkomascript}. \pkg*{setspaceenhanced} also does support |
| 277 |
the same options as \pkg{setspace}. So you can also replace, e.g. |
| 278 |
\begin{verbatim} |
| 279 |
\usepackage[onehalfspaceing]{setspace} |
| 280 |
\end{verbatim} |
| 281 |
by |
| 282 |
\begin{verbatim} |
| 283 |
\usepackage[onehalfspacing]{setspaceenhanced} |
| 284 |
\end{verbatim} |
| 285 |
|
| 286 |
If you want you can alternatively also load both packages explicitly, either |
| 287 |
\pkg{setspace} before \pkg*{setspaceenhanced} or---if you |
| 288 |
want---\pkg*{setspaceenhanced} before \pkg{setspace}. In this case, you should |
| 289 |
use the same options for both package. |
| 290 |
|
| 291 |
This is also useful, if you use a package, that uses \pkg{setspace} itself. In |
| 292 |
this case, you always should load \pkg*{setspaceenhanced} \emph{before} the |
| 293 |
package, that uses \pkg{setspace}. Otherwise it is very likely that the |
| 294 |
initial line spacing is still done with the unchanged commands and settings of |
| 295 |
\pkg{setspace} and therefore the full functionality of \pkg*{setspaceenhanced} |
| 296 |
cannot be reached. Only if \pkg*{setspaceenhanced} is loaded before the first |
| 297 |
use of \cs{singlespacing}, \cs{onehalfspacing}, \cs{doublespacing}, or |
| 298 |
\cs{setstretch} can it be ensured that the enhancements of |
| 299 |
\pkg*{setspaceenhanced} are initialized and used correctly. |
| 300 |
|
| 301 |
When using a class that uses \pkg{setspace}, the correct operation can be |
| 302 |
ensured with |
| 303 |
\begin{verbatim} |
| 304 |
\AddToHook{package/setspace/after}{\RequirePackage{setspaceenhanced}} |
| 305 |
\end{verbatim} |
| 306 |
even before \cs{documentclass}. This requires at least \LaTeX{} |
| 307 |
2020/10/01. For older versions of \LaTeX{} you can use |
| 308 |
\begin{verbatim} |
| 309 |
\RequirePackage{scrlfile} |
| 310 |
\AfterPackage{setspace}{\RequirePackage{setspaceenhanced}} |
| 311 |
\end{verbatim} |
| 312 |
also before \cs{documentclass}. This would require the \KOMAScript{} package |
| 313 |
\pkg{scrlfile}\nocite{pkg:scrlfile}. In both cases you should also use the |
| 314 |
same optional argument for \cs{RequirePackage}, that is used for loading |
| 315 |
\pkg{setspace}. |
| 316 |
|
| 317 |
\leavevmode\marginpar{\raggedleft\footnotesize\textcolor{black}{(added 2024-11-12)}}% |
| 318 |
Note: If package \pkg{setspace} has been loaded \emph{before} package |
| 319 |
\pkg*{setspaceenhanced}, \pkg*{setspaceenhanced} uses the options to |
| 320 |
package \pkg{setspace} for the initialization. But you can overwrite the |
| 321 |
initialization by loading \pkg*{setspaceenhancded} with options or passing |
| 322 |
options to \pkg*{setspaceenhanced}. On the other hand, package \pkg{setspace} |
| 323 |
\emph{should never} be loaded with options after loading |
| 324 |
\pkg*{setspaceenhanced}. So |
| 325 |
\begin{verbatim} |
| 326 |
\usepackage[doublespacing]{setspace} |
| 327 |
\usepackage{setspaceenhanced} |
| 328 |
\end{verbatim} |
| 329 |
would be the same like |
| 330 |
\begin{verbatim} |
| 331 |
\usepackage{setspace} |
| 332 |
\usepackage[doublespacing]{setspaceenhanced} |
| 333 |
\end{verbatim} |
| 334 |
or like |
| 335 |
\begin{verbatim} |
| 336 |
\usepackage[doublespacing]{setspaceenhanced} |
| 337 |
\usepackage{setspace} |
| 338 |
\end{verbatim} |
| 339 |
or like |
| 340 |
\begin{verbatim} |
| 341 |
\usepackage[doublespacing]{setspaceenhanced} |
| 342 |
\end{verbatim} |
| 343 |
But |
| 344 |
\begin{verbatim} |
| 345 |
\usepackage{setspaceenhanced} |
| 346 |
\usepackage[doublespacing]{setspace} |
| 347 |
\end{verbatim} |
| 348 |
would fail with an option clash error, because \pkg*{setspaceenhanced} already |
| 349 |
loaded \pkg{setspace} without options. |
| 350 |
|
| 351 |
Package \pkg*{setspaceenhanced} provides all options and commands of the user |
| 352 |
interface of \pkg{setspace}, see \autocite{pkg:setspace:manual}. Following we |
| 353 |
document only the differences and enhancements. |
| 354 |
|
| 355 |
There are some options influencing the behavior and result of the examples |
| 356 |
shown in the section before. All these options are |
| 357 |
\opt{\meta{key}=\meta{value}} options using the new \LaTeX{} kernel |
| 358 |
interface. Therefore the package needs at least \LaTeX{} 2022-06-01. |
| 359 |
|
| 360 |
\DescribeCommand{\spacesetup} |
| 361 |
Options can be set as global option via \cs{documentclass}, as package option |
| 362 |
via \cs{usepackage} or using: |
| 363 |
\begin{quote} |
| 364 |
\cs{spacesetup}\marg{options} |
| 365 |
\end{quote} |
| 366 |
The command can be used in the document preamble and also in the document |
| 367 |
body. In the document body the changes are local to the current |
| 368 |
group. |
| 369 |
|
| 370 |
\subsubsection*{Available options:} |
| 371 |
|
| 372 |
\begin{description}\setkomafont{descriptionlabel}{\ttfamily} |
| 373 |
\item[byselectfont=\meta{boolean}]% |
| 374 |
\DescribeOption{byselectfont}% |
| 375 |
\hfill initial=\optvalue{false}, default=\optvalue{true}\\ |
| 376 |
In the \pkg*{setspaceenhanced} examples in the previous section, the correct |
| 377 |
factor has only been used, because of using \cs{onehalfspacing} after |
| 378 |
changing the font size, e.g., to \cs{small}. If you use \cs{onehalfspacing} |
| 379 |
before changing the font size, the factor is calculated with the previous |
| 380 |
valid font size, which is the document font size 12\,pt in all these |
| 381 |
examples. This\SpecialCommandIndex{\selectfont}\marginline{\cs{selectfont}} |
| 382 |
behavior can be changed to a more dynamic automatism using option |
| 383 |
\opt{byselectfont} or \opt{byselectfont=true}. This will use the generic |
| 384 |
\LaTeX{} hook \texttt{selectfont} to reactivate \cs{onehalfspacing} or |
| 385 |
\cs{doublespacing} after every \cs{selectfont} if the font size has been |
| 386 |
changed. However note, this is only done if baselineskip is not less than |
| 387 |
the font size. So for a font selection like |\fontsize{6}{0}\selectfont| the |
| 388 |
factor recalculation is ignored, because it does not make sense.\footnote{In |
| 389 |
my opinion using a baselineskip less than the font size never makes |
| 390 |
sense. But \LaTeX{} itself uses baselineskip 0 inside the definition of |
| 391 |
\cs{LaTeX}.} |
| 392 |
|
| 393 |
Please note:\marginpar{\raggedleft\raisebox{\dimexpr\ht\strutbox-\height\relax}{\Huge\textcolor{red}{!}}} |
| 394 |
The capabilities of this option are unfortunately limited. |
| 395 |
Among other things, it is dependent on the internal function of |
| 396 |
\cs{selectfont}. It can therefore lead to undesirable effects in some cases. |
| 397 |
In this case, you should disable the option either locally or globally |
| 398 |
via |\spacesetup{byselectfont=false}| or directly when loading |
| 399 |
\pkg*{setspaceenhanced}. |
| 400 |
\item[doublespacing=\meta{real}]% |
| 401 |
\DescribeOption{onehalfspacing}% |
| 402 |
\hfill initial=\texttt{nan}, default=\emph{empty}\\ |
| 403 |
If this option is used without value, it is the same as \pkg{setspace}'s |
| 404 |
package option \opt{doublespacing} or using command \cs{doublespacing}. But |
| 405 |
if you assign a real number\footnote{\label{ftn:fp}Here are all values |
| 406 |
allowed, that would be allowed as second argument of \LaTeX3 function |
| 407 |
\cs{fp\string_set:Nn}} this would be used as the new stretch factor used |
| 408 |
for doublespacing. This also means, that the default calculation of the |
| 409 |
factor is deactivated. But a factor of \texttt{nan} would reactivate the |
| 410 |
calculation of the factor depending on the font size and the baseline skip |
| 411 |
set for the font size. It is recommended to use the option always without |
| 412 |
value! |
| 413 |
\item[keepfontsize=\meta{boolean}]% |
| 414 |
\DescribeOption{keepfontsize}% |
| 415 |
\marginpar{\raggedleft\footnotesize (changed 2023-09-19)}% |
| 416 |
\DescribeCommand{\setstretch}% |
| 417 |
\hfill initial=\optvalue{false}, default=\optvalue{true}\\ |
| 418 |
As explained in \autoref{sec:whywithoutkomascript}, \pkg{setspace}'s |
| 419 |
\cs{setstretch} behaves different after a font size command like \cs{Huge}, |
| 420 |
\cs{huge}, \cs{LARGE}, \cs{Large}, \cs{large}, \cs{normalsize}, \cs{small}, |
| 421 |
\cs{footnotesize}, \cs{scriptsize}, \cs{tiny}, or another command defined |
| 422 |
using \cs{@setsize} than after using |\fontsize{…}{…}\selectfont|. With the |
| 423 |
last the font size will be reset to the previous usage of one of the other |
| 424 |
or the document font size. For a lot of users this is somehow |
| 425 |
unexpected. With option \opt{keepfontsize} or \opt{keepfontsize=true} this |
| 426 |
is changed and using \cs{setstretch} does not reactivate the last used |
| 427 |
\cs{Huge}, \cs{huge}, \cs{LARGE}, \cs{Large}, \cs{large}, \cs{normalsize}, |
| 428 |
\cs{small}, \cs{footnotesize}, \cs{scriptsize}, \cs{tiny}. |
| 429 |
\item[onehalfspacing=\meta{real}]% |
| 430 |
\DescribeOption{onehalfspacing}% |
| 431 |
\hfill initial=\texttt{nan}, default=\emph{empty}\\ |
| 432 |
If this option is used without value, it is the same as \pkg{setspace}'s |
| 433 |
package option \opt{onehalfspacing} or using command |
| 434 |
\cs{onehalfspacing}. But if you assign a real number\footref{ftn:fp} this |
| 435 |
would be used as the new stretch factor used for onehalfspacing. This also |
| 436 |
means, that the default calculation of the factor is deactivated. But a |
| 437 |
factor of \texttt{nan} would reactivate the calculation of the factor |
| 438 |
depending on the font size and the baseline skip set for the font size. It |
| 439 |
is recommended to use the option always without value! |
| 440 |
\item[singlespacing=\meta{real}]% |
| 441 |
\DescribeOption{singlespacing}% |
| 442 |
\hfill initial=1, default=\emph{empty}\\ |
| 443 |
If this option is used without value, it is the same as \pkg{setspace}'s |
| 444 |
package option \opt{singlespacing} or using command \cs{singlespacing}. But |
| 445 |
if you assign a real number\footref{ftn:fp} this would be used as the new |
| 446 |
stretch factor used for singlespacing. So this is similar to using |
| 447 |
\cs{SetSinglespace}\marg{real}\cs{singlespacing}. A factor of \texttt{nan} |
| 448 |
would activate the calculation of the factor depending on the font size and |
| 449 |
the baseline skip set for the font size. It is recommended to use the option |
| 450 |
always without value! |
| 451 |
\item[nodispayskipstretch]% |
| 452 |
\DescribeOption{nodisplayskipstretch}% |
| 453 |
\marginpar{\raggedleft\footnotesize (added 2024-11-12)}% |
| 454 |
Same as with \pkg{setspace}. The option turns off the stretching of the |
| 455 |
space before and after displays using |\setdisplayskipstretch{1.0}|. |
| 456 |
\end{description} |
| 457 |
|
| 458 |
\subsubsection*{Compatibility Notes:} |
| 459 |
|
| 460 |
\begin{description} |
| 461 |
\item[\pkg*{scrhack}] If you want to use this package together with package |
| 462 |
\pkg*{scrhack} from \href{https://www.ctan.org/pkg/koma-script}{\KOMAScript} |
| 463 |
before version 3.42, you should deactivate the \file{setspace} hack using |
| 464 |
\pkg*{scrhack}' option \opt{setspace=false}. From version 3.42 |
| 465 |
\pkg*{scrhack} does not use the old hacks any longer but |
| 466 |
\pkg*{setspaceenhanced} and is therefore compatible again. |
| 467 |
\end{description} |
| 468 |
|
| 469 |
\section{How does the result of |
| 470 |
\texorpdfstring{\pkg*{setspaceenhanced}}{setspaceenhanced} differ from |
| 471 |
\texorpdfstring{\pkg{setspace}}{setspace} even for using the standard font |
| 472 |
sizes of the standard classes?} |
| 473 |
|
| 474 |
For example if you have a document: |
| 475 |
\begin{verbatim} |
| 476 |
\documentclass[12pt]{article} |
| 477 |
\usepackage{setspace} |
| 478 |
\begin{document} |
| 479 |
\small\onehalfspacing This is font size |
| 480 |
\csname f@size\endcsname pt with |
| 481 |
normal baseline skip \csname f@baselineskip\endcsname. |
| 482 |
The current stretch factor is \baselinestretch. This |
| 483 |
results in a baseline skip of \the\baselineskip. |
| 484 |
\end{document} |
| 485 |
\end{verbatim} |
| 486 |
this will result in: |
| 487 |
\begin{quote} |
| 488 |
This is font size 10.95pt with normal baseline skip 13.6pt. The current |
| 489 |
stretch factor is 1.241. This results in a baseline skip of 16.87756pt. |
| 490 |
\end{quote} |
| 491 |
But one moment: $10.95\,\textrm{pt}\cdot 1.5 = 16.425\,\textrm{pt}$. So the |
| 492 |
factor seems to be wrong. It is not real onehalfspacing depending on the used |
| 493 |
font size. It is also not onehalfspacing depending on the document font size, |
| 494 |
because this would need a baseline skip of 18\,pt. So what is it? It is using |
| 495 |
the stretch factor of 12\,pt for the 10.95\,pt of \cs{small}. |
| 496 |
|
| 497 |
With \pkg*{setspaceenhanced}: |
| 498 |
\begin{verbatim} |
| 499 |
\documentclass[12pt]{article} |
| 500 |
\usepackage{setspaceenhanced} |
| 501 |
\begin{document} |
| 502 |
\small\onehalfspacing This is font size |
| 503 |
\csname f@size\endcsname pt with |
| 504 |
normal baseline skip \csname f@baselineskip\endcsname. |
| 505 |
The current stretch factor is \baselinestretch. This |
| 506 |
results in a baseline skip of \the\baselineskip. |
| 507 |
\end{document} |
| 508 |
\end{verbatim} |
| 509 |
the result changes: |
| 510 |
\begin{quote} |
| 511 |
This is font size 10.95pt with normal baseline skip 13.6pt. The current |
| 512 |
stretch factor is 1.207720046225135. This results in a baseline skip of |
| 513 |
16.42496pt. |
| 514 |
\end{quote} |
| 515 |
Here the difference from the correct value 16.425\,pt is very, very small: |
| 516 |
0.00004\,pt. So you can say, this is really onehalfspacing depending on the |
| 517 |
used font size. |
| 518 |
|
| 519 |
Moreover if you have a document: |
| 520 |
\begin{verbatim} |
| 521 |
\documentclass[12pt]{article} |
| 522 |
\usepackage{setspace} |
| 523 |
\begin{document} |
| 524 |
\fontsize{5pt}{7pt}\selectfont\onehalfspacing This is font size |
| 525 |
\csname f@size\endcsname pt with |
| 526 |
normal baseline skip \csname f@baselineskip\endcsname. |
| 527 |
The current stretch factor is \baselinestretch. This |
| 528 |
results in a baseline skip of \the\baselineskip. |
| 529 |
\end{document} |
| 530 |
\end{verbatim} |
| 531 |
this result in: |
| 532 |
\begin{quote} |
| 533 |
This is font size 12pt with normal baseline skip 14.5pt. The current stretch |
| 534 |
factor is 1.241. This results in a baseline skip of 17.99446pt. |
| 535 |
\end{quote} |
| 536 |
But |
| 537 |
\begin{verbatim} |
| 538 |
\documentclass[12pt]{article} |
| 539 |
\usepackage[keepfontsize]{setspaceenhanced} |
| 540 |
\begin{document} |
| 541 |
\fontsize{5pt}{7pt}\selectfont\onehalfspacing This is font size |
| 542 |
\csname f@size\endcsname pt with |
| 543 |
normal baseline skip \csname f@baselineskip\endcsname. |
| 544 |
The current stretch factor is \baselinestretch. This |
| 545 |
results in a baseline skip of \the\baselineskip. |
| 546 |
\end{document} |
| 547 |
\end{verbatim} |
| 548 |
results in: |
| 549 |
\begin{quote} |
| 550 |
This is font size 5pt with normal baseline skip 7.0pt. The current stretch |
| 551 |
factor is 1.071428571428571. This results in a baseline skip of 7.49998pt. |
| 552 |
\end{quote} |
| 553 |
In my opinion this is more the expected result. See the previous |
| 554 |
\autoref{sec:howtouse} for more information about options like |
| 555 |
\opt{keepfontsize}. |
| 556 |
|
| 557 |
% \iffalse |
| 558 |
%</doc> |
| 559 |
% \fi |
| 560 |
% |
| 561 |
% \MaybeStop{\printbibliography[heading=bibintoc]\PrintIndex} |
| 562 |
% |
| 563 |
% \iffalse |
| 564 |
%<*package> |
| 565 |
%<@@=setspaceenhanced> |
| 566 |
% \fi |
| 567 |
% \section{Implementation} |
| 568 |
% |
| 569 |
% We use the new \LaTeX{} kernel feature of \opt{\meta{key}=\meta{value}} |
| 570 |
% options introduced in \autocite{latexnews35}. So we need at least \LaTeX{} |
| 571 |
% 2022-06-01: |
| 572 |
% \begin{macrocode} |
| 573 |
\ifnum 0=\ifcsname IfFormatAtLeastTF\endcsname |
| 574 |
\IfFormatAtLeastTF{2022-06-01}{1}{0} |
| 575 |
\else |
| 576 |
0 |
| 577 |
\fi\relax |
| 578 |
\PackageError{setspaceenhanced}{LaTeX~kernel~too~old}{ |
| 579 |
The~package~needs~at~least~LaTeX~2022-06-01.\MessageBreak |
| 580 |
This~error~is~fatal.~Loading~will~be~aborted |
| 581 |
} |
| 582 |
\endinput |
| 583 |
\fi |
| 584 |
% \end{macrocode} |
| 585 |
% |
| 586 |
% We do not pass any options to \pkg{setspace}, because we handle them |
| 587 |
% different. So we can just load the package here: |
| 588 |
% \begin{macrocode} |
| 589 |
\RequirePackage{setspace} |
| 590 |
% \end{macrocode} |
| 591 |
% |
| 592 |
% \ExplSyntaxOn |
| 593 |
% \begin{Constant}{\c_@@_single_fp,\c_@@_onehalf_fp,\c_@@_double_fp} |
| 594 |
% \ExplSyntaxOff |
| 595 |
% The internal constants store the absolute factor for singlespacing, |
| 596 |
% onehalfspacing and doublespacing used to calculate the stretch factors. |
| 597 |
% \begin{macrocode} |
| 598 |
\fp_const:Nn \c_@@_single_fp { 1.2 } |
| 599 |
\fp_const:Nn \c_@@_onehalf_fp { 1.5 } |
| 600 |
\fp_const:Nn \c_@@_double_fp { 2.0 } |
| 601 |
% \end{macrocode} |
| 602 |
% \end{Constant} |
| 603 |
% |
| 604 |
% \begin{Variable}{\g_@@_single_factor_fp, |
| 605 |
% \g_@@_onehalf_factor_fp, |
| 606 |
% \g_@@_double_factor_fp} |
| 607 |
% \ExplSyntaxOff |
| 608 |
% \changes{v1.02}{2023-10-09}{missing prefix \texttt{g} added to variable |
| 609 |
% name} |
| 610 |
% The internal variables used to store the configured stretch factors for |
| 611 |
% singlespacing, onehalfspacing and doublespacing. If \texttt{nan} |
| 612 |
% \cs{@@\_linespread} is calculated. |
| 613 |
% \begin{macrocode} |
| 614 |
\fp_new:N \g_@@_single_factor_fp |
| 615 |
\fp_set:Nn \g_@@_single_factor_fp { 1.0 } |
| 616 |
\fp_new:N \g_@@_onehalf_factor_fp |
| 617 |
\fp_set_eq:NN \g_@@_onehalf_factor_fp \c_nan_fp |
| 618 |
\fp_new:N \g_@@_double_factor_fp |
| 619 |
\fp_set_eq:NN \g_@@_double_factor_fp \c_nan_fp |
| 620 |
% \end{macrocode} |
| 621 |
% \end{Variable} |
| 622 |
% |
| 623 |
% \begin{Variable}{\g_@@_linespread_fp,\g_@@_fp} |
| 624 |
% \ExplSyntaxOff |
| 625 |
% \changes{v1.02}{2023-10-09}{missing prefix \texttt{g} added to variable |
| 626 |
% name} |
| 627 |
% Storage of the current calculated stretch factor and the used constant. |
| 628 |
% \begin{macrocode} |
| 629 |
\fp_new:N \g_@@_linespread_fp |
| 630 |
\fp_set:Nn \g_@@_linespread_fp { 1.0 } |
| 631 |
\fp_new:N \g_@@_fp |
| 632 |
% \end{macrocode} |
| 633 |
% \end{Variable} |
| 634 |
% |
| 635 |
% \begin{macro}{\@@_set_spacing:nn} |
| 636 |
% \ExplSyntaxOff |
| 637 |
% This function is used to set the stretch factor for one of the |
| 638 |
% spacings. |
| 639 |
% \begin{macrocode} |
| 640 |
\cs_new:Nn \@@_set_spacing:nn |
| 641 |
{ |
| 642 |
\tl_if_blank:nF { #1 } |
| 643 |
{ |
| 644 |
\fp_set:cn { g_@@_#2_factor_fp } { #1 } |
| 645 |
} |
| 646 |
\fp_if_nan:nTF { \tl_use:c { g_@@_#2_factor_fp } } |
| 647 |
{ |
| 648 |
\fp_set_eq:Nc \g_@@_fp { c_@@_#2_fp } |
| 649 |
\@@_calc_stretch: |
| 650 |
} |
| 651 |
{ |
| 652 |
\fp_set_eq:Nc \g_@@_linespread_fp { g_@@_#2_factor_fp } |
| 653 |
\fp_set_eq:NN \g_@@_fp \c_nan_fp |
| 654 |
} |
| 655 |
\setstretch{ \fp_to_decimal:N \g_@@_linespread_fp } |
| 656 |
} |
| 657 |
% \end{macrocode} |
| 658 |
% \end{macro} |
| 659 |
% |
| 660 |
% \begin{macro}{\@@_calc_stretch:} |
| 661 |
% \ExplSyntaxOff |
| 662 |
% \changes{v1.03}{2024/11/05}{special case \cs{f@baselineskip} < \cs{f@size}} |
| 663 |
% This macro is used to (re-)calculate the stretch factor |
| 664 |
% \cs{@@\_calcstretch} if the currently used constant is not |
| 665 |
% \texttt{nan}. |
| 666 |
% \begin{macrocode} |
| 667 |
\cs_new:Nn \@@_calc_stretch: |
| 668 |
{ |
| 669 |
\fp_if_nan:nF { \g_@@_fp } |
| 670 |
{ |
| 671 |
\fp_compare:nNnTF { \dim_to_fp:n \f@baselineskip } < \f@size |
| 672 |
{ |
| 673 |
\fp_set_eq:NN \g_@@_fp \g_@@_linespread_fp |
| 674 |
} |
| 675 |
{ |
| 676 |
\fp_set:Nn \g_@@_linespread_fp |
| 677 |
{ |
| 678 |
\f@size / \dim_to_fp:n { \f@baselineskip } * \g_@@_fp |
| 679 |
} |
| 680 |
} |
| 681 |
} |
| 682 |
} |
| 683 |
% \end{macrocode} |
| 684 |
% \end{macro} |
| 685 |
% \ExplSyntaxOff |
| 686 |
% |
| 687 |
% \begin{command}{\selectfont} |
| 688 |
% We also need to hook into \cs{selectfont} using the general |
| 689 |
% \texttt{selectfont} hook to re-calculate the stretch factor after the font |
| 690 |
% size has been changed and \opt{byselectfont=true}. |
| 691 |
% \begin{macrocode} |
| 692 |
\hook_gput_code:nnn { selectfont } { setspaceenhanced } |
| 693 |
{% |
| 694 |
\bool_if:NT \g_@@_byselectfont_bool |
| 695 |
{ |
| 696 |
\cs_if_exist:NT \size@update |
| 697 |
{ |
| 698 |
\fp_compare:nNnT \g_@@_linespread_fp = \f@linespread |
| 699 |
{ |
| 700 |
\@@_calc_stretch: |
| 701 |
\set@fontsize |
| 702 |
{ |
| 703 |
\fp_to_decimal:N \g_@@_linespread_fp |
| 704 |
} |
| 705 |
\f@size \f@baselineskip |
| 706 |
} |
| 707 |
} |
| 708 |
} |
| 709 |
} |
| 710 |
% \end{macrocode} |
| 711 |
% \end{command} |
| 712 |
% |
| 713 |
% \begin{command}{\setstretch} |
| 714 |
% If \opt{keepfontsize=false}, we use the original functionality of |
| 715 |
% \pkg{setspace}. But with \opt{keepfontsize=true} we use \cs{linespread}: |
| 716 |
% \begin{macrocode} |
| 717 |
\renewcommand*{\setstretch}[1]{ |
| 718 |
\bool_if:NTF \g_@@_fontsize_bool |
| 719 |
{ |
| 720 |
\linespread{#1}\selectfont |
| 721 |
} |
| 722 |
{ |
| 723 |
\def\baselinestretch{#1}% |
| 724 |
\@currsize |
| 725 |
} |
| 726 |
} |
| 727 |
% \end{macrocode} |
| 728 |
% \end{command} |
| 729 |
% |
| 730 |
% Almost the end of the package we define all options: |
| 731 |
% \changes{v1.01}{2023/09/19}{option \opt{fontsize} renamed to |
| 732 |
% \opt{keepfontsize} because of incompatibility (issue |
| 733 |
% \href{https://github.com/komascript/third-party-enhancements/issues/1} |
| 734 |
% {\#1})% |
| 735 |
% } |
| 736 |
% \changes{v1.04}{2024/11/12}{changed order for correct initialization before |
| 737 |
% executing code} |
| 738 |
% \changes{v1.04}{2024/11/12}{initialize \opt{singlespacing} (issue |
| 739 |
% \href{https://github.com/komascript/third-party-enhancements/issues/3} |
| 740 |
% {\#3})% |
| 741 |
% } |
| 742 |
% \changes{v1.04}{2024/11/12}{options \opt{displayskipstretch} and |
| 743 |
% \opt{nodisplayskipstretch} added% |
| 744 |
% } |
| 745 |
% \begin{macrocode} |
| 746 |
\DeclareKeys{% |
| 747 |
byselectfont .bool_set:N = \g_@@_byselectfont_bool, |
| 748 |
byselectfont .default:n = true, |
| 749 |
byselectfont .initial:n = false, |
| 750 |
byselectfont .usage = general, |
| 751 |
keepfontsize .bool_set:N = \g_@@_fontsize_bool, |
| 752 |
keepfontsize .default:n = true, |
| 753 |
keepfontsize .initial:n = false, |
| 754 |
keepfontsize .usage = general, |
| 755 |
singlespacing .code = \@@_set_spacing:nn {#1} {single}, |
| 756 |
singlespacing .usage = general, |
| 757 |
singlespacing .initial:n = , |
| 758 |
onehalfspacing .code = \@@_set_spacing:nn {#1} {onehalf}, |
| 759 |
onehalfspacing .usage = general, |
| 760 |
doublespacing .code = \@@_set_spacing:nn {#1} {double}, |
| 761 |
doublespacing .usage = general, |
| 762 |
nodisplayskipstretch .code = \setdisplayskipstretch{1.0}, |
| 763 |
nodisplayskipstretch .usage = general, |
| 764 |
} |
| 765 |
% \end{macrocode} |
| 766 |
% \changes{v1.04}{2024/11/12}{extended initialization by \pkg{setspace} |
| 767 |
% options |
| 768 |
% } |
| 769 |
% Now, test for the options used by \pkg{setspace} and use them also for |
| 770 |
% the initialization of the keys above. We do it option by option instead |
| 771 |
% of processing all \pkg{setspace} options, because we want to process only |
| 772 |
% those options \pkg*{setspaceenhanced} also knows. |
| 773 |
% \begin{macrocode} |
| 774 |
\clist_map_inline:nn |
| 775 |
{ nodisplayskipstretch, singlespacing, onehalfspacing, doublespacing } |
| 776 |
{ |
| 777 |
\@ifpackagewith {setspace} {#1} {\SetKeys{#1}} { } |
| 778 |
} |
| 779 |
% \end{macrocode} |
| 780 |
% Last but not least process the package options: |
| 781 |
% \begin{macrocode} |
| 782 |
\ProcessKeyOptions\relax |
| 783 |
% \end{macrocode} |
| 784 |
% |
| 785 |
% \begin{command}{\singlespacing,\onehalfspacing,\doublespacing,\SetSingleSpace} |
| 786 |
% We have to redefine the user interface commands for |
| 787 |
% singlespacing, onehalfspacing and doublespacing. |
| 788 |
% \begin{macrocode} |
| 789 |
\renewcommand*{\singlespacing}{ |
| 790 |
\@@_set_spacing:nn {} {single} |
| 791 |
} |
| 792 |
\renewcommand*{\onehalfspacing}{ |
| 793 |
\@@_set_spacing:nn {} {onehalf} |
| 794 |
} |
| 795 |
\renewcommand*{\doublespacing}{ |
| 796 |
\@@_set_spacing:nn {} {double} |
| 797 |
} |
| 798 |
\renewcommand*{\SetSinglespace}[1]{ |
| 799 |
\fp_set:Nn \g_@@_single_factor_fp { #1 } |
| 800 |
} |
| 801 |
% \end{macrocode} |
| 802 |
% \end{command} |
| 803 |
% |
| 804 |
% \begin{macro}{\setspace@singlespace} |
| 805 |
% \begin{description} |
| 806 |
% \item[Note:] Defining this internal macro does not work using |
| 807 |
% \pkg*{setspaceenhanced}. |
| 808 |
% \marginline{\raisebox{\dimexpr\ht\strutbox-\height\relax}{\Huge\textcolor{red}{?}}}^^A |
| 809 |
% Should we add a test for users and package authors, who do not use |
| 810 |
% \cs{SetSinglespace} but redefine the internal macro? |
| 811 |
% \end{description} |
| 812 |
% \end{macro} |
| 813 |
% |
| 814 |
% \begin{command}{spacesetup} |
| 815 |
% User interface to not need to use \cs{SetKeys}: |
| 816 |
% \begin{macrocode} |
| 817 |
\newcommand*{\spacesetup}{\SetKeys[setspaceenhanced]} |
| 818 |
% \end{macrocode} |
| 819 |
% \end{command} |
| 820 |
% |
| 821 |
% \iffalse |
| 822 |
%</package> |
| 823 |
% \fi |
| 824 |
% |
| 825 |
% \Finale |
| 826 |
% \PrintChanges |
| 827 |
% |
| 828 |
% \endinput |
| 829 |
% Local Variables: |
| 830 |
% mode: doctex |
| 831 |
% ispell-local-dictionary: "en_US" |
| 832 |
% eval: (flyspell-mode 1) |
| 833 |
% TeX-master: t |
| 834 |
% End: |