summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/sidenotes/sidenotes.sty
blob: 36d41bc7b31694bc49db304b1e7a1168be48c073 (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
%%
%% This is file `sidenotes.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% sidenotes.dtx  (with options: `package')
%% 
%% IMPORTANT NOTE:
%% 
%% This is a generated file and you are not allowed to distribute it
%% without the source of the work.  See below about more informations
%% about the files the work consists of.
%% 
\RequirePackage{l3keys2e}%
\ProvidesExplPackage{sidenotes}{2014/06/05}{0.97e}{rich text in the margin for LaTeX}
\RequirePackage{marginnote} % provides an offset option for the marginals instead of a float
\RequirePackage{caption} % handles the captions (in the margin)
\RequirePackage{xparse} % new LaTeX3 syntax to define macros and environments
\RequirePackage[strict]{changepage} % Changepage package for symmetric twoside handling
\ExplSyntaxOn
\keys_define:nn { sidenotes }
  {
    oneside .bool_set:N = \sidenotes_oneside
  }
\ProcessKeysOptions { sidenotes }
\newcounter{sidenote} % make a counter
\setcounter{sidenote}{1} % init the counter
\DeclareExpandableDocumentCommand{\IfNoValueOrEmptyTF}{ m m m }
{
 \IfNoValueTF{#1}
  {#2}
  {\tl_if_empty:nTF {#1} {#2} {#3}}
}
\NewDocumentCommand \@sidenotes@thesidenotemark { m }
{
    \leavevmode
    \ifhmode
        \edef \@x@sf {\the \spacefactor }
        \nobreak
    \fi
    \hbox {\@textsuperscript {\normalfont #1 }}
    \ifhmode
        \spacefactor \@x@sf
    \fi
    \relax
}
\NewDocumentCommand \@sidenotes@multisign { } {3sp}
\NewDocumentCommand \@sidenotes@multimarker { }
{
  \kern-\@sidenotes@multisign
  \kern\@sidenotes@multisign\relax
}
\NewDocumentCommand \@sidenotes@multichecker { }
{
  \dim_compare:nNnTF \lastkern = \@sidenotes@multisign
  {\@sidenotes@thesidenotemark{,}}
  {}
}
\NewDocumentCommand \@sidenotes@placemarginal { m m }
{
  \IfNoValueOrEmptyTF{#1}
    {\marginpar{#2}}
    {\marginnote{#2}[#1]}
}
\NewDocumentCommand \sidenote { o o +m }
{
  \sidenotemark[#1]
  \sidenotetext[#1][#2]{#3}
  \@sidenotes@multimarker
}
\NewDocumentCommand \sidenotemark { o }
{
  \@sidenotes@multichecker
  \IfNoValueOrEmptyTF{#1}
    {\@sidenotes@thesidenotemark{\thesidenote}}
    {\@sidenotes@thesidenotemark{#1}}
  \@sidenotes@multimarker
}
\NewDocumentCommand \sidenotetext { o o +m }
{
  \IfNoValueOrEmptyTF{#1}
    {
      \@sidenotes@placemarginal{#2}{\textsuperscript{\thesidenote}{}~#3}
  \refstepcounter{sidenote}
}
    {\@sidenotes@placemarginal{#2}{\textsuperscript{#1}~#3}}
}
\DeclareCaptionStyle{sidecaption}{font=footnotesize}
\NewDocumentCommand \sidecaption {s o o m}
{
  \captionsetup{style=sidecaption}
  \IfBooleanTF{#1}
  { % starred
    \IfNoValueOrEmptyTF{#2}
    {\marginnote{\caption*{#4}}}
    {\marginnote{\caption*{#4}}[#2]}
  }
  { % unstarred
  \IfNoValueOrEmptyTF{#2}
    {\def\@sidenotes@sidecaption@tof{#4}}
    {\def\@sidenotes@sidecaption@tof{#2}}
  \IfNoValueOrEmptyTF{#3}
    {\marginnote{\caption[\@sidenotes@sidecaption@tof]{#4}}}
    {\marginnote{\caption[\@sidenotes@sidecaption@tof]{#4}}[#3]}
  }
}
\newsavebox{\@sidenotes@marginfigurebox}
\DeclareCaptionStyle{marginfigure}{font=footnotesize}
\NewDocumentEnvironment{marginfigure} { o }
{
  \begin{lrbox}{\@sidenotes@marginfigurebox}
    \begin{minipage}{\marginparwidth}
      \captionsetup{type=figure,style=marginfigure}
}
{
    \end{minipage}%
  \end{lrbox}%
  \@sidenotes@placemarginal{#1}{\usebox{\@sidenotes@marginfigurebox}}
}
\newsavebox{\@sidenotes@margintablebox}
\DeclareCaptionStyle{margintable}{font=footnotesize}
\NewDocumentEnvironment{margintable} { o }
{
  \begin{lrbox}{\@sidenotes@margintablebox}
    \begin{minipage}{\marginparwidth}
      \captionsetup{type=table,style=margintable}
}
{
    \end{minipage}
  \end{lrbox}
  \@sidenotes@placemarginal{#1}{\usebox{\@sidenotes@margintablebox}}
}
\AtBeginDocument{%
\newlength{\@sidenotes@extrawidth}
\setlength{\@sidenotes@extrawidth}{\marginparwidth}
\addtolength{\@sidenotes@extrawidth}{\marginparsep}}
\NewDocumentEnvironment{autoadjustwidth}{ m m }%
{
    \bool_if:NTF \sidenotes_oneside
    {
        \begin{adjustwidth}{#1}{#2}
    }
    {
        \begin{adjustwidth*}{#1}{#2}
    }
}
{
    \bool_if:NTF \sidenotes_oneside
    {
        \end{adjustwidth}
    }
    {
        \end{adjustwidth*}
    }
}
\DeclareCaptionStyle{widefigure}{font=footnotesize}
\RenewDocumentEnvironment{figure*}{ O{htbp} }
{
    \begin{figure}[#1]
        \begin{autoadjustwidth}{}{-\@sidenotes@extrawidth}
        \captionsetup{style=widefigure}
}
{
        \end{autoadjustwidth}
    \end{figure}
}
\DeclareCaptionStyle{widetable}{font=footnotesize}
\RenewDocumentEnvironment{table*}{ O{htbp} }
{
    \begin{table}[#1]
        \begin{autoadjustwidth}{}{-\@sidenotes@extrawidth}
        \captionsetup{style=widetable}
}
{
        \end{autoadjustwidth}
    \end{table}
}
\ExplSyntaxOff
\endinput
%%
%% End of file `sidenotes.sty'.