Debian Codegraph @

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

raw
1 %\iffalse meta-comment
2 % ======================================================================
3 % marginnote.dtx
4 % Copyright © 2005—2026 Markus Kohm
5 %
6 % This file is part of the work marginnote.
7 %
8 % This work may be distributed and/or modified under the conditions of
9 % the LaTeX Project Public License, version 1.3c of the license.
10 % The latest version of this license is in
11 % http://www.latex-project.org/lppl.txt
12 % and version 1.3c or later is part of all distributions of LaTeX
13 % version 2005/12/01 or later and of this work.
14 %
15 % This work has the LPPL maintenance status "unmaintained".
16 % If you want to become the new maintainer please contact the author.
17 %
18 % This work consists of the files marginnote.dtx, README.md,
19 % LICENSE.md, and optionally the unpacked files marginnote.pdf and
20 % and marginnote.sty.
21 % ----------------------------------------------------------------------
22 % Note: This file is not only the source but also the docstrip batch
23 % file. To unpack marginnote.sty from the source, run:
24 %
25 % tex marginnote.dtx
26 %
27 % as usual. You can replace tex by pdftex, luatex or xetex.
28 % Usage of latex, pdflatex, lualatex or xelatex produces the
29 % manual marginnote.pdf.
30 % ======================================================================
31 %
32 %<*dtx>
33 \ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
34 \ProvidesFile{marginnote.dtx}[%
35 %</dtx>
36 %<package>\NeedsTeXFormat{LaTeX2e}[1995/12/01]
37 %<package>\ProvidesPackage{marginnote}[%
38 %<*package|dtx>
39 2026/01/02 1.4d non floating margin notes for LaTeX
40 %<*dtx>
41 (source + documentation)
42 %</dtx>
43 ]
44 %</package|dtx>
45 %<*dtx>
46 \ifx\documentclass\undefined
47 \input docstrip.tex
48
49 \keepsilent
50 \askforoverwritefalse
51 \usedir{tex/latex/marginnote}
52
53 \generate{%
54 \file{marginnote.sty}{\from{marginnote.dtx}{package}}%
55 }
56
57 \ifToplevel{%
58 \Msg{*********************************************************************}
59 \Msg{*}
60 \Msg{* marginnote}
61 \Msg{* ==========}
62 \Msg{*}
63 \Msg{* To finish the installation run}
64 \Msg{* \space\space pdflatex marginnote.dtx}
65 \Msg{* \space\space mkindex marginnote}
66 \Msg{* \space\space pdflatex marginnote.dtx}
67 \Msg{* \space\space mkindex marginnote}
68 \Msg{* \space\space pdflatex marginnote.dtx}
69 \Msg{* After this copy}
70 \Msg{* \space\space marginnote.sty to .../tex/latex/marginnote/}
71 \Msg{* \space\space marginnote.pdf to .../doc/latex/marginnote/}
72 \Msg{* \space\space marginnote.dtx to .../source/latex/marginnote/}
73 \Msg{* \space\space README.md
74 \space\space\space\space\space to
75 .../doc/latex/marginnote/}
76 \Msg{* \space\space LICENSE.md
77 \space\space\space\space to
78 .../doc/latex/marginnote/}
79 \Msg{* where .../ is your local TDS tree}
80 \Msg{*}
81 \Msg{*********************************************************************}
82 }
83 \else
84 \let\endbatchfile\relax
85 \fi
86 \endbatchfile
87 \documentclass{ltxdoc}
88 \usepackage{hvlogos}
89 \usepackage{marginnote}
90 \CodelineIndex
91 \RecordChanges
92 \begin{document}
93 \DocInput{marginnote.dtx}
94 \end{document}
95 %</dtx>
96 %\fi
97 %
98 % \GetFileInfo{marginnote.sty}
99 % \let\pkgversion\fileversion
100 % \let\pkgdate\filedate
101 % \GetFileInfo{marginnote.dtx}
102 %
103 % \title{Non-Floating Margin Notes with \textsf{marginnote}
104 % Package\thanks{This file has version \fileversion, last revised
105 % \filedate. \textsf{marginnote} is version \pkgversion, last revised
106 % \pkgdate.}}
107 % \author{Markus Kohm \textcolor{red}{(inactive)}\thanks{From version 1.4b the
108 % package is unmaintained. But there is a public repository with issue
109 % tracker at \url{https://codeberg.org/komascript/marginnote/issues}. So
110 % everybody can contribute and reported issues will not be lost, if a new
111 % maintainer will be found.}}
112 % \maketitle
113 %
114 % \begin{abstract}
115 % In \LaTeX{} the command \cs{marginpar}\oarg{left}\marg{right} can be used
116 % to create a note in the margin. But there is a problem with this command:
117 % It creates a special kind of float. So it cannot be used on floats or
118 % footnotes. The \textsl{marginnote} package supports another command
119 % \cs{marginnote} to create notes in the margin. This does not use any kind
120 % of float and therefore does not have the disadvantage of
121 % \cs{marginpar}. But there may be other problems \dots
122 % \end{abstract}
123 %
124 % \tableofcontents
125 %
126 % \changes{v1.0b}{2006/14/03}{spelling fixes}
127 % \changes{v1.2b}{2017/10/14}{spelling fixes (by Thomas Reuben)}
128 % \changes{v1.4c}{2023/09/07}{some documentation corrections only}
129 %
130 % \section{How to Use \textsf{marginnote} Package}
131 %
132 % First of all you have to load the package. You can use:
133 % \begin{verbatim}
134 % \usepackage{marginnote}
135 % \end{verbatim}\vskip-\baselineskip
136 % to do so. You can also use one of the following options to globally change
137 % the behaviour of \textsf{marginnote}:
138 % \begin{description}
139 % \item[\texttt{fulladjust}] adjusts the margin note to the height and depth
140 % of the current line. Note that this may sometimes add an extra height and
141 % depth to the current line, but gives the best vertical alignment. This is
142 % the default.
143 % \item[\texttt{heightadjust}] adjusts the margin note to the height of the
144 % current line, but not the depth. Note that this can sometimes result in
145 % extra height and vertical offset of the current line.
146 % \item[\texttt{depthadjust}] adjusts the margin note to the depth of the
147 % current line, but not the height. Note that this can sometimes result in
148 % extra depth and vertical offset of the current line.
149 % \item[\texttt{noadjust}] does not adjust the margin note to the height or
150 % depth of the current line. line. Note that this often results in vertical
151 % offsets, but rarely in vertical extra space before or after the current
152 % line.
153 % \item[\texttt{parboxrestore}] uses a reduced \cs{@parboxrestore} to restore
154 % the definition of \cs{par} and \cmd\\ and some other commands, and sets
155 % \cs{parindent} to 0, \cs{parfillskip} to 0\,pt plus 1\,fil and
156 % \cs{lineskip} to \cs{normallineskip}, \cs{baselineskip} to
157 % \cs{normalbaselineskip} and enables \cs{sloppy} for every margin
158 % note. This is the default since the 1.4b release of
159 % \textsf{marginnote}. Release 1.4 and 1.4a also set \cs{parskip} to 0, but
160 % this caused a vertical placement problem, e.g., inside lists like
161 % \texttt{itemize}.
162 % \item[\texttt{noparboxrestore}] does not restore any definition for the
163 % margin notes. This was the behaviour before the 1.4 release.
164 % \end{description}
165 %
166 % \DescribeMacro{\marginnote}
167 % The command \cs{marginnote}\oarg{left}\marg{right}\oarg{voffset} can be used
168 % to set a margin note using the \textsf{marginnote} package. The first
169 % optional argument and the mandatory argument are the same as for
170 % \cs{marginpar} from the \LaTeX{} kernel. Even \cs{reversemarginpar} is taken
171 % into account. The note \meta{left} or \meta{right} is set to the current
172 % vertical position. The second optional argument \meta{voffset} can be used
173 % to adjust the vertical position of the margin note. Use a negative dimension
174 % to move it up or a positive dimension to move it down.
175 %
176 % \DescribeMacro{\marginnotetextwidth}
177 % The \textsl{marginnote} package needs to know the real width of the text
178 % area to find the right margin. While some environments (e.g., of the
179 % \textsl{framed} package) change \cs{textwidth}, \textsl{marginnote} defines
180 % its own text width macro. If you change the text area after
181 % \cs{begin\{document\}} you should add
182 % \begin{verbatim}
183 % \edef\marginnotetextwidth{\the\textwidth}
184 % \end{verbatim}\vskip-\baselineskip
185 % after changing the text area. You may want to do this globally using
186 % \verb|\xdef| instead of \verb|\edef|. Most users will never need to change
187 % \cs{marginnotetextwidth}.
188 %
189 % \DescribeMacro{\marginnotevadjust}
190 % In some environments the vertical adjustment of the margin note is
191 % incorrect, e.g., one baseline too low. In this case, you can use the
192 % additional optional argument of \cs{marginnote} each time \cs{marginnote} is
193 % used, or redefine \cs{marginnotevadjust} at the beginning of the
194 % environment. The default definition is \texttt{0pt}.
195 %
196 % \DescribeMacro{\raggedleftmarginnote}
197 % \DescribeMacro{\raggedrightmarginnote}
198 % These macros define how the margin note is aligned. The defaults are
199 % \begin{itemize}
200 % \item align margin notes at the left margin right to the margin,
201 % \item align margin notes at the right margin left to the margin.
202 % \end{itemize}
203 % You can change this using \cs{renewcommand}, e.g., use^^A
204 % \changes{v1.0a}{2006/02/06}{Example to macros \cs{raggedleftmarginnote} and
205 % \cs{raggedrightmarginnote} at documentation fixed [thanks to Susumu
206 % Tanimura].}
207 % \begin{verbatim}
208 % \renewcommand*{\raggedleftmarginnote}{}
209 % \renewcommand*{\raggedrightmarginnote}{\centering}
210 % \end{verbatim}\vskip-\baselineskip
211 % to get justified text on the left and centered text on the right margin.
212 %
213 % \DescribeMacro{\marginfont}
214 % This macro sets the font to be used for margin notes. The
215 % default is \cs{normalcolor}. You may can \cs{renewcommand} to change this,
216 % e.g., use
217 % \begin{verbatim}
218 % \renewcommand*{\marginfont}{\color{red}\sffamily}
219 % \end{verbatim}\vskip-\baselineskip
220 % to get red colored margin notes in the sans serif font family. Don't forget:
221 % You need to load the \textsf{color} package or the \textsf{xcolor} package
222 % to use \cs{color}.
223 %
224 %
225 % \section{Issues Using \textsf{marginnote}}
226 %
227 % Some known issues are listed below. For new issues, it is recommended to
228 % either discuss them in a public \LaTeX{} forum or report them in
229 % \href{https://codeberg.org/komascript/marginnote}{the project's} issue
230 % tracker on Codeberg.
231 % \begin{itemize}
232 % \item Currently, the package lacks a new maintainer. The author no longer
233 % maintains the package anymore, as it was originally intended to be used as
234 % a small hack for for a few cases. But over the years it has grown and
235 % become a conglomerate of of hacks that hack hacks that are very widely
236 % used. A break with a complete overhaul of the design would be
237 % necessary. But nothing I can or want to do at the moment. If you want to
238 % do it, please \href{email:[email protected]}{contact the
239 % author}. But even without taking over maintenance, you can contribute,
240 % e.g. by participating in the issue tracker of the package.
241 % \item You cannot use paragraphs with \cs{par} or empty lines inside a margin
242 % note. In my opinion this would note make sense. However, if you really
243 % need paragraphs you can try using \cs{endgraf} instead of \cs{par}.
244 % \item From version 1.4a, a workaround is available for double-sided
245 % documents with consecutive odd or even pages. However, it is not advisable
246 % to use double-sided documents with such page sequences as printing such
247 % documents can be problematic. The \textsf{marginnote} package displays a
248 % warning message whenever it detects those page sequences.
249 % \item From version 1.3, the \texttt{marginnote} package no longer support
250 % \TeX{} engines that lack primitives \cs{pdfsavepos} and \cs{pdflastxpos},
251 % or \cs{savepos} and \cs{lastxpos}. The previous fallback option for manual
252 % adjustment has been removed. You will receive an error message if you try
253 % to use a \TeX{} engine without these primitives, and $\varepsilon$-\TeX{}
254 % primitves are also required. Nonetheless, this should not be an issue with
255 % current, free \TeX{} distributions like MiK\TeX{} or \TeX Live.
256 % \item When using double-side layout, such as with using the \texttt{twoside}
257 % class option, \cs{marginnote} requires page number information to
258 % determine if a page is odd or even, and therefore wich margin to
259 % use\,---\,left or right. \LaTeX{} operates using asynchronous
260 % output. Because of this, the counter \texttt{page} should not be used to
261 % obtain the current page number, unless at the header or footer of the
262 % page. To resolve the issue, the \textsf{marginnote} package employs a
263 % mechanism akin to labels. However, this implies that the accurate margin
264 % will not be determined during this \LaTeX{} run, but in the
265 % next. Therefore, after making any changes to the margin notes or page
266 % breaks, two \LaTeX{} runs are necessary to ensure all margins are correct.
267 % \item The \cs{marginnote} command utilizes \cs{strut} and \cs{vadjust} to
268 % position the margin note accurately. However, it may fail under certain
269 % circumstances. You may adjust the vertical position of the margin note
270 % using the second optional argument of \cs{marginnote}. Sometimes, the use
271 % of \cs{marginnote} command can cause the text outside to shift
272 % unnecessarily. You can choose from the package options
273 % \texttt{fulladjust}, \texttt{heightadjust}, \texttt{depthajust}, or
274 % \texttt{noajust} to globally adjust, or locally redefine |\mn@strut| or
275 % |\mn@zbox|.
276 %
277 % Note: The margin note always will be placed at the current vertical
278 % line. This means, if you are using two \cs{marginnote} commands at the
279 % same line, they will be put on the same place. This is not a bug but a
280 % feature!
281 % \item From version~1.1b, \cs{marginnote} commands inserted between
282 % paragraphs (or in \TeX terms: \emph{in vertical mode}) will result in the
283 % note being placed between the paragraphs instead of at the end of the
284 % preceding paragraph. You may use \cs{leavevmode} or the third optional
285 % argument of \cs{marginnote} to place it differently.
286 % \item No page break can occur within a margin note created using the
287 % \cs{marginnote} command.
288 % \item The use of \cs{marginnote} immediately after \cs{item} results in a
289 % different behavior compared to \cs{marginpar}. This is not a bug, but
290 % rather a deliberate feature!
291 % \item With math, using the \cs{marginnote} command may work or not work,
292 % depending on the math environment.
293 % \item If the horizontal position of the margin note is not correct, try
294 % another \LaTeX{} run.
295 % \item Sometimes lines may stretch vertically when using \cs{marginnote},
296 % particularly if you use \cs{marginnote} within a list \emph{and} upper
297 % case umlauts like ``\"U'', or if you have \verb|\lineskiplimit>0pt|. To
298 % resolve this issue, you can set \verb|\lineskiplimit=0pt| or
299 % \verb|\lineskiplimit=-\maxdimen| or use other available package options.
300 % \item You should not use \cs{marginnote} within the optional argument of
301 % \cs{item}.
302 % \item If \cs{if@twocolumn} is \cs{iftrue}, e.g., because you are using the
303 % |twocolumn| class option or the |\twocolumn| command, \cs{marginnote}
304 % decides whether the note should be placed to the left or right the columns
305 % by comparing the current horizontal position with \emph{left
306 % margin}|+\columnwidth+.5\columnsep|. If the current horizontal position is
307 % somewhere on the left column, the note is placed in the left margin. If
308 % the current horizontal position is somewhere right of the left column and
309 % therefore on the right column, the note is placed in the right
310 % margin. However, supporting twocolumn mode is as problematic as supporting
311 % reverse margin notes. It is not preferred. It may be revised in the
312 % future. The current support for twocolumn mode has only been implemented
313 % due to a feature request from Florent Chervet.
314 % \end{itemize}
315 %
316 % \StopEventually{\PrintIndex\PrintChanges}
317 %
318 % \section{Implementation}
319 %
320 % \iffalse
321 %<*package>
322 % \fi
323 %
324 % \changes{v1.3}{2018/04/13}{$\varepsilon$-\TeX{} removed}
325 % \changes{v1.3}{2018/04/13}{early \cs{pdfsavepos}/\cs{savepos} test}
326 %
327 % \begin{macro}{\mn@savepos}
328 % \changes{v1.3}{2018/04/13}{new internal command}
329 % \begin{macro}{\mn@lastxpos}
330 % \changes{v1.3}{2018/04/13}{new internal command}
331 % Since version 1.3 \texttt{marginnote} does need either \cs{pdfsavepos} and
332 % \cs{pdflastxpos} or \cs{savepos} and \cs{lastxpos} and does not longer
333 % support engines without these primitives. All these engines also provide
334 % $\varepsilon$-\TeX{} extensions. So we do not longer need an explicite
335 % $\varepsilon$-\TeX{} test.
336 % \begin{macrocode}
337 \begingroup
338 \@ifundefined{pdfsavepos}{%
339 \@ifundefined{savepos}{%
340 \PackageError{marginnote}{%
341 neither \string\pdfsavepos\space nor \string\savepos\space
342 available
343 }{%
344 Package `marginnote' depends on extended features of
345 PDFLaTeX,\MessageBreak
346 LuaLaTeX or XeLaTeX. It does not work without those
347 feature.\MessageBreak
348 If you'd continue the package will not provide any feature.
349 }%
350 \aftergroup\endinput
351 }{%
352 \@ifundefined{lastxpos}{%
353 \PackageError{marginnote}{%
354 \string\savepos\space but not \string\lastxpos\space
355 available
356 }{%
357 Package `marginnote' depends on extended features of
358 PDFLaTeX,\MessageBreak
359 LuaLaTeX or XeLaTeX. It does not work without those
360 feature.\MessageBreak
361 If you'd continue the package will not provide any feature.
362 }%
363 \aftergroup\endinput
364 }{%
365 \global\let\mn@savepos\savepos
366 \global\let\mn@lastxpos\lastxpos
367 \global\let\mn@pagewidth\pagewidth
368 }%
369 }%
370 }{%
371 \@ifundefined{pdflastxpos}{%
372 \PackageError{marginnote}{%
373 \string\pdfsavepos\space but not \string\pdflastxpos\space
374 available
375 }{%
376 Package `marginnote' depends on extended features of
377 PDFLaTeX,\MessageBreak
378 LuaLaTeX or XeLaTeX. It does not work without those
379 feature.\MessageBreak
380 If you'd continue the package will not provide any feature.
381 }%
382 \aftergroup\endinput
383 }{%
384 \global\let\mn@savepos\pdfsavepos
385 \global\let\mn@lastxpos\pdflastxpos
386 \global\let\mn@pagewidth\pdfpagewidth
387 }%
388 }%
389 \endgroup
390 % \end{macrocode}
391 % \end{macro}
392 % \end{macro}
393 %
394 % Next declare and process the options.
395 %
396 % \begin{macro}{\if@mn@verbose}
397 % Use verbose output mode by default. But you may change this using option
398 % \texttt{quiet}.
399 % \begin{macrocode}
400 \newif\if@mn@verbose\@mn@verbosetrue
401 \DeclareOption{verbose}{\@mn@verbosetrue}
402 \DeclareOption{quiet}{\@mn@verbosefalse}
403 % \end{macrocode}
404 % \end{macro}
405 %
406 % \changes{v1.1e}{2009/06/06}{new options \texttt{fulladjust},
407 % \texttt{heightadjust}, \texttt{depthadjust}, and \texttt{noadjust}}
408 % \begin{macro}{\mn@strut}
409 % \changes{v1.1e}{2009/06/06}{new (semi internal)}
410 % The package needs to adjust the margin note at the current line. Sometimes
411 % this causes extra vertical line spacing. To avoid this you may redefine
412 % \cs{mn@strut}. The default value is \cs{strut}.
413 % \begin{macrocode}
414 \newcommand*{\mn@strut}{}
415 % \end{macrocode}
416 % \begin{macro}{\mn@zbox}
417 % \changes{v1.1b}{2009/02/16}{new (internal)}
418 % This macro is used to set a horizontal box without height, depth and width.
419 % \begin{macrocode}
420 \newcommand{\mn@zbox}[1]{}
421 % \end{macrocode}
422 % The options do redefine both, \cs{mn@strut} and \cs{mn@zbox}.
423 % \begin{macrocode}
424 \DeclareOption{fulladjust}{%
425 \renewcommand*{\mn@strut}{\strut}%
426 \renewcommand{\mn@zbox}[1]{%
427 \bgroup
428 \setbox\@tempboxa\vbox{#1}%
429 \ht\@tempboxa\ht\strutbox
430 \dp\@tempboxa\dp\strutbox
431 \wd\@tempboxa\z@
432 \box\@tempboxa
433 \egroup
434 }%
435 }
436 \DeclareOption{heightadjust}{%
437 \renewcommand*{\mn@strut}{\begingroup\dp\strutbox\z@\strut\endgroup}%
438 \renewcommand{\mn@zbox}[1]{%
439 \bgroup
440 \setbox\@tempboxa\vbox{#1}%
441 \ht\@tempboxa\ht\strutbox
442 \dp\@tempboxa\dp\z@
443 \wd\@tempboxa\z@
444 \box\@tempboxa
445 \egroup
446 }%
447 }
448 \DeclareOption{depthadjust}{%
449 \renewcommand*{\mn@strut}{\begingroup\ht\strutbox\z@\strut\endgroup}%
450 \renewcommand{\mn@zbox}[1]{%
451 \bgroup
452 \setbox\@tempboxa\vbox{#1}%
453 \ht\@tempboxa\ht\z@
454 \dp\@tempboxa\dp\strutbox
455 \wd\@tempboxa\z@
456 \box\@tempboxa
457 \egroup
458 }%
459 }
460 \DeclareOption{noadjust}{%
461 \renewcommand*{\mn@strut}{\relax}%
462 \renewcommand{\mn@zbox}[1]{%
463 \bgroup
464 \setbox\@tempboxa\vbox{\kern-\ht\strutbox #1}%
465 \ht\@tempboxa\ht\z@
466 \dp\@tempboxa\dp\z@
467 \wd\@tempboxa\z@
468 \box\@tempboxa
469 \egroup
470 }%
471 }
472 % \end{macrocode}
473 % \end{macro}
474 % \end{macro}
475 %
476 % \changes{v1.4}{2018/07/01}{new options \texttt{parboxrestore} (default) and
477 % \texttt{noparboxrestore}}^^A
478 % \begin{macro}{\mn@parboxrestore}
479 % \changes{v1.4}{2018/07/01}{new internal command}^^A
480 % We can either use \cs{@parboxrestore} inside the margin notes or dont use
481 % it. I would recommend to use it, so this will be the new default.
482 % \begin{macrocode}
483 \newcommand*{\mn@parboxrestore}{}
484 \DeclareOption{parboxrestore}{%
485 \renewcommand*{\mn@parboxrestore}{%
486 \@tempskipa\parskip
487 \@parboxrestore
488 \parskip\@tempskipa
489 }%
490 }
491 \DeclareOption{noparboxrestore}{%
492 \renewcommand*{\mn@parboxrestore}{}%
493 }
494 % \end{macrocode}
495 % \end{macro}
496 %
497 % \begin{macrocode}
498 \ExecuteOptions{verbose,fulladjust,parboxrestore}
499 \ProcessOptions\relax
500 % \end{macrocode}
501 %
502 % \begin{macro}{\newmarginnote}
503 % We need a macro to define a new note at the \texttt{aux} file. This will
504 % be done using the mechanism of \LaTeX{} that is used for
505 % \cs{newlabel}. But we use another prefix. This will result in the usual
506 % ``Labels(s) may have changed. Rerun to get cross-references right.'' if a
507 % margin note is new or have moved to another page.
508 % \begin{macrocode}
509 \newcommand*{\newmarginnote}{\@newl@bel{mn}}
510 % \end{macrocode}
511 % \end{macro}
512 %
513 % \begin{macro}{\if@mn@pdfmode}
514 % \changes{v1.1}{2006/10/23}{new switch}^^A
515 % \changes{v1.1a}{2008/11/10}{PDF\TeX\ since 1.40 allows \cs{pdfsavepos} in
516 % DVI mode too}^^A
517 % \changes{v1.1b}{2009/02/16}{if level fixed}^^A
518 % \changes{v1.1c}{2009/02/26}{\protect\XeTeX has working \cs{pdflastxpos}^^A
519 % but no \cs{pdftexversion}}^^A
520 % \changes{v1.2}{2016/06/02}{addition for lua\TeX{} from 0.85}^^A
521 % \changes{v1.3}{2018/04/13}{removed}^^A
522 % \begin{macro}{\@mn@mode@prefix}
523 % \changes{v1.2}{2016/06/02}{(new (internal)}^^A
524 % \changes{v1.3}{2018/04/13}{removed}^^A
525 % \end{macro}
526 % \end{macro}
527 %
528 % \begin{macro}{\marginnotetextwidth}
529 % \changes{v1.1}{2006/10/23}{new macro}
530 % Some environments change \cs{textwidth}. But at PDF mode we need to know the
531 % real text width to find the right margin. So we use our own text width
532 % macro. Sometimes it may be useful if the user can set it up. Because of
533 % this it is a user command.
534 % \begin{macrocode}
535 \newcommand*{\marginnotetextwidth}{}
536 \let\marginnotetextwidth\textwidth
537 \AtBeginDocument{\edef\marginnotetextwidth{\the\textwidth}}
538 % \end{macrocode}
539 % \end{macro}
540 %
541 % \begin{macro}{\@mn@margintest}
542 % \changes{v1.1}{2006/10/23}{new PDF mode feature}
543 % \begin{macro}{\@mn@thispage}
544 % \begin{macro}{\@mn@atthispage}
545 % \begin{macro}{\@mn@currpage}
546 % \changes{v1.1}{2006/10/23}{new (internal)}
547 % \begin{macro}{\@mn@currxpos}
548 % \changes{v1.1}{2006/10/23}{new (internal)}
549 % \begin{macro}{\mn@abspage}
550 % Macro \cs{@mn@margintest} does the complete test, which margin to use. The
551 % result may be found at \cs{if@tempswa}. To avoid changes on the last page
552 % if there is a new note on the first page, try to count the notes by
553 % page. We know that this can not be successful, but never the less it may
554 % be a good try. \cs{@mn@thispage} saves the page number of the last usage
555 % of \cs{@mn@margintest}. \cs{@mn@atthispage} saves the number of margin
556 % note at this page. But we need to know the absolut page number to do
557 % this. So we increase the absolut page number \texttt{mn@abspage} at every
558 % \cs{@outputpage}. \cs{@mn@currpage} is the page from the page label if
559 % found. \cs{@mn@currxpos} is the real $x$ position may be written with the
560 % page label and used to calculate the correct horizontal offset.
561 % \begin{macrocode}
562 \newcommand*{\@mn@thispage}{}
563 \newcommand*{\@mn@currpage}{}
564 \newcommand*{\@mn@currxpos}{}
565 \newcounter{mn@abspage}
566 \AtBeginDocument{\setcounter{mn@abspage}{1}%
567 \g@addto@macro\@outputpage{%
568 \stepcounter{mn@abspage}%
569 % \end{macrocode}
570 % \changes{v1.4a}{2018/07/21}{workaround for screwball page order}^^A
571 % \changes{v1.4d}{2026/01/05}{info only in verbose mode}^^A
572 % From version 1.4a there is a workaround for consecutive odd pages or
573 % consecutive even pages in a twoside document.
574 % \begin{macrocode}
575 \ifodd\value{mn@abspage}%
576 \ifodd\value{page}%
577 \else
578 \if@twoside
579 \begingroup
580 \advance\c@page\m@ne
581 \PackageWarningNoLine{marginnote}{%
582 Consecutive odd pages found.\MessageBreak
583 Note, it is not recommended to use consecutive\MessageBreak
584 odd pages in a double-ended document.\MessageBreak
585 The pages of your document should always\MessageBreak
586 be a sequence: odd-even-odd-even-...\MessageBreak
587 Maybe you've forgotten a
588 \@ifundefined{KOMAClassName}%
589 {\string\cleardoublepage}%
590 {\string\cleardoubleoddpage}
591 before\MessageBreak
592 changing the page numbering on page \thepage
593 }%
594 \endgroup
595 \fi
596 \if@mn@verbose
597 \PackageInfo{marginnote}{Using workaround for absolute page number}%
598 \fi
599 \stepcounter{mn@abspage}%
600 \fi
601 \else
602 \ifodd\value{page}%
603 \if@twoside
604 \begingroup
605 \advance\c@page\m@ne
606 \PackageWarningNoLine{marginnote}{%
607 Consecutive even pages found.\MessageBreak
608 Note, it is not recommended to use consecutive\MessageBreak
609 even pages in a double-ended document.\MessageBreak
610 The pages of your document should always\MessageBreak
611 be a sequence: odd-even-odd-even-...\MessageBreak
612 Maybe you've forgotten a
613 \@ifundefined{KOMAClassName}%
614 {\string\cleardoublepage}%
615 {\string\cleardoubleevenpage}
616 before\MessageBreak
617 changing the page numbering on page \thepage
618 }%
619 \endgroup
620 \fi
621 \if@mn@verbose
622 \PackageInfo{marginnote}{Using workaround for absolute page number}%
623 \fi
624 \stepcounter{mn@abspage}%
625 \fi
626 \fi
627 }%
628 }
629 \newcommand*{\@mn@margintest}{%
630 % \end{macrocode}
631 % \changes{v1.2}{2016/06/02}{addition for lua\TeX{} from 0.85}^^A
632 % Number of the next margin note at this page.
633 % \begin{macrocode}
634 \expandafter\ifx\csname @mn@thispage\endcsname\@empty
635 \gdef\@mn@atthispage{1}%
636 \else\expandafter\ifnum \@mn@thispage=\value{mn@abspage}%
637 \begingroup
638 \@tempcnta\@mn@atthispage\advance\@tempcnta by \@ne
639 \xdef\@mn@atthispage{\the\@tempcnta}%
640 \endgroup
641 \else
642 \gdef\@mn@atthispage{1}%
643 \fi
644 \fi
645 \xdef\@mn@thispage{\themn@abspage}%
646 % \end{macrocode}
647 % Use the number of the page and the number of the margin note at this page
648 % to save the real number of this page at the \texttt{aux} file. At PDF mode
649 % save the current $x$ position too.
650 % \changes{v1.3}{2018/04/13}{use new internals \cs{mn@savepos} and
651 % \cs{mn@lastxpos}}^^A
652 % \changes{v1.3}{2018/04/13}{non PDF mode removed}^^A
653 % \begin{macrocode}
654 \let\@mn@currpage\relax
655 \let\@mn@currxpos\relax
656 \mn@savepos
657 \protected@write\@auxout{\let\themn@abspage\relax}{%
658 \string\newmarginnote{note.\@mn@thispage.\@mn@atthispage}{%
659 {\themn@abspage}{\noexpand\number\mn@lastxpos sp}}%
660 }%
661 % \end{macrocode}
662 % If the margin note label was not defined, it seems to be new. In this case
663 % the absolut page number will be used for the test instead of the saved
664 % real page number.
665 % \begin{macrocode}
666 \expandafter\ifx\csname mn@note.\@mn@thispage.\@mn@atthispage\endcsname\relax
667 % \end{macrocode}
668 % If we are not in two side mode, we are on a odd page.
669 % \begin{macrocode}
670 \if@twoside
671 \if@mn@verbose
672 \PackageInfo{marginnote}{Suggest that margin
673 note \@mn@thispage.\@mn@atthispage\space will be on\MessageBreak
674 absolute page \themn@abspage.\MessageBreak
675 This may be wrong}%
676 \fi
677 \ifodd\value{mn@abspage}\@tempswatrue\else\@tempswafalse\fi
678 \else
679 \if@mn@verbose
680 \PackageInfo{marginnote}{right page because not two side mode}%
681 \fi
682 \@tempswatrue
683 \fi
684 \else
685 \edef\@mn@currpage{\csname
686 mn@note.\@mn@thispage.\@mn@atthispage\endcsname}%
687 \edef\@mn@currxpos{\expandafter\@secondoftwo\@mn@currpage}%
688 % \end{macrocode}
689 % \changes{v1.1d}{2009/05/06}{take care of \cs{hoffset}}^^A
690 % Ulrike Fischer suggested a simple change to take care of \cs{hoffset},
691 % e.g., using package \textsf{crop}.
692 % \changes{v1.1d}{2009/05/06}{take care of \cs{pdfhorigin}}^^A
693 % We use this occasion to take care of \cs{pdfhorigin}, too.
694 % \changes{v1.2a}{2016/10/21}{redefine \cs{@mn@currxpos} only if not empty}^^A
695 % If \cs{@mn@currxpos} is not empty here, it should be corrected by
696 % \cs{hoffset} and maybe by \cs{pdfhorigin}.
697 % \begin{macrocode}
698 \ifx\@mn@currxpos\@empty\else
699 \edef\@mn@currxpos{\the\dimexpr \@mn@currxpos -\hoffset\relax}%
700 \begingroup\expandafter\expandafter\expandafter\endgroup
701 \expandafter\ifx\csname pdfhorigin\endcsname\relax\else
702 \begingroup\expandafter\expandafter\expandafter\endgroup
703 \expandafter\ifx\csname pdfoutput\endcsname\relax
704 \begingroup\expandafter\expandafter\expandafter\endgroup
705 \expandafter\ifx\csname outputmode\endcsname\relax\else
706 \ifnum \outputmode=1 %
707 \edef\@mn@currxpos{\the\dimexpr \@mn@currxpos -\pdfhorigin
708 +1in\relax}%
709 \fi
710 \fi
711 \else
712 \ifnum \pdfoutput=1 %
713 \edef\@mn@currxpos{\the\dimexpr \@mn@currxpos -\pdfhorigin
714 +1in\relax}%
715 \fi
716 \fi
717 \fi
718 % \end{macrocode}
719 % \changes{v1.2b}{2017/04/22}{\textsf{bidi} code added}^^A
720 % \changes{v1.3}{2018/04/13}{\texttt{twocolumn} test added}^^A
721 % \changes{v1.4d}{2026/01/02}{column detection fixed by cabohah}^^A
722 % \changes{v1.4d}{2026/01/05}{info only in verbose mode}^^A
723 % If you are using package \textsf{bidi} and RTL mode is active, the position
724 % is from right instead of left. So we have to substract \cs{@mn@currxpos}
725 % from \cs{pdfpagewidth} (or \cs{pagewidth} using Lua\TeX, but this cannot be,
726 % because \textsf{bidi} is not Lua\TeX-compatible).
727 % \begin{macrocode}
728 \ifdefined\mn@pagewidth
729 \@mn@if@RTL{%
730 \if@mn@verbose
731 \PackageInfo{marginnote}{Margin note
732 \@mn@thispage.\@mn@atthispage\space in RTL mode}%
733 \fi
734 \edef\@mn@currxpos{%
735 \the\dimexpr\mn@pagewidth-\@mn@currxpos\relax
736 }%
737 }{}%
738 \fi
739 \fi
740 \edef\@mn@currpage{\expandafter\@firstoftwo\@mn@currpage}%
741 \if@mn@verbose
742 \PackageInfo{marginnote}{Margin note \@mn@thispage.\@mn@atthispage\space
743 is on absolute page \@mn@currpage}%
744 \fi
745 \if@twoside
746 \ifodd\@mn@currpage\relax
747 \@tempswatrue
748 \if@twocolumn
749 \ifdim \@mn@currxpos
750 < \dimexpr 1in+\oddsidemargin+\columnwidth+.5\columnsep\relax
751 \@tempswafalse
752 \fi
753 \fi
754 \else
755 \@tempswafalse
756 \if@twocolumn
757 \ifdim\@mn@currxpos>\dimexpr 1in+\evensidemargin+.5\columnwidth\relax
758 \@tempswatrue
759 \fi
760 \fi
761 \fi
762 \else
763 \if@mn@verbose
764 \PackageInfo{marginnote}{right page because not two side mode}%
765 \fi
766 \@tempswatrue
767 \if@twocolumn
768 \ifdim \@mn@currxpos
769 < \dimexpr 1in+\oddsidemargin+\columnwidth+.5\columnsep\relax
770 \@tempswafalse
771 \fi
772 \fi
773 \fi
774 \fi
775 }
776 % \end{macrocode}
777 % \begin{macro}{@mn@ifRTL}
778 % \changes{v1.2b}{2017/04/22}{new internal}
779 % Test, whether or not \cs{if@RTL} exists and is true or false.
780 % \begin{macrocode}
781 \newcommand*{\@mn@if@RTL}{%
782 \begingroup\expandafter\expandafter\expandafter\endgroup
783 \expandafter\ifx\csname if@RTL\endcsname\iftrue
784 \expandafter\@firstoftwo
785 \else
786 \expandafter\@secondoftwo
787 \fi
788 }
789 % \end{macrocode}
790 % \end{macro}
791 % \end{macro}
792 % \end{macro}
793 % \end{macro}
794 % \end{macro}
795 % \end{macro}
796 % \end{macro}
797 %
798 % \begin{macro}{\marginnote}
799 % \begin{macro}{\@mn@marginnote}
800 % \begin{macro}{\@mn@@marginnote}
801 % \changes{v1.1g}{2011/04/11}{missing \cs{long} added}
802 % \begin{macro}{\@mn@@@marginnote}
803 % \changes{v1.1}{2006/10/23}{new PDF mode feature}
804 % \changes{v1.1g}{2011/04/11}{missing \cs{long} added}
805 % Command \cs{marginnote} is the main macro of the package. The others are
806 % helpers to manage the optional arguments.
807 % \begin{macrocode}
808 \newcommand*{\marginnote}{%
809 \@dblarg\@mn@marginnote
810 }
811 \newcommand{\@mn@marginnote}[2][]{%
812 \ifhmode
813 \@bsphack
814 \begingroup
815 \ifdim\@savsk>\z@\else
816 \def\:{\@xifnch}\expandafter\def\: { \futurelet\@let@token\@ifnch}%
817 \fi
818 \else
819 \begingroup
820 \fi
821 \@ifnextchar [{\@mn@@marginnote[{#1}]{#2}}{\@mn@@marginnote[{#1}]{#2}[\z@]}%
822 }
823 \newcommand{\@mn@@marginnote}{}
824 \long\def\@mn@@marginnote[#1]#2[#3]{%
825 \endgroup
826 % \end{macrocode}
827 % In horizontal mode the space hack of the \LaTeX{} kernel will be used. In
828 % vertical mode this should not be used.
829 % \begin{macrocode}
830 \ifhmode
831 \@mn@@@marginnote[{#1}]{#2}[{#3}]%
832 \@esphack
833 \else
834 \@mn@@@marginnote[{#1}]{#2}[{#3}]%
835 \fi
836 }
837 \newcommand{\@mn@@@marginnote}{}
838 \long\def\@mn@@@marginnote[#1]#2[#3]{%
839 % \end{macrocode}
840 % \changes{v1.1b}{2009/02/16}{use \cs{mn@vadjust} instead of \cs{vadjust}}%
841 % \changes{v1.1e}{2009/06/06}{use \cs{mn@strut} instead of \cs{strut}}%
842 % All changes (but change of counters that are global because of using the
843 % \LaTeX{} commands to change them an \cs{gdef} and \cs{xdef}) should be
844 % local. In h-mode a \cs{strut} will be used to fix base line. The margin
845 % note will be put to vertical list using \cs{vadjust}. This also means that
846 % wie are one line to deep. This will be corrected later using negative kern.
847 % In v-mode wie use a special kind of vbox to simply set everything. Math
848 % mode should behave like v-mode. And if we are just after an item we have
849 % to leave v-mode first.
850 % \begin{macrocode}
851 \begingroup
852 \ifmmode\mn@strut\let\@tempa\mn@vadjust\else
853 \if@inlabel\leavevmode\fi
854 \ifhmode\mn@strut\let\@tempa\mn@vadjust\else\let\@tempa\mn@vlap\fi
855 \fi
856 \@tempa{%
857 % \end{macrocode}
858 % Everything will be put upwards using a \cs{vbox} with zero height and depth
859 % and \cs{vss}. At this box the margin test will be done. If
860 % \cs{reversemarginpar} was used, the logic reverses. Then the note will be
861 % places to the margin.
862 % \begin{macrocode}
863 \vbox to\z@{%
864 \vss
865 \@mn@margintest
866 \if@reversemargin\if@tempswa
867 \@tempswafalse
868 \else
869 \@tempswatrue
870 \fi\fi
871 \if@tempswa
872 \rlap{%
873 % \end{macrocode}
874 % If \cs{@mn@currxpos} is neither \cs{relax} nor empty it is the real
875 % current $x$ position of the last PDF\LaTeX{} run and may be used to
876 % calculate the real horizontal offset.
877 % \begin{macrocode}
878 \if@mn@verbose
879 \PackageInfo{marginnote}{xpos seems to be \@mn@currxpos}%
880 \fi
881 \begingroup
882 \ifx\@mn@currxpos\relax\else\ifx\@mn@currxpos\@empty\else
883 \kern-\dimexpr\@mn@currxpos\relax
884 \fi\fi
885 \ifx\@mn@currpage\relax
886 \let\@mn@currpage\@ne
887 \fi
888 \if@twoside\ifodd\@mn@currpage\relax
889 \kern\oddsidemargin
890 \else
891 \kern\evensidemargin
892 \fi
893 \else
894 \kern\oddsidemargin
895 \fi
896 \kern 1in
897 \endgroup
898 \kern\marginnotetextwidth\kern\marginparsep
899 \vbox to\z@{\kern\marginnotevadjust\kern #3
900 \vbox to\z@{%
901 \hsize\marginparwidth
902 % \end{macrocode}
903 % \changes{v1.1g}{2011/04/11}{set \cs{linewidth}}
904 % \begin{macrocode}
905 \linewidth\hsize
906 % \end{macrocode}
907 % Here's the correction of the vertical position. The remain is simple.
908 % \changes{v1.1i}{2012/03/29}{\cs{strut} moved to fix hyphenation (thanks to
909 % Ulrike Fischer)}
910 % \changes{v1.1i}{2012/03/29}{\cs{ignorespaces} added}^^A
911 % \changes{v1.4}{2018/07/01}{\cs{mn@parboxrestore} added}^^A
912 % \begin{macrocode}
913 \kern-\parskip
914 \mn@parboxrestore
915 \marginfont\raggedrightmarginnote\strut\hspace{\z@}%
916 \ignorespaces#2\endgraf
917 \vss}%
918 \vss}%
919 }%
920 \else
921 % \end{macrocode}
922 % Using the left margin.
923 % \changes{v1.1f}{2010/01/05}{missing usage of \cs{marginnotevadjust} on
924 % left margin fixed}
925 % \begin{macrocode}
926 \llap{%
927 \vbox to\z@{\kern\marginnotevadjust\kern #3
928 \vbox to\z@{%
929 \hsize\marginparwidth
930 % \end{macrocode}
931 % \changes{v1.1g}{2011/04/11}{set \cs{linewidth}}
932 % \begin{macrocode}
933 \linewidth\hsize
934 % \end{macrocode}
935 % Same like above for left margins.
936 % \begin{macrocode}
937 \kern-\parskip
938 \mn@parboxrestore
939 \marginfont\raggedleftmarginnote\strut\hspace{\z@}%
940 \ignorespaces#1\endgraf
941 \vss
942 }%
943 \vss
944 }%
945 \if@mn@verbose
946 \PackageInfo{marginnote}{xpos seems to be \@mn@currxpos}%
947 \fi
948 \begingroup
949 \ifx\@mn@currxpos\relax\else\ifx\@mn@currpos\@empty\else
950 \kern\@mn@currxpos
951 \fi\fi
952 \ifx\@mn@currpage\relax
953 \let\@mn@currpage\@ne
954 \fi
955 \if@twoside\ifodd\@mn@currpage\relax
956 \kern-\oddsidemargin
957 \else
958 \kern-\evensidemargin
959 \fi
960 \else
961 \kern-\oddsidemargin
962 \fi
963 \kern-1in
964 \endgroup
965 \kern\marginparsep
966 }%
967 \fi
968 }%
969 }%
970 \endgroup
971 }
972 % \end{macrocode}
973 % \end{macro}
974 % \end{macro}
975 % \end{macro}
976 % \end{macro}
977 %
978 % \begin{macro}{\marginnoterightadjust}
979 % \changes{v1.3}{2018/04/13}{removed}^^A
980 % \begin{macro}{\marginnoteleftadjust}
981 % \changes{v1.3}{2018/04/13}{removed}^^A
982 % \end{macro}
983 % \end{macro}
984 %
985 % \begin{macro}{\marginnotevadjust}
986 % This may be used to define an automatic vertical adjust. The defaul tis
987 % zero. Values greater than zero will move the margin note down, values less
988 % than zero will move the margin note up.
989 % \begin{macrocode}
990 \newcommand*{\marginnotevadjust}{}
991 \let\marginnotevadjust\z@
992 % \end{macrocode}
993 % \end{macro}
994 %
995 % \begin{macro}{\mn@vlap}
996 % This macro is used to set a vertical box without size at vertical mode.
997 % \begin{macrocode}
998 \newcommand{\mn@vlap}[1]{%
999 \setbox\@tempboxa\vbox to \ht\strutbox{#1\vss}%
1000 \box\@tempboxa\vskip-\baselineskip
1001 }
1002 % \end{macrocode}
1003 % \end{macro}
1004 %
1005 % \begin{macro}{\mn@vadjust}
1006 % \changes{v1.1b}{2009/02/16}{new (internal)}
1007 % This macro is used to set a vertical box at horizontal mode.
1008 % \begin{macrocode}
1009 \newcommand{\mn@vadjust}[1]{%
1010 \mn@zbox{\kern-\parskip
1011 \leavevmode\vadjust{#1}%
1012 \kern\parskip
1013 }%
1014 }
1015 % \end{macrocode}
1016 % \end{macro}
1017 %
1018 % \begin{macro}{\marginfont}
1019 % \changes{v1.0a}{2006/02/06}{Use \cs{providecommand} to define it.}
1020 % \begin{macro}{\raggedleftmarginnote}
1021 % \begin{macro}{\raggedrightmarginnote}
1022 % These are very simple. A class may also define \cs{marginfont}. Use this
1023 % if available. I don't use \cs{let} for the definitions of the ragged
1024 % macros, so the meaning may change loading e.g. package \textsf{ragged2e}.
1025 % \begin{macrocode}
1026 \providecommand*{\marginfont}{}
1027 \newcommand*{\raggedleftmarginnote}{\raggedleft}
1028 \newcommand*{\raggedrightmarginnote}{\raggedright}
1029 % \end{macrocode}
1030 % \end{macro}
1031 % \end{macro}
1032 % \end{macro}
1033 %
1034 % \Finale
1035 %
1036 \endinput
1037 %
1038 % end of `marginnote.dtx'
1039 %
1040 % Local Variables:
1041 % mode: doc-tex
1042 % TeX-master: t
1043 % End: