diff options
-rw-r--r-- | Master/texmf-dist/doc/latex/macroswap/macroswap.pdf | bin | 160800 -> 162297 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/macroswap/macroswap.dtx | 104 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/macroswap/macroswap.sty | 40 |
3 files changed, 74 insertions, 70 deletions
diff --git a/Master/texmf-dist/doc/latex/macroswap/macroswap.pdf b/Master/texmf-dist/doc/latex/macroswap/macroswap.pdf Binary files differindex 304741e95f1..f6c2c5f8a86 100644 --- a/Master/texmf-dist/doc/latex/macroswap/macroswap.pdf +++ b/Master/texmf-dist/doc/latex/macroswap/macroswap.pdf diff --git a/Master/texmf-dist/source/latex/macroswap/macroswap.dtx b/Master/texmf-dist/source/latex/macroswap/macroswap.dtx index c0fd61c4db1..6853e77d4fb 100644 --- a/Master/texmf-dist/source/latex/macroswap/macroswap.dtx +++ b/Master/texmf-dist/source/latex/macroswap/macroswap.dtx @@ -17,7 +17,7 @@ % \iffalse % <package>\NeedsTeXFormat{LaTeX2e}[1999/12/01] % <package>\ProvidesPackage{macroswap} -% <package> [2013/09/16 v1.0 dtx macro swapper] +% <package> [2013/08/21 v1.1 dtx macro swapper] % %<*driver> \documentclass{ltxdoc} @@ -47,15 +47,18 @@ % Grave accent \` Left brace \{ Vertical bar \| % Right brace \} Tilde \~} % -% \CheckSum{54} +% \CheckSum{62} % -% \changes{v1.0}{2013/09/18}{Initial version} +% \changes{v1.0}{2013/08/18}{Initial version} +% \changes{v1.1}{2013/08/20}{Correct month in version date, remove +% (unstated) dependency on \texttt{etoolbox} package, support swapping +% macros that expect parameters, improved error reporting (thanks to +% Christian Tellechea, Ulrich Diez and Dan)} % % \GetFileInfo{macroswap.sty} % % \DoNotIndex{\let, \edef, \xdef, \relax, \newcommand} % \DoNotIndex{\csname, \endcsname} -% \DoNotIndex{\makeatletter, \makeatother} % % \title{The Macroswap Package\thanks{This document corresponds to \textsf{Macroswap}~\fileversion, dated \filedate.}} % \author{Robert J Lee \\ latex@rjlee.homelinux.org} @@ -136,79 +139,72 @@ % \section*{Implementation} %\StopEventually{\PrintChanges \pagebreak[4] \PrintIndex} % -% First we make the @ symbol a letter so wo can use it internally -% \begin{macrocode} -\makeatletter -% \end{macrocode} -% % \begin{macro}{\gmacroswap} -% given the name of two macros, swap their definitions. +% Given the name of two macros, swap their definitions. % Produces no output. -% This version is global. +% This version uses plain |\let| to produce a local assignment. % \begin{macrocode} -\newcommand{\gmacroswap}[2]{% +\newcommand{\macroswap}[2]{% % \end{macrocode} -% NB: we don't use ifcsname, because there's no guarantee that |#1| or -% |#2| will be a single token -% |macro@swap@left| and |macro@swap@right| are the contents of the -% passed-in macro names. The |edef| would normally fully expand its -% parameter but the |csexpandonce| prevents the full expansion and -% returns only the token list that we want. +% NB: there's no guarantee that |#1| or |#2| will be a single token. +% +% First verify that they expand to a single macro name: % \begin{macrocode} - \edef\macro@swap@left{\csexpandonce{#1}}% - \edef\macro@swap@right{\csexpandonce{#2}}% + \expandafter\ifcsname#1\endcsname% + \else% + \PackageError{macrocode}{Two macro names are required for macroswap % + (got ``#1'' and ``#2'')}{% + Two macro names are required, but the first parameter does not % + expand to a defined macro name. Macros have not been swapped.}% + \fi% + \expandafter\ifcsname#2\endcsname% + \else% + \PackageError{macrocode}{Two macro names are required for macroswap % + (got ``#1'' and ``#2'')}{% + Two macro names are required, but the second parameter does not % + expand to a defined macro name. Macros have not been swapped.}% + \fi% % \end{macrocode} -% Having taken a copy of the passed-in macro, we then reassign it to -% the values in our tokens, which we get using |expandonce| to strip -% off our temporary macro names. Again, |xdef| would normally expand -% its macros as well as being a global assignment; however, the -% |expandonce| prevents the full expansion. -% -% |expandafter| is used to evaluate the |csname|\dots|\endcsname| -% become the |xdef|, as |xdef| will only redefine its first parameter. +% First we use a temporary variable, |macroswap@temp|, to hold the value of the first macro. +% +% |\expandafter| is used to evaluate the |\csname|\dots|\endcsname| +% become the |\let|, as |\let| will only redefine its first parameter. % \begin{macrocode} - \expandafter\xdef\csname#2\endcsname{\expandonce{\macro@swap@left}}% - \expandafter\xdef\csname#1\endcsname{\expandonce{\macro@swap@right}}% + \expandafter\let\expandafter\macroswap@temp\csname#1\endcsname% % \end{macrocode} % -% Finally, we throw away our temporary macros: +% Next, the same method is used to reassign each passed-in macro. +% +% \begin{macrocode} + \expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname% + \expandafter\let\csname#2\endcsname\macroswap@temp% +% \end{macrocode} +% Finally, we throw away our temporary macro: % \begin{macrocode} - \let\macroswap@left\relax% - \let\macroswap@right\relax% + \let\macroswap@temp\relax% } % \end{macrocode} % \end{macro} % % \begin{macro}{\macroswap} -% given the name of two macros, swap their definitions. +% Given the name of two macros, swap their definitions. % Produces no output. -% This version is local. -% \begin{macrocode} -\newcommand{\macroswap}[2]{% -% \end{macrocode} -% NB: we don't use ifcsname, because there's no guarantee that |#1| or |#2| will be a single token +% +% This version is global; the only difference here is that |\global| +% is used to modify |\let| to applied globally. % \begin{macrocode} - \edef\macro@swap@left{\csexpandonce{#1}}% - \edef\macro@swap@right{\csexpandonce{#2}}% +\newcommand{\gmacroswap}[2]{% + \expandafter\let\expandafter\macroswap@temp\csname#1\endcsname% % \end{macrocode} -% The only difference here is the use of |edef| instead of |xdef|, -% which expands its second argument and overwrites its first argument -% locally, so the original values will be restored at the end of the -% current group or environment. +% NB: |\expandafter| is used before |\global| so that the |let| becomes global... % \begin{macrocode} - \expandafter\edef\csname#2\endcsname{\expandonce{\macro@swap@left}}% - \expandafter\edef\csname#1\endcsname{\expandonce{\macro@swap@right}}% - \let\macroswap@left\relax% - \let\macroswap@right\relax% + \expandafter\global\expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname% + \expandafter\global\expandafter\let\csname#2\endcsname\macroswap@temp% + \let\macroswap@temp\relax% } % \end{macrocode} % \end{macro} % -% Leave @ as another character -% \begin{macrocode} -\makeatother -% \end{macrocode} -% % That is all % \Finale \endinput diff --git a/Master/texmf-dist/tex/latex/macroswap/macroswap.sty b/Master/texmf-dist/tex/latex/macroswap/macroswap.sty index 6d719cde5a0..cecd5aa8ef7 100644 --- a/Master/texmf-dist/tex/latex/macroswap/macroswap.sty +++ b/Master/texmf-dist/tex/latex/macroswap/macroswap.sty @@ -20,24 +20,32 @@ %% and version 1.2 or later is part of all distributions of %% LaTeX version 1999/12/01 or later. %% -\makeatletter -\newcommand{\gmacroswap}[2]{% - \edef\macro@swap@left{\csexpandonce{#1}}% - \edef\macro@swap@right{\csexpandonce{#2}}% - \expandafter\xdef\csname#2\endcsname{\expandonce{\macro@swap@left}}% - \expandafter\xdef\csname#1\endcsname{\expandonce{\macro@swap@right}}% - \let\macroswap@left\relax% - \let\macroswap@right\relax% -} \newcommand{\macroswap}[2]{% - \edef\macro@swap@left{\csexpandonce{#1}}% - \edef\macro@swap@right{\csexpandonce{#2}}% - \expandafter\edef\csname#2\endcsname{\expandonce{\macro@swap@left}}% - \expandafter\edef\csname#1\endcsname{\expandonce{\macro@swap@right}}% - \let\macroswap@left\relax% - \let\macroswap@right\relax% + \expandafter\ifcsname#1\endcsname% + \else% + \PackageError{macrocode}{Two macro names are required for macroswap % + (got ``#1'' and ``#2'')}{% + Two macro names are required, but the first parameter does not % + expand to a defined macro name. Macros have not been swapped.}% + \fi% + \expandafter\ifcsname#2\endcsname% + \else% + \PackageError{macrocode}{Two macro names are required for macroswap % + (got ``#1'' and ``#2'')}{% + Two macro names are required, but the second parameter does not % + expand to a defined macro name. Macros have not been swapped.}% + \fi% + \expandafter\let\expandafter\macroswap@temp\csname#1\endcsname% + \expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname% + \expandafter\let\csname#2\endcsname\macroswap@temp% + \let\macroswap@temp\relax% +} +\newcommand{\gmacroswap}[2]{% + \expandafter\let\expandafter\macroswap@temp\csname#1\endcsname% + \expandafter\global\expandafter\let\csname#1\expandafter\endcsname\csname#2\endcsname% + \expandafter\global\expandafter\let\csname#2\endcsname\macroswap@temp% + \let\macroswap@temp\relax% } -\makeatother \endinput %% %% End of file `macroswap.sty'. |