| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% File: postnotes.tex |
| 4 |
% |
| 5 |
% This file is part of the LaTeX package "postnotes". |
| 6 |
% |
| 7 |
% Copyright (C) 2022-2023 gusbrs |
| 8 |
% |
| 9 |
% It may be distributed and/or modified under the conditions of the |
| 10 |
% LaTeX Project Public License (LPPL), either version 1.3c of this |
| 11 |
% license or (at your option) any later version. The latest version |
| 12 |
% of this license is in the file: |
| 13 |
% |
| 14 |
% https://www.latex-project.org/lppl.txt |
| 15 |
% |
| 16 |
% and version 1.3 or later is part of all distributions of LaTeX |
| 17 |
% version 2005/12/01 or later. |
| 18 |
% |
| 19 |
% |
| 20 |
% This work is "maintained" (as per LPPL maintenance status) by gusbrs. |
| 21 |
% |
| 22 |
% This work consists of the files postnotes.dtx, |
| 23 |
% postnotes.ins, |
| 24 |
% postnotes-doc.tex, |
| 25 |
% postnotes-code.tex, |
| 26 |
% and the files generated from them. |
| 27 |
% |
| 28 |
% The released version of this package is available from CTAN. |
| 29 |
% |
| 30 |
% ----------------------------------------------------------------------- |
| 31 |
% |
| 32 |
% The development version of the package can be found at |
| 33 |
% |
| 34 |
% https://github.com/gusbrs/postnotes |
| 35 |
% |
| 36 |
% for those people who are interested. |
| 37 |
% |
| 38 |
% ----------------------------------------------------------------------- |
| 39 |
% |
| 40 |
% \fi |
| 41 |
|
| 42 |
\documentclass{l3doc} |
| 43 |
|
| 44 |
% The package itself *must* be loaded so that \GetFileInfo can pick up date |
| 45 |
% and version data. |
| 46 |
\usepackage{postnotes} |
| 47 |
\postnotesetup{ |
| 48 |
heading={ |
| 49 |
\section*{\pntitle} |
| 50 |
\markright{\pnheaderdefault} |
| 51 |
\addcontentsline{toc}{section}{\pntitle} |
| 52 |
} , |
| 53 |
} |
| 54 |
|
| 55 |
\usepackage[T1]{fontenc} |
| 56 |
|
| 57 |
\usepackage[sc]{mathpazo} |
| 58 |
\linespread{1.05} |
| 59 |
\usepackage[scale=.88]{tgheros} % sans |
| 60 |
\usepackage[varqu,scaled=1.03]{inconsolata} % tt |
| 61 |
\usepackage{microtype} |
| 62 |
|
| 63 |
\hypersetup{hidelinks} |
| 64 |
|
| 65 |
\usepackage{zref-clever} |
| 66 |
\zcsetup{cap} |
| 67 |
\usepackage{zref-titleref} |
| 68 |
\usepackage{zref-check} |
| 69 |
|
| 70 |
\usepackage{listings} |
| 71 |
\lstdefinestyle{code}{ |
| 72 |
language=[LaTeX]TeX, |
| 73 |
alsoletter = {_:}, |
| 74 |
moretexcs={ |
| 75 |
\chapter , |
| 76 |
\@mkboth , |
| 77 |
\@textsuperscript , |
| 78 |
\thechapter , |
| 79 |
\AddToHook , |
| 80 |
\AddToHookNext , |
| 81 |
\counterwithin , |
| 82 |
\tableofcontents , |
| 83 |
\ExplSyntaxOn , |
| 84 |
\ExplSyntaxOff , |
| 85 |
\NewDocumentCommand , |
| 86 |
\RenewDocumentCommand , |
| 87 |
\NewCommandCopy , |
| 88 |
\IfBooleanTF , |
| 89 |
\IfNoValueTF , |
| 90 |
\tl_if_eq:NNTF , |
| 91 |
\tl_if_eq:eeTF , |
| 92 |
\tl_new:N , |
| 93 |
\tl_gset:Nv , |
| 94 |
\prop_new:N , |
| 95 |
\prop_gput:NeV , |
| 96 |
\prop_item:NV , |
| 97 |
\bool_case:nF , |
| 98 |
\str_if_eq_p:ee , |
| 99 |
\prg_replicate:nn , |
| 100 |
\lipsum , |
| 101 |
\addto , |
| 102 |
\gappto , |
| 103 |
\extras , |
| 104 |
\captions , |
| 105 |
\FirstMark , |
| 106 |
\LastMark , |
| 107 |
} |
| 108 |
} |
| 109 |
\lstdefinestyle{postnotes}{ |
| 110 |
style=code, |
| 111 |
moretexcs={ |
| 112 |
\postnote , |
| 113 |
\postnoteref , |
| 114 |
\postnotesection , |
| 115 |
\printpostnotes , |
| 116 |
\postnotesetup , |
| 117 |
\pntitle , |
| 118 |
\pnhdnotes , |
| 119 |
\pnhdtopage , |
| 120 |
\pnhdtopages , |
| 121 |
\pnheaderdefault , |
| 122 |
\pnthechapter , |
| 123 |
\pnthesection , |
| 124 |
\pnthechapternextnote , |
| 125 |
\pnthesectionnextnote , |
| 126 |
\pnidnextnote , |
| 127 |
\mypnheader , |
| 128 |
\thepostnote , |
| 129 |
\demochapter , |
| 130 |
\origlatexchapter , |
| 131 |
\l_postnotes_note_id_tl , |
| 132 |
\g_my_currentname_tl , |
| 133 |
\g_my_names_prop , |
| 134 |
} |
| 135 |
} |
| 136 |
\lstset{ |
| 137 |
style=postnotes, |
| 138 |
basicstyle=\ttfamily\small, |
| 139 |
columns=fullflexible, |
| 140 |
keepspaces, |
| 141 |
xleftmargin=\leftmargin, |
| 142 |
xrightmargin=.5\leftmargin, |
| 143 |
} |
| 144 |
% Setup inspired by https://tex.stackexchange.com/a/4068. For how to use these |
| 145 |
% environments in a .dtx context see https://tex.stackexchange.com/a/31026. |
| 146 |
\newcounter{pnexample} |
| 147 |
\lstnewenvironment{pnexample}[1][]{% |
| 148 |
\renewcommand{\lstlistingname}{Example}% |
| 149 |
\renewcommand*\theHlstlisting{ht.\thelstlisting}% |
| 150 |
\zcsetup{countertype={lstlisting=example}}% |
| 151 |
\lstset{#1}% |
| 152 |
\stepcounter{pnexample}% |
| 153 |
\setcounter{lstlisting}{\value{pnexample}-1}% |
| 154 |
}{} |
| 155 |
\lstnewenvironment{pnsnippet}[1][]{% |
| 156 |
\renewcommand{\lstlistingname}{Example}% |
| 157 |
\lstset{#1}% |
| 158 |
}{} |
| 159 |
|
| 160 |
\setlength{\marginparsep}{2\labelsep} |
| 161 |
|
| 162 |
\NewDocumentCommand\opt{m}{\texttt{#1}} |
| 163 |
|
| 164 |
\NewDocumentCommand\username{m}{`\texttt{#1}'} |
| 165 |
|
| 166 |
\begin{document} |
| 167 |
|
| 168 |
\GetFileInfo{postnotes.sty} |
| 169 |
|
| 170 |
\title{% |
| 171 |
The \pkg{postnotes} package% |
| 172 |
\texorpdfstring{\\{}\medskip{}}{ - }% |
| 173 |
User manual% |
| 174 |
\texorpdfstring{\medskip{}}{}% |
| 175 |
} |
| 176 |
|
| 177 |
\author{% |
| 178 |
\texorpdfstring{\texttt{gusbrs}\\[0.8em] |
| 179 |
\url{https://github.com/gusbrs/postnotes}\\ |
| 180 |
\url{https://www.ctan.org/pkg/postnotes}}{gusbrs}} |
| 181 |
|
| 182 |
\date{Version \fileversion\ -- \filedate} |
| 183 |
|
| 184 |
\maketitle |
| 185 |
|
| 186 |
\begin{center} |
| 187 |
{\bfseries \abstractname\vspace{-.5em}\vspace{0pt}} |
| 188 |
\end{center} |
| 189 |
|
| 190 |
\begin{quotation} |
| 191 |
\pkg{postnotes} is an endnotes package for \LaTeX{}. Its user interface |
| 192 |
provides means to print multiple sections of notes along the document, and |
| 193 |
to subdivide them either automatically -- by chapter, by section -- or at |
| 194 |
manually specified places, thus being able to easily handle both numbered |
| 195 |
and unnumbered headings. The package also provides infrastructure for |
| 196 |
setting up contextual running headers for printed notes. The default is a |
| 197 |
simple but useful one, in the form ``Notes to pages N--M'', but more |
| 198 |
elaborate ones can be built. When \pkg{hyperref} is loaded, \pkg{postnotes} |
| 199 |
provides hyperlinked notes, including back links. |
| 200 |
\end{quotation} |
| 201 |
|
| 202 |
\clearpage{} |
| 203 |
|
| 204 |
\tableofcontents |
| 205 |
|
| 206 |
\clearpage{} |
| 207 |
|
| 208 |
\section{Introduction} |
| 209 |
|
| 210 |
\pkg{postnotes} is an endnotes package for \LaTeX{}. Its user interface |
| 211 |
provides means to print multiple sections of notes along the document, and to |
| 212 |
subdivide them either automatically -- by chapter, by section -- or at |
| 213 |
manually specified places, thus being able to easily handle both numbered and |
| 214 |
unnumbered headings. The package also provides infrastructure for setting up |
| 215 |
contextual running headers for printed notes. The default is a simple but |
| 216 |
useful one, in the form ``Notes to pages N--M'', but more elaborate ones can |
| 217 |
be built. When \pkg{hyperref} is loaded, \pkg{postnotes} provides hyperlinked |
| 218 |
notes, including back links. |
| 219 |
|
| 220 |
Though this feature set is mostly (albeit not completely) available in one or |
| 221 |
another of the existing endnotes packages for \LaTeX{}, subsets of it exist in |
| 222 |
individual packages, not necessarily compatible with each other. |
| 223 |
\pkg{postnotes} brings these features together in one place, with no external |
| 224 |
dependencies except an up-to-date kernel. |
| 225 |
|
| 226 |
On the technical side, \pkg{postnotes} is peculiar among existing \LaTeX{} |
| 227 |
packages in this area of functionality by the fact that it does not use an |
| 228 |
external file to store the notes. Both the notes' contents and its metadata |
| 229 |
are stored in variables which are later retrieved at the time of printing. In |
| 230 |
particular, the content of the note is stored and retrieved with ``no |
| 231 |
manipulation'' (as in \texttt{expl3}'s \texttt{N}/\texttt{n} function |
| 232 |
signatures) and only gets to be expanded at the time it is meant to be |
| 233 |
typeset. The \file{.aux} file is leveraged to set page labels for the notes, |
| 234 |
since that particular information has to be retrieved asynchronously but, |
| 235 |
other than that, variables are employed to pass information around. |
| 236 |
|
| 237 |
This has some advantages. First, as is well known, sending arbitrary content |
| 238 |
to a file to be read later is not a noiseless process in \LaTeX{}. Thus, not |
| 239 |
doing so makes things smoother. Second, the external file approach is |
| 240 |
strictly linear: the notes which were written to the file get printed as such, |
| 241 |
in the order they were written. Having the notes available as a set of |
| 242 |
variables allows for some more flexibility than that, through the possibility |
| 243 |
of pre-processing the notes before printing. It also brings some extra |
| 244 |
degrees of freedom in storing note metadata, and in restoring part of the |
| 245 |
environment where the note is called to where the note's content is printed. |
| 246 |
|
| 247 |
|
| 248 |
\section{Loading the package} |
| 249 |
|
| 250 |
\pkg{postnotes} can be loaded with the usual: |
| 251 |
|
| 252 |
\begin{pnsnippet} |
| 253 |
\usepackage{postnotes} |
| 254 |
\end{pnsnippet} |
| 255 |
|
| 256 |
The package does not accept load-time options, package options must be set |
| 257 |
using \cs{postnotesetup} (see \zcref{sec:options}, |
| 258 |
\zcref[ref=title,noname]{sec:package-options}). |
| 259 |
|
| 260 |
\section{User interface} |
| 261 |
|
| 262 |
\begin{function}{\postnote} |
| 263 |
\begin{syntax} |
| 264 |
\cs{postnote}\oarg{options}\marg{text} |
| 265 |
\end{syntax} |
| 266 |
\end{function} |
| 267 |
Sets a postnote with content \meta{text}. A note ``mark'' is typeset at the |
| 268 |
place \cs{postnote} is called, and \meta{text} is stored to be typeset later, |
| 269 |
on the next call to \cs{printpostnotes}. The mark is usually determined by |
| 270 |
the printed representation of the main counter, \texttt{postnote}, but can be |
| 271 |
manually set too. \cs{postnote} can receive a number of \meta{options}, which |
| 272 |
are presented in \zcref{sec:options}, |
| 273 |
\zcref[ref=title,noname]{sec:note-options}. |
| 274 |
|
| 275 |
\begin{function}{\postnotesection} |
| 276 |
\begin{syntax} |
| 277 |
\cs{postnotesection}\oarg{options}\marg{text} |
| 278 |
\end{syntax} |
| 279 |
\end{function} |
| 280 |
Sets a postnote section with content \meta{text}. This is the basic interface |
| 281 |
for making notes subdivisions, and it places \meta{text} between the notes |
| 282 |
where it occurs, at the point the notes are printed by \cs{printpostnotes}. |
| 283 |
For more details and some examples, see \zcref{sec:notes-sections}. Its |
| 284 |
\meta{options} are presented in \zcref{sec:options}, |
| 285 |
\zcref[ref=title,noname]{sec:section-options}. |
| 286 |
|
| 287 |
\begin{function}{\printpostnotes} |
| 288 |
\begin{syntax} |
| 289 |
\cs{printpostnotes} |
| 290 |
\end{syntax} |
| 291 |
\end{function} |
| 292 |
Prints the \cs{postnote}s set since the last call of \cs{printpostnotes}, or |
| 293 |
since the beginning of the document. For two basic usage illustrations, see |
| 294 |
\zcref{ex:sect:basic,ex:x:multi-print}. |
| 295 |
|
| 296 |
\begin{function}{\postnoteref} |
| 297 |
\begin{syntax} |
| 298 |
\cs{postnoteref}\meta{*}\marg{label} |
| 299 |
\end{syntax} |
| 300 |
\end{function} |
| 301 |
Typesets a postnote reference to \meta{label}. Of course, \meta{label} must |
| 302 |
have been set to a particular postnote, which can be done by the standard |
| 303 |
\cs{label} command. The starred version of the command inhibits hyperlinking. |
| 304 |
When the \pkg{zref-user} package is loaded, a corresponding \cs{postnotezref} |
| 305 |
is also provided, and if \pkg{zref-hyperref} is also loaded, it is hyperlinked |
| 306 |
as its counterpart. |
| 307 |
|
| 308 |
|
| 309 |
\section{Options} |
| 310 |
\label{sec:options} |
| 311 |
|
| 312 |
\subsection*{Package options} |
| 313 |
\label{sec:package-options} |
| 314 |
|
| 315 |
\begin{function}{\postnotesetup} |
| 316 |
\begin{syntax} |
| 317 |
\cs{postnotesetup}\marg{options} |
| 318 |
\end{syntax} |
| 319 |
\end{function} |
| 320 |
Package options can be configured by means of \cs{postnotesetup}, which |
| 321 |
receives options and values in \texttt{key=value} fashion. |
| 322 |
|
| 323 |
\bigskip{} |
| 324 |
|
| 325 |
\DescribeOption{heading} % |
| 326 |
\DescribeMacro{\pnheading} % |
| 327 |
The \opt{heading} option sets the heading for the printed notes or, more |
| 328 |
generally put, that which is printed at the beginning of \cs{printpostnotes}. |
| 329 |
Its default value depends on the document class in use. If \cs{chapter} is |
| 330 |
defined, the default is: |
| 331 |
\begin{pnsnippet} |
| 332 |
\chapter*{\pntitle} |
| 333 |
\@mkboth{\pnheaderdefault}{\pnheaderdefault} |
| 334 |
\end{pnsnippet} |
| 335 |
but otherwise, it is: |
| 336 |
\begin{pnsnippet} |
| 337 |
\section*{\pntitle} |
| 338 |
\@mkboth{\pnheaderdefault}{\pnheaderdefault} |
| 339 |
\end{pnsnippet} |
| 340 |
where \cs{pntitle} is localizable string, which by default contains ``Notes'' |
| 341 |
(see \zcref{sec:localization}), and \cs{pnheaderdefault} is a function which |
| 342 |
takes no arguments, but processes a number of variables, to set a contextual |
| 343 |
running header for the printed notes (see \zcref{sec:headers}). |
| 344 |
\cs{pnheaderdefault} produces a header in the form ``Notes to pages N--M'', |
| 345 |
according to the notes in each page. If you prefer, you can redefine |
| 346 |
\cs{pnheading} instead of using the \opt{heading} option, to the same effect. |
| 347 |
|
| 348 |
\DescribeOption{format} % |
| 349 |
The \opt{format} option stores formatting instructions for printing the |
| 350 |
notes. It is called at \cs{printpostnotes}, every time a block of notes is |
| 351 |
about to start. The default value is \cs{small}. |
| 352 |
|
| 353 |
\DescribeOption{listenv} % |
| 354 |
The \opt{listenv} option sets the list environment inside which the notes are |
| 355 |
printed in \cs{printpostnotes}. This must be the name of an existing list |
| 356 |
environment, and \pkg{postnotes} provides two suitable ones for convenience: |
| 357 |
\env{postnoteslist}, which is the default, and \env{postnoteslisthang} which |
| 358 |
typesets the notes with a hanging indent. You can also create your own, with |
| 359 |
\pkg{enumitem} or otherwise, of course. \opt{listenv} can also receive the |
| 360 |
special value \texttt{none}, in which case the notes blocks are not wrapped in |
| 361 |
a list environment, but rather typeset as plain paragraphs. |
| 362 |
\texttt{\opt{listenv}=none} already sets \opt{postprintnote} to \cs{par} for |
| 363 |
that reason but, when using \texttt{none}, you'll probably also want to set |
| 364 |
\opt{maketextmark}, \opt{pretextmark}, or \opt{posttextmark} to values |
| 365 |
different than the defaults. |
| 366 |
|
| 367 |
\DescribeOption{makemark} % |
| 368 |
\DescribeOption{maketextmark} % |
| 369 |
\DescribeMacro{\pnthepage} % |
| 370 |
The \opt{makemark} and \opt{maketextmark} options control how the mark is to |
| 371 |
be typeset, at the point \cs{postnote} is called and at the point the note's |
| 372 |
text is printed at \cs{printpostnotes}, respectively. They both can receive |
| 373 |
three arguments: \texttt{\#1} is the mark itself, and arguments \texttt{\#2} |
| 374 |
and \texttt{\#3} are, respectively, the start and the end of the hyperlink |
| 375 |
(hence they must be used in this order, and always in pair). Their default |
| 376 |
values are: |
| 377 |
\begin{pnsnippet} |
| 378 |
makemark = {#2\hbox{\@textsuperscript{\normalfont#1}}#3} , |
| 379 |
maketextmark = {#2#1.#3} , |
| 380 |
\end{pnsnippet} |
| 381 |
At the point \opt{maketextmark} gets typeset, the \cs{pnthepage} variable |
| 382 |
contains the value of \cs{thepage} where its corresponding note was set. |
| 383 |
|
| 384 |
\DescribeOption{pretextmark} % |
| 385 |
\DescribeOption{posttextmark} % |
| 386 |
\DescribeOption{postprintnote} % |
| 387 |
The options \opt{pretextmark}, \opt{posttextmark}, and \opt{postprintnote} |
| 388 |
allow to insert additional material in \cs{printpostnotes}, respectively, |
| 389 |
right before the mark, right after the mark, and after the note's content. |
| 390 |
All in all, when \opt{listenv} is not \texttt{none}, each note in the list is |
| 391 |
laid out in the form: |
| 392 |
\begin{pnsnippet}[escapeinside=`'] |
| 393 |
\item[`\meta{pretextmark}'`\meta{mark}'`\meta{posttextmark}']`\meta{note content}'`\meta{postprintnote}' |
| 394 |
\end{pnsnippet} |
| 395 |
and when \opt{listenv} is \texttt{none}, each note is laid out in the form: |
| 396 |
\begin{pnsnippet}[escapeinside=`'] |
| 397 |
`\meta{pretextmark}'`\meta{mark}'`\meta{posttextmark}'`\meta{note content}'`\meta{postprintnote=\textbackslash{}\textbf{par}}' |
| 398 |
\end{pnsnippet} |
| 399 |
|
| 400 |
\DescribeOption{style} % |
| 401 |
\opt{style} is just a convenience ``meta'' option which sets a number of |
| 402 |
``base'' options -- such as \opt{listenv}, \opt{format}, \opt{maketextmark}, |
| 403 |
etc.\ -- in order to emulate known styles of printing the notes. It accepts |
| 404 |
the values \texttt{endnotes} or \texttt{pagenote} so that \cs{printpostnotes} |
| 405 |
works as its counterparts in each of these packages. |
| 406 |
|
| 407 |
\DescribeOption{multiple} % |
| 408 |
\DescribeOption{multisep} % |
| 409 |
Just as for footnotes, when two or more \cs{postnote}s are called in imediate |
| 410 |
sequence, the marks typeset in superscript give impression of being one large |
| 411 |
number, instead of the sequence of smaller ones they were supposed to convey. |
| 412 |
Enabling the \opt{multiple} option makes \pkg{postnotes} typeset a separator |
| 413 |
between marks occurring in sequence. The separator can be configured with the |
| 414 |
\opt{multisep} option, which has a comma as initial value. \opt{multiple} is |
| 415 |
a boolean option, and has \texttt{false} as initial value. |
| 416 |
|
| 417 |
\DescribeOption{hyperref} % |
| 418 |
\DescribeOption{backlink} % |
| 419 |
The \opt{hyperref} option controls the use of \pkg{hyperref} by |
| 420 |
\pkg{postnotes} and takes values \opt{auto}, \opt{true} or \opt{false}. The |
| 421 |
default value, \opt{auto}, makes \pkg{postnotes} use \pkg{hyperref} if it is |
| 422 |
loaded. \opt{true} does the same thing, but warns if \pkg{hyperref} is not |
| 423 |
loaded (\pkg{hyperref} is never loaded for you). \opt{false} means not to use |
| 424 |
\pkg{hyperref} regardless of its availability. The \opt{backlink} option |
| 425 |
controls whether only a link from the note's mark to its respective text at |
| 426 |
\cs{printpostnotes} is created, or if a back link from the text at |
| 427 |
\cs{printpostnotes} back to where the note's mark is placed is also made |
| 428 |
available. It is a boolean option, defaults to \texttt{true}, and is only |
| 429 |
operational if \opt{hyperref} is not \texttt{false}. These are both preamble |
| 430 |
only options. |
| 431 |
|
| 432 |
\DescribeOption{sort} % |
| 433 |
The \opt{sort} option controls whether the notes queue is sorted or not at |
| 434 |
\cs{printpostnotes}. Normally, the order the notes should be printed is the |
| 435 |
one in which the notes were placed along the document. However, in cases |
| 436 |
where some manual intervention was required, sorting the notes can be quite |
| 437 |
useful, and difficult to handle in its absence. Two typical examples are: a |
| 438 |
note inside a float which disturbed the sequence of the \texttt{postnote} |
| 439 |
counter (see \zcref{ex:x:float} in \zcref{sec:further-examples} for an |
| 440 |
illustration) and a manually set mark, in which case \pkg{postnotes} also |
| 441 |
allows to manually set a sort value with the \opt{sortnum} option of |
| 442 |
\cs{postnote}. Sorting does not cross boundaries of notes sections, as set by |
| 443 |
\cs{postnotesection}, in other words, if notes sections exist, sorting is only |
| 444 |
ever carried out within the boundaries of each section. This may be a |
| 445 |
restriction for cases in which floats cross sections' boundaries, but it's the |
| 446 |
only reasonable thing to do. \opt{sort} is a boolean option, and defaults to |
| 447 |
\texttt{true}. |
| 448 |
|
| 449 |
\DescribeOption{checkduplicates} % |
| 450 |
\DescribeOption{checkfloats} % |
| 451 |
Issue warnings in case of duplicate notes resulting from measuring/trial |
| 452 |
passes and from mismatches in the sequence of notes resulting from floats, |
| 453 |
respectively. These checks are only expected to be meaningful in a document |
| 454 |
for which the compilation has stabilized: with labels and floats already in |
| 455 |
place. See \zcref{sec:thorns} for discussion. Note that the |
| 456 |
\opt{checkfloats} option does not test ``if my notes are in numeric order'' |
| 457 |
(that's the job of \opt{sort}), but rather whether the order the marks are |
| 458 |
typeset along the document and the order the notes are printed in |
| 459 |
\cs{printposnotes} are the same. These options are booleans. |
| 460 |
\opt{checkduplicates} is initially enabled, since whether a place performs |
| 461 |
measuring passes does not really change, and it is easy to deal with a note in |
| 462 |
this situation with the \opt{maybemulti} option. \opt{checkfloats}, on the |
| 463 |
other hand, is initially disabled. Float placement (and its implications for |
| 464 |
\pkg{postnotes}) is something one should not worry about until the very last |
| 465 |
stages of the document. At that time, I expect it to be useful, but during |
| 466 |
the writing phase, such a warning would only be distracting. Think of if as |
| 467 |
something to use like you would use the \pkg{widows-and-orphans} package, for |
| 468 |
example. |
| 469 |
|
| 470 |
\DescribeOption{maybemulti} % |
| 471 |
A \cs{postnote} set while \opt{maybemulti} is true is checked at |
| 472 |
\cs{printposnotes} and only kept in the printing queue if its corresponding |
| 473 |
(internal) page label exists. See \zcref{sec:thorns} for discussion. The |
| 474 |
drawback is that, since it requires the label for the check, a new note set |
| 475 |
with \opt{maybemulti} will need one more compilation run than otherwise. This |
| 476 |
is a boolean option, and the initial value is false. |
| 477 |
|
| 478 |
\DescribeOption{counteraux} % |
| 479 |
\DescribeMacro{\pnsetcounteraux\marg{int}} % |
| 480 |
\DescribeMacro{\pnaddtocounteraux\marg{int}} % |
| 481 |
(Experimental) Build the printing queue based on the (internal) page labels |
| 482 |
set in the \file{.aux} file, and also handle the counter stepping at the same |
| 483 |
time. This should provide us with a fully automated sequence of notes which |
| 484 |
is both exempt from duplicates resulting from measuring passes and from notes |
| 485 |
order issues caused by floats. See \zcref{sec:thorns} for discussion. Since |
| 486 |
the counter sequence is determined during the input of the \file{.aux} file, |
| 487 |
the regular counter commands will not work as intended. \cs{pnsetcounteraux} |
| 488 |
and \cs{pnaddtocounteraux} take an integer number as argument, and do what |
| 489 |
their names imply, but at the time they can actually affect the sequence used |
| 490 |
by \opt{counteraux}. The option is a boolean, is initially disabled, and is |
| 491 |
preamble only. Enabling \opt{counteraux} also disables \opt{sort} at |
| 492 |
\texttt{begindocument/before}.\footnote{The truth is, I have not yet thought |
| 493 |
it through how these options may interact. So, this is done out of caution. |
| 494 |
I don't expect them to clash but, in principle, with \opt{counteraux}, |
| 495 |
\opt{sort} is not needed. You are not blocked from re-enabling it later |
| 496 |
but, if you do, be mindful of possible interactions.} |
| 497 |
|
| 498 |
|
| 499 |
\subsection*{Note options} |
| 500 |
\label{sec:note-options} |
| 501 |
|
| 502 |
The options accepted by \cs{postnote}\oarg{options}\marg{text} are the |
| 503 |
following: |
| 504 |
|
| 505 |
\bigskip{} |
| 506 |
|
| 507 |
\DescribeOption{mark} % |
| 508 |
\DescribeOption{markstr} % |
| 509 |
By default, the mark generated by \cs{postnote} is determined by the printed |
| 510 |
representation of the \texttt{postnote} counter, \cs{thepostnote}, which is |
| 511 |
stepped when \cs{postnote} is called. But the \opt{mark} and \opt{markstr} |
| 512 |
options allow you to manually set it, in case you want, or need, to do so. |
| 513 |
When either \opt{mark} or \opt{markstr} is manually set, the \texttt{postnote} |
| 514 |
counter is not stepped. The difference between them is that \opt{mark} must |
| 515 |
receive a number as value, and uses its value to also set the \opt{sortnum} |
| 516 |
option, while \opt{markstr}, differently from the optional argument of |
| 517 |
\cs{footnote}, can receive a string as value which is directly used as the |
| 518 |
mark, but it does not set \opt{sortnum}. |
| 519 |
|
| 520 |
\DescribeOption{sortnum} % |
| 521 |
Normally, the sort value used for sorting the notes queue (see the \opt{sort} |
| 522 |
package option above) is determined by the value of the \texttt{postnote} |
| 523 |
counter (that is, by \cs{the}\cs{c@postnote}, and not by its printed |
| 524 |
representation, \cs{thepostnote}). But you may specify this sort value |
| 525 |
manually with the \opt{sortnum} option, typically, when you have also manually |
| 526 |
specified the mark. It receives a floating point number as value. So, for |
| 527 |
example, if one needed to insert a note between notes 2 and 3, without |
| 528 |
disturbing the numbering of other notes, one could use |
| 529 |
\texttt{\cs{postnote}[markstr=2*,sortnum=2.5]\marg{text}}. |
| 530 |
|
| 531 |
\DescribeOption{nomark} % |
| 532 |
The \opt{nomark} option makes \cs{postnote} inhibit the typesetting of the |
| 533 |
mark. Of course, normally, we do want the visual cue of the mark, but the |
| 534 |
intended use case for this option is for a \cs{postnote} with \opt{nomark} to |
| 535 |
be paired with a \cs{postnoteref}, so as to be able to typeset a note in |
| 536 |
places where doing so directly may be problematic. For a practical example |
| 537 |
and an illustration on how to use it, see \zcref{ex:x:caption} in |
| 538 |
\zcref{sec:further-examples}. |
| 539 |
|
| 540 |
\DescribeOption{label} % |
| 541 |
The \opt{label} option sets a standard \cs{label} named with the value given |
| 542 |
to the option. When the \pkg{zref-user} package is loaded, a corresponding |
| 543 |
\opt{zlabel} option is also provided. See \zcref{sec:cross-references} for |
| 544 |
details about cross-referencing. |
| 545 |
|
| 546 |
\DescribeOption{maybemulti} % |
| 547 |
Does the same thing as the corresponding package option, but is applied for a |
| 548 |
particular \cs{postnote}. |
| 549 |
|
| 550 |
|
| 551 |
\subsection*{Section options} |
| 552 |
\label{sec:section-options} |
| 553 |
|
| 554 |
The options accepted by \cs{postnotesection}\oarg{options}\marg{text} are the |
| 555 |
following: |
| 556 |
|
| 557 |
\bigskip{} |
| 558 |
|
| 559 |
\DescribeOption{name} % |
| 560 |
For the purposes of building running headers, each \cs{postnotesection} can be |
| 561 |
identified by its \opt{name}. This is mainly intended to support unnumbered |
| 562 |
headings, but its mechanism is general. The name of a note section is made |
| 563 |
available through the (lt)mark class \opt{postnotes/sectname}, for details on |
| 564 |
how to use it, see \zcref{sec:headers} and, in particular, |
| 565 |
\zcref{ex:hd:fancy}. |
| 566 |
|
| 567 |
\DescribeOption{exp} % |
| 568 |
By default, \cs{postnotesection} stores its \meta{text} argument with ``no |
| 569 |
manipulation''. The \opt{exp} option allows one to fully expand |
| 570 |
(\cs{protected@edef} expansion) \meta{text} in place before storing it. It is |
| 571 |
a boolean option, and the option given with no value is equivalent to |
| 572 |
\texttt{exp=true}. |
| 573 |
|
| 574 |
|
| 575 |
\section{Notes sections} |
| 576 |
\label{sec:notes-sections} |
| 577 |
|
| 578 |
As mentioned above, \cs{postnotesection} is the basic interface for |
| 579 |
subdividing the notes when printed. For those familiar with it, this command |
| 580 |
is \pkg{postnotes}' equivalent to \pkg{endnotes}' \cs{addtoendnotes}. It has |
| 581 |
the same intended use -- to add text or commands along the notes' sequence at |
| 582 |
the point it is called -- and the way it works is quite similar to |
| 583 |
\cs{addtoendnotes}. But there are some differences, prominently a |
| 584 |
\cs{postnotesection} is skipped at \cs{printpostnotes} if it contains no |
| 585 |
notes. In other words, if two (or more) calls of \cs{postnotesection} occur |
| 586 |
in immediate sequence, with no \cs{postnote} in between, the latter call takes |
| 587 |
precedence over the former, instead of being accumulated in the queue. This |
| 588 |
is intended to facilitate the automation of the subdivision of the notes. So, |
| 589 |
one can, for example, use a hook to \cs{chapter} and not have to worry if a |
| 590 |
chapter with no notes will generate an empty section inside |
| 591 |
\cs{printpostnotes}, e.g., by the call to \cs{chapter*} at the table of |
| 592 |
contents, and so on. Or, one can use the heading number for the automated |
| 593 |
case, but be able to override it manually for an occasional unnumbered one. |
| 594 |
For this reason, a more semantic name was chosen for it, instead of the |
| 595 |
generic ``add to''. |
| 596 |
|
| 597 |
\DescribeMacro{\pnthechapter} % |
| 598 |
\DescribeMacro{\pnthesection} % |
| 599 |
\DescribeMacro{\pnthechapternextnote} % |
| 600 |
\DescribeMacro{\pnthesectionnextnote} % |
| 601 |
\DescribeMacro{\pnidnextnote} % |
| 602 |
Just like with \cs{postnote}, the contents of \cs{postnotesection} are not |
| 603 |
expanded in place, but rather stored with ``no manipulation'' to be typeset |
| 604 |
later at \cs{printpostnotes}. For this reason, some contextual information is |
| 605 |
stored at the place \cs{postnotesection} is called, and made available at the |
| 606 |
point it's content gets expanded by means of some variables (you can use |
| 607 |
\cs{postnotesection}\texttt{[exp]} instead, in which case these variables are |
| 608 |
of little use). When the content of a notes section gets typeset, |
| 609 |
\cs{pnthechapter} contains the value of \cs{thechapter} where |
| 610 |
\cs{postnotesection} was originally called. Similarly, \cs{pnthesection} |
| 611 |
contains the value of \cs{thesection}. \cs{pnthechapternextnote} and |
| 612 |
\cs{pnthesectionnextnote} are meant to support the automation of the notes |
| 613 |
subdivision by using hooks to sectioning commands, which is a quite natural |
| 614 |
way to do this. However, since it may be problematic to hook \emph{after} |
| 615 |
sectioning commands -- \cs{section}, for example, figures prominently in the |
| 616 |
documentation of \pkg{ltcmdhooks} as a case of ``look ahead'' command for |
| 617 |
which the \texttt{after} hook is not supported -- we will typically want to |
| 618 |
hook \emph{before} them. But, at this point the values of the |
| 619 |
\texttt{chapter} or \texttt{section} counters have not yet been stepped, |
| 620 |
therefore \cs{thechapter} and \cs{thesection} do not correspond to what we |
| 621 |
would like to refer to. For this reason, \cs{pnthechapternextnote} contains |
| 622 |
the value of \cs{thechapter} at the point the ``next note'' is placed (a |
| 623 |
\cs{postnote}, that is), the first in the chapter, and already inside it, thus |
| 624 |
with an expected value of the \texttt{chapter} counter. Similarly, |
| 625 |
\cs{pnthesectionnextnote} contains the value of \cs{thesection} for the ``next |
| 626 |
note''. \cs{pnidnextnote}, in turn, stores the Id number of the ``next |
| 627 |
note''. Of course, the ``next note'' variables are \emph{proxies}, but they |
| 628 |
are meant to support the automation of the subdivision of the notes through |
| 629 |
the use of \texttt{before} hooks to the document's sectioning commands, in |
| 630 |
which case the subdivision of the notes will correspond to the document's |
| 631 |
structure and, given empty notes sections are skipped, the values will be the |
| 632 |
ones we are interested in. But more complex use cases may require something |
| 633 |
different. Either way, it is up to the user to judge whether the \emph{proxy} |
| 634 |
is a good one for their use case, the variables just do what they say, and |
| 635 |
contain the values of interest for the ``next note''. |
| 636 |
|
| 637 |
This is meant to be simple. Some examples might make things more concrete. |
| 638 |
At its most basic, \cs{postnotesection} can just be set manually: |
| 639 |
|
| 640 |
\begin{pnexample}[caption={Basic usage},label={ex:sect:basic}] |
| 641 |
\documentclass{book} |
| 642 |
\usepackage{postnotes} |
| 643 |
\usepackage{hyperref} |
| 644 |
\begin{document} |
| 645 |
\chapter{First chapter} |
| 646 |
\postnotesection{\section*{Notes to chapter \pnthechapter}} |
| 647 |
Foo.\postnote{Foo note.} |
| 648 |
Bar.\postnote{Bar note.} |
| 649 |
\chapter{Second chapter} |
| 650 |
\postnotesection{\section*{Notes to chapter \pnthechapter}} |
| 651 |
\setcounter{postnote}{0} |
| 652 |
Baz.\postnote{Baz note.} |
| 653 |
Boo.\postnote{Boo note.} |
| 654 |
\printpostnotes |
| 655 |
\end{document} |
| 656 |
\end{pnexample} |
| 657 |
|
| 658 |
The document in \zcref{ex:sect:basic} resets the \texttt{postnote} counter for each |
| 659 |
chapter, and manually sets notes sections by chapter, which results in |
| 660 |
\cs{printpostnotes} being correspondingly subdivided. But it is easy to make |
| 661 |
this automatic: |
| 662 |
|
| 663 |
\begin{pnexample}[caption={Automating notes subdivision with a hook},label={ex:sect:auto}] |
| 664 |
\documentclass{book} |
| 665 |
\usepackage{postnotes} |
| 666 |
\AddToHook{cmd/chapter/before}{% |
| 667 |
\postnotesection{\section*{Notes to chapter \pnthechapternextnote}}} |
| 668 |
\counterwithin*{postnote}{chapter} |
| 669 |
\usepackage{hyperref} |
| 670 |
\begin{document} |
| 671 |
\tableofcontents |
| 672 |
\chapter{First chapter} |
| 673 |
Foo.\postnote{Foo note.} |
| 674 |
Bar.\postnote{Bar note.} |
| 675 |
\chapter{Second chapter} |
| 676 |
Baz.\postnote{Baz note.} |
| 677 |
Boo.\postnote{Boo note.} |
| 678 |
\printpostnotes |
| 679 |
\end{document} |
| 680 |
\end{pnexample} |
| 681 |
|
| 682 |
\zcref{ex:sect:auto} uses the \texttt{cmd/chapter/before} hook, and thus |
| 683 |
\cs{pnthechapternextnote} to retrieve the correct chapter number for |
| 684 |
\cs{postnotesection}, as explained above. The counter is reset every chapter |
| 685 |
by means of \cs{counterwithin*}. Note that the call to \cs{chapter*} inside |
| 686 |
\cs{tableofcontents} does not generate a spurious notes section at |
| 687 |
\cs{printpostnotes} (as long as you don't place a note in a sectioning command |
| 688 |
with no short argument, which you shouldn't do anyway). But what if we have, |
| 689 |
among mostly numbered chapters, an ocasional unnumbered one?\footnote{The |
| 690 |
example here counts on the lucky circumstance of having only a single |
| 691 |
initial unnumbered section. But, in general, if that's not the case, |
| 692 |
\cs{counterwithin*} is insufficient and the resetting of the |
| 693 |
\texttt{postnote} counter at unnumbered sections must be handled somehow |
| 694 |
else.} \cs{pnthechapternextnote} wouldn't possibly work in this case. |
| 695 |
Since immediately successive calls to \cs{postnotesection} override the |
| 696 |
previous ones, it is straightforward to just manually adjust the exception: |
| 697 |
|
| 698 |
\begin{pnexample}[caption={Fine-tuning automation},label={ex:sect:fine-auto}] |
| 699 |
\documentclass{book} |
| 700 |
\usepackage{postnotes} |
| 701 |
\AddToHook{cmd/chapter/before}{% |
| 702 |
\postnotesection{\section*{Notes to chapter \pnthechapternextnote}}} |
| 703 |
\counterwithin*{postnote}{chapter} |
| 704 |
\usepackage{hyperref} |
| 705 |
\begin{document} |
| 706 |
\tableofcontents |
| 707 |
\chapter*{Introduction} |
| 708 |
\postnotesection{\section*{Notes to the introduction}} |
| 709 |
Intro.\postnote{Intro note.} |
| 710 |
\chapter{First chapter} |
| 711 |
Foo.\postnote{Foo note.} |
| 712 |
Bar.\postnote{Bar note.} |
| 713 |
\chapter{Second chapter} |
| 714 |
Baz.\postnote{Baz note.} |
| 715 |
Boo.\postnote{Boo note.} |
| 716 |
\printpostnotes |
| 717 |
\end{document} |
| 718 |
\end{pnexample} |
| 719 |
|
| 720 |
If one wants to use section names/titles, the technique above (of using |
| 721 |
something similar to \cs{pnthechapternextnote}) is less useful, since if the |
| 722 |
first note in the section occurs within a subsection we would lose the |
| 723 |
information of interest. So we have a little more work to do in this case. |
| 724 |
\zcref{ex:sect:names} uses the \texttt{cmd/chapter/before} hook to store the |
| 725 |
value of \cs{@currentlabelname} in a dedicated variable after the next call to |
| 726 |
\cs{NR@gettitle} (presuming the use of \pkg{nameref}, through \pkg{hyperref}). |
| 727 |
We then store the value of this variable for each note using the |
| 728 |
\texttt{postnotes/note/store} hook and the note's Id number |
| 729 |
\cs{l_postnotes_note_id_tl}. Finally we can retrieve this stored value using |
| 730 |
\cs{pnidnextnote} inside \cs{postnotesection}. Indeed, this example is also |
| 731 |
meant to illustrate the general technique for storing/restoring variables of |
| 732 |
interest for this purpose. |
| 733 |
|
| 734 |
\begin{pnexample}[caption={Section names},label={ex:sect:names}] |
| 735 |
\documentclass{book} |
| 736 |
\usepackage{postnotes} |
| 737 |
\ExplSyntaxOn |
| 738 |
\tl_new:N \g_my_currentname_tl |
| 739 |
\prop_new:N \g_my_names_prop |
| 740 |
\AddToHook{cmd/chapter/before}{ |
| 741 |
\AddToHookNext{cmd/NR@gettitle/after}{ |
| 742 |
\tl_gset:Nv \g_my_currentname_tl { @currentlabelname } } } |
| 743 |
\AddToHook{postnotes/note/store}{ |
| 744 |
\prop_gput:NeV \g_my_names_prop |
| 745 |
{ \l_postnotes_note_id_tl } \g_my_currentname_tl } |
| 746 |
\AddToHook{cmd/chapter/before}{ |
| 747 |
\postnotesection{ |
| 748 |
\section*{Notes~to~\prop_item:NV \g_my_names_prop \pnidnextnote}}} |
| 749 |
\ExplSyntaxOff |
| 750 |
\counterwithin*{postnote}{chapter} |
| 751 |
\usepackage{hyperref} |
| 752 |
\begin{document} |
| 753 |
\chapter*{Introduction} |
| 754 |
Intro.\postnote{Intro note.} |
| 755 |
\chapter{First chapter} |
| 756 |
Foo.\postnote{Foo note.} |
| 757 |
Bar.\postnote{Bar note.} |
| 758 |
\chapter{Second chapter} |
| 759 |
Baz.\postnote{Baz note.} |
| 760 |
Boo.\postnote{Boo note.} |
| 761 |
\printpostnotes |
| 762 |
\end{document} |
| 763 |
\end{pnexample} |
| 764 |
|
| 765 |
While \pkg{postnotes} goes through great lengths to avoid tampering with |
| 766 |
sectioning commands, the fact that in general we cannot use \texttt{cmd} hooks |
| 767 |
after \cs{chapter} or \cs{section} does complicate things. And |
| 768 |
\zcref{ex:sect:names} is indeed a good illustration of how a supposedly simple |
| 769 |
task can become quite convoluted if we are not allowed to observe the |
| 770 |
variables of interest \emph{after} the sectioning commands. However, things |
| 771 |
are quite different from the perspective of a user, considering the problem at |
| 772 |
the document level. In this case, the definition of the sectioning commands |
| 773 |
is known, and unique, so that it may make sense to use of the traditional |
| 774 |
technique of storing the definition of the sectioning command, and then |
| 775 |
redefining it to do what it used to, plus something |
| 776 |
else.\footnote{\username{egreg} commonly applies the technique for the same |
| 777 |
purpose in answers using \pkg{endnotes} at TeX.SX. For example: |
| 778 |
\url{https://tex.stackexchange.com/a/62425}, |
| 779 |
\url{https://tex.stackexchange.com/a/109566}, and |
| 780 |
\url{https://tex.stackexchange.com/a/85001}. But things are somewhat simpler |
| 781 |
with \pkg{postnotes}, since there's no need to handle the case of sections |
| 782 |
with no notes, given that empty \cs{postnotesection}s are already skipped.} |
| 783 |
In which case, we can set \cs{postnotesection}s with full generality and |
| 784 |
flexibility. |
| 785 |
|
| 786 |
\begin{pnexample}[caption={Redefining sections},label={ex:sect:redefined}] |
| 787 |
\documentclass{book} |
| 788 |
\usepackage{postnotes} |
| 789 |
\counterwithin*{postnote}{chapter} |
| 790 |
\NewCommandCopy\origlatexchapter\chapter |
| 791 |
\RenewDocumentCommand{\chapter}{som}{% |
| 792 |
\IfBooleanTF{#1}{% |
| 793 |
\origlatexchapter*{#3}% |
| 794 |
\setcounter{postnote}{0}% |
| 795 |
\postnotesection{\section*{Notes to ``#3''}}% |
| 796 |
}{% |
| 797 |
\IfNoValueTF{#2}{% |
| 798 |
\origlatexchapter{#3}% |
| 799 |
}{% |
| 800 |
\origlatexchapter[#2]{#3}% |
| 801 |
}% |
| 802 |
\postnotesection{\section*{Notes to chapter \pnthechapter}}% |
| 803 |
}% |
| 804 |
} |
| 805 |
\usepackage{hyperref} |
| 806 |
\begin{document} |
| 807 |
\chapter*{Introduction} |
| 808 |
Intro.\postnote{Intro note.} |
| 809 |
\chapter{First chapter} |
| 810 |
Foo.\postnote{Foo note.} |
| 811 |
Bar.\postnote{Bar note.} |
| 812 |
\chapter{Second chapter} |
| 813 |
Baz.\postnote{Baz note.} |
| 814 |
Boo.\postnote{Boo note.} |
| 815 |
\printpostnotes |
| 816 |
\end{document} |
| 817 |
\end{pnexample} |
| 818 |
|
| 819 |
Things could easily get fancier, of course. But that's the basic structure. |
| 820 |
|
| 821 |
|
| 822 |
\section{Headers} |
| 823 |
\label{sec:headers} |
| 824 |
|
| 825 |
\pkg{postnotes}' support for running headers comprises a basic header, enabled |
| 826 |
by default, generating headers in the form ``Notes to pages N--M'', but it is |
| 827 |
actually focused on generating mark data, using the \pkg{ltmarks} kernel |
| 828 |
module,\footnote{Note that ``mark'' in the context of \pkg{ltmarks} is a |
| 829 |
completely different thing than what is usually meant in the context of an |
| 830 |
end notes package. I won't try to invent terminology here, and hopefully |
| 831 |
context is sufficient for the difference to be clear. But beware.} so that |
| 832 |
users can build their own headers, possibly more elaborate ones. |
| 833 |
|
| 834 |
The default headers are generated by the function \cs{pnheaderdefault} which, |
| 835 |
as we saw in \zcref{sec:section-options} is used to set the headers in option |
| 836 |
\opt{heading} (with \cs{@mkboth}). So, the default headers are enabled |
| 837 |
through that particular setting, depending on the page style in use. |
| 838 |
|
| 839 |
Examining a slightly simplified version of the definition of |
| 840 |
\cs{pnheaderdefault} is possibly the most direct way to explore how to use the |
| 841 |
mark data generated by the package.\footnote{The ``slight simplification'' is, |
| 842 |
namely, that I'm using here a L3 \texttt{e}-type expansion for comparing the |
| 843 |
equality between the marks, instead of expanding them with |
| 844 |
\cs{protected@edef} before comparing them. The contents of the marks set by |
| 845 |
\pkg{postnotes} are typically ``safe'' in the context of an \texttt{e}-type |
| 846 |
expansion, but not necessarily so. You know them: \cs{thepage}, |
| 847 |
\cs{thechapter}, \cs{thesection}, etc. So I won't overburden the User |
| 848 |
manual with this technical aspect. But if your marks may contain fragile |
| 849 |
content, you'd need to expand them with \cs{protected@edef} before comparing |
| 850 |
with \cs{tl_if_eq:NNTF} or equivalent, as \cs{pnheaderdefault} actually |
| 851 |
does.} |
| 852 |
|
| 853 |
\begin{pnsnippet} |
| 854 |
\ExplSyntaxOn |
| 855 |
\NewDocumentCommand \pnheaderdefault {} |
| 856 |
{ |
| 857 |
\tl_if_eq:eeTF |
| 858 |
{ \FirstMark{postnotes/page} } |
| 859 |
{ \LastMark{postnotes/page} } |
| 860 |
{ \pnhdnotes{}~\pnhdtopage{}~ \FirstMark{postnotes/page} } |
| 861 |
{ |
| 862 |
\pnhdnotes{}~\pnhdtopages{}~ |
| 863 |
\FirstMark{postnotes/page}--\LastMark{postnotes/page} |
| 864 |
} |
| 865 |
} |
| 866 |
\ExplSyntaxOff |
| 867 |
\end{pnsnippet} |
| 868 |
|
| 869 |
\cs{pnhdnotes}, \cs{pnhdtopage}, and \cs{pnhdtopages} are localizable strings, |
| 870 |
which by default respectively contain ``Notes'', ``to page'', and ``to pages'' |
| 871 |
(see \zcref{sec:localization}). Let's replace them to examine the interesting |
| 872 |
part of the definition: |
| 873 |
|
| 874 |
\begin{pnsnippet} |
| 875 |
\ExplSyntaxOn |
| 876 |
\NewDocumentCommand \pnheaderdefault {} |
| 877 |
{ |
| 878 |
\tl_if_eq:eeTF |
| 879 |
{ \FirstMark{postnotes/page} } |
| 880 |
{ \LastMark{postnotes/page} } |
| 881 |
{ Notes~to~page~\FirstMark{postnotes/page} } |
| 882 |
{ Notes~to~pages~\FirstMark{postnotes/page}--\LastMark{postnotes/page} } |
| 883 |
} |
| 884 |
\ExplSyntaxOff |
| 885 |
\end{pnsnippet} |
| 886 |
|
| 887 |
What the definition of \cs{pnheaderdefault} does is to build a rule in the |
| 888 |
form: ``if the page of the first and last notes are equal, write a singular |
| 889 |
form and just one value but, if they are different, write a plural form and a |
| 890 |
range of both values''. The data used for this purpose, retrieved there by |
| 891 |
the \cs{FirstMark}/\cs{LastMark} calls, is provided by some \pkg{ltmarks} mark |
| 892 |
classes set by \pkg{postnotes}. |
| 893 |
|
| 894 |
\DescribeOption{\normalfont\emph{Mark classes}} % |
| 895 |
\DescribeOption{postnotes/page} % |
| 896 |
\DescribeOption{postnotes/chapter} % |
| 897 |
\DescribeOption{postnotes/section} % |
| 898 |
\DescribeOption{postnotes/sectname} % |
| 899 |
These mark classes class keep track of the information of interest, and can be |
| 900 |
accessed through \pkg{ltmarks}' user interface: particularly, but not only, |
| 901 |
\cs{TopMark}, \cs{FirstMark}, and \cs{LastMark}. Now, \pkg{postnotes} inserts |
| 902 |
the marks when the notes are being printed, but the values being tracked are |
| 903 |
those from where the respective note marks were originally placed, since |
| 904 |
that's what interests us for a purpose of building running headers for |
| 905 |
\cs{printpostnotes}. As their names suggest, the \opt{postnotes/page}, |
| 906 |
\opt{postnotes/chapter}, and \opt{postnotes/section} classes keep track of |
| 907 |
\cs{thepage}, \cs{thechapter}, and \cs{thesection}, respectively. The |
| 908 |
\opt{postnotes/sectname} class, in turn, tracks the name of the notes section, |
| 909 |
the one given with the \opt{name} option of \cs{postnotesection} (and is empty |
| 910 |
in case no \opt{name} was provided). |
| 911 |
|
| 912 |
With that in hand, fancier headers can be built. For example, if we'd like |
| 913 |
headers in the form ``Notes to chapters A--C, pages N--M'', we could define: |
| 914 |
\begin{pnsnippet} |
| 915 |
\ExplSyntaxOn |
| 916 |
\NewDocumentCommand \mypnheader {} |
| 917 |
{ |
| 918 |
\tl_if_eq:eeTF |
| 919 |
{ \FirstMark{postnotes/chapter} } |
| 920 |
{ \LastMark{postnotes/chapter} } |
| 921 |
{ Notes~to~chapter~\FirstMark{postnotes/chapter},~ } |
| 922 |
{ |
| 923 |
Notes~to~chapters~ |
| 924 |
\FirstMark{postnotes/chapter}--\LastMark{postnotes/chapter},~ |
| 925 |
} |
| 926 |
\tl_if_eq:eeTF |
| 927 |
{ \FirstMark{postnotes/page} } |
| 928 |
{ \LastMark{postnotes/page} } |
| 929 |
{ page~\FirstMark{postnotes/page} } |
| 930 |
{ pages~\FirstMark{postnotes/page}--\LastMark{postnotes/page} } |
| 931 |
} |
| 932 |
\ExplSyntaxOff |
| 933 |
\end{pnsnippet} |
| 934 |
and then set \opt{heading} to use \cs{mypnheader} instead of |
| 935 |
\cs{pnheaderdefault}. This definition should work well as long as all the |
| 936 |
chapters (containing notes) are numbered, but if unnumbered ones come into |
| 937 |
play, again we can fine-tune the automation, adjusting for the exception. |
| 938 |
That's the purpose of the \opt{name} option for \cs{postnotesection}, and of |
| 939 |
the \opt{postnotes/sectname} mark class. \zcref{ex:hd:fancy} illustrates |
| 940 |
their use (of course, the use of \pkg{lipsum} is just for demonstration): |
| 941 |
|
| 942 |
\begin{pnexample}[caption={Fancy headers},label={ex:hd:fancy}] |
| 943 |
\documentclass{book} |
| 944 |
\usepackage{postnotes} |
| 945 |
\postnotesetup{ |
| 946 |
heading = {% |
| 947 |
\chapter*{\pntitle} |
| 948 |
\markboth{\mypnheader}{\mypnheader}% |
| 949 |
} , |
| 950 |
} |
| 951 |
\counterwithin*{postnote}{chapter} |
| 952 |
\AddToHook{cmd/chapter/before}{% |
| 953 |
\postnotesection{\section*{Notes to chapter \pnthechapternextnote}}% |
| 954 |
} |
| 955 |
\ExplSyntaxOn |
| 956 |
\NewDocumentCommand \mypnheader {} |
| 957 |
{ |
| 958 |
\bool_case:nF |
| 959 |
{ |
| 960 |
{ |
| 961 |
\str_if_eq_p:ee { \FirstMark{postnotes/sectname} } { intro } && |
| 962 |
\str_if_eq_p:ee { \LastMark{postnotes/sectname} } { intro } |
| 963 |
} |
| 964 |
{ Notes~to~the~introduction,~ } |
| 965 |
{ |
| 966 |
\str_if_eq_p:ee { \FirstMark{postnotes/sectname} } { intro } && |
| 967 |
! \str_if_eq_p:ee { \LastMark{postnotes/sectname} } { intro } |
| 968 |
} |
| 969 |
{ Notes~to~the~introduction~and~chapter~\LastMark{postnotes/chapter},~ } |
| 970 |
} |
| 971 |
{ |
| 972 |
\tl_if_eq:eeTF |
| 973 |
{ \FirstMark{postnotes/chapter} } |
| 974 |
{ \LastMark{postnotes/chapter} } |
| 975 |
{ Notes~to~chapter~\FirstMark{postnotes/chapter},~ } |
| 976 |
{ |
| 977 |
Notes~to~chapters~ |
| 978 |
\FirstMark{postnotes/chapter}--\LastMark{postnotes/chapter},~ |
| 979 |
} |
| 980 |
} |
| 981 |
\tl_if_eq:eeTF |
| 982 |
{ \FirstMark{postnotes/page} } |
| 983 |
{ \LastMark{postnotes/page} } |
| 984 |
{ page~\FirstMark{postnotes/page} } |
| 985 |
{ pages~\FirstMark{postnotes/page}--\LastMark{postnotes/page} } |
| 986 |
} |
| 987 |
\ExplSyntaxOff |
| 988 |
\usepackage{hyperref} |
| 989 |
\usepackage{lipsum} |
| 990 |
\ExplSyntaxOn |
| 991 |
\NewDocumentCommand \demochapter { m } |
| 992 |
{ \prg_replicate:nn { #1 } { \lipsum[1-2]\postnote{\lipsum[3]}\par } } |
| 993 |
\ExplSyntaxOff |
| 994 |
\begin{document} |
| 995 |
\tableofcontents |
| 996 |
\chapter*{Introduction} |
| 997 |
\postnotesection[name=intro]{\section*{Notes to the introduction}} |
| 998 |
\demochapter{12} |
| 999 |
\chapter{Chapter 1} |
| 1000 |
\demochapter{15} |
| 1001 |
\chapter{Chapter 2} |
| 1002 |
\demochapter{15} |
| 1003 |
\printpostnotes |
| 1004 |
\end{document} |
| 1005 |
\end{pnexample} |
| 1006 |
|
| 1007 |
Note that there's absolutely no ``prescriptive'' aspect in this particular way |
| 1008 |
of setting the headers used in the examples above, by means of these functions |
| 1009 |
then used as content for \cs{markboth} or similar. This is just a way to do |
| 1010 |
things which is mostly independent of the document class in use and of the |
| 1011 |
presence of other related packages. Indeed, if you just set the \opt{heading} |
| 1012 |
option removing call to \cs{@mkboth}, or simply use a page style which |
| 1013 |
disables it, \pkg{postnotes} is completely ``hands-off'' in this area. The |
| 1014 |
main effort of the package is to generate the data, by setting appropriate |
| 1015 |
\texttt{ltmarks}, so that it is available. How to use this data is the |
| 1016 |
business of the user. The facilities of your favorite document class, or |
| 1017 |
\pkg{fancyhdr}, may well be be better options than this simple minded setup. |
| 1018 |
|
| 1019 |
|
| 1020 |
\section{Cross-references} |
| 1021 |
\label{sec:cross-references} |
| 1022 |
|
| 1023 |
Cross-referencing with \pkg{postnotes} works in a pretty standard way: set a |
| 1024 |
label, make references to it. However, there are two ways to set a label to a |
| 1025 |
note. One can either set a label with the \opt{label} option of |
| 1026 |
\cs{postnote}, or one can directly set it with the standard \cs{label} as part |
| 1027 |
of the note's content. They are both valid, but they are not equivalent, they |
| 1028 |
have different meanings and, accordingly, behave differently. |
| 1029 |
|
| 1030 |
The label set with the \opt{label} option is set at the place where |
| 1031 |
\cs{postnote} is. The label set with \cs{label} in the note's content, is |
| 1032 |
just stored, and only gets expanded when this content gets to be typeset, at |
| 1033 |
\cs{printpostnotes}. In short, the \opt{label} option belongs to the |
| 1034 |
``mark'', while the \cs{label} set in the content belongs to the ``text''. |
| 1035 |
|
| 1036 |
Of course, the data stored in each label will correspond to this difference. |
| 1037 |
Even if the plain \cs{ref} to both will get the same value (the mark), a |
| 1038 |
\cs{pageref} will be different, the links to either will point to different |
| 1039 |
places, etc. |
| 1040 |
|
| 1041 |
|
| 1042 |
\section{Localization} |
| 1043 |
\label{sec:localization} |
| 1044 |
|
| 1045 |
\DescribeMacro{\pntitle} % |
| 1046 |
\DescribeMacro{\pnhdnotes} % |
| 1047 |
\DescribeMacro{\pnhdtopage} % |
| 1048 |
\DescribeMacro{\pnhdtopages} % |
| 1049 |
\pkg{postnotes} uses a few localized strings, stored in the variables |
| 1050 |
\cs{pntitle}, \cs{pnhdnotes}, \cs{pnhdtopage}, and \cs{pnhdtopages}. The |
| 1051 |
first one is used in the default value of the \opt{heading} option and |
| 1052 |
defaults to ``Notes''. The remaining three are used in \cs{pnheaderdefault} |
| 1053 |
(and thus, indirectly also in the \opt{heading} option) and their respective |
| 1054 |
defaults are: ``Notes'', ``to page'', and ``to pages''. So, if you changed |
| 1055 |
the default value of \opt{heading} and is not using \cs{pnheaderdefault}, you |
| 1056 |
don't have to worry about them. |
| 1057 |
|
| 1058 |
These strings will automatically adjust to the document language, set either |
| 1059 |
by \pkg{babel} or by \pkg{polyglossia}, \emph{if} the language is supported by |
| 1060 |
\pkg{postnotes}. Currently supported are English, German, French, and |
| 1061 |
Portuguese. Either way, you can always change these variables to the values |
| 1062 |
of your preference. If you are not using either \pkg{babel} or |
| 1063 |
\pkg{polyglossia}, you can do so directly, for example, with: |
| 1064 |
\begin{pnsnippet} |
| 1065 |
\renewcommand*{\pntitle}{My title} |
| 1066 |
\end{pnsnippet} |
| 1067 |
However, with \pkg{babel} or \pkg{polyglossia}, and specially in a multi |
| 1068 |
language document, you must use the appropriate hooks of your language package |
| 1069 |
for this, otherwise, the next call to \cs{selectlanguage} will override your |
| 1070 |
settings. For \pkg{babel} you should use: |
| 1071 |
\begin{pnsnippet}[escapeinside=`'] |
| 1072 |
\addto\extras`\meta{language}'{\renewcommand*{\pntitle}{My title}} |
| 1073 |
\end{pnsnippet} |
| 1074 |
and for \pkg{polyglossia}: |
| 1075 |
\begin{pnsnippet}[escapeinside=`'] |
| 1076 |
\gappto\captions`\meta{language}'{\renewcommand*{\pntitle}{My title}} |
| 1077 |
\end{pnsnippet} |
| 1078 |
|
| 1079 |
|
| 1080 |
\section{Further examples} |
| 1081 |
\label{sec:further-examples} |
| 1082 |
|
| 1083 |
This section collects some further usage examples which did not fit into the |
| 1084 |
previous sections, but might still be of interest. |
| 1085 |
|
| 1086 |
\bigskip{} |
| 1087 |
|
| 1088 |
\zcref{ex:x:multi-print} illustrates a basic procedure of how to obtain a note |
| 1089 |
section for each chapter of a book, by calling \cs{printpostnotes} at the end |
| 1090 |
of each chapter: |
| 1091 |
|
| 1092 |
\begin{pnexample}[caption={Notes for each chapter},label={ex:x:multi-print}] |
| 1093 |
\documentclass{book} |
| 1094 |
\usepackage{postnotes} |
| 1095 |
\postnotesetup{heading={\section*{\pntitle}}} |
| 1096 |
\usepackage{hyperref} |
| 1097 |
\begin{document} |
| 1098 |
\chapter{First chapter} |
| 1099 |
Foo.\postnote{Foo note.} |
| 1100 |
Bar.\postnote{Bar note.} |
| 1101 |
\printpostnotes |
| 1102 |
\chapter{Second chapter} |
| 1103 |
\setcounter{postnote}{0} |
| 1104 |
Baz.\postnote{Baz note.} |
| 1105 |
Boo.\postnote{Boo note.} |
| 1106 |
\printpostnotes |
| 1107 |
\end{document} |
| 1108 |
\end{pnexample} |
| 1109 |
|
| 1110 |
\zcref{ex:x:float} shows a case of a float which disturbs the order of the |
| 1111 |
notes. It demonstrates a (traditional) technique to deal with the situation, |
| 1112 |
by setting a manual mark and adjusting the counter where appropriate. It also |
| 1113 |
illustrates the role the sorting of notes can have, by producing not only |
| 1114 |
correctly ordered note marks (as a result of the manual adjustments), but also |
| 1115 |
correctly ordered printed notes (as a result of sorting): |
| 1116 |
|
| 1117 |
\begin{pnexample}[caption={Sorting and floats},label={ex:x:float}] |
| 1118 |
\documentclass{book} |
| 1119 |
\usepackage{postnotes} |
| 1120 |
\usepackage{hyperref} |
| 1121 |
\begin{document} |
| 1122 |
\chapter{First chapter} |
| 1123 |
\postnote{1} |
| 1124 |
\postnote{2} |
| 1125 |
\begin{table}[p] |
| 1126 |
\caption{Table} |
| 1127 |
Table.\postnote[mark=5]{3} |
| 1128 |
\end{table} |
| 1129 |
\postnote{4} |
| 1130 |
\postnote{5} |
| 1131 |
\stepcounter{postnote} |
| 1132 |
\clearpage |
| 1133 |
\postnote{6} |
| 1134 |
\printpostnotes |
| 1135 |
\end{document} |
| 1136 |
\end{pnexample} |
| 1137 |
|
| 1138 |
\zcref{ex:x:caption} illustrates a couple of techniques to handle long |
| 1139 |
captions. Captions pose a problem to \cs{postnote} because, if you set a |
| 1140 |
\cs{postnote} inside a standard caption whose text is long enough to require |
| 1141 |
two lines, the content of the caption ends up being typeset twice: once to |
| 1142 |
check if it would have fitted in a single line, the second to typeset the two |
| 1143 |
lines since it didn't fit in one.\footnote{This is the case for the |
| 1144 |
\cs{caption} command provided by the kernel, but it may be different |
| 1145 |
depending on the document class, packages and options in use.} This |
| 1146 |
triggers the \texttt{postnote} counter to be stepped twice (and any other |
| 1147 |
counter that happens to be there too). One way to handle the situation is to |
| 1148 |
use the pairing between a \opt{nomark} \cs{postnote} and \cs{postnoteref}: |
| 1149 |
place a note outside the caption (but close to it, since its position will |
| 1150 |
determine the anchor for the backlink) with the \opt{nomark} option, set a |
| 1151 |
label inside it and, inside the caption make a \cs{postnoteref} to the label. |
| 1152 |
Another method is to call \cs{stepcounter}\texttt{\{postnote\}} before the |
| 1153 |
caption, then place a \cs{postnote} setting the \opt{mark} option with |
| 1154 |
\cs{arabic}\texttt{\{postnote\}}. In practice: |
| 1155 |
|
| 1156 |
\begin{pnexample}[caption={Long caption},label={ex:x:caption}] |
| 1157 |
\documentclass{article} |
| 1158 |
\usepackage[textwidth=8cm]{geometry} |
| 1159 |
\usepackage{postnotes} |
| 1160 |
\usepackage{hyperref} |
| 1161 |
\begin{document} |
| 1162 |
\begin{figure} |
| 1163 |
Figure. |
| 1164 |
\postnote[nomark]{\label{en:1}A note.}% |
| 1165 |
\caption[Short caption]{A long caption, long enough to require two |
| 1166 |
lines\postnoteref{en:1}} |
| 1167 |
\end{figure} |
| 1168 |
\begin{figure} |
| 1169 |
Figure. |
| 1170 |
\stepcounter{postnote} |
| 1171 |
\caption[Short caption]{A long caption, long enough to require two |
| 1172 |
lines\postnote[mark=\arabic{postnote}]{A note.}} |
| 1173 |
\end{figure} |
| 1174 |
\printpostnotes |
| 1175 |
\end{document} |
| 1176 |
\end{pnexample} |
| 1177 |
|
| 1178 |
Arguably, the second method is more interesting for normal cases, since it |
| 1179 |
does not offset the note's anchor. The first one would work for multiple |
| 1180 |
notes as well, and it is also more robust to multiple passes of the content. |
| 1181 |
\pkg{postnotes} controls for this in a number of known cases to avoid notes in |
| 1182 |
duplicity, but obviously cannot cover every possibility, in which case |
| 1183 |
\opt{nomark} with \cs{postnoteref} has you covered. Caveat, these techniques |
| 1184 |
assume the floats do not disturb the order of the notes, otherwise we are back |
| 1185 |
to the case discussed in \zcref{ex:x:float}. |
| 1186 |
|
| 1187 |
The (experimental) \opt{counteraux} option, shown in \zcref{ex:x:counteraux}, |
| 1188 |
is an attempt to fully ``automate away'' the issues illustrated in |
| 1189 |
\zcref{ex:x:float,ex:x:caption}, so that there's no need to manipulate either |
| 1190 |
the counter or the mark. See \zcref{sec:thorns} for discussion. |
| 1191 |
|
| 1192 |
\begin{pnexample}[caption={\opt{counteraux} option},label={ex:x:counteraux}] |
| 1193 |
\documentclass{book} |
| 1194 |
\usepackage[textwidth=8cm]{geometry} |
| 1195 |
\usepackage{postnotes} |
| 1196 |
\postnotesetup{counteraux} |
| 1197 |
\usepackage{hyperref} |
| 1198 |
\begin{document} |
| 1199 |
\chapter{First chapter} |
| 1200 |
\postnote{one} |
| 1201 |
\postnote{two} |
| 1202 |
\begin{figure}[p] |
| 1203 |
Figure.% |
| 1204 |
\caption[Short caption]{A long caption, long enough to require two |
| 1205 |
lines\postnote{three}} |
| 1206 |
\end{figure} |
| 1207 |
\postnote{four} |
| 1208 |
\postnote{five} |
| 1209 |
\clearpage |
| 1210 |
\postnote{six} |
| 1211 |
\printpostnotes |
| 1212 |
\end{document} |
| 1213 |
\end{pnexample} |
| 1214 |
|
| 1215 |
Nested notes. To be honest, the design of the package was not made with this |
| 1216 |
use case in mind. However, since \pkg{postnotes} does not use the method of |
| 1217 |
writing the notes' contents to an external file and printing the notes by |
| 1218 |
inputting it, the technical restriction of the traditional method does not |
| 1219 |
apply. Hence, it mostly works. However, nested notes are not included in the |
| 1220 |
ongoing \cs{printpostnotes}, but are left for the next call. So, if nesting, |
| 1221 |
call \cs{printpostnotes} again to print the nested ones. Which is actually |
| 1222 |
convenient, since different settings may be applied to each set. Also, expect |
| 1223 |
limitations, particularly with regard to the context variables stored by the |
| 1224 |
package: the context of a nested note is the notes section, not the one to |
| 1225 |
which the parent note belongs to. Finally, be watchful of results, because |
| 1226 |
what works does so more by luck than by design. Still, it is not too bad that |
| 1227 |
\pkg{postnotes} can handle not only nesting but even split sections of nested |
| 1228 |
notes as shown in \zcref{ex:x:nesting}. |
| 1229 |
|
| 1230 |
\begin{pnexample}[caption={Nested notes},label={ex:x:nesting}] |
| 1231 |
\documentclass{book} |
| 1232 |
\usepackage{postnotes} |
| 1233 |
\usepackage{hyperref} |
| 1234 |
\counterwithin*{postnote}{chapter} |
| 1235 |
\begin{document} |
| 1236 |
\chapter{First chapter} |
| 1237 |
\postnotesection{\section*{Notes to chapter 1}% |
| 1238 |
\setcounter{postnote}{0}% |
| 1239 |
\postnotesection{\section*{Editor's notes to chapter 1}}} |
| 1240 |
Foo.\postnote{Foo note.}\par |
| 1241 |
Bar.\postnote{Bar note.\postnote{Editor's note bar.}}\par |
| 1242 |
Baz.\postnote{A note.\postnote{Editor's note baz.}} |
| 1243 |
\chapter{Second chapter} |
| 1244 |
\postnotesection{\section*{Notes to chapter 2}% |
| 1245 |
\setcounter{postnote}{0}% |
| 1246 |
\postnotesection{\section*{Editor's notes to chapter 2}}} |
| 1247 |
Foo.\postnote{Foo note.}\par |
| 1248 |
Bar.\postnote{Bar note.\postnote{Editor's note bar.}}\par |
| 1249 |
Baz.\postnote{A note.\postnote{Editor's note baz.}} |
| 1250 |
\begingroup |
| 1251 |
\renewcommand*{\thepostnote}{\roman{postnote}} |
| 1252 |
\printpostnotes |
| 1253 |
\renewcommand*{\pntitle}{Editor's notes} |
| 1254 |
\printpostnotes |
| 1255 |
\endgroup |
| 1256 |
\end{document} |
| 1257 |
\end{pnexample} |
| 1258 |
|
| 1259 |
|
| 1260 |
\section{Thorny cases} |
| 1261 |
\label{sec:thorns} |
| 1262 |
|
| 1263 |
Depending on where one places a \cs{postnote}, some undesirable side-effects |
| 1264 |
may ensue. A note set somewhere which is subject to measuring/trial passes |
| 1265 |
may be stored multiple times, thus appearing in duplicity at |
| 1266 |
\cs{printpostnotes}.\footnote{That would normally be the case, but |
| 1267 |
\pkg{postnotes} already handles some known instances of this, avoiding the |
| 1268 |
duplicates. It doesn't mean there are not places unknown to the package |
| 1269 |
which do the same.} Also, a note placed within a float may result in the |
| 1270 |
sequence of notes being disturbed, depending on where the float ends up being |
| 1271 |
typeset. These problems are usually not too frequent, but they come up |
| 1272 |
occasionally and, when they do, they can be a pain. |
| 1273 |
|
| 1274 |
\pkg{postnotes} offers some ways to deal with these issues. Sorting falls |
| 1275 |
into this category. The traditional ``counter juggling'' around a float which |
| 1276 |
disrupted the sequence of the notes could always be used to fix the sequence |
| 1277 |
the marks got typeset (see \zcref{ex:x:float}), and the \opt{sort} option |
| 1278 |
handles the sequence at \cs{printpostnotes}. |
| 1279 |
|
| 1280 |
Besides sorting, what the package does offer is, ultimately, based on the page |
| 1281 |
labels each \cs{postnote} sets internally, the \cs{post@note}s in the |
| 1282 |
\file{.aux} file. These labels are non-immediate writes (whatsits, in the |
| 1283 |
jargon), as they must be, since we are interested in the page number. As a |
| 1284 |
result, measuring passes don't get written, and they are also written in the |
| 1285 |
order the document elements get shipped out. Hence, the labels set in the |
| 1286 |
\file{.aux} file are free of duplicates resulting from measuring passes, and |
| 1287 |
are also ordered the same as the typeset order of the document, floats |
| 1288 |
considered. Based on the information gathered from these labels, we have a |
| 1289 |
number of options. |
| 1290 |
|
| 1291 |
For known cases of measuring/trial passes where it's possible to distinguish |
| 1292 |
the measuring from the final pass, \pkg{postnotes} uses that information to |
| 1293 |
inhibit the note and also handles the counter appropriately so that the |
| 1294 |
measuring pass has the correct value to measure. Currently, such support is |
| 1295 |
provided for \pkg{amsmath} display math environments, \pkg{csquotes}' |
| 1296 |
\cs{blockcquote}s, \pkg{tabularx}, \pkg{tabularray}, and \pkg{xltabular}. For |
| 1297 |
cases where it is not possible to distinguish the trial from the final pass, |
| 1298 |
\pkg{postnotes} uses the page labels mentioned above, and for \cs{postnote}s |
| 1299 |
flagged as potential duplicates, it checks whether the page label exists, and |
| 1300 |
drops the (duplicate) note if it doesn't. Prominent example here is the |
| 1301 |
kernel's \cs{caption}. This mechanism is exposed to users through the |
| 1302 |
\opt{maybemulti} option. Important distinction here between this method and |
| 1303 |
the more controlled inhibition above is that there's little we can do about |
| 1304 |
the counter. The counter itself can be adjusted manually if need be, to |
| 1305 |
restore the sequence. But the value the measuring pass receives is out of our |
| 1306 |
hands, hence it may be off. Of course, the expected difference should |
| 1307 |
normally be small. But if the measuring is presumed to be exact, some |
| 1308 |
mysterious slightly overfull \cs{hbox}es may occur. |
| 1309 |
|
| 1310 |
\pkg{postnotes} also offers some checks, to issue warnings for cases of |
| 1311 |
duplicates or sequence problems: the \opt{checkduplicates} and |
| 1312 |
\opt{checkfloats} options. They use the information generated by the page |
| 1313 |
labels to perform some consistency checks, and report problems. I expect them |
| 1314 |
to be useful, since this is the kind of issue that may trick even a competent |
| 1315 |
proofreader. |
| 1316 |
|
| 1317 |
Finally, \pkg{postnotes} also provides the (experimental) \opt{counteraux} |
| 1318 |
option, which is an attempt to fully ``automate away'' these issues. The |
| 1319 |
basic idea is that, since we are already using the data generated by the page |
| 1320 |
labels to handle some of the issues and perform some checks, why not use that |
| 1321 |
information directly? The page labels are already net of duplicates and in |
| 1322 |
the order the document elements are typeset. Indeed, why not use them? |
| 1323 |
That's what \opt{counteraux} does: the queue which feeds \cs{printpostnotes} |
| 1324 |
is built from the calls of \cs{post@note} in the \file{.aux} file and the |
| 1325 |
counter is also stepped, as appropriate, at the same time. Technically, I |
| 1326 |
should say ``a counter'', which is then used to locally set the value of the |
| 1327 |
user facing counter, \texttt{postnote}, at the moment \cs{postnote} is called, |
| 1328 |
with a cross-reference of sorts. |
| 1329 |
|
| 1330 |
Some differences. In the standard behavior, a \cs{postnote} inside a float |
| 1331 |
belongs where the float environment was set, because that's where the |
| 1332 |
numbering of the note is defined. With \opt{counteraux}, a \cs{postnote} |
| 1333 |
inside a float belongs where the float ends up being typeset, and for the same |
| 1334 |
reason. This means a note inside a float may float past a subsequent call of |
| 1335 |
\cs{printpostnotes}, and will belong to the next call. That's actually neat, |
| 1336 |
and I'd call it a feature. But you should be mindful of the warning for |
| 1337 |
``stray notes'' issued at \texttt{enddocument} by the package, and make sure |
| 1338 |
to extinguish your floats before a final \cs{printpostnotes}. A limitation of |
| 1339 |
the package's design is that the opposite cannot occur, if a note inside a |
| 1340 |
float goes to the top of the page and happens to be typeset before a |
| 1341 |
\cs{printpostnotes} which actually precedes it, the information to print the |
| 1342 |
note is not available, so it's still left for the next call, but the numbering |
| 1343 |
will be off. |
| 1344 |
|
| 1345 |
Some inconveniences. You cannot set the counter directly, as you normally |
| 1346 |
would. Also \cs{counterwithin} will not affect the counter being stepped in |
| 1347 |
the \file{.aux} file. \pkg{postnotes} offers \cs{pnsetcounteraux} and |
| 1348 |
\cs{pnaddtocounteraux} for the purpose. But, normally, all you should ever |
| 1349 |
need is a \texttt{\textbackslash{}pnsetcounteraux\{0\}} when splitting |
| 1350 |
sections for your notes. Also, the heavy reliance on labels will normally |
| 1351 |
require one additional compilation run, and some possible transitory content |
| 1352 |
swings. |
| 1353 |
|
| 1354 |
Some caveats. I mentioned above that, in the case of multiple passes handled |
| 1355 |
with the \opt{maybemulti} method, it is hard to ensure the value of the |
| 1356 |
counter is correct for the measuring pass(es). \opt{counteraux} makes this |
| 1357 |
issue worse, because even in the cases where we can identify the measuring |
| 1358 |
pass, we can't ensure the correct value, since the sequence of the passes is |
| 1359 |
lost in the \file{.aux} file. Indeed, the measuring passes do not even exist |
| 1360 |
there, and we cannot, in general, reestablish the connection the original |
| 1361 |
sequence offered. Fortunately, there is a reasonable way around it. If a |
| 1362 |
\cs{postnote} sets a label (through the \opt{label} option of the note, not |
| 1363 |
inside the content), the connection can be reestablished. ``Connection'' is |
| 1364 |
perhaps too much of a word for this, it's simpler. With the label, a |
| 1365 |
cross-reference to the mark is available, which can then be fed to the |
| 1366 |
measuring pass. And we know that value to be correct, because the label |
| 1367 |
belongs to the pass which is actually typeset. In sum, if some measuring |
| 1368 |
problems do occur, set a label for the note, even if you do not refer to it, |
| 1369 |
\pkg{postnotes} will use it. Alas, if you are unlucky enough, you may even |
| 1370 |
find yourself stuck in an infinite loop.\footnote{In a situation similar to |
| 1371 |
\pkg{varioref}, but in the choice of which pass is the measuring and which |
| 1372 |
is the final, instead of the reference crossing page boundaries. However, |
| 1373 |
given the typical width of a mark, and the even smaller variations of those |
| 1374 |
widths which may result from floating, I expect the likelihood of meeting |
| 1375 |
such case in practice to be narrow. There is no attempt to warn about this |
| 1376 |
here though, as \pkg{varioref} does, and probably no way to do it either.} |
| 1377 |
In this case, setting the label is no relief, and the alternatives I can think |
| 1378 |
of are either using a manual mark with \cs{pnaddtocounteraux} or a |
| 1379 |
\opt{nomark} \cs{postnote} with \cs{postnoteref}. |
| 1380 |
|
| 1381 |
|
| 1382 |
\section{Acknowledgments} |
| 1383 |
|
| 1384 |
Some people have kindly contributed to \pkg{postnotes}. Suggestions, ideas, |
| 1385 |
insightful comments, solutions to problems, bug reports were generously |
| 1386 |
provided by (in chronological order): |
| 1387 |
Ulrike Fischer, |
| 1388 |
% 2022-03-22: https://chat.stackexchange.com/transcript/message/60708390#60708390 |
| 1389 |
% 2022-03-28: https://chat.stackexchange.com/transcript/message/60754383#60754383 |
| 1390 |
% 2022-03-31: https://github.com/latex3/hyperref/issues/230 |
| 1391 |
% 2022-04-09: https://github.com/latex3/hyperref/issues/229 |
| 1392 |
% 2023-02-10: https://chat.stackexchange.com/transcript/message/62955941#62955941 (and discussion) |
| 1393 |
% 2023-02-19: https://tex.stackexchange.com/q/675818#comment1678904_675818 |
| 1394 |
% 2023-12-12: https://chat.stackexchange.com/transcript/message/64848034#64848034 (and discussion) |
| 1395 |
% 2024-01-28: https://chat.stackexchange.com/transcript/message/65071091#65071091 (discussion) |
| 1396 |
% 2024-10-09: https://chat.stackexchange.com/transcript/message/66415504#66415504 (discussion) |
| 1397 |
% 2024-10-10: https://chat.stackexchange.com/transcript/message/66421777#66421777 (discussion) |
| 1398 |
% 2024-10-15: https://chat.stackexchange.com/transcript/message/66444011#66444011 (discussion) |
| 1399 |
% 2024-10-17: https://chat.stackexchange.com/transcript/message/66456022#66456022 |
| 1400 |
% 2024-10-22: https://github.com/gusbrs/postnotes/issues/8#issuecomment-2429501962 |
| 1401 |
% 2024-10-25: https://chat.stackexchange.com/transcript/message/66510334#66510334 (discussion) |
| 1402 |
% 2024-11-03: https://chat.stackexchange.com/transcript/message/66554870#66554870 (discussion) |
| 1403 |
% 2024-11-27: https://chat.stackexchange.com/transcript/message/66696438#66696438 (discussion) |
| 1404 |
David Carlisle, |
| 1405 |
% 2022-03-28: https://chat.stackexchange.com/transcript/message/60754383#60754383 |
| 1406 |
% 2022-04-08: https://tex.stackexchange.com/a/640035 (comments) |
| 1407 |
% 2023-02-10: https://chat.stackexchange.com/transcript/message/62955941#62955941 (and discussion) |
| 1408 |
% 2023-02-10: https://tex.stackexchange.com/a/674846 |
| 1409 |
% 2023-12-12: https://chat.stackexchange.com/transcript/message/64848034#64848034 (and discussion) |
| 1410 |
% 2024-01-28: https://chat.stackexchange.com/transcript/message/65071091#65071091 (discussion) |
| 1411 |
% 2024-10-15: https://chat.stackexchange.com/transcript/message/66444011#66444011 (discussion) |
| 1412 |
% 2024-11-27: https://chat.stackexchange.com/transcript/message/66696438#66696438 (discussion) |
| 1413 |
Moritz Wemheuer, |
| 1414 |
% 2022-04-05: https://tex.stackexchange.com/q/597359#comment1594585_597389 |
| 1415 |
Joseph Wright, |
| 1416 |
% 2023-02-10: https://chat.stackexchange.com/transcript/message/62955941#62955941 (and discussion) |
| 1417 |
% 2023-12-12: https://chat.stackexchange.com/transcript/message/64848034#64848034 (and discussion) |
| 1418 |
% 2024-10-15: https://chat.stackexchange.com/transcript/message/66444011#66444011 (discussion) |
| 1419 |
\username{SwitWu}, |
| 1420 |
% 2023-11-29: https://github.com/gusbrs/postnotes/pull/4 |
| 1421 |
% 2023-11-30: https://github.com/gusbrs/postnotes/pull/5 |
| 1422 |
Jonathan P. Spratte, % @Skillmon |
| 1423 |
% 2023-12-12: https://chat.stackexchange.com/transcript/message/64848034#64848034 (and discussion) |
| 1424 |
Clea F. Rees, % @cfr |
| 1425 |
% 2024-10-24: https://chat.stackexchange.com/transcript/message/66493234#66493234 (discussion) |
| 1426 |
Romano Giannetti, % @Rmano |
| 1427 |
% 2024-10-24: https://chat.stackexchange.com/transcript/message/66493234#66493234 (discussion) |
| 1428 |
and Frank Mittelbach. |
| 1429 |
% 2024-10-29: https://github.com/latex3/latex2e/issues/1514#issuecomment-2444889179 |
| 1430 |
|
| 1431 |
The package's language support have been provided or improved thanks to: |
| 1432 |
\username{Pika78} (French) |
| 1433 |
% 2022-04-25: https://github.com/gusbrs/postnotes/issues/1#issuecomment-1108634938 |
| 1434 |
and Herbert Voß (German). |
| 1435 |
% 2022-11-12: https://github.com/gusbrs/postnotes/issues/2 |
| 1436 |
|
| 1437 |
If I have inadvertently left anyone off the list I apologize, and please let |
| 1438 |
me know, so that I can correct the oversight. |
| 1439 |
|
| 1440 |
Thank you all very much! |
| 1441 |
|
| 1442 |
|
| 1443 |
\section{Change history} |
| 1444 |
|
| 1445 |
A change log with relevant changes for each version, eventual upgrade |
| 1446 |
instructions, and upcoming changes, is maintained in the package's repository, |
| 1447 |
at \url{https://github.com/gusbrs/postnotes/blob/main/CHANGELOG.md}. The |
| 1448 |
change log is also distributed with the package's documentation through CTAN |
| 1449 |
upon release so, most likely, \texttt{texdoc postnotes/changelog} should |
| 1450 |
provide easy local access to it. An archive of historical versions of the |
| 1451 |
package is also kept at \url{https://github.com/gusbrs/postnotes/releases}. |
| 1452 |
|
| 1453 |
|
| 1454 |
\end{document} |