diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/parnotes/parnotes.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/parnotes/parnotes.sty | 237 |
1 files changed, 167 insertions, 70 deletions
diff --git a/Master/texmf-dist/tex/latex/parnotes/parnotes.sty b/Master/texmf-dist/tex/latex/parnotes/parnotes.sty index 797ca6319f6..5d394b7b92e 100644 --- a/Master/texmf-dist/tex/latex/parnotes/parnotes.sty +++ b/Master/texmf-dist/tex/latex/parnotes/parnotes.sty @@ -1,45 +1,47 @@ % The parnotes package % Notes after every paragraph, or elsewhere -% Copyright 2012, Michael Hughes +% Copyright (c) 2016 Chelsea Hughes % % This work is distributed under the LaTeX Project Public License, -% version 1.3 or later, available at +% version 1.3 or later, available at % http://www.latex-project.org/lppl.txt -% I currently maintain this project and will receive error reports at -% mcrh <at> uw <dot> edu +% I currently maintain this project (comprising parnotes.sty, parnotes.tex, +% README.md, and the derived file parnotes.pdf) and will receive error reports at +% https://github.com/chelh/LaTeX-parnotes % % This package was started due to a question at the TeX Stack Exchange: % http://tex.stackexchange.com/questions/34746/ % -% Thanks to Stack Exchange users Ahmed Musa and Bruno Le Floch +% Thanks to Stack Exchange users Ahmed Musa, Bruno Le Floch, and David Carlisle. \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{parnotes}[2012/01/03 rev. 1 Notes after every paragraph, or elsewhere] +\ProvidesPackage{parnotes}[2016/07/26 rev. 2 Notes after every paragraph, or elsewhere] % % These are the user-modifiable format commands % -% Format for parnotes - \PN@notes@shape is \rmfamily by default +% Format for parnotes - \PN@notes@shape is blank (\relax) by default \providecommand{\parnotefmt}[1]{\footnotesize% \PN@notes@shape\PN@narrower@optional\noindent #1} -% Format for parnote marks - \PN@mark@set is \arabic by default -\providecommand{\parnotemarkfmt}[1]{\textsuperscript{\PN@mark@set{#1}}} +% Number format (arabic, roman, etc.) for the parnote mark counter +\providecommand{\theparnotemark}{\arabic{parnotemark}} % Minimum vertical space before and after parnotes \providecommand{\parnotevskip}{\medskipamount} % Full command used between parnotes -\providecommand{\parnoteintercmd}{\hspace{1em}} +\providecommand{\parnoteintercmd}{\hspace{1em plus 0.3em minus 0.2em}} +% Basic formatting for parnote marks +\providecommand{\parnotecusmarkfmt}[1]{\textsuperscript{#1}} % % Internal variables below this line % + % This holds all the parnote text \global\def\PN@text{} -% Counter for parnote marks left by \parnote -\global\newcount\c@PN@t -% Counter for parnote marks *within* parnotes -\global\newcount\c@PN@n +% Counter for parnote marks +\newcounter{parnotemark} % autopn environment name \def\@PN@autopn{autopn} % True if currently setting parnotes @@ -51,15 +53,11 @@ % Optionally reset the counter within \parnotes % \let\PN@reset@optional\relax -\DeclareOption{restart}{\def\PN@reset@optional{% - \global\c@PN@t=\z@ - \global\c@PN@n=\z@ -}} +\DeclareOption{restart}{\def\PN@reset@optional{\parnotereset}} % % Parnote marks are arabic by default, but an option changes them to roman % -\let\PN@mark@set\arabic -\DeclareOption{roman}{\let\PN@mark@set\roman} +\DeclareOption{roman}{\renewcommand\theparnotemark{\roman{parnotemark}}} % breakwithin just changes \parnoteintercmd \DeclareOption{breakwithin}{\renewcommand{\parnoteintercmd}{\\}} % And indentafter just clears \PN@disable@indent @@ -69,66 +67,164 @@ % \let\PN@narrower@optional\relax \DeclareOption{narrower}{\let\PN@narrower@optional\narrower} +% Allow the user to disable separators between multiple parnote marks +\DeclareOption{nomultiple}{\def\FN@mf@prepare{\relax}\def\FN@mf@check{\relax}} % % Font-changing options % -\let\PN@notes@shape\rmfamily +\let\PN@notes@shape\relax \DeclareOption{notesrm}{\let\PN@notes@shape\rmfamily} \DeclareOption{notessf}{\let\PN@notes@shape\sffamily} \DeclareOption{notesit}{\let\PN@notes@shape\itshape} % Finally process the options \ProcessOptions\relax -\long\def\PN@parnote@real#1{% - % Advance the counter used in TEXT immediately - \global\advance\c@PN@t\@ne - % - % Then add the command's argument to a macro to be called at the end - % of the paragraph (or wherever \parnotes gets called) - % - \g@addto@macro\PN@text{% - % Advance the counter used in the parnotes as the parnotes are set - \global\advance\c@PN@n\@ne - \parnotemarkfmt{PN@n}\nolinebreak\thinspace#1% - % - % This way, if the in-text counter equals the in-note counter, we - % know that we're at the final parnote for this batch and - % \parnoteintercmd shouldn't be executed - % - \unless\ifnum\c@PN@n=\c@PN@t - \parnoteintercmd - \fi - }% - \unskip\parnotemarkfmt{PN@t}% -} +% +% Provide a null implementation of \phantomsection in case hyperref +% isn't loaded +% +\providecommand\phantomsection{} +% Later, we'll check to see if this command was redefined +\let\parnotemarkfmt\@gobble + +% +% A wrapper for \PN@parnote@real. Takes an optional (manually-specified) +% mark and mandatory note text, and transforms them into the two mandatory +% arguments (mark and note text) for \PN@parnote@real. If no mark is +% specified, it will increment the counter parnotemark and pass its FULLY +% EXPANDED text value to \PN@parnote@real. That's two cases: +% +% 1: \parnote[MARK]{TEXT} -> \PN@parnote@real{MARK}{TEXT} +% 2: \parnote{TEXT} -> \PN@parnote@real{EXPANDED COUNTER}{TEXT} +% +% \parnote supports behavior like the stable option of the package +% footmisc, by Robin Fairbairns: If encountered in the Table of Contents, +% it will do nothing and expand nothing. That adds two more cases: % -% \parnote calls \PN@parnote@real if in typesetting mode, but does nothing -% elsewhere (i.e., in the table of contents) - this is based on the stable -% option of the footmisc package +% 3: \parnote[MARK]{TEXT} -> {} +% 4: \parnote{TEXT} -> {} % + \long\def\parnote{% +\ifx\@gobble\parnotemarkfmt\else + % Crash if the user has defined \parnotemarkfmt, as this is + % no longer supported + \PackageError{parnotes}{% + Cannot use custom definition of \protect\parnotemarkfmt\MessageBreak + in parnotes rev. 2 or later. Use + \protect\theparnotemark\MessageBreak + and \protect\parnotecusmarkfmt\space instead% + }{% + You've used an option that is no longer supported. + Downgrade back\MessageBreak + to parnotes rev. 1, or redefine \protect\theparnotemark\space + and \protect\parnotecusmarkfmt\MessageBreak + instead of \protect\parnotemarkfmt. See section + 2.2 of the parnotes manual for\MessageBreak + details. + }% +\fi +% This incorporates changes suggested by David Carlisle +\relax\ifx\@footnotetext\TX@trial@ftn\else \ifx\protect\@typeset@protect - \expandafter\PN@parnote@real + \expandafter\expandafter\expandafter\PN@check@args \else - \expandafter\@gobble + \expandafter\expandafter\expandafter\@gobble + \fi +\fi +} +\def\PN@check@args{% + \@ifnextchar [ + \PN@parnote@twoargs% Case 1 + \PN@parnote@onearg% Case 2 +} +\DeclareRobustCommand\PN@gobble@opt{% + \@ifnextchar [ + \PN@gobble@opt@@% Case 3 + \@gobble% Case 4 +} +\def\PN@parnote@twoargs[#1]#2{\PN@parnote@real{#1}{#2}} +\def\PN@parnote@onearg#1{% + % Fully expand the new counter value, as text + \begingroup\edef\@x{\endgroup\noexpand\PN@parnote@real% + {\theparnotemark}}\@x{#1}% + \global\advance\c@parnotemark\@ne +} +\def\PN@gobble@opt@@[#1]#2{} + +% +% Collects tokens into \PN@text, to be set when \parnotes is called. +% Everything added to \PN@text is expanded first. Takes two MANDATORY +% arguments, a mark and some note text. +% +\long\def\PN@parnote@real#1#2{% + \parnotemark{#1}% + % Unless this is the first parnote in \PN@text, add a separator first + \unless\ifx\PN@text\@empty\g@addto@macro\PN@text{\parnoteintercmd}\fi + % Redefine \@currentlabel to the parnote label, so \label works + \g@addto@macro\PN@text{\phantomsection\def\@currentlabel{#1}}% + \g@addto@macro\PN@text{\parnotemark{#1}\nolinebreak\thinspace#2}% +} + +\long\def\PN@parnote@compat#1{% + \parnotemarkfmt{parnotemark} + \unless\ifx\PN@text\@empty\g@addto@macro\PN@text{\parnoteintercmd}\fi + \g@addto@macro\PN@text{\phantomsection\def\@currentlabel{\arabic{parnotemark}}}% + \g@addto@macro\PN@text{\parnotemarkfmt{parnotemark}\nolinebreak\thinspace#1}% +} + +% +% Definitions to get multiple consecutive parnotes/footnotes working, as +% in footmisc and manyfoot; this is cribbed directly from footmisc +% +\providecommand*{\multiplefootnotemarker}{3sp} +\providecommand*{\multfootsep}{,} +\providecommand\FN@mf@prepare{% + \kern-\multiplefootnotemarker + \kern\multiplefootnotemarker\relax +} +\providecommand\FN@mf@check{% + \ifdim\lastkern=\multiplefootnotemarker\relax + \edef\@x@sf{\the\spacefactor}% + \unkern + \textsuperscript{\multfootsep}% + \spacefactor\@x@sf\relax + \fi +} + +% +% Sets the parnote mark (included as a MANDATORY argument) +% +\newcommand\parnotemark[1]{% + \leavevmode + \ifhmode + % Save the spacefactor, like \footnote + \edef\@x@sf{\the\spacefactor}% + \FN@mf@check + \nobreak + \fi + \parnotecusmarkfmt{#1}% + \FN@mf@prepare + \ifhmode\spacefactor\@x@sf\fi + \relax +} + +% +% Calls \PN@parnotes@real, if there are parnotes to set. +% +\newcommand\parnotes{% + \unless\ifx\PN@text\@empty + \expandafter\PN@parnotes@real \fi } \def\PN@parnotes@real{% % We call \par later, so this avoids recursion with \PN@parnotes@auto \PN@inparnotestrue - % - % Get into vmode if we aren't already - % - \unless\ifvmode - \par - \fi + \unless\ifvmode\par\fi % Avoid page breaks between a paragraph and its parnotes \nopagebreak\addvspace{\parnotevskip}% - % \parnotefmt goes in a separate group to avoid having formatting - % commands and local redefinitions of \parnotemarkfmt contaminate the - % following paragraphs {\parnotefmt{\PN@text}\par}% \global\def\PN@text{}% \addvspace{\parnotevskip}% @@ -153,15 +249,6 @@ {\PN@parnotes@auto} % At the environment's end, set any notes we've missed % -% If a user calls \parnotes, check that there are parnotes to set -% -\def\parnotes{% - \unless\ifx\PN@text\@empty - \expandafter\PN@parnotes@real - \fi -} - -% % If autopn calls parnotes, check for nested environments, and that this % isn't a call to \par from within \PN@parnotes@real, AND that there are % parnotes to set @@ -177,9 +264,19 @@ } % -% Reset both mark counters to 0 +% Set parnote counter to 1 % -\def\parnotereset{% - \global\c@PN@t=\z@ - \global\c@PN@n=\z@ +\newcommand\parnotereset{\setcounter{parnotemark}{1}} +% A variant also clears \PN@text +\newcommand\parnoteclear{% + \gdef\PN@text{}% + \parnotereset } + +% +% A wrapper around \ref to provide formatted parnote references +% +\newcommand\parnoteref[1]{\parnotemark{\ref{#1}}} + +% Set parnote mark counter to 1 initially +\parnotereset |