summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/marginnote/marginnote.sty
blob: 4ca7f8a546a0a3f5cd224915451b948219a2f621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
%%
%% This is file `marginnote.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% marginnote.dtx  (with options: `package')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from marginnote.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file marginnote.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%%% From File: $Id: marginnote.dtx 27 2018-08-09 09:17:04Z mjk $
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{marginnote}[%
  2018/08/09 v1.4b
  non floating margin notes for LaTeX]
\begingroup
  \@ifundefined{pdfsavepos}{%
    \@ifundefined{savepos}{%
      \PackageError{marginnote}{%
        neither \string\pdfsavepos\space nor \string\savepos\space
        available
      }{%
        Package `marginnote' depends on extended features of
        PDFLaTeX,\MessageBreak
        LuaLaTeX or XeLaTeX. It does not work without those
        feature.\MessageBreak
        If you'd continue the package will not provide any feature.
      }%
      \aftergroup\endinput
    }{%
      \@ifundefined{lastxpos}{%
        \PackageError{marginnote}{%
          \string\savepos\space but not \string\lastxpos\space
          available
        }{%
          Package `marginnote' depends on extended features of
          PDFLaTeX,\MessageBreak
          LuaLaTeX or XeLaTeX. It does not work without those
          feature.\MessageBreak
          If you'd continue the package will not provide any feature.
        }%
        \aftergroup\endinput
      }{%
        \global\let\mn@savepos\savepos
        \global\let\mn@lastxpos\lastxpos
        \global\let\mn@pagewidth\pagewidth
      }%
    }%
  }{%
    \@ifundefined{pdflastxpos}{%
      \PackageError{marginnote}{%
        \string\pdfsavepos\space but not \string\pdflastxpos\space
        available
      }{%
        Package `marginnote' depends on extended features of
        PDFLaTeX,\MessageBreak
        LuaLaTeX or XeLaTeX. It does not work without those
        feature.\MessageBreak
        If you'd continue the package will not provide any feature.
      }%
      \aftergroup\endinput
    }{%
      \global\let\mn@savepos\pdfsavepos
      \global\let\mn@lastxpos\pdflastxpos
      \global\let\mn@pagewidth\pdfpagewidth
    }%
  }%
\endgroup
\newif\if@mn@verbose\@mn@verbosetrue
\DeclareOption{verbose}{\@mn@verbosetrue}
\DeclareOption{quiet}{\@mn@verbosefalse}
\newcommand*{\mn@strut}{}
\newcommand{\mn@zbox}[1]{}
\DeclareOption{fulladjust}{%
  \renewcommand*{\mn@strut}{\strut}%
  \renewcommand{\mn@zbox}[1]{%
    \bgroup
      \setbox\@tempboxa\vbox{#1}%
      \ht\@tempboxa\ht\strutbox
      \dp\@tempboxa\dp\strutbox
      \wd\@tempboxa\z@
      \box\@tempboxa
    \egroup
  }%
}
\DeclareOption{heightadjust}{%
  \renewcommand*{\mn@strut}{\begingroup\dp\strutbox\z@\strut\endgroup}%
  \renewcommand{\mn@zbox}[1]{%
    \bgroup
      \setbox\@tempboxa\vbox{#1}%
      \ht\@tempboxa\ht\strutbox
      \dp\@tempboxa\dp\z@
      \wd\@tempboxa\z@
      \box\@tempboxa
    \egroup
  }%
}
\DeclareOption{depthadjust}{%
  \renewcommand*{\mn@strut}{\begingroup\ht\strutbox\z@\strut\endgroup}%
  \renewcommand{\mn@zbox}[1]{%
    \bgroup
      \setbox\@tempboxa\vbox{#1}%
      \ht\@tempboxa\ht\z@
      \dp\@tempboxa\dp\strutbox
      \wd\@tempboxa\z@
      \box\@tempboxa
    \egroup
  }%
}
\DeclareOption{noadjust}{%
  \renewcommand*{\mn@strut}{\relax}%
  \renewcommand{\mn@zbox}[1]{%
    \bgroup
      \setbox\@tempboxa\vbox{\kern-\ht\strutbox #1}%
      \ht\@tempboxa\ht\z@
      \dp\@tempboxa\dp\z@
      \wd\@tempboxa\z@
      \box\@tempboxa
    \egroup
  }%
}
\newcommand*{\mn@parboxrestore}{}
\DeclareOption{parboxrestore}{%
  \renewcommand*{\mn@parboxrestore}{%
    \@tempskipa\parskip
    \@parboxrestore
    \parskip\@tempskipa
  }%
}
\DeclareOption{noparboxrestore}{%
  \renewcommand*{\mn@parboxrestore}{}%
}
\ExecuteOptions{verbose,fulladjust,parboxrestore}
\ProcessOptions\relax
\newcommand*{\newmarginnote}{\@newl@bel{mn}}
\newcommand*{\marginnotetextwidth}{}
\let\marginnotetextwidth\textwidth
\AtBeginDocument{\edef\marginnotetextwidth{\the\textwidth}}
\newcommand*{\@mn@thispage}{}
\newcommand*{\@mn@currpage}{}
\newcommand*{\@mn@currxpos}{}
\newcounter{mn@abspage}
\AtBeginDocument{\setcounter{mn@abspage}{1}%
  \g@addto@macro\@outputpage{%
    \stepcounter{mn@abspage}%
    \ifodd\value{mn@abspage}%
      \ifodd\value{page}%
      \else
        \if@twoside
          \begingroup
            \advance\c@page\m@ne
            \PackageWarningNoLine{marginnote}{%
              Consecutive odd pages found.\MessageBreak
              Note, it is not recommended to use consecutive\MessageBreak
              odd pages in a double-ended document.\MessageBreak
              The pages of your document should always\MessageBreak
              be a sequence: odd-even-odd-even-...\MessageBreak
              Maybe you've forgotten a
              \@ifundefined{KOMAClassName}%
                           {\string\cleardoublepage}%
                           {\string\cleardoubleoddpage}
              before\MessageBreak
              changing the page numbering on page \thepage
            }%
          \endgroup
        \fi
        \PackageInfo{marginnote}{Using workaround for absolute page number}%
        \stepcounter{mn@abspage}%
      \fi
    \else
      \ifodd\value{page}%
        \if@twoside
          \begingroup
            \advance\c@page\m@ne
            \PackageWarningNoLine{marginnote}{%
              Consecutive even pages found.\MessageBreak
              Note, it is not recommended to use consecutive\MessageBreak
              even pages in a double-ended document.\MessageBreak
              The pages of your document should always\MessageBreak
              be a sequence: odd-even-odd-even-...\MessageBreak
              Maybe you've forgotten a
              \@ifundefined{KOMAClassName}%
                           {\string\cleardoublepage}%
                           {\string\cleardoubleevenpage}
              before\MessageBreak
              changing the page numbering on page \thepage
            }%
          \endgroup
        \fi
        \PackageInfo{marginnote}{Using workaround for absolute page number}%
        \stepcounter{mn@abspage}%
      \fi
    \fi
  }%
}
\newcommand*{\@mn@margintest}{%
  \expandafter\ifx\csname @mn@thispage\endcsname\@empty
    \gdef\@mn@atthispage{1}%
  \else\expandafter\ifnum \@mn@thispage=\value{mn@abspage}%
      \begingroup
        \@tempcnta\@mn@atthispage\advance\@tempcnta by \@ne
        \xdef\@mn@atthispage{\the\@tempcnta}%
      \endgroup
    \else
      \gdef\@mn@atthispage{1}%
    \fi
  \fi
  \xdef\@mn@thispage{\themn@abspage}%
  \let\@mn@currpage\relax
  \let\@mn@currxpos\relax
  \mn@savepos
  \protected@write\@auxout{\let\themn@abspage\relax}{%
    \string\newmarginnote{note.\@mn@thispage.\@mn@atthispage}{%
      {\themn@abspage}{\noexpand\number\mn@lastxpos sp}}%
  }%
  \expandafter\ifx\csname mn@note.\@mn@thispage.\@mn@atthispage\endcsname\relax
    \if@twoside
      \if@mn@verbose
        \PackageInfo{marginnote}{Suggest that margin
          note \@mn@thispage.\@mn@atthispage\space will be on\MessageBreak
          absolute page \themn@abspage.\MessageBreak
          This may be wrong}%
      \fi
      \ifodd\value{mn@abspage}\@tempswatrue\else\@tempswafalse\fi
    \else
      \if@mn@verbose
        \PackageInfo{marginnote}{right page because not two side mode}%
      \fi
      \@tempswatrue
    \fi
  \else
    \edef\@mn@currpage{\csname
      mn@note.\@mn@thispage.\@mn@atthispage\endcsname}%
    \edef\@mn@currxpos{\expandafter\@secondoftwo\@mn@currpage}%
    \ifx\@mn@currxpos\@empty\else
      \edef\@mn@currxpos{\the\dimexpr \@mn@currxpos -\hoffset\relax}%
      \begingroup\expandafter\expandafter\expandafter\endgroup
      \expandafter\ifx\csname pdfhorigin\endcsname\relax\else
        \begingroup\expandafter\expandafter\expandafter\endgroup
        \expandafter\ifx\csname pdfoutput\endcsname\relax
          \begingroup\expandafter\expandafter\expandafter\endgroup
          \expandafter\ifx\csname outputmode\endcsname\relax\else
            \ifnum \outputmode=1 %
              \edef\@mn@currxpos{\the\dimexpr \@mn@currxpos -\pdfhorigin
                +1in\relax}%
            \fi
          \fi
        \else
          \ifnum \pdfoutput=1 %
            \edef\@mn@currxpos{\the\dimexpr \@mn@currxpos -\pdfhorigin
              +1in\relax}%
          \fi
        \fi
      \fi
      \ifdefined\mn@pagewidth
        \@mn@if@RTL{%
          \PackageInfo{marginnote}{Margin note
            \@mn@thispage.\@mn@atthispage\space in RTL mode}%
          \edef\@mn@currxpos{%
            \the\dimexpr\mn@pagewidth-\@mn@currxpos\relax
          }%
        }{}%
      \fi
    \fi
    \edef\@mn@currpage{\expandafter\@firstoftwo\@mn@currpage}%
    \if@mn@verbose
      \PackageInfo{marginnote}{Margin note \@mn@thispage.\@mn@atthispage\space
        is on absolute page \@mn@currpage}%
    \fi
    \if@twoside
      \ifodd\@mn@currpage\relax
        \@tempswatrue
        \if@twocolumn
          \ifdim \@mn@currxpos
                 < \dimexpr\oddsidemargin+\columnwidth+\columnsep\relax
            \@tempswafalse
          \fi
        \fi
      \else
        \@tempswafalse
        \if@twocolumn
          \ifdim\@mn@currxpos>\dimexpr\evensidemargin+\columnwidth\relax
            \@tempswatrue
          \fi
        \fi
      \fi
    \else
      \if@mn@verbose
        \PackageInfo{marginnote}{right page because not two side mode}%
      \fi
      \@tempswatrue
      \if@twocolumn
        \ifdim \@mn@currxpos
               < \dimexpr\oddsidemargin+\columnwidth+\columnsep\relax
          \@tempswafalse
        \fi
      \fi
    \fi
  \fi
}
\newcommand*{\@mn@if@RTL}{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname if@RTL\endcsname\iftrue
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\newcommand*{\marginnote}{%
  \@dblarg\@mn@marginnote
}
\newcommand{\@mn@marginnote}[2][]{%
  \ifhmode
    \@bsphack
    \begingroup
    \ifdim\@savsk>\z@\else
      \def\:{\@xifnch}\expandafter\def\: { \futurelet\@let@token\@ifnch}%
    \fi
  \else
    \begingroup
  \fi
  \@ifnextchar [{\@mn@@marginnote[{#1}]{#2}}{\@mn@@marginnote[{#1}]{#2}[\z@]}%
}
\newcommand{\@mn@@marginnote}{}
\long\def\@mn@@marginnote[#1]#2[#3]{%
  \endgroup
  \ifhmode
    \@mn@@@marginnote[{#1}]{#2}[{#3}]%
    \@esphack
  \else
    \@mn@@@marginnote[{#1}]{#2}[{#3}]%
  \fi
}
\newcommand{\@mn@@@marginnote}{}
\long\def\@mn@@@marginnote[#1]#2[#3]{%
  \begingroup
    \ifmmode\mn@strut\let\@tempa\mn@vadjust\else
      \if@inlabel\leavevmode\fi
      \ifhmode\mn@strut\let\@tempa\mn@vadjust\else\let\@tempa\mn@vlap\fi
    \fi
    \@tempa{%
      \vbox to\z@{%
        \vss
        \@mn@margintest
        \if@reversemargin\if@tempswa
            \@tempswafalse
          \else
            \@tempswatrue
        \fi\fi
        \if@tempswa
          \rlap{%
            \if@mn@verbose
              \PackageInfo{marginnote}{xpos seems to be \@mn@currxpos}%
            \fi
            \begingroup
              \ifx\@mn@currxpos\relax\else\ifx\@mn@currxpos\@empty\else
                  \kern-\dimexpr\@mn@currxpos\relax
              \fi\fi
              \ifx\@mn@currpage\relax
                \let\@mn@currpage\@ne
              \fi
              \if@twoside\ifodd\@mn@currpage\relax
                  \kern\oddsidemargin
                \else
                  \kern\evensidemargin
                \fi
              \else
                \kern\oddsidemargin
              \fi
              \kern 1in
            \endgroup
            \kern\marginnotetextwidth\kern\marginparsep
            \vbox to\z@{\kern\marginnotevadjust\kern #3
              \vbox to\z@{%
                \hsize\marginparwidth
                \linewidth\hsize
                \kern-\parskip
                \mn@parboxrestore
                \marginfont\raggedrightmarginnote\strut\hspace{\z@}%
                \ignorespaces#2\endgraf
                \vss}%
              \vss}%
          }%
        \else
          \llap{%
            \vbox to\z@{\kern\marginnotevadjust\kern #3
              \vbox to\z@{%
                \hsize\marginparwidth
                \linewidth\hsize
                \kern-\parskip
                \mn@parboxrestore
                \marginfont\raggedleftmarginnote\strut\hspace{\z@}%
                \ignorespaces#1\endgraf
                \vss
              }%
              \vss
            }%
            \if@mn@verbose
              \PackageInfo{marginnote}{xpos seems to be \@mn@currxpos}%
            \fi
            \begingroup
              \ifx\@mn@currxpos\relax\else\ifx\@mn@currpos\@empty\else
                  \kern\@mn@currxpos
              \fi\fi
              \ifx\@mn@currpage\relax
                \let\@mn@currpage\@ne
              \fi
              \if@twoside\ifodd\@mn@currpage\relax
                  \kern-\oddsidemargin
                \else
                  \kern-\evensidemargin
                \fi
              \else
                \kern-\oddsidemargin
              \fi
              \kern-1in
            \endgroup
            \kern\marginparsep
          }%
        \fi
      }%
    }%
  \endgroup
}
\newcommand*{\marginnotevadjust}{}
\let\marginnotevadjust\z@
\newcommand{\mn@vlap}[1]{%
  \setbox\@tempboxa\vbox to \ht\strutbox{#1\vss}%
  \box\@tempboxa\vskip-\baselineskip
}
\newcommand{\mn@vadjust}[1]{%
  \mn@zbox{\kern-\parskip
    \leavevmode\vadjust{#1}%
    \kern\parskip
  }%
}
\providecommand*{\marginfont}{}
\newcommand*{\raggedleftmarginnote}{\raggedleft}
\newcommand*{\raggedrightmarginnote}{\raggedright}
\endinput
%%
%% End of file `marginnote.sty'.