summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-11-13 00:25:00 +0000
committerKarl Berry <karl@freefriends.org>2010-11-13 00:25:00 +0000
commit306767375ba1c4126f233bc8c7d52499635ce3ac (patch)
tree67d4825faf4f14849677dad2c3bcbdceac72a76f /Master/texmf-dist
parent63f449cec5129e9c1b8024681cc6b8ca3e3a35de (diff)
locality 0.2 (13nov10)
git-svn-id: svn://tug.org/texlive/trunk@20422 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/doc/latex/locality/README10
-rw-r--r--Master/texmf-dist/doc/latex/locality/changes.txt8
-rw-r--r--Master/texmf-dist/doc/latex/locality/locality.pdfbin180126 -> 186910 bytes
-rw-r--r--Master/texmf-dist/source/latex/locality/locality.dtx252
-rw-r--r--Master/texmf-dist/tex/latex/locality/locality.sty137
5 files changed, 345 insertions, 62 deletions
diff --git a/Master/texmf-dist/doc/latex/locality/README b/Master/texmf-dist/doc/latex/locality/README
index 2e53e9d5343..ffe43d84364 100644
--- a/Master/texmf-dist/doc/latex/locality/README
+++ b/Master/texmf-dist/doc/latex/locality/README
@@ -15,9 +15,17 @@ Abstract:
CTAN: macros/latex/contrib/locality
Recent changes:
+ [Release 0.2]
+ * Switched the order of tests in \manyaftergroup, eliminating an infinite loop.
+ * Added \DeclareNonlocal*s, \pushvalues, \popvalues, \pushvalue, \popvalue, and a few others.
+ * Fixed \DeclareNonlocal* to work with \aftergroup.
+ * Added requirement for etoolbox, so that patching takes place at the end of the preamble.
[Release 0.1]
* Initial release. Some macros untested.
+EOF
+
+
Files:
* README - this file
* changes.txt - history of changes
@@ -57,4 +65,4 @@ License:
Happy TeXing!
Jason Gross
-EOF \ No newline at end of file
+EOF
diff --git a/Master/texmf-dist/doc/latex/locality/changes.txt b/Master/texmf-dist/doc/latex/locality/changes.txt
index 0f16d884630..fee40d76653 100644
--- a/Master/texmf-dist/doc/latex/locality/changes.txt
+++ b/Master/texmf-dist/doc/latex/locality/changes.txt
@@ -1,4 +1,10 @@
+2010/11/11 Release 0.2
+ * Switched the order of tests in \manyaftergroup, eliminating an infinite loop.
+ * Added \DeclareNonlocal*s, \pushvalues, \popvalues, \pushvalue, \popvalue, and a few others.
+ * Fixed \DeclareNonlocal* to work with \aftergroup.
+ * Added requirement for etoolbox, so that patching takes place at the end of the preamble.
+
2010-06-29 Release 0.1
* Initial release. Some macros untested.
-EOF \ No newline at end of file
+EOF
diff --git a/Master/texmf-dist/doc/latex/locality/locality.pdf b/Master/texmf-dist/doc/latex/locality/locality.pdf
index 7b89a902073..21ac991b048 100644
--- a/Master/texmf-dist/doc/latex/locality/locality.pdf
+++ b/Master/texmf-dist/doc/latex/locality/locality.pdf
Binary files differ
diff --git a/Master/texmf-dist/source/latex/locality/locality.dtx b/Master/texmf-dist/source/latex/locality/locality.dtx
index c9f5abfa691..f6fb4047392 100644
--- a/Master/texmf-dist/source/latex/locality/locality.dtx
+++ b/Master/texmf-dist/source/latex/locality/locality.dtx
@@ -18,7 +18,8 @@
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{locality}
-%<package> [2010/06/29 v0.1 Various macros for keeping things local]
+%<package> [2010/11/11 v0.2 Various macros for keeping things local]
+%<package>\RequirePackage{etoolbox}[2009/08/06]
%
%<*driver>
\documentclass{ltxdoc}
@@ -32,7 +33,7 @@
%</driver>
% \fi
%
-% \CheckSum{390}
+% \CheckSum{573}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -52,6 +53,13 @@
%
% \changes{v0.1}{2010/06/15}{Initial version. Please note that some macros
% have not yet been tested.}
+% \changes{v0.2}{2010/11/11}{Switched the order of tests in \string
+% \manyaftergroup, eliminating an infinite loop. Added \string
+% \DeclareNonlocal*s\space, \string\pushvalues, \string\popvalues,
+% \string\pushvalue, \string\popvalue, and a few others. Fixed
+% \string\DeclareNonlocal*\space to work with \string\aftergroup.
+% Added requirement for etoolbox, so that patching takes place at
+% the end of the preamble.}
%
% \GetFileInfo{locality.sty}
%
@@ -111,12 +119,27 @@
% This macro generalized |\locallydefine|.
%
%
-% \DescribeMacro{\DeclareNonlocalCount}\DescribeMacro{\DeclareNonlocalLength}\DescribeMacro{\DeclareNonlocalToks}
+% \DescribeMacro{\DeclareNonlocalMacros}
+% \noindent Usage: |\DeclareNonlocalMacros|\marg{macro list} \par\noindent
+% \noindent Example: |\DeclareNonlocalMacros{\macroi,\macroii}| \par\noindent
+% Specification: \marg{macro list} Should be a comma-separated list of macros.
+% This command will run |\DeclareNonlocalMacro| on each argument.
+%
+%
+% \DescribeMacro{\DeclareNonlocalTheRegister}\DescribeMacro{\DeclareNonlocalCount}
+% \DescribeMacro{\DeclareNonlocalDimen}\DescribeMacro{\DeclareNonlocalSkip}
+% \DescribeMacro{\DeclareNonlocalMuskip}\DescribeMacro{\DeclareNonlocalToks}
% \noindent Usage: |\DeclareNonlocalCount|\marg{count} \par\noindent
-% \phantom{Usage:} |\DeclareNonlocalLength|\marg{length} \par\noindent
+% \phantom{Usage:} |\DeclareNonlocalDimen|\marg{dimen} \par\noindent
+% \phantom{Usage:} |\DeclareNonlocalSkip|\marg{skip} \par\noindent
+% \phantom{Usage:} |\DeclareNonlocalMuskip|\marg{muskip} \par\noindent
% \phantom{Usage:} |\DeclareNonlocalToks|\marg{toks} \par\noindent
% Specification: Any changes to the value in \meta{register} persist
% after the end of the current group. \par\noindent
+%
+% Registers for \meta{count}s, \meta{dimen}s, \meta{skip}s, and \meta{muskips}s
+% can all be made nonlocal with |\DeclareNonlocalTheRegister|.
+%
% Bugs: Only works with |\begingroup| |\endgroup| (not with braces). Only
% works if the argument is a single token.
%
@@ -124,6 +147,25 @@
% \meta{tok}s) that |\DeclareNonlocalMacro| does to macros.
%
%
+% \DescribeMacro{\DeclareNonlocalTheRegister}\DescribeMacro{\DeclareNonlocalCount}
+% \DescribeMacro{\DeclareNonlocalDimen}\DescribeMacro{\DeclareNonlocalSkip}
+% \DescribeMacro{\DeclareNonlocalMuskip}\DescribeMacro{\DeclareNonlocalToks}
+% \noindent Usage: |\DeclareNonlocalCounts|\marg{list of counts (comma separated)} \par\noindent
+% \phantom{Usage:} |\DeclareNonlocalDimens|\marg{list of dimens (comma separated)} \par\noindent
+% \phantom{Usage:} |\DeclareNonlocalSkips|\marg{list of skips (comma separated)} \par\noindent
+% \phantom{Usage:} |\DeclareNonlocalMuskips|\marg{list of muskips} \par\noindent
+% \phantom{Usage:} |\DeclareNonlocalTokses|\marg{list of toks (comma separated)} \par\noindent
+% Specification: Any changes to the value in \meta{register}s persist
+% after the end of the current group. \par\noindent
+%
+% \DescribeMacro{\pushvalue}\DescribeMacro{\popvalue}\noindent
+% Usage: |\pushvalue|\marg{macro} \par\noindent
+% \phantom{Usage:} |\popvalue|\marg{macro} \par
+% \noindent Specification: The argument \marg{macro} is backed up by
+% |\pushvalue|, and the most recently backed up value is restored by
+% |\popvalue|. The macro definitions are saved using a stack.
+%
+%
% \DescribeMacro{\savevalues}\DescribeMacro{\restorevalues}
% \noindent Usage: |\savevalues|\marg{list of macros (no separator)} \par\noindent
% \phantom{Usage:} |\restorevalues|\marg{list of macros (no separator)} \par\noindent
@@ -132,6 +174,14 @@
% |\restorevalues|.
%
%
+% \DescribeMacro{\pushvalues}\DescribeMacro{\popvalues}\noindent
+% Usage: |\pushvalues|\marg{list of macros (comma separated)} \par\noindent
+% \phantom{Usage:} |\popvalues|\marg{list of macros (comma separated)} \par
+% \noindent Specification: Every macro in the passed argument is backed up by
+% |\pushvalues|, and the most recently backed up values are restored by
+% |\popvalues|. The macro definitions are saved using a stack.
+%
+%
% \DescribeMacro{\makecommandslocal}
% \noindent Usage: |\makecommandslocal|\marg{list of macros (no separator)}\marg{code} \par\noindent
% Specification: Every token in the first argument is made local to \meta{code};
@@ -170,6 +220,8 @@
% a stack overflow error.
\def\if@nil#1{\@if@nil#1\@@nil}
\def\@if@nil#1#2\@@nil{\ifx\@nil#1}
+% We'll be messing with |\global|, so we better have a backup.
+\let\locality@tex@global=\global
% \end{macrocode}
%
% \begin{macro}{\locality@global@non@collision@unique@count}
@@ -190,7 +242,7 @@
% time, and applying |\aftergroup| to each argument. It checks for the end
% with |\@nil|.
% \begin{macrocode}
-\long\def\@manyaftergroup#1{\ifx#1\@nil \else \aftergroup#1
+\long\def\@manyaftergroup#1{\if@nil#1 \else \aftergroup#1
\expandafter\@manyaftergroup\fi}
\newcommand{\manyaftergroup}[1]{\@manyaftergroup#1\@nil}
% \end{macrocode}
@@ -210,18 +262,45 @@
% The |\DeclareNonlocal| macros do some fancy stuff with |\begingroup| and
% |\endgroup|, so the old definitions must be saved.
% \begin{macrocode}
-\let\@old@begingroup=\begingroup
-\let\@old@endgroup=\endgroup
+\let\locality@tex@begingroup=\begingroup
+\let\locality@tex@endgroup=\endgroup
% \end{macrocode}
% These macros are extended versions of the |\locallydefine| macro; they
% redefine |\endgroup| to preserve definitions after the current group ends.
%
+% Because |\aftergroup| would occur before definition restoration, we patch
+% |\aftergroup| so that it instead appends tokens to the end of |\endgroup|.
+% This doesn't fix all use cases, but it should fix a problem with the calc
+% package.
+% \begin{macrocode}
+\newcount\locality@global@aftergroup@count
+\locality@global@aftergroup@count=-1
+\newcommand\locality@patch@aftergroup{%
+ \def\aftergroup{%
+ \locality@tex@global\advance\locality@global@aftergroup@count by 1
+ \afterassignment\locality@aftergroup\locality@tex@global
+ \expandafter\let\csname locality@nextchar\space\the
+ \locality@global@aftergroup@count\endcsname=%
+ }%
+}
+\newcommand\locality@aftergroup{%
+ \expandafter\expandafter\expandafter\def
+ \expandafter\expandafter\expandafter\endgroup
+ \expandafter\expandafter\expandafter{\expandafter\endgroup
+ \csname locality@nextchar\space\the\locality@global@aftergroup@count
+ \endcsname}%
+}
+% \end{macrocode}
+%
+%
% \begin{macro}{\DeclareNonlocalMacro}
% This macro redefines |\endgroup| to do this for macro passed to it.
%
% First, back up |\endgroup| to a new macro.
% \begin{macrocode}
-\newcommand{\DeclareNonlocalMacro}[1]{\expandafter\let
+\newcommand{\DeclareNonlocalMacro}[1]{%
+ \locality@patch@aftergroup % first, patch |\aftergroup|
+ \expandafter\let
\csname endgroup \the\locality@local@group@non@local@macro@count
\endcsname=\endgroup
% \end{macrocode}
@@ -240,12 +319,32 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macrocode}
+\newcommand\locality@declarenonlocals[2]{%
+ \@for\locality@declarenonlocals@name:=#2\do{%
+ \expandafter #1\expandafter{\locality@declarenonlocals@name}%
+ }%
+}
+% \end{macrocode}
+%
+% \begin{macro}{\DeclareNonlocalMacros}
+% \begin{macrocode}
+\newcommand{\DeclareNonlocalMacros}[1]{\locality@declarenonlocals{\DeclareNonlocalMacro}{#1}}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\DeclareNonlocalTheRegister}
% \begin{macro}{\DeclareNonlocalCount}
-% \begin{macro}{\DeclareNonlocalLength}
+% \begin{macro}{\DeclareNonlocalDimen}
+% \begin{macro}{\DeclareNonlocalSkip}
+% \begin{macro}{\DeclareNonlocalMuskip}
% This works the same way as as |\DeclareNonlocalMacro|, but uses |\the| instead of
% |\def|.
% \begin{macrocode}
-\newcommand{\DeclareNonlocalCount}[1]{\expandafter\let
+\newcommand{\DeclareNonlocalTheRegister}[1]{%
+ \locality@patch@aftergroup % first, patch |\aftergroup|
+ \expandafter\let
\csname endgroup \the\locality@local@group@non@local@macro@count
\endcsname=\endgroup
\expandafter\def\expandafter\endgroup\expandafter{%
@@ -260,16 +359,42 @@
% from setting |\tempc| to 11.
\advance\locality@local@group@non@local@macro@count by 1
}%
-\let\DeclareNonlocalLength=\DeclareNonlocalCount
+\let\DeclareNonlocalCount=\DeclareNonlocalTheRegister
+\let\DeclareNonlocalDimen=\DeclareNonlocalTheRegister
+\let\DeclareNonlocalSkip=\DeclareNonlocalTheRegister
+\let\DeclareNonlocalMuskip=\DeclareNonlocalTheRegister
% \end{macrocode}
% \end{macro}
% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\DeclareNonlocalTheRegisters}
+% \begin{macro}{\DeclareNonlocalCounts}
+% \begin{macro}{\DeclareNonlocalDimens}
+% \begin{macro}{\DeclareNonlocalSkips}
+% \begin{macro}{\DeclareNonlocalMuskips}
+% \begin{macrocode}
+\newcommand{\DeclareNonlocalTheRegisters}[1]{\locality@declarenonlocals{\DeclareNonlocalTheRegister}{#1}}
+\let\DeclareNonlocalCounts=\DeclareNonlocalTheRegisters
+\let\DeclareNonlocalDimens=\DeclareNonlocalTheRegisters
+\let\DeclareNonlocalSkips=\DeclareNonlocalTheRegisters
+\let\DeclareNonlocalMuskips=\DeclareNonlocalTheRegisters
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
%
% \begin{macro}{\DeclareNonlocalToks}
% This works the same way as as |\DeclareNonlocalCount|, but puts braces around
% the assigned value; |\toks0=1| fails, and should be |\toks0={1}|.
% \begin{macrocode}
-\newcommand{\DeclareNonlocalToks}[1]{\expandafter\let
+\newcommand{\DeclareNonlocalToks}[1]{%
+ \locality@patch@aftergroup % first, patch |\aftergroup|
+ \expandafter\let
\csname endgroup \the\locality@local@group@non@local@macro@count
\endcsname=\endgroup
\expandafter\def\expandafter\endgroup\expandafter{%
@@ -282,13 +407,21 @@
}%
% \end{macrocode}
% \end{macro}
+%
+% \begin{macro}{\DeclareNonlocalTokses}
+% \begin{macrocode}
+\newcommand{\DeclareNonlocalTokses}[1]{\locality@declarenonlocals{\DeclareNonlocalToks}{#1}}
+% \end{macrocode}
+% \end{macro}
+%
% I redefine |\begingroup| to reset the locality macros, so nesting works.
% \begin{macrocode}
\newcount\locality@local@group@non@local@macro@count % Hopefully, this
% won't collide with anything. I hope putting this out here allows
% proper nesting of groups
-\def\begingroup{\@old@begingroup
- \let\endgroup=\@old@endgroup
+\def\begingroup{\locality@tex@begingroup
+ \def\endgroup{\locality@tex@endgroup}% not \let, because
+ % that would break my |\aftergroup| patch
\locality@local@group@non@local@macro@count=0
}
% \end{macrocode}
@@ -323,6 +456,41 @@
% \end{macro}
%
%
+% \begin{macro}{\pushvalues}
+% \begin{macro}{\popvalues}
+% \begin{macro}{\pushvalue}
+% \begin{macro}{\popvalue}
+% \begin{macrocode}
+\newcommand{\pushvalue}[1]{%
+ \@ifundefined{locality\space backup\space \string#1}{}{%
+ \expandafter\pushvalue\csname locality\space backup\space \string#1\endcsname%
+ }%
+ \expandafter\let\csname locality\space backup\space \string#1\endcsname=#1%
+}
+\newcommand{\pushvalues}[1]{%
+ \@for\locality@pushvalues@macroname:=#1\do{%
+ \expandafter\pushvalue\locality@pushvalues@macroname
+ }%
+}
+\newcommand{\popvalue}[1]{%
+ \@ifundefined{locality\space backup\space \string#1}{%
+ \let#1=\relax
+ }{%
+ \expandafter\let\expandafter#1\expandafter=\csname locality\space backup\space \string#1\endcsname
+ \expandafter\popvalue\csname locality\space backup\space \string#1\endcsname%
+ }%
+}
+\newcommand{\popvalues}[1]{%
+ \@for\locality@popvalues@macroname:=#1\do{%
+ \expandafter\popvalue\locality@popvalues@macroname
+ }%
+}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
% \begin{macro}{\makecommandslocal}
% Save the macros, run the code, then restore the values.
% \begin{macrocode}
@@ -354,7 +522,8 @@
% \begin{macrocode}
\savevalues{\global\gdef\xdef\@cons}
{\def\begingroup{\begingroup\DeclareNonlocalMacro{##1}}%
-\expandafter\expandafter\expandafter}%
+ \expandafter\expandafter\expandafter
+}%
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter\locality@cons
\expandafter\expandafter\expandafter#%
@@ -362,14 +531,16 @@
\expandafter\expandafter\expandafter#%
\expandafter\expandafter\expandafter2%
\expandafter\expandafter\expandafter{\@cons{#1}{#2}}%
-\newcommand{\obeyglobal}{\restorevalues{\globabl\gdef\xdef\@cons}}
-\let\unignoreglobal=\obeyglobal
+\newcommand{\obeyglobal}{\restorevalues{\global\gdef\xdef\@cons}}
+\newcommand{\unignoreglobal}{\popvalues{\global,\gdef,\xdef,\@cons}}
\newcommand{\ignoreglobal}{%
-\let\global=\relax\let\gdef=\def\let\xdef=\edef
-\let\@cons=\locality@cons
-\expandafter\def\expandafter\unignoreglobal\expandafter{\expandafter
-\def\expandafter\unignoreglobal\expandafter{\unignoreglobal}%
- \unignoreglobal}}
+ \pushvalues{\global,\gdef,\xdef,\@cons}%
+ \let\global=\relax \let\gdef=\def \let\xdef=\edef
+ \let\@cons=\locality@cons
+ \expandafter\def\expandafter\unignoreglobal\expandafter{\expandafter
+ \def\expandafter\unignoreglobal\expandafter{\unignoreglobal}%
+ \unignoreglobal}%
+}
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -422,25 +593,42 @@
\expandafter\ignoreglobal\@definecounter{##1}%
\unignoreglobal
}%
+ \locality@fix@for@amstext
+ \locality@fix@for@calc
+}
% \end{macrocode}
%
% Following the example of the |calc| package, if the amstext package is loaded
% we must add the |\iffirstchoice@| switch as well. We patch the commands this
% way since it's good practice when we know how many arguments they take.
+%
+% We use |\AtEndPreamble| to ensure that we catch the other package loads.
% \begin{macrocode}
- \@ifpackageloaded{amstext}{%
- \expandafter\def\expandafter\stepcounter
- \expandafter##\expandafter1\expandafter{%
- \expandafter\iffirstchoice@\stepcounter{##1}\fi
- }
- \expandafter\def\expandafter\addtocounter
- \expandafter##\expandafter1%
- \expandafter##\expandafter2\expandafter{%
- \expandafter\iffirstchoice@\addtocounter{##1}{##2}\fi
+\AtEndPreamble{
+ \@ifpackageloaded{amstext}{
+ \newcommand{\locality@fix@for@amstext}{
+ \expandafter\def\expandafter\stepcounter
+ \expandafter##\expandafter1\expandafter{%
+ \expandafter\iffirstchoice@\stepcounter{##1}\fi
+ }
+ \expandafter\def\expandafter\addtocounter
+ \expandafter##\expandafter1%
+ \expandafter##\expandafter2\expandafter{%
+ \expandafter\iffirstchoice@\addtocounter{##1}{##2}\fi
+ }
}
- }{}
+ }{
+ \let\locality@fix@for@amstext=\relax
+ }
+ \@ifpackageloaded{calc}{%
+ \def\locality@fix@for@calc{\expandafter\def\expandafter\begingroup\expandafter{\begingroup\DeclareNonlocalTheRegister{\calc@A}}}
+ }{
+ \let\locality@fix@for@calc=\relax
+ }
}
% \end{macrocode}
% \end{macro}
+%
+%
% \Finale
\endinput
diff --git a/Master/texmf-dist/tex/latex/locality/locality.sty b/Master/texmf-dist/tex/latex/locality/locality.sty
index a674c1a8e98..3268661fd4a 100644
--- a/Master/texmf-dist/tex/latex/locality/locality.sty
+++ b/Master/texmf-dist/tex/latex/locality/locality.sty
@@ -21,20 +21,41 @@
%% LaTeX version 1999/12/01 or later.
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{locality}
- [2010/06/29 v0.1 Various macros for keeping things local]
+ [2010/11/11 v0.2 Various macros for keeping things local]
+\RequirePackage{etoolbox}[2009/08/06]
\def\@nil{\@nil\relax} % this way, I'll know if I've messed up; I'll get
\def\if@nil#1{\@if@nil#1\@@nil}
\def\@if@nil#1#2\@@nil{\ifx\@nil#1}
+\let\locality@tex@global=\global
\newcount\locality@global@non@collision@unique@count
\locality@global@non@collision@unique@count=0
-\long\def\@manyaftergroup#1{\ifx#1\@nil \else \aftergroup#1
+\long\def\@manyaftergroup#1{\if@nil#1 \else \aftergroup#1
\expandafter\@manyaftergroup\fi}
\newcommand{\manyaftergroup}[1]{\@manyaftergroup#1\@nil}
\newcommand{\locallydefine}[2]{{#2\expandafter}%
\expandafter\def\expandafter#1\expandafter{#1}}
-\let\@old@begingroup=\begingroup
-\let\@old@endgroup=\endgroup
-\newcommand{\DeclareNonlocalMacro}[1]{\expandafter\let
+\let\locality@tex@begingroup=\begingroup
+\let\locality@tex@endgroup=\endgroup
+\newcount\locality@global@aftergroup@count
+\locality@global@aftergroup@count=-1
+\newcommand\locality@patch@aftergroup{%
+ \def\aftergroup{%
+ \locality@tex@global\advance\locality@global@aftergroup@count by 1
+ \afterassignment\locality@aftergroup\locality@tex@global
+ \expandafter\let\csname locality@nextchar\space\the
+ \locality@global@aftergroup@count\endcsname=%
+ }%
+}
+\newcommand\locality@aftergroup{%
+ \expandafter\expandafter\expandafter\def
+ \expandafter\expandafter\expandafter\endgroup
+ \expandafter\expandafter\expandafter{\expandafter\endgroup
+ \csname locality@nextchar\space\the\locality@global@aftergroup@count
+ \endcsname}%
+}
+\newcommand{\DeclareNonlocalMacro}[1]{%
+ \locality@patch@aftergroup % first, patch |\aftergroup|
+ \expandafter\let
\csname endgroup \the\locality@local@group@non@local@macro@count
\endcsname=\endgroup
\expandafter\def\expandafter\endgroup\expandafter{%
@@ -45,7 +66,15 @@
\expandafter\def\expandafter#1\expandafter{#1}}%
\advance\locality@local@group@non@local@macro@count by 1
}%
-\newcommand{\DeclareNonlocalCount}[1]{\expandafter\let
+\newcommand\locality@declarenonlocals[2]{%
+ \@for\locality@declarenonlocals@name:=#2\do{%
+ \expandafter #1\expandafter{\locality@declarenonlocals@name}%
+ }%
+}
+\newcommand{\DeclareNonlocalMacros}[1]{\locality@declarenonlocals{\DeclareNonlocalMacro}{#1}}
+\newcommand{\DeclareNonlocalTheRegister}[1]{%
+ \locality@patch@aftergroup % first, patch |\aftergroup|
+ \expandafter\let
\csname endgroup \the\locality@local@group@non@local@macro@count
\endcsname=\endgroup
\expandafter\def\expandafter\endgroup\expandafter{%
@@ -57,8 +86,18 @@
\expandafter#1\expandafter=\the#1 }% Note the space. This is to
\advance\locality@local@group@non@local@macro@count by 1
}%
-\let\DeclareNonlocalLength=\DeclareNonlocalCount
-\newcommand{\DeclareNonlocalToks}[1]{\expandafter\let
+\let\DeclareNonlocalCount=\DeclareNonlocalTheRegister
+\let\DeclareNonlocalDimen=\DeclareNonlocalTheRegister
+\let\DeclareNonlocalSkip=\DeclareNonlocalTheRegister
+\let\DeclareNonlocalMuskip=\DeclareNonlocalTheRegister
+\newcommand{\DeclareNonlocalTheRegisters}[1]{\locality@declarenonlocals{\DeclareNonlocalTheRegister}{#1}}
+\let\DeclareNonlocalCounts=\DeclareNonlocalTheRegisters
+\let\DeclareNonlocalDimens=\DeclareNonlocalTheRegisters
+\let\DeclareNonlocalSkips=\DeclareNonlocalTheRegisters
+\let\DeclareNonlocalMuskips=\DeclareNonlocalTheRegisters
+\newcommand{\DeclareNonlocalToks}[1]{%
+ \locality@patch@aftergroup % first, patch |\aftergroup|
+ \expandafter\let
\csname endgroup \the\locality@local@group@non@local@macro@count
\endcsname=\endgroup
\expandafter\def\expandafter\endgroup\expandafter{%
@@ -69,9 +108,11 @@
\expandafter#1\expandafter=\expandafter{\the#1}}%
\advance\locality@local@group@non@local@macro@count by 1
}%
+\newcommand{\DeclareNonlocalTokses}[1]{\locality@declarenonlocals{\DeclareNonlocalToks}{#1}}
\newcount\locality@local@group@non@local@macro@count % Hopefully, this
-\def\begingroup{\@old@begingroup
- \let\endgroup=\@old@endgroup
+\def\begingroup{\locality@tex@begingroup
+ \def\endgroup{\locality@tex@endgroup}% not \let, because
+ % that would break my |\aftergroup| patch
\locality@local@group@non@local@macro@count=0
}
\def\@savevalues#1{\ifx#1\@nil \else \expandafter\let
@@ -92,10 +133,35 @@
\fi
}
\newcommand{\restorevalues}[1]{\@restorevalues#1\@nil}
+\newcommand{\pushvalue}[1]{%
+ \@ifundefined{locality\space backup\space \string#1}{}{%
+ \expandafter\pushvalue\csname locality\space backup\space \string#1\endcsname%
+ }%
+ \expandafter\let\csname locality\space backup\space \string#1\endcsname=#1%
+}
+\newcommand{\pushvalues}[1]{%
+ \@for\locality@pushvalues@macroname:=#1\do{%
+ \expandafter\pushvalue\locality@pushvalues@macroname
+ }%
+}
+\newcommand{\popvalue}[1]{%
+ \@ifundefined{locality\space backup\space \string#1}{%
+ \let#1=\relax
+ }{%
+ \expandafter\let\expandafter#1\expandafter=\csname locality\space backup\space \string#1\endcsname
+ \expandafter\popvalue\csname locality\space backup\space \string#1\endcsname%
+ }%
+}
+\newcommand{\popvalues}[1]{%
+ \@for\locality@popvalues@macroname:=#1\do{%
+ \expandafter\popvalue\locality@popvalues@macroname
+ }%
+}
\newcommand{\makecommandslocal}[2]{\savevalues{#1}#2\restorevalues{#1}}
\savevalues{\global\gdef\xdef\@cons}
{\def\begingroup{\begingroup\DeclareNonlocalMacro{##1}}%
-\expandafter\expandafter\expandafter}%
+ \expandafter\expandafter\expandafter
+}%
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter\locality@cons
\expandafter\expandafter\expandafter#%
@@ -103,14 +169,16 @@
\expandafter\expandafter\expandafter#%
\expandafter\expandafter\expandafter2%
\expandafter\expandafter\expandafter{\@cons{#1}{#2}}%
-\newcommand{\obeyglobal}{\restorevalues{\globabl\gdef\xdef\@cons}}
-\let\unignoreglobal=\obeyglobal
+\newcommand{\obeyglobal}{\restorevalues{\global\gdef\xdef\@cons}}
+\newcommand{\unignoreglobal}{\popvalues{\global,\gdef,\xdef,\@cons}}
\newcommand{\ignoreglobal}{%
-\let\global=\relax\let\gdef=\def\let\xdef=\edef
-\let\@cons=\locality@cons
-\expandafter\def\expandafter\unignoreglobal\expandafter{\expandafter
-\def\expandafter\unignoreglobal\expandafter{\unignoreglobal}%
- \unignoreglobal}}
+ \pushvalues{\global,\gdef,\xdef,\@cons}%
+ \let\global=\relax \let\gdef=\def \let\xdef=\edef
+ \let\@cons=\locality@cons
+ \expandafter\def\expandafter\unignoreglobal\expandafter{\expandafter
+ \def\expandafter\unignoreglobal\expandafter{\unignoreglobal}%
+ \unignoreglobal}%
+}
\newcommand{\makecounterslocal}{% FIX, to make more robust
\expandafter\def\expandafter\stepcounter
\expandafter##\expandafter1\expandafter{%
@@ -150,17 +218,30 @@
\expandafter\ignoreglobal\@definecounter{##1}%
\unignoreglobal
}%
- \@ifpackageloaded{amstext}{%
- \expandafter\def\expandafter\stepcounter
- \expandafter##\expandafter1\expandafter{%
- \expandafter\iffirstchoice@\stepcounter{##1}\fi
- }
- \expandafter\def\expandafter\addtocounter
- \expandafter##\expandafter1%
- \expandafter##\expandafter2\expandafter{%
- \expandafter\iffirstchoice@\addtocounter{##1}{##2}\fi
+ \locality@fix@for@amstext
+ \locality@fix@for@calc
+}
+\AtEndPreamble{
+ \@ifpackageloaded{amstext}{
+ \newcommand{\locality@fix@for@amstext}{
+ \expandafter\def\expandafter\stepcounter
+ \expandafter##\expandafter1\expandafter{%
+ \expandafter\iffirstchoice@\stepcounter{##1}\fi
+ }
+ \expandafter\def\expandafter\addtocounter
+ \expandafter##\expandafter1%
+ \expandafter##\expandafter2\expandafter{%
+ \expandafter\iffirstchoice@\addtocounter{##1}{##2}\fi
+ }
}
- }{}
+ }{
+ \let\locality@fix@for@amstext=\relax
+ }
+ \@ifpackageloaded{calc}{%
+ \def\locality@fix@for@calc{\expandafter\def\expandafter\begingroup\expandafter{\begingroup\DeclareNonlocalTheRegister{\calc@A}}}
+ }{
+ \let\locality@fix@for@calc=\relax
+ }
}
\endinput
%%