From 24c665a0318bee395de0d1f35c1174119174e644 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 10 Mar 2013 22:33:09 +0000 Subject: newenviron (10mar13) git-svn-id: svn://tug.org/texlive/trunk@29331 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/newenviron/README | 44 +++++ .../doc/latex/newenviron/newenviron-examples.tex | 74 ++++++++ .../texmf-dist/tex/latex/newenviron/newenviron.sty | 188 +++++++++++++++++++++ Master/tlpkg/bin/tlpkg-ctan-check | 5 +- Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc | 1 + Master/tlpkg/tlpsrc/newenviron.tlpsrc | 0 6 files changed, 311 insertions(+), 1 deletion(-) create mode 100644 Master/texmf-dist/doc/latex/newenviron/README create mode 100644 Master/texmf-dist/doc/latex/newenviron/newenviron-examples.tex create mode 100644 Master/texmf-dist/tex/latex/newenviron/newenviron.sty create mode 100644 Master/tlpkg/tlpsrc/newenviron.tlpsrc (limited to 'Master') diff --git a/Master/texmf-dist/doc/latex/newenviron/README b/Master/texmf-dist/doc/latex/newenviron/README new file mode 100644 index 00000000000..9bb80720ceb --- /dev/null +++ b/Master/texmf-dist/doc/latex/newenviron/README @@ -0,0 +1,44 @@ +This is the README file for the 'newenviron' package. + +AUTHOR + +Ahmed Musa + +VERSION + +Version 1.0, 2013/02/10. + +LOCATION ON CTAN + +macros/latex/contrib/newenviron/ + +LICENSE + +Copyright (c) 2013 Ahmed Musa + +This software is author-maintained. Permission is granted to copy, +distribute and/or modify this software under the terms of the +LaTeX Project Public License, version 1.3 or higher. This software +is provided 'as it is', without warranty of any kind, either +expressed or implied, including, but not limited to, the implied +warranties of merchantability and fitness for any particular purpose. + +SUMMARY + +The 'newenviron' package provides the commands \newenviron and +\renewenviron that can be used to define environments whose bodies +will be collected in the macros \envbody and \body. These +macros can used to apply some code to the environment body at invocation +time. + +The user-defined environments can be mixed and nested to any depth, +both at definition and invocation times. + +There also exist the commands \EveryBeginOfEnvironment and +\EveryEndOfEnvironment for adding code to the start or end of the +environment at invocation time. + +See the accompanying example file 'newenviron-examples.tex'. + + +% End of README file of newenviron.sty diff --git a/Master/texmf-dist/doc/latex/newenviron/newenviron-examples.tex b/Master/texmf-dist/doc/latex/newenviron/newenviron-examples.tex new file mode 100644 index 00000000000..58b80bfea84 --- /dev/null +++ b/Master/texmf-dist/doc/latex/newenviron/newenviron-examples.tex @@ -0,0 +1,74 @@ +\documentclass{article} +\usepackage{newenviron,xcolor} + +% \envbody will always work for 'unnested' environments: + +% \newenviron{assertion}{}{Assertion: \envbody} + +% But if you intend to nest the environment, it will be safer to use +% \assertionbody: + +\newenviron{assertion}{% + % Test . Note the doubling of the hash characters: + \def\acmd##1{##1}% +}{% + \def\bcmd##1{##1}% + Assertion: \assertionbody +} + +\newenviron{outerassertion}{% + % Put any start code here. +}{% + \textcolor{blue}{Outer assertion:} % + \begin{assertion}\outerassertionbody\end{assertion}% +} + +\begin{document} + +% Just for testing: +\EveryEndOfEnvironment{\def\ccmd#1{#1}} + +\begin{assertion} + test +\end{assertion} +\endgraf\bigskip + +\begin{outerassertion} + test2 +\end{outerassertion} +\endgraf\bigskip + +% Another test. Note the use of \usename{env-1body} and \usename{env-2body}: +\newenviron{env-1}[2][blue]{% + \fboxrule=#2\relax + \cptdimdef\temp{.5\textwidth-0.1cm*\currentgrouplevel}% + \endgraf\noindent + \fcolorbox{#1}{gray!10}{\parbox{\temp}{\textcolor{#1}{\usename{env-1body}}}}% +}{} +\newenviron*{env-2}[1][black]{% + \noindent + \fcolorbox{#1}{gray!30}{% + \parbox{.7\textwidth}{% + \leftskip=1cm + \textcolor{#1}{\usename{env-2body}}% + }% + }% +}{% + \def\testcmd##1{##1}% +} + +\begin{env-2}[red] + Outer box\endgraf + \def\tempa#1{***#1***}\tempa{aa}% + \endgraf\vspace*{5mm}% + \begin{env-1}[blue]{1pt}% + Inner box\endgraf\vspace*{5mm}% + \def\tempa#1{+++#1+++}\tempa{bb}% + \end{env-1}% + \begin{env-1}[brown]{4pt}% + Inner box\endgraf\vspace*{5mm}% + \def\tempa#1{---#1---}\tempa{cc}% + \end{env-1}% +\end{env-2} + +\end{document} diff --git a/Master/texmf-dist/tex/latex/newenviron/newenviron.sty b/Master/texmf-dist/tex/latex/newenviron/newenviron.sty new file mode 100644 index 00000000000..c121330e953 --- /dev/null +++ b/Master/texmf-dist/tex/latex/newenviron/newenviron.sty @@ -0,0 +1,188 @@ +%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% +% This is file 'newenviron.sty', version 1.0, Match 2013. % +% % +% This package and accompanying files may be distributed and/or % +% modified under the conditions of the LaTeX Project Public License, % +% either version 1.3 of this license or any later version. The latest % +% version of this license is in http://www.latex-project.org/lppl.txt % +% and version 1.3 or later is part of all distributions of LaTeX % +% version 2005/12/01 or later. % +% % +% The LPPL maintenance status of this software is 'author-maintained'. % +% % +% This software is provided 'as it is', without warranty of any kind, % +% either expressed or implied, including, but not limited to, the % +% implied warranties of merchantability and fitness for a particular % +% purpose. % +% % +% Copyright (c) 2013 Ahmed Musa (amusa22@gmail.com). % +%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% + +\@ifpackageloaded{catoptions}{}{\RequirePackage{catoptions}[2011/12/12]} +\UseNormalCatcodes +\StyleFilePurpose{Collect and execute environment body (AM)} +\StyleFileRCSInfo +$Id: newenviron.sty,v 1.0 2013/03/08 09:00:00 Ahmed Musa Exp $ +\ProvidesPackage{newenviron}[\StyleFileInfo] +\NeedsTeXFormat{LaTeX2e}[2011/06/27] + +% Collect environment body in macro \envbody and \body. +% +\cptnewvariables{toks}[nenv@]{temptoks} +\new@def\nenv@gobbletomarker#1\nenv@endmarker{} +\new@def*\nevn@quark{} +\new@def*\AlwaysTrimEnvEntries{\global\nenv@alwaystrimtrue} +\new@def*\nenv@trimspace{% + \ifdefboolTF{nenv@alwaystrim}\cpttrimspace\unexpanded +} +\new@def*\nenv@everybegin@hook{} +\robust@def*\EveryBeginOfEnvironment#1{% + \xifinsetTF + {\detokenize{\nevn@quark#1\nevn@quark}} + {\cptoxdetok\nenv@everybegin@hook}{}{% + \edef\nenv@everybegin@hook{% + \expandcsonce\nenv@everybegin@hook + \noexpand\nevn@quark\unexpanded{#1}\noexpand\nevn@quark + }% + }% +} +\new@def*\nenv@everyend@hook{} +\robust@def*\EveryEndOfEnvironment#1{% + \xifinsetTF + {\detokenize{\nevn@quark#1\nevn@quark}} + {\cptoxdetok\nenv@everyend@hook}{}{% + \edef\nenv@everyend@hook{% + \expandcsonce\nenv@everyend@hook + \noexpand\nevn@quark\unexpanded{#1}\noexpand\nevn@quark + }% + }% +} +\EveryEndOfEnvironment{\@ignoretrue} +\robust@def*\nenv@appto#1#2{% + \ifdefTF#1{% + \edef#1{\expandcsonce#1\unexpanded{#2}}% + }{% + \edef#1{\unexpanded{#2}}% + }% +} +% +% \newenviron +% {}[][]{}{} +% +% \renewenviron +% {}[][]{}{} +% +\robust@def*\newenviron{\cpt@starorlong\nenv@newenviron} +\robust@def*\nenv@newenviron#1{% + \edef\cpt@tempa{\cpttrimspace{#1}}% + \cptexpandarg\cpt@testopt + {\nenv@newenviron@a{\expandcsonce\cpt@tempa}}{0}% +} +\robust@def*\nenv@newenviron@a#1[#2]{% + \cpt@ifbrack{\nenv@newenviron@b#1[#2]}{\nenv@newenviron@c{#1}{[#2]}}% +} +\robust@def*\nenv@newenviron@b#1[#2][#3]{\nenv@newenviron@c{#1}{[#2][{#3}]}} +\robust@def\nenv@newenviron@c#1#2#3#4{% + \ifcsndefTF{#1}{}{\letcsntocsn{#1}{end#1}}% + \aftercsname\new@command{#1}#2{% + \edef\nenv@beforebody{\nenv@trimspace{#3}}% + \nenv@everybegin@hook + \nenv@collectbody + }% + \l@ngrel@x\csn@edef{end#1}{% + % We want any parameter characters in #4 to be doubled by + % the user at environment definition time. The aim is that in both + % and , the parameter characters should be + % doubled for any new macro definition. For example, + % + % \newenviron{assertion} + % {\def\acmd##1{##1}} + % {\def\bcmd##1{##1}\assertionbody} + % + % Any #1, #2, etc. in refer to the parameters of + % \assertion. + % + \def\noexpand\cpt@prova{\nenv@trimspace{#4}}\noexpand\cpt@prova + \noexpand\nenv@everyend@hook + }% +} +\robust@def*\nenv@collectbody{% + \begingroup + \toks@{}% + \everyeof{\end{EOF}\relax}% + \nenv@collectbody@a +} +\robust@def\nenv@collectbody@a#1\end#2{% + \nenv@temptoks{% + \cptexpanded{% + \toks@{% + \the\toks@\nenv@trimspace{#1}% + \noexpand\end{\expandcsonce\cpt@argofend}% + }% + }% + \nenv@collectbody@a + }% + \edef\cpt@argofend{\cpttrimspace{#2}}% + \ifcseqTF\cpt@argofend\@currenvir{% + \def\cpt@tempa{}% + \nenv@pushbegin#1\begin\end\nenv@endmarker + \ifcsemptyTF\cpt@tempa{% + % Last end of \newenviron grabbed: + \cptexpanded{\endgroup + \csn@edef{\@currenvir body}{% + \noexpand\unexpanded{\the\toks@\nenv@trimspace{#1}}% + }% + \letcstocsn\noexpand\envbody{\@currenvir body}% + \unexpanded{% + \nenv@beforebody\relax + \ifdefboolTF{nenv@alwaystrim}\@ignoretrue\relax + }% + \noexpand\end{\cpt@argofend}% + }% + }{% + % Nested \newenviron: add current #1 and continue: + \the\nenv@temptoks + }% + }{% + \oifstrcmpTF{\cpt@argofend}{document}{% + \expandafter\endgroup\expandafter + \@checkend\expandafter{\cpt@argofend}% + }{% + \oifstrcmpTF{\cpt@argofend}{EOF}{% + \expandafter\endgroup\expandafter + \@checkend\expandafter{\cpt@argofend}% + }{% + \the\nenv@temptoks + }% + }% + }% +} +\new@def\nenv@pushbegin#1\begin#2{% + \expandafter\ifx\cpt@car#2x\car@nil\end + \expandafter\@gobble + \else + \edef\cpt@prova{\cpttrimspace{#2}}% + \ifx\cpt@prova\cpt@argofend + \def\cpt@tempa{x}% + \expandafter\expandafter\expandafter\nenv@gobbletomarker + \else + \expandafter\expandafter\expandafter\nenv@pushbegin + \fi + \fi +} +\robust@def*\renewenviron{\cpt@starorlong\nenv@renewenviron} +\robust@def*\nenv@renewenviron#1{% + \edef\cpt@tempa{\cpttrimspace{#1}}% + \ifcsndefTF\cpt@tempa + {} + {\@latex@error{Environment #1 is undefined}\@ehd}% + \letcsntocs\cpt@tempa\relax + \letcsntocs{end\cpt@tempa}\relax + \expandafter\nenv@newenviron\expandafter{\cpt@tempa}% +} +\XDeclareBooleanOption{alwaystrim}[true](nenv@){}{} +\XDeclareOption*{\@@warning{Unknown option '\CurrentOption' ignored}} +\XExecuteOptions{alwaystrim} +\XProcessOptions*\relax + +\endinput diff --git a/Master/tlpkg/bin/tlpkg-ctan-check b/Master/tlpkg/bin/tlpkg-ctan-check index 7e6a68b0ca7..27dbb694791 100755 --- a/Master/tlpkg/bin/tlpkg-ctan-check +++ b/Master/tlpkg/bin/tlpkg-ctan-check @@ -296,7 +296,8 @@ my @TLP_working = qw( mychemistry mycv mylatexformat nag nameauth namespc natbib nath nature navigator ncclatex ncctools nddiss needspace nestquot - newcommand newfile newlfm newsletr newspaper newtx newunicodechar newvbtm + newcommand newenviron newfile newlfm newsletr newspaper + newtx newunicodechar newvbtm newverbs nextpage nfssext-cfr niceframe nicefilelist nicetext nih nkarta nlctdoc noitcrul nolbreaks @@ -532,6 +533,7 @@ my @TLP_no_check = ( "kluwer", # not on CTAN, old LPPL, not worth pursuing or removing "kpathsea", # binary "lacheck", # binary + "lambda", # not on CTAN, too old to worry about "latex-bin", # binary "latexconfig", # we maintain "lcdftypetools", # binary @@ -539,6 +541,7 @@ my @TLP_no_check = ( "makeindex", # binary "metafont", # binary "metapost", # binary + "mex", # GUST, requested 2013 "mfware", # binary "mltex", # binary "norasi-c90", # part of cjk diff --git a/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc b/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc index bbc173477eb..7b172c9baad 100644 --- a/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc +++ b/Master/tlpkg/tlpsrc/collection-latexextra.tlpsrc @@ -524,6 +524,7 @@ depend ncctools depend needspace depend nestquot depend newcommand +depend newenviron depend newfile depend newlfm depend newspaper diff --git a/Master/tlpkg/tlpsrc/newenviron.tlpsrc b/Master/tlpkg/tlpsrc/newenviron.tlpsrc new file mode 100644 index 00000000000..e69de29bb2d -- cgit v1.2.3