Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 % Copyright 2017, 2018 Maurice Leclaire <[email protected]>
4 %
5 % This work may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either
7 % version 1.3 of this license or (at your option) any later
8 % version. The latest version of this license is in:
9 %
10 % http://www.latex-project.org/lppl.txt
11 %
12 % and version 1.3 or later is part of all distributions of LaTeX
13 % version 2005/12/01 or later.
14 %
15 % This work has the LPPL maintenance status `author-maintained'.
16 %
17 % This work consists of the files marginfit.dtx and marginfit.ins
18 % and the derived file marginfit.sty.
19 %
20 % \fi
21 %
22 % \iffalse
23 %<package>\NeedsTeXFormat{LaTeX2e}
24 %<package>\ProvidesPackage{marginfit}[2018/06/08 v1.1 Fit Margin Paragraphs]
25 %
26 %<*driver>
27 \documentclass{ltxdoc}
28 \CheckSum{0}
29 \makeatletter
30 \usepackage{mparhack}
31 \let\mparhack@addmarginpar\@addmarginpar
32 \let\@addmarginpar\mph@orig@addmarginpar
33 \let\marginfix@orig@marginpar\marginpar
34 \let\marginfix@orig@addmarginpar\@addmarginpar
35 \let\marginfix@orig@combinefloats\@combinefloats
36 \usepackage{marginfix}
37 \let\marginfix@marginpar\marginpar
38 \let\marginfix@addmarginpar\@addmarginpar
39 \let\marginfix@combinefloats\@combinefloats
40 \let\marginpar\marginfix@orig@marginpar
41 \let\@addmarginpar\marginfix@orig@addmarginpar
42 \let\@combinefloats\marginfix@orig@combinefloats
43 \let\marginfit@orig@marginpar\marginpar
44 \usepackage{marginfit}
45 \let\marginfit@marginpar\marginpar
46 \let\marginpar\marginfit@orig@marginpar
47 \makeatother
48 \usepackage[pass]{geometry}
49 \usepackage{minidocument}
50 \usepackage{blindtext}
51 \EnableCrossrefs
52 \CodelineIndex
53 \RecordChanges
54 \begin{document}
55 \DocInput{marginfit.dtx}
56 \end{document}
57 %</driver>
58 % \fi
59 %
60 % \changes{v1.0}{2017/07/07}{Initial version}
61 %
62 % \GetFileInfo{marginfit.sty}
63 %
64 % \DoNotIndex{\def,\let,\global,\long,\expandafter}
65 % \DoNotIndex{\csname,\endcsname,\advance,\string}
66 % \DoNotIndex{\if,\else,\fi,\ifdim,\ifodd,\ifvoid,\ifcsname,\@ifnextchar}
67 % \DoNotIndex{\chardef,\count,\dimen,\skip,\box,\setbox,\lastbox,\copy}
68 % \DoNotIndex{\hbox,\vbox,\unhbox,\unvbox,\hskip,\vskip,\hss,\hrule,\vfill}
69 % \DoNotIndex{\the,\ht,\dp,\@ne,\z@,\maxdimen}
70 %
71 % \title{The \textsf{marginfit} package}
72 % \author{Maurice Leclaire\\\texttt{[email protected]}}
73 % \date{\fileversion\ -- \filedate}
74 % \maketitle
75 %
76 % \begin{abstract}
77 % The \textsf{marginfit} package fixes various bugs with the margin paragraph
78 % implementation of \LaTeX. Those bugs include margin notes that are attached
79 % to the wrong side as well as those that stick out of the bottom of the page.
80 % This package provides a drop-in replacement solution.
81 % \end{abstract}
82 %
83 % \tableofcontents
84 %
85 % \def\minidocumentscale{0.3}
86 %
87 % \newcounter{margin}
88 % \def\testmargin{\stepcounter{margin}\rule{0.7em}{0.7em}\marginpar[{
89 % \hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hbox to 0pt {\rule[-0.1em]{3\marginparsep}{0.1em}\hss}\hfill\null\\
90 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
91 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\[-0.1em]
92 % \null\hfill\rule[-0.3em]{0.3\marginparwidth}{2.5em}\hbox to 0.4\marginparwidth {\hfill\Huge\themargin\hfill}\rule[-0.3em]{0.3\marginparwidth}{2.5em}\hfill\null\\
93 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
94 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
95 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
96 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
97 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
98 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null
99 % }]{
100 % \hfill\hbox to 0pt {\hss\rule[-0.1em]{3\marginparsep}{0.1em}}\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
101 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
102 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\[-0.1em]
103 % \null\hfill\rule[-0.3em]{0.3\marginparwidth}{2.5em}\hbox to 0.4\marginparwidth {\hfill\Huge\themargin\hfill}\rule[-0.3em]{0.3\marginparwidth}{2.5em}\hfill\null\\
104 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
105 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
106 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
107 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
108 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null\\
109 % \null\hfill\rule[-0.3em]{\marginparwidth}{1.2em}\hfill\null
110 % }}
111 %
112 % \def\testdocument{
113 % \begin{minidocument}
114 % \newgeometry{
115 % twoside,
116 % inner=1in,
117 % outer=2in,
118 % top=1in,
119 % bottom=1in,
120 % marginparwidth=1in,
121 % marginparsep=0.5in
122 % }
123 % \normalmarginpar
124 % \setlength{\marginparpush}{1em}
125 % \setcounter{page}{2}
126 % \setcounter{margin}{0}
127 % \blindtext\par
128 % \blindtext\par
129 % \blindtext\par
130 % \testmargin
131 % \blindtext\par
132 % \blindtext\par
133 % \begin{itemize}
134 % \item First formula $$ f(x) = 1 / x$$
135 % \item Second formula $$ f(x) = 1 / x$$
136 % \item Third formula $$ f(x) = 1 / x$$
137 % \end{itemize}
138 % \testmargin
139 % \blindtext
140 % \vfill
141 % \blindtext
142 % \testmargin
143 % \blindtext
144 % \blindtext
145 % \testmargin
146 % \blindtext
147 % \testmargin
148 % \blindtext
149 % \clearpage
150 % \end{minidocument}
151 % }
152 %
153 % \newbox\doclatex
154 % \newbox\docmparhack
155 % \newbox\docmarginfix
156 % \newbox\docmarginfit
157 %
158 % \makeatletter
159 % \begingroup
160 % \testdocument
161 % \endgroup
162 % \setbox\doclatex\hbox{\lastminidocument}
163 % \Gm@changelayout
164 % \makeatother
165 %
166 % \makeatletter
167 % \begingroup
168 % \let\@addmarginpar\mparhack@addmarginpar
169 % \mph@setcol{ii:2}{1}
170 % \mph@setcol{ii:3}{5}
171 % \testdocument
172 % \endgroup
173 % \setbox\docmparhack\hbox{\lastminidocument}
174 % \Gm@changelayout
175 % \makeatother
176 %
177 % \makeatletter
178 % \begingroup
179 % \let\marginpar\marginfix@marginpar
180 % \let\@addmarginpar\marginfix@addmarginpar
181 % \let\@combinefloats\marginfix@combinefloats
182 % \testdocument
183 % \endgroup
184 % \setbox\docmarginfix\hbox{\lastminidocument}
185 % \Gm@changelayout
186 % \makeatother
187 %
188 % \makeatletter
189 % \begingroup
190 % \let\marginpar\marginfit@marginpar
191 % \testdocument
192 % \endgroup
193 % \setbox\docmarginfit\hbox{\lastminidocument}
194 % \Gm@changelayout
195 % \makeatother
196 %
197 % \begin{figure}[p]
198 % \hbox to \textwidth {\hss\unhbox\doclatex}
199 % \caption{Plain \LaTeX}
200 % \label{fig:latex}
201 % \end{figure}
202 %
203 % \begin{figure}[p]
204 % \hbox to \textwidth {\hss\unhbox\docmparhack}
205 % \caption{\textsf{mparhack} package}
206 % \label{fig:mparhack}
207 % \end{figure}
208 %
209 % \begin{figure}[p]
210 % \hbox to \textwidth {\hss\unhbox\docmarginfix}
211 % \caption{\textsf{marginfix} package}
212 % \label{fig:marginfix}
213 % \end{figure}
214 %
215 % \begin{figure}[p]
216 % \hbox to \textwidth {\hss\unhbox\docmarginfit}
217 % \caption{\textsf{marginfit} package}
218 % \label{fig:marginfit}
219 % \end{figure}
220 %
221 % \section{Motivation}
222 %
223 % The margin paragraph mechanism of \LaTeX\ has two main problems:
224 % \begin{enumerate}
225 % \item Near after a page break, it can happen that a margin note is placed
226 % at the wrong side. See Margin Note~2 in Figure~\ref{fig:latex}.
227 % \item Margin notes can stick out the bottom of the page. See Margin
228 % Note~5 in Figure~\ref{fig:latex}. This happens if margin notes are too
229 % large for the remaining space on the page or if they are shifted down,
230 % because they do not fit at the callout position. However, \LaTeX\ does
231 % not shift margin notes upwards, even if there would be enough space.
232 % \end{enumerate}
233 % Those problems are caused by calling the output routine for each margin
234 % paragraph and placing it separately, only considering previously placed
235 % margin notes. This can lead to wrong assumptions concerning the actual page
236 % break, which then results in Problem~1. Further, this mechanism prevents look
237 % ahead, which is the reason for Problem~2. Margin notes can be shifted down
238 % based on the previous margin notes, but there is no possibility to shift them
239 % up, if that would be necessary for later margin notes.
240 %
241 % The \textsf{mparhack} package\cite{mparhack} addresses Problem~1. This is
242 % demonstrated in Figure~\ref{fig:mparhack}. Problem~1 is completely fixed by
243 % this package without any known drawbacks and it also works in twocolumn mode.
244 % However, the package does not consider problem~2.
245 %
246 % On the other hand, the \textsf{marginfix} package\cite{marginfix} addresses
247 % Problem~2. This is shown in Figure~\ref{fig:marginfix}. However, this comes
248 % with a lot of disadvantages:
249 % \begin{itemize}
250 % \item The \textsf{marginfix} package does not support twocolumn mode.
251 % \item The \LaTeX\ Problem~1 manifests itself in another way: Margin notes
252 % are attached to the wrong page instead of the wrong side.
253 % \item The baseline (of the first line) of the margin note is not aligned
254 % with the baseline of the callout position. Instead the top of the margin
255 % note is aligned with the top of a strut at the callout position. This
256 % gives us the misalignement seen for Margin Note~1 as the height of this
257 % margin note is a bit more than that of a strut.
258 % \item The margin notes are positioned at the natural height of the
259 % callout position. However, the actual height can be different depending on
260 % the glue on the page. The \textsf{marginfix} package does not consider
261 % this glue and the effect can be seen for Margin Note~3.
262 % \end{itemize}
263 %
264 % In contrast to the packages above, the \textsf{marginfit} package is not a
265 % hack to the margin paragraph mechanism of \LaTeX\ but a complete
266 % reimplementation. Instead of calling the output routine for each margin note,
267 % it uses \TeX\ insertions. Hence, the margin notes are not placed individually
268 % at callout time but together at the time a complete column is assembled.
269 % Therefore, it does not suffer from the problems described above. The result
270 % can be observed in Figure~\ref{fig:marginfit}.
271 %
272 % \section{Usage}
273 %
274 % The \textsf{marginfit} package is a drop-in replacement for the normal margin
275 % paragraph mechanism. Therefore, putting \verb|\usepackage{marginfit}| into the
276 % preamble of your document is sufficient. This package requires the
277 % \verb|\pdfsavepos| functionality from pdf\TeX.
278 %
279 % \StopEventually{
280 % \begin{thebibliography}{1}
281 % \raggedright
282 % \bibitem{mparhack}
283 % Tom Sgouros and Stefan Ulrich.
284 % \newblock \texttt{mparhack.sty}.
285 % \newblock \textsc{ctan}: \url{http://ctan.org/pkg/mparhack}
286 % \bibitem{marginfix}
287 % Stephen Hicks.
288 % \newblock \textsf{marginfix} package documentation.
289 % \newblock \textsc{ctan}: \url{http://ctan.org/pkg/marginfix}
290 % \end{thebibliography}
291 % \PrintChanges
292 % \setcounter{IndexColumns}{2}
293 % \PrintIndex
294 % }
295 %
296 % \section{Implementation}
297 %
298 % \begin{macro}{\marginfit@insert}
299 % We define a new insertion class named \verb|\marginfit@insert|. All margin
300 % paragraphs will be inserted there. At shipout time the respective box will
301 % hold all the inserted margins for the respective page or column.
302 % \begin{macrocode}
303 \newinsert\marginfit@insert
304 % \end{macrocode}
305 % As a margin note does not account for the page goal, we set the corresponding
306 % magnification count to zero.
307 % \begin{macrocode}
308 \count\marginfit@insert0
309 % \end{macrocode}
310 % Also the respective skip with the amount of fixed size material is set to
311 % 0\,pt.
312 % \begin{macrocode}
313 \skip\marginfit@insert\z@
314 % \end{macrocode}
315 % As the magnification factor is zero, we can not track the amount of margin
316 % material. Also, we do not want margins to be shifted to another page. Hence,
317 % the corresponding dimension with the maximum amount of insertions per page is
318 % set to the maximum.
319 % \begin{macrocode}
320 \dimen\marginfit@insert\maxdimen
321 % \end{macrocode}
322 % \end{macro}
323 % \begin{macro}{\marginfit@reverse}
324 % We allocate a new box register were we store the margin notes in reverse
325 % order.
326 % \begin{macrocode}
327 \newbox\marginfit@reverse
328 % \end{macrocode}
329 % \end{macro}
330 %
331 % \begin{macro}{\marginfit@box}
332 % \begin{macro}{\marginfit@left}
333 % \begin{macro}{\marginfit@right}
334 % We also define a few aliases for temporary box registers.
335 % \begin{macrocode}
336 \chardef\marginfit@box0
337 \chardef\marginfit@left0
338 \chardef\marginfit@right1
339 % \end{macrocode}
340 % \end{macro}
341 % \end{macro}
342 % \end{macro}
343 %
344 % \begin{macro}{\c@marginfit@w}
345 % \begin{macro}{\c@marginfit@r}
346 % \begin{macro}{\c@marginfit@t}
347 % A few counters are needed to enumerate labels. The first counter is used when
348 % writing the positions of margin notes to the aux file and the second is used
349 % when reading them in again. The third counter is used for the top positions of
350 % margin columns.
351 % \begin{macrocode}
352 \newcount\c@marginfit@w
353 \newcount\c@marginfit@r
354 \newcount\c@marginfit@t
355 % \end{macrocode}
356 % \end{macro}
357 % \end{macro}
358 % \end{macro}
359 %
360 % \begin{macro}{\marginfit@top}
361 % \begin{macro}{\marginfit@min}
362 % \begin{macro}{\marginfit@pos}
363 % We need some dimension registers to compute the placement of margin notes.
364 % Those are the current top of the margin column, the minimal position the
365 % current margin note can be placed in and the callout position of the current
366 % margin note.
367 % \begin{macrocode}
368 \newdimen\marginfit@top
369 \newdimen\marginfit@min
370 \newdimen\marginfit@pos
371 % \end{macrocode}
372 % \end{macro}
373 % \end{macro}
374 % \end{macro}
375 %
376 % \begin{macro}{\marginfit@writepos}
377 % The following macro saves the current position as a label to the aux file. The
378 % parameter takes the number\,/\,name of the label in already expanded form.
379 % \begin{macrocode}
380 \def\marginfit@writepos#1{%
381 \pdfsavepos%
382 \write\@auxout{\string\@newl@bel{label@marginfit}{#1}{\the\pdflastypos}}%
383 }
384 % \end{macrocode}
385 % \end{macro}
386 %
387 % \begin{macro}{\marginfit@boxforeach}
388 % We define a macro that loops over a vbox to execute code for each hbox in
389 % that vbox. Due to the limited possibilities to access the inner boxes, we
390 % must do that in reverse order. The first parameter is the box register number
391 % and the second parameter is the code that should be executed for each hbox.
392 % During execution \verb|\marginfit@box| holds the current hbox.
393 % \begin{macrocode}
394 \def\marginfit@boxforeach#1#2{%
395 \setbox#1\vbox{\unvbox#1 \global\setbox\marginfit@box\lastbox}%
396 \ifvoid\marginfit@box\else%
397 #2%
398 \marginfit@boxforeach#1{#2}%
399 \fi%
400 }
401 % \end{macrocode}
402 % \end{macro}
403 %
404 % \begin{macro}{\marginfit@pass@i}
405 % This is the first pass of the margin positioning routine. For each margin
406 % note, the following macro splits the packed hbox to get the left and right
407 % version of the margin paragraph. In the following we will use the correct
408 % version, due to the setting of \verb|\marginfit@side|. The minimum position
409 % is updated based on the size of the margin. The margin notes will be saved in
410 % reverse order in the reverse box.
411 % \begin{macrocode}
412 \def\marginfit@pass@i{%
413 \setbox\marginfit@left\hbox{\unhbox\marginfit@box%
414 \global\setbox\marginfit@right\lastbox}%
415 \setbox\marginfit@right\hbox{\box\marginfit@right}%
416 \advance\marginfit@min\ht\marginfit@side%
417 \advance\marginfit@min\dp\marginfit@side%
418 \advance\marginfit@min\marginparpush%
419 \setbox\marginfit@reverse\vbox{\unvbox\marginfit@reverse%
420 \box\marginfit@side}%
421 }
422 % \end{macrocode}
423 % \end{macro}
424 %
425 % \begin{macro}{\marginfit@pass@ii}
426 % This is the second pass of the margin positioning routine. For each margin
427 % note, the callout position is read from the aux file. We compute the glue
428 % above the margin note. If the minimum position requires it, we shift the
429 % margin note upwards. If the current top position requires it, we shift the
430 % margin note downwards. Afterwards we update the top and minimum positions.
431 % Finally, the margin note is attached to the margin box.
432 % \begin{macrocode}
433 \def\marginfit@pass@ii{%
434 \global\advance\c@marginfit@r\@ne%
435 \ifcsname label@marginfit@\the\c@marginfit@r @m\endcsname%
436 \marginfit@pos\csname label@marginfit@\the\c@marginfit@r @m\endcsname sp%
437 \fi%
438 \advance\marginfit@pos\ht\marginfit@box%
439 \ifdim\marginfit@pos<\marginfit@min%
440 \marginfit@pos\marginfit@min%
441 \fi%
442 \advance\marginfit@top-\marginfit@pos%
443 \ifdim\marginfit@top<\marginparpush%
444 \advance\marginfit@pos\marginfit@top%
445 \advance\marginfit@pos-\marginparpush%
446 \marginfit@top\marginparpush%
447 \fi%
448 \vskip\marginfit@top%
449 \marginfit@top\marginfit@pos%
450 \advance\marginfit@top-\ht\marginfit@box%
451 \advance\marginfit@top-\dp\marginfit@box%
452 \advance\marginfit@min-\ht\marginfit@box%
453 \advance\marginfit@min-\dp\marginfit@box%
454 \advance\marginfit@min-\marginparpush%
455 \hrule height\z@%
456 \box\marginfit@box%
457 \hrule height\z@%
458 }%
459 % \end{macrocode}
460 % \end{macro}
461 %
462 % \begin{macro}{\marginfit@marginbox}
463 % The following macro constructs the margin box. First, at the top of the box
464 % the position is saved and read in as \verb|\marginfit@top| if available. Then,
465 % \verb|\marginfit@min| is computed as the bottom of the box. The first
466 % boxforeach loop is executed on the box with the margin insertions. It computes
467 % the real \verb|\marginfit@min| for the first margin note and saves the margin
468 % notes in reverse order into the reverse box. The second pass is executed on
469 % that reverse box and puts the margins into the right positions.
470 % \begin{macrocode}
471 \def\marginfit@marginbox{%
472 \vbox to\@colht {%
473 \global\advance\c@marginfit@t\@ne%
474 \expandafter\marginfit@writepos\expandafter{\the\c@marginfit@t @t}%
475 \ifcsname label@marginfit@\the\c@marginfit@t @t\endcsname%
476 \marginfit@top\csname label@marginfit@\the\c@marginfit@t @t\endcsname sp%
477 \fi%
478 \marginfit@min\marginfit@top%
479 \advance\marginfit@min-\@colht%
480 \advance\marginfit@min-\marginparpush%
481 \advance\marginfit@top\marginparpush%
482 \vskip-\marginparpush%
483 \marginfit@boxforeach\marginfit@insert\marginfit@pass@i%
484 \marginfit@boxforeach\marginfit@reverse\marginfit@pass@ii%
485 \vfill%
486 }%
487 }%
488 % \end{macrocode}
489 % \end{macro}
490 %
491 % \begin{macro}{\marginfit@leftmargin}
492 % The following macro appends a left margin to the current column.
493 % \begin{macrocode}
494 \def\marginfit@leftmargin{%
495 \let\marginfit@side\marginfit@left%
496 \hss%
497 \marginfit@marginbox%
498 \hskip\marginparsep%
499 \box\@outputbox%
500 }
501 % \end{macrocode}
502 % \end{macro}
503 %
504 % \begin{macro}{\marginfit@rightmargin}
505 % The following macro appends a right margin to the current column.
506 % \begin{macrocode}
507 \def\marginfit@rightmargin{%
508 \let\marginfit@side\marginfit@right%
509 \box\@outputbox%
510 \hskip\marginparsep%
511 \marginfit@marginbox%
512 \hss%
513 }
514 % \end{macrocode}
515 % \end{macro}
516 %
517 % \begin{macro}{\@makecol}
518 % We redefine \verb|\@makecol| and add the procedure to append a margin to the
519 % current column. First, the original \verb|\@makecol| is executed. Then, the
520 % width of \verb|\@outputbox| is set to \verb|\columnwidth| (added in v1.1).
521 % \changes{v1.1}{2018/06/07}{Fix width of \texttt{\symbol{`\\}@outputbox}}
522 % This is necessary as a \verb|\parshape| that overflows on the right will
523 % enlarge \verb|\@outputbox|. If we have margin material, we decide on which
524 % side the margin column will be and add it to that side. A check for onesided
525 % documents was added in v1.1.
526 % \changes{v1.1}{2018/06/08}{Margin placement in onesided documents}
527 % \begin{macrocode}
528 \let\marginfit@makecol\@makecol
529 \def\@makecol{%
530 \marginfit@makecol%
531 \wd\@outputbox\columnwidth%
532 \ifvoid\marginfit@insert\else%
533 \setbox\@outputbox\vbox to\@colht {%
534 \hbox to\columnwidth {%
535 \if@twocolumn%
536 \if@firstcolumn%
537 \marginfit@leftmargin%
538 \else%
539 \marginfit@rightmargin%
540 \fi%
541 \else%
542 \if@twoside%
543 \ifodd\c@page%
544 \marginfit@rightmargin%
545 \else%
546 \marginfit@leftmargin%
547 \fi%
548 \else%
549 \marginfit@rightmargin%
550 \fi%
551 \fi%
552 }%
553 }%
554 \fi%
555 }
556 % \end{macrocode}
557 % \end{macro}
558 %
559 % \begin{macro}{\marginpar}
560 % We redefine \verb|\marginpar| to do an insertion instead of a call to the
561 % output routine. First, we save the callout position to the aux file. Then, we
562 % combine the left and right versions of the margin paragraph into an hbox and,
563 % finally, make an insertion with that hbox.
564 % \begin{macrocode}
565 \def\marginpar{%
566 \global\advance\c@marginfit@w\@ne%
567 \expandafter\marginfit@writepos\expandafter{\the\c@marginfit@w @m}%
568 \@ifnextchar[\marginfit@mpar@ii\marginfit@mpar@i%
569 }
570 \long\def\marginfit@mpar@i#1{%
571 \@savemarbox\marginfit@box{#1}%
572 \setbox\marginfit@box\hbox{\copy\marginfit@box\box\marginfit@box}%
573 \marginfit@mpar@iii%
574 }
575 \long\def\marginfit@mpar@ii[#1]#2{%
576 \@savemarbox\marginfit@left{#1}%
577 \@savemarbox\marginfit@right{#2}%
578 \setbox\marginfit@box\hbox{\box\marginfit@left\box\marginfit@right}%
579 \marginfit@mpar@iii%
580 }
581 \def\marginfit@mpar@iii{%
582 \insert\marginfit@insert{\box\marginfit@box}%
583 }
584 % \end{macrocode}
585 % \end{macro}
586 %
587 % \iffalse
588 \endinput
589 % \fi
590 %
591 % \Finale