summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/marginnote/marginnote.sty
blob: c03e5406bd674f20554d1d414eda00f9bbc0a56f (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
%%
%% This is file `marginnote.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% marginnote.dtx  (with options: `package')
%% 
%% IMPORTANT NOTE:
%% 
%% This is a generated file and you are not allowed to distribute it
%% without the source ot the work.  See below about more informations
%% about the files the work consists of.
%% 
%% Copyright (c) Markus Kohm  2005-2009
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.
%%
%% This work has the LPPL maintenance status "maintained".
%%
%% The author of the initial version of these work was
%% Markus Kohm <komascript@gmx.info>
%%
%% This work consists of the files marginnote.dtx, marginnote.ins,
%% and REAMDE.
%%
%% Important Recommendation:
%%   The LPPL requires that distributions of the Work contain all the files of
%%   the Work (see ``Important Recommendations'' at lppl.txt).
%%
\ProvidesPackage{marginnote}[%
  2009/05/06 v1.1d non floating margin notes for LaTeX]
\begingroup
  \def\@tempb{}%
  \def\@tempa{%
    \PackageError{marginnote}{seems you are not running e-TeX\@tempb}{%
      Since 2004 the LaTeX team recommends to use e-TeX.\MessageBreak
      marginnote since version 1.1d uses e-TeX features.\MessageBreak
      At actual systems `latex' should already use e-TeX.\MessageBreak
      At deprecated systems it may be called `elatex'.\MessageBreak
      Use either unsupported marginnote up to version 1.1c or\MessageBreak
      ask you administrator for LaTeX using e-TeX\@tempb.\MessageBreak
      Not using e-TeX\@tempb\space is a fatal error!\MessageBreak
      Processing cannot be continued!}%
    \endgroup
    \batchmode \errmessage{}\csname @@end\endcsname\end\relax
    \csname endinput\endcsname
  }%
  \expandafter\ifx\csname eTeXversion\endcsname\relax\else
    \ifnum\eTeXversion <2
      \def\@tempb{ V 2}%
    \else
      \let\@tempa\endgroup
    \fi
  \fi
\@tempa
\newif\if@mn@verbose\@mn@verbosetrue
\DeclareOption{verbose}{\@mn@verbosetrue}
\DeclareOption{quiet}{\@mn@verbosefalse}
\ExecuteOptions{verbose}
\ProcessOptions\relax
\newcommand*{\newmarginnote}{\@newl@bel{mn}}
\newif\if@mn@pdfmode\@mn@pdfmodefalse
\AtBeginDocument{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname pdflastxpos\endcsname\relax\else % bg or 1
    \begingroup\expandafter\expandafter\expandafter\endgroup
    \expandafter\ifx\csname pdftexversion\endcsname\relax % bg 2
      \begingroup\expandafter\expandafter\expandafter\endgroup
      \expandafter\ifx\csname pdfoutput\endcsname\relax % bg 3
        \begingroup\expandafter\expandafter\expandafter\endgroup
        \expandafter\ifx\csname XeTeXrevision\endcsname\relax\else % bg 4
          \@mn@pdfmodetrue
        \fi % ed 4
      \else % or 3
        \ifcase\pdfoutput\else\@mn@pdfmodetrue\fi % bg ed 4
      \fi % ed 3
    \else % or 2
      \ifnum \pdftexversion<140 % bg 3
        \begingroup\expandafter\expandafter\expandafter\endgroup
        \expandafter\ifx\csname pdfoutput\endcsname\relax % bg 4
        \else % or 4
          \ifcase\pdfoutput\else\@mn@pdfmodetrue\fi % bg ed 5
        \fi % ed 4
      \else % or 3
        \@mn@pdfmodetrue
      \fi % ed 3
    \fi % ed 2
  \fi % ed 1
  \if@mn@verbose
    \if@mn@pdfmode
      \PackageInfo{marginnote}{%
        \string\pdfoutput\space not 0 and \string\pdflastxpos\space
        available.\MessageBreak
        Extended position detection mode activated\@gobble
      }%
    \else
      \PackageInfo{marginnote}{%
        either \string\pdflastxpos\space or \string\pdfoutput\space not
        available\MessageBreak
        or \string\pdfoutput\space set to 0.\MessageBreak
        Extended position detection mode deactivated\@gobble
      }%
    \fi
  \fi
}
\newcommand*{\marginnotetextwidth}{}
\let\marginnotetextwidth\textwidth
\AtBeginDocument{\if@mn@pdfmode\edef\marginnotetextwidth{\the\textwidth}\fi}
\newcommand*{\@mn@thispage}{}
\newcommand*{\@mn@currpage}{}
\newcommand*{\@mn@currxpos}{}
\newcounter{mn@abspage}
\AtBeginDocument{\setcounter{mn@abspage}{1}%
  \g@addto@macro\@outputpage{\stepcounter{mn@abspage}}}
\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
  \if@mn@pdfmode
    \pdfsavepos
    \protected@write\@auxout{\let\themn@abspage\relax}{%
      \string\newmarginnote{note.\@mn@thispage.\@mn@atthispage}{%
        {\themn@abspage}{\noexpand\number\pdflastxpos sp}}%
    }%
  \else
    \protected@write\@auxout{\let\themn@abspage\relax}{%
      \string\newmarginnote{note.\@mn@thispage.\@mn@atthispage}{%
        {\themn@abspage}{}}%
    }%
  \fi
  \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}%
    \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\else
        \ifnum \pdfoutput=1 %
          \edef\@mn@currxpos{\the\dimexpr \@mn@currxpos -\pdfhorigin
            +1in\relax}%
        \fi
      \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\MessageBreak}%
    \fi
    \if@twoside
      \ifodd\@mn@currpage\relax
        \@tempswatrue
      \else
        \@tempswafalse
      \fi
    \else
      \if@mn@verbose
        \PackageInfo{marginnote}{right page because not two side mode}%
      \fi
      \@tempswatrue
    \fi
  \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}{}
