diff options
author | Karl Berry <karl@freefriends.org> | 2011-01-28 23:13:37 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2011-01-28 23:13:37 +0000 |
commit | d708bf6768840e9e6d64ebdee9e6352df197816a (patch) | |
tree | 86f9f2e97e982d2334df8117ba7c0fce253c3dcb /Master/texmf-dist/tex | |
parent | c7356318aaf68da51bfe55c0f408b0d83cfd4416 (diff) |
cprotect (28jan11)
git-svn-id: svn://tug.org/texlive/trunk@21209 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/cprotect/cprotect.sty | 243 |
1 files changed, 192 insertions, 51 deletions
diff --git a/Master/texmf-dist/tex/latex/cprotect/cprotect.sty b/Master/texmf-dist/tex/latex/cprotect/cprotect.sty index d340995fb55..c80acbe4b2a 100644 --- a/Master/texmf-dist/tex/latex/cprotect/cprotect.sty +++ b/Master/texmf-dist/tex/latex/cprotect/cprotect.sty @@ -7,48 +7,90 @@ %% cprotect.dtx (with options: `package') %% ---------------------------------------------------------------- %% cprotect --- verbatim in macro arguments -%% E-mail: bruno@le-floch.fr +%% E-mail: blflatex@gmail.com %% Released under the LaTeX Project Public License v1.3c or later %% See http://www.latex-project.org/lppl.txt %% ---------------------------------------------------------------- %% \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{cprotect}[2010/12/30 v1.0 (Bruno Le Floch)] +\ProvidesPackage{cprotect}[2011/01/27 v1.0e (Bruno Le Floch)] \RequirePackage{ifthen} \RequirePackage{suffix} +\def\CPT@qend{\CPT@qend} +\def\CPT@option@head#1=#2\CPT@qend{#1} +\def\CPT@option@tail#1=#2\CPT@qend{#2} +\DeclareOption*{% + \ifthenelse{% + \equal{gobbling-escape}{% + \expandafter\CPT@option@head\CurrentOption=\CPT@qend}% + }{% + \edef\CPT@gobbling@escape{% + \expandafter\CPT@option@tail\CurrentOption\CPT@qend + }% + }{% + \ifthenelse{% + \equal{gobbling-letter}{% + \expandafter\CPT@option@head\CurrentOption=\CPT@qend}% + }{% + \edef\CPT@gobbling@letter{% + \expandafter\CPT@option@tail\CurrentOption\CPT@qend + }% + }{% + \PackageError{cprotect}{Unknown option \CurrentOption}{}% + }% + }% +} +\def\CPT@gobbling@escape{E} +\def\CPT@gobbling@letter{L} +\ProcessOptions\relax \newwrite\CPT@WriteOut \newcounter{CPT@WriteCount} +\edef\CPT@filename{\jobname.cpt} \newcommand{\CPT@Write}[1]{% - \stepcounter{CPT@WriteCount}% - \immediate\openout\CPT@WriteOut=\jobname-% - \arabic{CPT@WriteCount}.cpt% + \immediate\openout\CPT@WriteOut=\CPT@filename% \newlinechar`\^^M% \immediate\write\CPT@WriteOut{#1}% \immediate\closeout\CPT@WriteOut% - \aftergroup\CPT@setLastFileName% -} -\newcommand{\CPT@setLastFileName}{% - \def\CPT@lastFileName{\jobname-\arabic{CPT@WriteCount}.cpt}} -\newcommand{\CPT@input@last}{% - \expandafter\protect\expandafter\input - \expandafter{\CPT@lastFileName}} -\newcommand{\makeallletters}{% - \count0=0\relax % - \loop % - \catcode\count0=11\relax % - \advance\count0 by 1\relax % - \ifnum\count0<256 % - \repeat % + \expandafter\xdef\csname CPT@\CPT@filename\endcsname{% + \noexpand\scantokens{#1}% + }% + %\expandafter\gdef\csname \string\CPT@\CPT@filename\expandafter\endcsname\expandafter{% + % \expandafter\protect\csname CPT@\CPT@filename\endcsname}% + %\expandafter\show\csname \string\CPT@\CPT@filename\endcsname% + %\expandafter\show\csname CPT@\CPT@filename\endcsname% } +\newcommand{\makeallother}{% + \count0=0\relax + \loop + \catcode\count0=12\relax + \advance\count0 by 1\relax + \ifnum\count0<256 + \repeat +} +{ + \catcode`\/=0 + /catcode`/\=12 + /catcode`/^=12 + /xdef/CPT@escape@hat@hat@L{\^^/CPT@gobbling@letter/space} + /xdef/CPT@escape@hat@hat@E{\^^/CPT@gobbling@escape/space} + /xdef/CPT@hat@hat@E@hat@hat@L{% + ^^/CPT@gobbling@escape^^/CPT@gobbling@letter/space} +} +\expandafter\scantokens\expandafter{% + \expandafter\catcode\expandafter`\CPT@escape@hat@hat@E=0} +\expandafter\scantokens\expandafter{% + \expandafter\catcode\expandafter`\CPT@hat@hat@E@hat@hat@L=11} +\expandafter\scantokens\expandafter{% + \expandafter\def\CPT@hat@hat@E@hat@hat@L{}} \newcommand\ReadVerbatimUntil[2][]{% \def\CPT@commandatend{#2}% \begingroup #1% - \makeallletters% + \makeallother% \CPT@setup} \WithSuffix\newcommand\ReadVerbatimUntil*[2][]{% \def\CPT@commandatend{#2}% \begingroup #1% - \makeallletters% + \makeallother% \CPT@starsetup} \newcommand{\CPT@def}[2]{\expandafter\def\expandafter#1% \expandafter##\expandafter1#2} @@ -65,7 +107,6 @@ \CPT@readPreText% } \newcommand{\CPT@starsetup}[1]{\CPT@setup#1#1#1} -\def\CPT@qend{\CPT@qend} \newcounter{CPT@numB} \newcommand{\CPT@store}[1]{\edef\CPT@storage{\CPT@storage#1}} \newcommand{\CPT@readContent}{% @@ -89,49 +130,149 @@ \def\CPT@storage{\CPT@preText}% \CPT@gobbleUntilE% } -\newcommand{\cprotect}[1]{\def\CPT@cs{#1}% - \afterassignment\CPT@A\let\CPT@next} +\outer\long\def\cprotect{\icprotect} +\newtoks\CPT@commandatend@toks +\newcommand{\icprotect}[2][om]{% + \def\CPT@argsig{#1}% + \def\CPT@cs{#2}% + \CPT@commandatend@toks{#2}% + \def\CPT@commandatend{\CPT@read@args}% used by RVU. + \CPT@commandatend% +} +\def\CPT@argsig@pop{% + \edef\CPT@argsig{\expandafter\@gobble\CPT@argsig}% +} + %\newcommand\CPT@read@args{\CPT@read@m} +\newcommand\CPT@read@args{% + \ifx\CPT@argsig\empty + \expandafter\the\expandafter\CPT@commandatend@toks + \else + \expandafter\expandafter\expandafter\CPT@read@one + \expandafter\CPT@argsig\expandafter\CPT@qend% + \fi +} +\def\CPT@read@one#1#2\CPT@qend{% + \def\CPT@argsig{#2}% + \def\CPT@tempii{\csname CPT@read@#1\endcsname}% To make the \afterassignment simpler. + \afterassignment\CPT@tempii\let\CPT@next=% +} +\newcommand\CPT@read@m{% + \ifx\CPT@next\bgroup% + \expandafter\CPT@read@mbeg% + \else% + \expandafter\CPT@read@mone% + \fi% +} +\def\CPT@read@mone{\CPT@cs\CPT@next} \begingroup - \catcode`\{=11 \catcode`\}=11 \catcode`\+=11 + \catcode`\{=12 \catcode`\}=12 \catcode`\(=1 \catcode`\)=2 - \gdef\CPT@A(% - \ifx\CPT@next\bgroup% - \expandafter\CPT@n{% - \else% - \expandafter\CPT@N% - \fi) - \gdef\CPT@n{(\ReadVerbatimUntil*(% - \CPT@cs(\CPT@input@last))+{+}+)% - \gdef\CPT@N(\expandafter\CPT@n{\CPT@next })% + \gdef\CPT@other@bgroup({) + \gdef\CPT@other@egroup(}) \endgroup +\def\CPT@read@mbeg{% + \stepcounter{CPT@WriteCount}% + \edef\CPT@filename{\jobname-\arabic{CPT@WriteCount}.cpt}% + \expandafter\expandafter\expandafter\CPT@commandatend@toks + \expandafter\expandafter\expandafter{% + \expandafter\the + \expandafter\CPT@commandatend@toks + % Input a file: + \expandafter{% + \expandafter\protect + \expandafter\input + \CPT@filename + \relax + }% + % % Using \scantokens: requires '%' active. + % \expandafter{% + % \csname \string\CPT@\CPT@filename\endcsname + % \expandafter\protect + % \expandafter\csname CPT@\CPT@filename\endcsname + % }% + }% + %\showthe\CPT@commandatend@toks% + \begingroup% + \makeallother% + \def\CPT@preText{}% + \let\CPT@postText\CPT@hat@hat@E@hat@hat@L% + \let\CPT@begin\CPT@other@bgroup% + \let\CPT@end\CPT@other@egroup% + \CPT@readContent% +}% +\def\CPT@read@o{\CPT@read@d[]} +\def\CPT@read@d#1#2{% + \if\noexpand\CPT@next#1% + \expandafter\CPT@read@d@beg% + \else% + \expandafter\CPT@read@d@none% + \fi% + {#1}{#2}% +} +\def\CPT@read@d@none#1#2{% + \CPT@read@args\CPT@next% +} +\def\CPT@read@d@beg#1#2{% + \stepcounter{CPT@WriteCount}% + \edef\CPT@filename{\jobname-\arabic{CPT@WriteCount}.cpt}% + \expandafter\expandafter\expandafter\CPT@commandatend@toks% + \expandafter\expandafter\expandafter{% + \expandafter\the% + \expandafter\CPT@commandatend@toks% + \expandafter #1% + \expandafter\protect% + \expandafter\input% + \CPT@filename% + \relax% + #2% + }% + \begingroup% + \makeallother% + \def\CPT@preText{}% + \let\CPT@postText\CPT@hat@hat@E@hat@hat@L% + \def\CPT@begin{#1}% + \def\CPT@end{#2}% + \CPT@readContent% +}% \newcommand{\cMakeRobust}[1]{% \def\CPT@cs@name{\expandafter\@gobble\string#1}% \expandafter\let\csname CPT@old@\CPT@cs@name\endcsname #1% - \expandafter\def\csname\CPT@cs@name\endcsname{% - \expandafter\cprotect\csname CPT@old@\CPT@cs@name\endcsname}% + \expandafter\outer\expandafter\def\csname\CPT@cs@name\endcsname{% + \expandafter\icprotect\csname CPT@old@\CPT@cs@name\endcsname}% } \newcommand{\CPTbegin}[1]{% - \def\CPT@commandatend{\begin{#1}\CPT@input@last\end{#1}}% + \stepcounter{CPT@WriteCount}% + \edef\CPT@filename{\jobname-\arabic{CPT@WriteCount}.cpt}% + \edef\CPT@commandatend{% + \noexpand\begin\noexpand{\noexpand#1\noexpand}% + \noexpand\expandafter\noexpand\protect% + \noexpand\expandafter\noexpand\input \CPT@filename\relax% + \noexpand\end\noexpand{\noexpand#1\noexpand}% + }% \begingroup% \CPT@env@setup{#1}% - \makeallletters% + \makeallother% \CPT@readContent% } -\begingroup\catcode`\/=0 -/begingroup/catcode`/\=11 - /catcode`/{=11 /catcode`/}=11 /catcode`/-=11 - /catcode`/(=1 /catcode`/)=2 - /gdef/CPT@env@setup#1(% - /def/CPT@preText(\relax )% - /def/CPT@postText(\relax )% - /def/CPT@begin(\begin{#1})% - /def/CPT@end(\end{#1})% - ) -/endgroup -\endgroup +\newcommand{\CPT@otherify}[1]{% + \expandafter\expandafter\expandafter\@gobble + \expandafter\string\csname #1\endcsname +} +\newcommand{\CPT@env@setup}[1]{% + \def\CPT@temp{#1}% + \edef\CPT@temp{\CPT@otherify{#1}}% + \edef\CPT@temp{\expandafter\strip@prefix\meaning\CPT@temp}% + \expandafter\CPT@env@setup@\expandafter{\CPT@temp}% +} +\def\CPT@env@setup@#1{% + \let\CPT@preText\CPT@hat@hat@E@hat@hat@L% + \let\CPT@postText\CPT@hat@hat@E@hat@hat@L% + \edef\CPT@begin{\string\begin\string{#1\string}}% + \edef\CPT@end{\string\end\string{#1\string}}% +} \def\cprotEnv\begin{\CPTbegin} %% -%% Copyright (C) 2010 by Bruno Le Floch <bruno@le-floch.fr> +%% Copyright (C) 2010-2011 by Bruno Le Floch <blflatex@gmail.com> %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License (LPPL), either |