From 306767375ba1c4126f233bc8c7d52499635ce3ac Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 13 Nov 2010 00:25:00 +0000 Subject: locality 0.2 (13nov10) git-svn-id: svn://tug.org/texlive/trunk@20422 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/locality/locality.sty | 137 +++++++++++++++++----- 1 file changed, 109 insertions(+), 28 deletions(-) (limited to 'Master/texmf-dist/tex/latex/locality') 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 %% -- cgit v1.2.3