\def\@mn@@marginnote[#1]#2[#3]{%
  \endgroup
  \ifhmode
    \@mn@@@marginnote[{#1}]{#2}[{#3}]%
    \@esphack
  \else
    \@mn@@@marginnote[{#1}]{#2}[{#3}]%
  \fi
}
\newcommand{\@mn@@@marginnote}{}
\def\@mn@@@marginnote[#1]#2[#3]{%
  \begingroup
    \ifmmode\strut\let\@tempa\mn@vadjust\else
      \if@inlabel\leavevmode\fi
      \ifhmode\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{%
            \ifx\@mn@currxpos\relax
              \kern\marginnoterightadjust
              \if@mn@verbose
                \PackageInfo{marginnote}{%
                  xpos not known,\MessageBreak
                  using \string\marginnoterightadjust}%
              \fi
            \else\ifx\@mn@currxpos\@empty
                \kern\marginnoterightadjust
                \if@mn@verbose
                  \PackageInfo{marginnote}{%
                    xpos not known,\MessageBreak
                    using \string\marginnoterightadjust}%
                \fi
              \else
                \if@mn@verbose
                  \PackageInfo{marginnote}{%
                    xpos seams to be \@mn@currxpos,\MessageBreak
                    \string\marginnoterightadjust
                    \space ignored}%
                \fi
                \begingroup
                  \setlength{\@tempdima}{\@mn@currxpos}%
                  \kern-\@tempdima
                  \if@twoside\ifodd\@mn@currpage\relax
                      \kern\oddsidemargin
                    \else
                      \kern\evensidemargin
                    \fi
                  \else
                    \kern\oddsidemargin
                  \fi
                  \kern 1in
                \endgroup
              \fi
            \fi
            \kern\marginnotetextwidth\kern\marginparsep
            \vbox to\z@{\kern\marginnotevadjust\kern #3
              \vbox to\z@{%
                \hsize\marginparwidth
                \kern-\parskip
                \marginfont\raggedrightmarginnote\hspace{\z@}\strut#2\endgraf
                \vss}%
              \vss}%
          }%
        \else
          \llap{%
            \vbox to\z@{\kern #3
              \vbox to\z@{%
                \hsize\marginparwidth
                \kern-\parskip
                \marginfont\raggedleftmarginnote\hspace{\z@}\strut#1\endgraf
                \vss}%
              \vss}%
            \ifx\@mn@currxpos\relax
              \kern\marginnoteleftadjust
              \if@mn@verbose
                \PackageInfo{marginnote}{%
                  xpos not known,\MessageBreak
                  using \string\marginnoteleftadjust}%
              \fi
            \else\ifx\@mn@currxpos\@empty
                \kern\marginnoteleftadjust
                \if@mn@verbose
                  \PackageInfo{marginnote}{%
                    xpos not known,\MessageBreak
                    using \string\marginnoteleftadjust}%
                \fi
              \else
                \if@mn@verbose
                  \PackageInfo{marginnote}{%
                    xpos seams to be \@mn@currxpos,\MessageBreak
                    \string\marginnoteleftadjust
                    \space ignored}%
                \fi
               \begingroup
                  \kern\@mn@currxpos
                  \if@twoside\ifodd\@mn@currpage\relax
                      \kern-\oddsidemargin
                    \else
                      \kern-\evensidemargin
                    \fi
                  \else
                    \kern-\oddsidemargin
                  \fi
                  \kern-1in
                \endgroup
              \fi
            \fi
            \kern\marginparsep
          }%
        \fi
      }%
    }%
  \endgroup
}
\newcommand*{\marginnoterightadjust}{}
\newcommand*{\marginnoteleftadjust}{}
\let\marginnoterightadjust\z@
\let\marginnoteleftadjust\z@
\newcommand*{\marginnotevadjust}{}
\let\marginnotevadjust\z@
\newcommand{\mn@vlap}[1]{%
  \setbox\@tempboxa\vbox to \ht\strutbox{#1\vss}%
  \box\@tempboxa\vskip-\baselineskip
}
\newcommand{\mn@zbox}[1]{%
  \bgroup
    \setbox\@tempboxa\vbox{#1}%
    \ht\@tempboxa\ht\strutbox
    \dp\@tempboxa\dp\strutbox
    \wd\@tempboxa\z@
    \box\@tempboxa
  \egroup
}
\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'.