summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-09-18 22:58:48 +0000
committerKarl Berry <karl@freefriends.org>2014-09-18 22:58:48 +0000
commit3aa3efe34a10c31514aa576e82aae2beb265fe8e (patch)
treec4100da6d045aa6ec65b6d43c108dbc66d9015d2
parent5c46cbe2d34d3ae0d9f584f9b183265358484397 (diff)
sidenotes (16sep14)
git-svn-id: svn://tug.org/texlive/trunk@35200 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/latex/sidenotes/caesar_example.pdfbin75325 -> 75329 bytes
-rw-r--r--Master/texmf-dist/doc/latex/sidenotes/sidenotes.pdfbin215619 -> 218392 bytes
-rw-r--r--Master/texmf-dist/source/latex/sidenotes/sidenotes.dtx273
-rw-r--r--Master/texmf-dist/tex/latex/sidenotes/sidenotes.sty242
4 files changed, 324 insertions, 191 deletions
diff --git a/Master/texmf-dist/doc/latex/sidenotes/caesar_example.pdf b/Master/texmf-dist/doc/latex/sidenotes/caesar_example.pdf
index d4661fa4de5..9e14e369b94 100644
--- a/Master/texmf-dist/doc/latex/sidenotes/caesar_example.pdf
+++ b/Master/texmf-dist/doc/latex/sidenotes/caesar_example.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/sidenotes/sidenotes.pdf b/Master/texmf-dist/doc/latex/sidenotes/sidenotes.pdf
index ded0402e859..1c5f3cf32de 100644
--- a/Master/texmf-dist/doc/latex/sidenotes/sidenotes.pdf
+++ b/Master/texmf-dist/doc/latex/sidenotes/sidenotes.pdf
Binary files differ
diff --git a/Master/texmf-dist/source/latex/sidenotes/sidenotes.dtx b/Master/texmf-dist/source/latex/sidenotes/sidenotes.dtx
index c482389ccee..5aef80beab6 100644
--- a/Master/texmf-dist/source/latex/sidenotes/sidenotes.dtx
+++ b/Master/texmf-dist/source/latex/sidenotes/sidenotes.dtx
@@ -15,12 +15,10 @@
% The author of this work is Andy Thomas
%
%<*driver>
-\ProvidesFile{sidenotes.dtx}[%
+\ProvidesFile{sidenotes.dtx}[2014/06/05 v0.97e rich text in the margin for LaTeX]%
%</driver>
-%<package>\ProvidesPackage{sidenotes}[%
-%<*driver|package>
- 2014/02/14 v0.96a rich text in the margin for LaTeX]
-%</driver|package>
+%<package>\RequirePackage{l3keys2e}%
+%<package>\ProvidesExplPackage{sidenotes}{2014/06/05}{0.97e}{rich text in the margin for LaTeX}
%<package>\RequirePackage{marginnote} % provides an offset option for the marginals instead of a float
%<package>\RequirePackage{caption} % handles the captions (in the margin)
%<package>\RequirePackage{xparse} % new LaTeX3 syntax to define macros and environments
@@ -69,6 +67,8 @@
% \changes{v0.90}{2012/06/02}{two opt package is required, the definitions are too confusing otherwise}
% \changes{v0.92}{2012/11/09}{corrected typo in email address}
% \changes{v0.95}{2014/01/23}{cleaned up the documentation.}
+% \changes{v0.97}{2014/06/05}{make it a expl package}
+% \changes{v0.97}{2014/06/05}{introduce package option oneside }
%
% \begin{abstract}
% \noindent This package allows the typesetting of rich content in the margin.
@@ -163,6 +163,7 @@
% \changes{v0.52}{2011/10/06}{added a section that the package needs marginnote, caption and xifthen.}
% \changes{v0.90}{2012/06/02}{added a section that the package needs twoopt and changepage.}
% \changes{v0.94}{2014/01/22}{start using xparse}
+% \changes{v0.97}{2014/06/05}{start using l3keys2e}
%
% \begin{description}
% \item[marginnote]
@@ -176,6 +177,7 @@
% \emph{caption} manual for details on styles.
% \item[xparse] is used to take advantage of the improved \LaTeX3 syntax.
% All macros and environments are defined using this package.
+% \item[l3keys2e] provides a key/value mechanism
% \item[changepage] is used to correctly shift figure* and table*. It has
% to use the option [strict] to work properly. This might lead to an
% option clash, if the same package is loaded without this option.
@@ -187,6 +189,18 @@
%<*package>
% \fi
%
+% Process the package options: onside
+%
+% \begin{macrocode}
+\ExplSyntaxOn
+%
+\keys_define:nn { sidenotes }
+ {
+ oneside .bool_set:N = \sidenotes_oneside
+ }
+\ProcessKeysOptions { sidenotes }
+% \end{macrocode}
+%
% \changes{v0.91}{2012/06/03}{sidenotetextstyle is not needed any more}
% \changes{v0.94}{2014/01/22}{change sidenote counter behavior}
%
@@ -203,28 +217,64 @@
% optional arguments.
%
% \begin{macrocode}
-\ExplSyntaxOn
-\DeclareExpandableDocumentCommand{\IfNoValueOrEmptyTF}{mmm}
+\DeclareExpandableDocumentCommand{\IfNoValueOrEmptyTF}{ m m m }
{
\IfNoValueTF{#1}
- {#2} % true
- {\tl_if_empty:nTF {#1} {#2} {#3}} % false
+ {#2}
+ {\tl_if_empty:nTF {#1} {#2} {#3}}
}
-\ExplSyntaxOff
% \end{macrocode}
%
% \changes{v0.93}{2012/04/17}{regular ifnextchar gobbles trailing whitespaces, introduce a new one that does not.}
+% \changes{v0.97}{2014/05/29}{New mechanism to detect subsequent sidenotemarks}
+%
+% \noindent Put a marker in the horizontal list to detect subsequent sidenotemarks.
+%
+% \begin{macrocode}
+\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{,}}
+ {}
+}
+%
+% \end{macrocode}
%
-% \noindent The regular \verb+\ifnextchar+ gobbles trailing whitespaces,
-% introduce a new one that does not.
+% \changes{v0.97}{2014/05/27}{introduce an internal macro to place the marginal text}
+%
+% \noindent Introduce an internal macro to place the marginal text. Use
+% margin note in case an offset is given and marginpar otherwise.
%
% \begin{macrocode}
-\def\@sidenotes@ifnextchar#1#2#3{%
-\let\@sidenotes@buffere #1\def\@sidenotes@buffera{#2}%
-\def\@sidenotes@bufferb{#3}\futurelet\@sidenotes@bufferc\@sidenotes@ifnextchar@real}%
-\def\@sidenotes@ifnextchar@real{%
-\ifx\@sidenotes@bufferc \@sidenotes@buffere \let\@sidenotes@bufferd\@sidenotes@buffera%
-\else\let\@sidenotes@bufferd\@sidenotes@bufferb\fi\@sidenotes@bufferd}%
+\NewDocumentCommand \@sidenotes@placemarginal { m m }
+{
+ \IfNoValueOrEmptyTF{#1}
+ {\marginpar{#2}}
+ {\marginnote{#2}[#1]}
+}
+%
% \end{macrocode}
%
% \begin{macro}{\sidenote}
@@ -240,11 +290,11 @@
% \changes{v0.94}{2014/01/11}{use xparse syntax}
%
% \begin{macrocode}
-\NewDocumentCommand \sidenote { o o +m } {%
-\sidenotemark[#1]%
-\sidenotetext[#1][#2]{#3}%
-\@sidenotes@ifnextchar\sidenote{\kern-0.07em\textsuperscript{,}}%
-{\@sidenotes@ifnextchar\sidecite{\kern-0.07em\textsuperscript{,}}{}}%
+\NewDocumentCommand \sidenote { o o +m }
+{
+ \sidenotemark[#1]
+ \sidenotetext[#1][#2]{#3}
+ \@sidenotes@multimarker
}
% \end{macrocode}
% \end{macro}
@@ -257,16 +307,14 @@
% \changes{v0.96}{2014/02/14}{increase the sidenote counter in sidenotetext now}
%
% \begin{macrocode}
-\NewDocumentCommand \sidenotemark { o } {%
-\nobreak\hspace{0.1pt}\nobreak%
-\IfNoValueOrEmptyTF{#1}%
-{%
-\textsuperscript{\thesidenote}%
-}% if no argument is given use sidenote counter%
-{\textsuperscript{#1}}% print out the argument otherwise
-\@sidenotes@ifnextchar\sidenote{\textsuperscript{,}}{}%
-\ignorespaces%
-}%
+\NewDocumentCommand \sidenotemark { o }
+{
+ \@sidenotes@multichecker
+ \IfNoValueOrEmptyTF{#1}
+ {\@sidenotes@thesidenotemark{\thesidenote}}
+ {\@sidenotes@thesidenotemark{#1}}
+ \@sidenotes@multimarker
+}
% \end{macrocode}
% \end{macro}
%
@@ -281,16 +329,15 @@
% \changes{v0.94}{2014/01/11}{use xparse syntax, change counter behavior}
%
% \begin{macrocode}
-\NewDocumentCommand \sidenotetext { o o +m } {%
-\IfNoValueOrEmptyTF{#1}{% sitenotemark given?
-\IfNoValueOrEmptyTF{#2}% offset given?
-{\marginpar{\textsuperscript{\thesidenote}{} #3}}%
-{\marginnote{\textsuperscript{\thesidenote}{} #3}[#2]}%
-\refstepcounter{sidenote}}%
-{\IfNoValueOrEmptyTF{#2}% offset given?
-{\marginpar{\textsuperscript{#1} #3}}%
-{\marginnote{\textsuperscript{#1} #3}[#2]}}%
-}%
+\NewDocumentCommand \sidenotetext { o o +m }
+{
+ \IfNoValueOrEmptyTF{#1}
+ {
+ \@sidenotes@placemarginal{#2}{\textsuperscript{\thesidenote}{}~#3}
+ \refstepcounter{sidenote}
+ }
+ {\@sidenotes@placemarginal{#2}{\textsuperscript{#1}~#3}}
+}
% \end{macrocode}
% \end{macro}
%
@@ -305,21 +352,23 @@
%
% \begin{macrocode}
\DeclareCaptionStyle{sidecaption}{font=footnotesize}
-\NewDocumentCommand \sidecaption {s o o m} {%
-\captionsetup{style=sidecaption}%
-\IfBooleanTF{#1}%is the macro starred
-{\IfNoValueOrEmptyTF{#2}%
-{\marginnote{\caption*{#4}}}%
-{\marginnote{\caption*{#4}}[#2]}%
-}% yes, starred macro
-{%
-\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]}%
-}% no, unstarred macro
+\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]}
+ }
}
% \end{macrocode}
% \end{macro}
@@ -334,17 +383,18 @@
% figure is put in the margin.
%
% \begin{macrocode}
-\newsavebox{\@sidenotes@sidefigurebox}
+\newsavebox{\@sidenotes@marginfigurebox}
\DeclareCaptionStyle{marginfigure}{font=footnotesize}
-\NewDocumentEnvironment{marginfigure}{o}
-{\begin{lrbox}{\@sidenotes@sidefigurebox}%
-\begin{minipage}{\marginparwidth}%
-\captionsetup{type=figure,style=marginfigure}}%
-{\end{minipage}%
-\end{lrbox}%
-\IfNoValueOrEmptyTF{#1}% offset?
-{\marginpar{\usebox{\@sidenotes@sidefigurebox}}}% no offset
-{\marginnote{\usebox{\@sidenotes@sidefigurebox}}[#1]}% offset
+\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}}
}
% \end{macrocode}
% \end{environment}
@@ -361,22 +411,24 @@
% \begin{macrocode}
\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}%
-\IfNoValueOrEmptyTF{#1}% offset?
-{\marginpar{\usebox{\@sidenotes@margintablebox}}} %
-{\marginnote{\usebox{\@sidenotes@margintablebox}}[#1]}%
-}%
+\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}}
+}
% \end{macrocode}
% \end{environment}
%
% \begin{environment}{figure*}
%
% \changes{v0.85}{2011/06/01}{added the figure* environment}
+% \changes{v0.97}{2014/05/27}{use adjustwidth in figure* environment}
%
% The figure* environment provides a figure environment for figures that
% span across the full page (text plus margin width).
@@ -385,36 +437,63 @@
\AtBeginDocument{%
\newlength{\@sidenotes@extrawidth}
\setlength{\@sidenotes@extrawidth}{\marginparwidth}
-\addtolength{\@sidenotes@extrawidth}{\marginparsep}
+\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{widefigure}{margin={0pt,-\@sidenotes@extrawidth},font=footnotesize}
-\newcommand{\@sidenotes@adjust}{%
- \checkoddpage%
- \ifoddpage%
- %
- \else%
- \hspace{-\@sidenotes@extrawidth}%
- \fi}
-\renewenvironment{figure*}[1][htbp]{\begin{figure}[#1]%
- \@sidenotes@adjust%
- \captionsetup{style=widefigure}%
-}{\end{figure}}%
% \end{macrocode}
% \end{environment}
-
+%
% \begin{environment}{table*}
%
% \changes{v0.85}{2011/06/01}{added the table* environment}
+% \changes{v0.97}{2014/05/27}{use adjustwidth in table* environment}
%
% The table* environment provides a table environment for figures across
% text and margin width.
%
% \begin{macrocode}
-\DeclareCaptionStyle{widetable}{margin={0pt,-\@sidenotes@extrawidth},font=footnotesize}
-\renewenvironment{table*}[1][htbp]{\begin{table}[#1]%
- \@sidenotes@adjust%
- \captionsetup{style=widetable}%
-}{\end{table}}%
+\DeclareCaptionStyle{widetable}{font=footnotesize}
+\RenewDocumentEnvironment{table*}{ O{htbp} }
+{
+ \begin{table}[#1]
+ \begin{autoadjustwidth}{}{-\@sidenotes@extrawidth}
+ \captionsetup{style=widetable}
+}
+{
+ \end{autoadjustwidth}
+ \end{table}
+}
+\ExplSyntaxOff
% \end{macrocode}
% \end{environment}
% \Finale
diff --git a/Master/texmf-dist/tex/latex/sidenotes/sidenotes.sty b/Master/texmf-dist/tex/latex/sidenotes/sidenotes.sty
index 47596038a85..36d41bc7b31 100644
--- a/Master/texmf-dist/tex/latex/sidenotes/sidenotes.sty
+++ b/Master/texmf-dist/tex/latex/sidenotes/sidenotes.sty
@@ -12,117 +12,171 @@
%% without the source of the work. See below about more informations
%% about the files the work consists of.
%%
-\ProvidesPackage{sidenotes}[%
- 2014/02/14 v0.96a rich text in the margin for LaTeX]
+\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
-\ExplSyntaxOn
-\DeclareExpandableDocumentCommand{\IfNoValueOrEmptyTF}{mmm}
+\DeclareExpandableDocumentCommand{\IfNoValueOrEmptyTF}{ m m m }
{
\IfNoValueTF{#1}
- {#2} % true
- {\tl_if_empty:nTF {#1} {#2} {#3}} % false
+ {#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}}
}
-\ExplSyntaxOff
-\def\@sidenotes@ifnextchar#1#2#3{%
-\let\@sidenotes@buffere #1\def\@sidenotes@buffera{#2}%
-\def\@sidenotes@bufferb{#3}\futurelet\@sidenotes@bufferc\@sidenotes@ifnextchar@real}%
-\def\@sidenotes@ifnextchar@real{%
-\ifx\@sidenotes@bufferc \@sidenotes@buffere \let\@sidenotes@bufferd\@sidenotes@buffera%
-\else\let\@sidenotes@bufferd\@sidenotes@bufferb\fi\@sidenotes@bufferd}%
-\NewDocumentCommand \sidenote { o o +m } {%
-\sidenotemark[#1]%
-\sidenotetext[#1][#2]{#3}%
-\@sidenotes@ifnextchar\sidenote{\kern-0.07em\textsuperscript{,}}%
-{\@sidenotes@ifnextchar\sidecite{\kern-0.07em\textsuperscript{,}}{}}%
-}
-\NewDocumentCommand \sidenotemark { o } {%
-\nobreak\hspace{0.1pt}\nobreak%
-\IfNoValueOrEmptyTF{#1}%
-{%
-\textsuperscript{\thesidenote}%
-}% if no argument is given use sidenote counter%
-{\textsuperscript{#1}}% print out the argument otherwise
-\@sidenotes@ifnextchar\sidenote{\textsuperscript{,}}{}%
-\ignorespaces%
-}%
-\NewDocumentCommand \sidenotetext { o o +m } {%
-\IfNoValueOrEmptyTF{#1}{% sitenotemark given?
-\IfNoValueOrEmptyTF{#2}% offset given?
-{\marginpar{\textsuperscript{\thesidenote}{} #3}}%
-{\marginnote{\textsuperscript{\thesidenote}{} #3}[#2]}%
-\refstepcounter{sidenote}}%
-{\IfNoValueOrEmptyTF{#2}% offset given?
-{\marginpar{\textsuperscript{#1} #3}}%
-{\marginnote{\textsuperscript{#1} #3}[#2]}}%
-}%
\DeclareCaptionStyle{sidecaption}{font=footnotesize}
-\NewDocumentCommand \sidecaption {s o o m} {%
-\captionsetup{style=sidecaption}%
-\IfBooleanTF{#1}%is the macro starred
-{\IfNoValueOrEmptyTF{#2}%
-{\marginnote{\caption*{#4}}}%
-{\marginnote{\caption*{#4}}[#2]}%
-}% yes, starred macro
-{%
-\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]}%
-}% no, unstarred macro
-}
-\newsavebox{\@sidenotes@sidefigurebox}
+\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@sidefigurebox}%
-\begin{minipage}{\marginparwidth}%
-\captionsetup{type=figure,style=marginfigure}}%
-{\end{minipage}%
-\end{lrbox}%
-\IfNoValueOrEmptyTF{#1}% offset?
-{\marginpar{\usebox{\@sidenotes@sidefigurebox}}}% no offset
-{\marginnote{\usebox{\@sidenotes@sidefigurebox}}[#1]}% offset
+\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}%
-\IfNoValueOrEmptyTF{#1}% offset?
-{\marginpar{\usebox{\@sidenotes@margintablebox}}} %
-{\marginnote{\usebox{\@sidenotes@margintablebox}}[#1]}%
-}%
+\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}
-}
-\DeclareCaptionStyle{widefigure}{margin={0pt,-\@sidenotes@extrawidth},font=footnotesize}
-\newcommand{\@sidenotes@adjust}{%
- \checkoddpage%
- \ifoddpage%
- \else%
-\hspace{-\@sidenotes@extrawidth}%
- \fi}
-\renewenvironment{figure*}[1][htbp]{\begin{figure}[#1]%
- \@sidenotes@adjust%
- \captionsetup{style=widefigure}%
-}{\end{figure}}%
-
-\DeclareCaptionStyle{widetable}{margin={0pt,-\@sidenotes@extrawidth},font=footnotesize}
-\renewenvironment{table*}[1][htbp]{\begin{table}[#1]%
- \@sidenotes@adjust%
- \captionsetup{style=widetable}%
-}{\end{table}}%
+\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'.