diff options
author | Karl Berry <karl@freefriends.org> | 2013-10-14 22:31:43 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-10-14 22:31:43 +0000 |
commit | 9778d89f9f3ed407031c3116ba1e3d621c7e0da4 (patch) | |
tree | 8b9012f12ae2e12ef1bdb925e191d283b3bc2eed /Master/texmf-dist | |
parent | 24530adc39b721401c8037360aea53c67cc968fa (diff) |
withargs (14oct13)
git-svn-id: svn://tug.org/texlive/trunk@31906 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/withargs/README | 37 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/withargs/withargs.pdf | bin | 0 -> 471742 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/withargs/withargs.tex | 219 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/withargs/withargs-dry.sty | 52 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/withargs/withargs-packagedoc.cls | 330 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/withargs/withargs.sty | 331 |
6 files changed, 969 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/withargs/README b/Master/texmf-dist/doc/latex/withargs/README new file mode 100644 index 00000000000..e3df5955260 --- /dev/null +++ b/Master/texmf-dist/doc/latex/withargs/README @@ -0,0 +1,37 @@ +LaTeX Package : withargs 0.0.2 + +Last Modified : 2013-10-07 + +Author : Michiel Helvensteijn (www.mhelvens.net) + +===== Prerequisites ===== + +To use this package, you need the following expl3 packages: +* expl3 +* l3regex +* xparse + +To generate the documentation some extra packages are needed. + +===== Installation ===== + +withargs.sty is provided directly in the package archive. Put +it in a place where your LaTeX distribution can find it. + +(withargs.sty is not generated, but manually maintained; you + may use docstrip to remove the documentation, but you don't + have to; it will just work the way it is) + +===== Documentation ===== + +withargs.pdf is provided directly in the package archive. To +generate the documentation yourself, run LaTeX on withargs.tex. + +(withargs.tex does not contain the package code itself; it inputs + withargs.sty directly to document the implementation) + +===== License ===== + +This material is subject to the LaTeX Project Public License. See +http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html +for the details of that license. diff --git a/Master/texmf-dist/doc/latex/withargs/withargs.pdf b/Master/texmf-dist/doc/latex/withargs/withargs.pdf Binary files differnew file mode 100644 index 00000000000..9c07ddcf128 --- /dev/null +++ b/Master/texmf-dist/doc/latex/withargs/withargs.pdf diff --git a/Master/texmf-dist/doc/latex/withargs/withargs.tex b/Master/texmf-dist/doc/latex/withargs/withargs.tex new file mode 100644 index 00000000000..7301260a9c4 --- /dev/null +++ b/Master/texmf-dist/doc/latex/withargs/withargs.tex @@ -0,0 +1,219 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \iffalse %%%% +% % +% Copyright (c) 2013 - Michiel Helvensteijn (www.mhelvens.net) % +% % +% This work may be distributed and/or modified under the conditions % +% of the LaTeX Project Public License, either version 1.3 of this % +% license or (at your option) 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. % +% % +% This work has the LPPL maintenance status `maintained'. % +% % +% The Current Maintainer of this work is Michiel Helvensteijn. % +% % +% This work consists of the files withargs.tex and withargs.sty. % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \fi %%%% + +\documentclass[a4paper]{withargs-packagedoc} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Setup % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\moretexcs{ + withargs,foo,bar,bas,expectedResult, + actualResult,MyPost,A,uniquecsname,NewPost, + cs_generate_variant:Nn, + withargs:nn,withargs:cn +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Global Changes % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\changes{0.0.1}{2013/10/01} + {initial version} + +\changes{0.0.2}{2013/10/11} + {renamed package to \texttt{withargs}} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{document} % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\maketitle + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Introduction} % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +An example is worth a thousand words: + +\begin{latex-example-show} +\withargs [!] [Hello] [world] { #2 #3#1 } +\end{latex-example-show} + +A quick explanation: we're passing three pieces of \LaTeX\ code in the form +of optional arguments to the final argument, which forms the output. We're +defining a new anonymous macro and invoking it right away. +Up to seven optional arguments are supported. + + + +\subsection{Why is this useful?} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +One of the main use-cases for this package is to insert the expanded +result of a computation into the middle of a big +blob of code that \emph{shouldn't} be expanded. This is possible because +argument substitution bypasses the expansion process: + +\begin{latex-example-show} +\def \expectedResult {\bar} +\def \actualResult {\bas} +\withargs (oo) [\actualResult] [\expectedResult] { + \texttt{\detokenize{ + The \foo variable resulted in `#1' instead of `#2'! + }} +} +\end{latex-example-show} + +`|(oo)|' indicates that both arguments should be expanded `once'. +Any optional \LaTeX3 style argument specification between parentheses +may be specified to control expansion. + +\needspace{10\baselineskip} +You can define your own commands accepting `templates' +with \TeX-style parameters: + +\begin{latex-example-show} +\newcommand{\NewPost}[4]{ + % #1: author % #2: title + % #3: content % #4: template + \withargs (xnn) [#1] [#2] [#3] {#4} +} + +\def\MyPost{ \NewPost{Author}{Title} + {Boy, do I have some important stuff to say!} } + +\begin{tabular}{p{3.5cm}p{3.5cm}p{3.5cm}} + \MyPost{\textbf{#2\hfill#1}\vskip1mm\hrule\vskip1mm\textit{#3}} & + \MyPost{\fbox{#1: ``#2''}\par#3\vskip1mm\hrule} & + \MyPost{#2: #3\hfill\textit{(#1)}} +\end{tabular} +\end{latex-example-show} + +Generally, if speed is not a concern, |\withargs| can be used +to make \LaTeX\ code more readable in a variety of situations. + + + +%\vskip-.4\baselineskip +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Document Level Commands} % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%\vskip-.5\baselineskip + +\def\mystrut{\rule{0pt}{4mm}} + +\describemacro{\withargs}{ + \texttt{\bfseries(}% + \(\overbrace{\mystrut\hbox{\meta{argument specification}}}^x\)% + \texttt{\bfseries)} + \(\overbrace{\mystrut\hbox{\oarg{1} \oarg{2} \oarg{3} \oarg{4} \oarg{5} \oarg{6} \oarg{7}}}^x\) + \marg{body} +} + +Leaves \meta{body} in the output with |#1|\ldots|#7| replaced +by optional arguments \meta{1}\ldots\!\meta{7}. + +An optional \LaTeX3 style \meta{argument specification} between parentheses +can be provided, in which case the arguments undergo expansion as specified +before being placed in the \meta{body}. +%% +Here is an example demonstrating the possible expansion types: + +\begin{latex-example-show} +\def\foo{\bar} \def\s{s} \def\bar{ba\s} \def\bas{FOO-BAR-BAS} + +\withargs (n o f x c v ) + [\foo][\foo][\foo][\foo][\foo][\foo] { + \begin{tabular}{llll} + n: & \texttt{\detokenize{#1}} & % no expansion + o: & \texttt{\detokenize{#2}} \\ % expand once + f: & \texttt{\detokenize{#3}} & % expand until unexpandable + x: & \texttt{\detokenize{#4}} \\ % exhaustive expansion + c: & \texttt{\detokenize{#5}} & % \csname conversion + v: & \texttt{\detokenize{#6}} % `c', then `o' + \end{tabular} +} +\end{latex-example-show} + +Note that all spaces in the \meta{argument specification} are ignored. +For details about \LaTeX3 argument specifications, have a look at the +following documentation: + +\begin{center} + \url{http://www.ctan.org/pkg/expl3} +\end{center} + + +\describemacro{\uniquecsname}{}\vskip-2\baselineskip + +Perhaps a bit misleading, |\uniquecsname| is not actually defined as a command, +but |\withargs| recognizes it as a special marker. If an optional |\withargs| +argument consists entirely of |\uniquecsname|, it is replaced by a +command sequence name which is guaranteed to be unique\ldots unless +you look at the source code (Section~\ref{sec:implementation}) +and intentionally replicate the naming scheme. + +\begin{latex-example-show} +\withargs (ccc) [\uniquecsname][\uniquecsname][\uniquecsname] { + \def#1{A} \let\A#1 + \def#2{B} + \def#3{C} + #3#2#1% +}% +(\A) +\end{latex-example-show} + +\vskip5mm + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{\LaTeX3 Functions} % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +The \LaTeX3 functions underlying the functionality of |\withargs| are +also available as is. + +\describeanymacro{\texttt{\textbackslash withargs:\smash{\(\overbrace{\mystrut\hbox{nnnnnnnn}\!}^x\,\)}n}}{ + \(\overbrace{\mystrut\hbox{\marg{1} \marg{2} \marg{3} \marg{4} \marg{5} \marg{6} \marg{7} \marg{8}}}^x\) + \marg{body} +} + +These functions do pretty much the same thing as the main |\withargs| macro, +except that the argument specification is embedded in the function name +as per \LaTeX3 coding convention, so a parameter slot is freed up for +custom use. They are slightly faster than |\withargs|, as there is no +need to gather optional arguments or do any error checking. +The downside is that the |\uniquecsname| marker doesn't work for these. + +To use a specific expansion scheme, you have to define a variant: + +\begin{latex-example-show} +\ExplSyntaxOn + \cs_generate_variant:Nn \withargs:nn {cn} + \withargs:cn {LaTeX} {#1} +\ExplSyntaxOff +\end{latex-example-show} + +Read the \LaTeX3 documentation for details. + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\end{document} % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/Master/texmf-dist/tex/latex/withargs/withargs-dry.sty b/Master/texmf-dist/tex/latex/withargs/withargs-dry.sty new file mode 100644 index 00000000000..acf5795c82e --- /dev/null +++ b/Master/texmf-dist/tex/latex/withargs/withargs-dry.sty @@ -0,0 +1,52 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \iffalse %%%% +% % +% Copyright (c) 2013 - Michiel Helvensteijn (www.mhelvens.net) % +% % +% This work may be distributed and/or modified under the conditions % +% of the LaTeX Project Public License, either version 1.3 of this % +% license or (at your option) 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. % +% % +% This work has the LPPL maintenance status `maintained'. % +% % +% The Current Maintainer of this work is Michiel Helvensteijn. % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \fi %%%% + +% I will 'officially' release this file at some point in the future. For +% now I'm just using it to document a couple of packages. Still, it's +% released under LPPL, so use it as you will. +% +% -- Michiel Helvensteijn + +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{dry} + [2013/10/11 convenience macros for reusing LaTeX code] + +\RequirePackage{filecontents} +\RequirePackage{xparse} +\RequirePackage{etoolbox} +\RequirePackage{withargs} + +\newcommand\minput[1]{% + \input{#1}\unskip% +} + +\NewDocumentCommand{\NewDRYer}{m +m}{% + \withargs [\uniquecsname] [#2] {% + \newenvironment{#1}{% + \begingroup% + \@tempswafalse\filec@ntents{##1.tmp}% + }{% + \endfilecontents% + \endgroup% + }% + \AfterEndEnvironment{#1}{% + \withargs (xn) [##1.tmp] [\minput{##1.tmp}] {% + ##2% + }% + }% + }% +} diff --git a/Master/texmf-dist/tex/latex/withargs/withargs-packagedoc.cls b/Master/texmf-dist/tex/latex/withargs/withargs-packagedoc.cls new file mode 100644 index 00000000000..bf648d019f4 --- /dev/null +++ b/Master/texmf-dist/tex/latex/withargs/withargs-packagedoc.cls @@ -0,0 +1,330 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% Copyright (C) 2013 by Michiel Helvensteijn - www.mhelvens.net % +% % +% This work may be distributed and/or modified under the % +% conditions of the LaTeX Project Public License, either % +% version 1.3 of this license or (at your option) 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. % +% % +% This work has the LPPL maintenance status `author-maintained'. % +% % +% The Current Maintainer of this work is Michiel Helvensteijn. % +% % +% This work consists of the file packagedoc.cls. % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\let\packagename\jobname + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Document Class % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\LoadClassWithOptions{l3doc} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Importing The Main Package % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\RequirePackage{\packagename} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Importing Other Packages % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\RequirePackage{etoolbox} +\RequirePackage[xcolor]{mdframed} +\RequirePackage{marginnote} +\RequirePackage{listings} +\RequirePackage{textcomp} +\RequirePackage{hyperref} +\RequirePackage{needspace} +\RequirePackage{noindentafter} + +\RequirePackage{withargs-dry} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Documentation Options % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\EnableCrossrefs +\CodelineIndex +\RecordChanges + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% File Info % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\GetFileInfo{\packagename.sty} + +\title{The \textsf{\packagename} package\thanks{% + This document corresponds to \textsf{\packagename}~\fileversion, + dated \filedate.% +}} + +\author{ + Michiel Helvensteijn\\ + \href{mailto:mhelvens+latex@gmail.com}{mhelvens+latex@gmail.com} +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Development Info % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newmdenv[ + leftline = false, + rightline = false +]{bannerframe} + +\apptocmd{\maketitle}{ + \begin{bannerframe} + \small + \begin{center} + Development of this package is organized at + \href{https://github.com/mhelvens/latex-\packagename} + {github.com/mhelvens/latex-\packagename}.\\ + I am happy to receive feedback there! + \end{center} + \end{bannerframe} +}{}{} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Example Environment Setup % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%% Extra keywords for LaTeX +% +\newcommand{\moretexcs}[1]{ + \lstdefinelanguage{latex}{ + language=[LaTeX]tex, + alsoletter={_,:}, + moretexcs={ExplSyntaxOn,ExplSyntaxOff,lstinputlisting,detokenize,#1} + } +} + +%%% Code formatting +% +\lstdefinestyle{examplecode}{% + language=latex,% + basicstyle=\ttfamily\small,% + texcsstyle=*\bfseries,% + keywordstyle=\bfseries% +} + +%%% Setting up example code block +% +\definecolor{examplecodelinecolor}{rgb}{0,0,0} +\definecolor{examplecodebackgroundcolor}{rgb}{.9,.9,.9} +\newmdenv[ + linecolor = examplecodelinecolor, + backgroundcolor = examplecodebackgroundcolor, + skipabove = 0bp, + skipbelow = 0bp, + innertopmargin = -3bp, + innerrightmargin = 4bp, + innerbottommargin = -3bp, + innerleftmargin = 4bp +]{examplecodeframe} + +%%% Defining example output block +% +\definecolor{exampleoutputbackgroundcolor}{rgb}{1,1,1} +\newmdenv[ + linecolor = examplecodelinecolor, + backgroundcolor = exampleoutputbackgroundcolor, + skipabove = 0bp, + skipbelow = 0bp, + innertopmargin = 4bp, + innerrightmargin = 4bp, + innerbottommargin = 4bp, + innerleftmargin = 4bp +]{exampleoutputframe} + +%%% Macros for counting lines in file, adapted from +%%% http://andreas.scherbaum.la/blog/archives/ +%%% 670-Read-number-lines-in-a-file-in-LaTeX.html +% +\RequirePackage{ifthen} +\newboolean{packagedoc@restfile} +\newcommand*{\packagedoc@fileline}{} +\newread\packagedoc@file +\newcommand*{\packagedoc@readnextline}[1]{% + \ifthenelse{\boolean{packagedoc@restfile}}{% + \read#1 to \packagedoc@fileline% + \ifeof#1\setboolean{packagedoc@restfile}{false}% + \else\fi% + }{}% +} +\newcommand*{\countlinesinfile}[2]{% + \setboolean{packagedoc@restfile}{true}% + \setcounter{packagedoc@linecount}{0}% + \openin\packagedoc@file=#1% + \whiledo{\boolean{packagedoc@restfile}}{% + \packagedoc@readnextline{\packagedoc@file}% + \ifthenelse{\boolean{packagedoc@restfile}}{% + \stepcounter{packagedoc@linecount}% + }{}% + }% + \closein\packagedoc@file% + \edef#2{\thepackagedoc@linecount}% +} + +\newcounter{packagedoc@linecount} +\newlength{\packagedoc@spacetoreserve} + +%%% DRYer without output +% +\NewDRYer{latex-example}{% + \addvspace{4bp}% + {% + \ttfamily\small% + \countlinesinfile{#1}{\countedlines}% + \setlength{\packagedoc@spacetoreserve}{\countedlines\baselineskip}% + \addtolength{\packagedoc@spacetoreserve}{-4bp}% + \needspace{\packagedoc@spacetoreserve}% + }% + \begin{examplecodeframe}% + \renewcommand{\ttdefault}{pcr}% + \lstinputlisting[style=examplecode]{#1}% + \end{examplecodeframe}% + #2% + \addvspace{4bp}% +} + +\NoIndentAfterEnv{latex-example} + +%%% DRYer WITH output but WITHOUT side-effects +% +\NewDRYer{latex-example-show}{% + \addvspace{4bp}% + {% + \ttfamily\small% + \countlinesinfile{#1}{\countedlines}% + \setlength{\packagedoc@spacetoreserve}{\countedlines\baselineskip}% + \addtolength{\packagedoc@spacetoreserve}{\baselineskip}% + \needspace{\packagedoc@spacetoreserve}% + }% + \begin{examplecodeframe}% + \renewcommand{\ttdefault}{pcr}% + \lstinputlisting[style=examplecode]{#1}% + \end{examplecodeframe}\vspace{-4bp}% + \begin{exampleoutputframe}% + #2% + \end{exampleoutputframe}% + \addvspace{4bp}% +} + +\NoIndentAfterEnv{latex-example-show} + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Implementation Code Box Setup % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%% Saving old implementation code block font +% +\AtBeginDocument{\let\old@macro@font\macro@font} + +%%% Setup for 'interesting' implementation code blocks +% +\definecolor{interestingcodebackgroundcolor}{rgb}{.9,.9,.9} +\definecolor{interestingcodelinecolor}{rgb}{0,0,0} +\mdfdefinestyle{interestingcode}{ + linecolor = interestingcodelinecolor, + backgroundcolor = interestingcodebackgroundcolor +} +\newcommand*{\interesting}{% + \def\codestyle{interestingcode}% + \let\macro@font\old@macro@font% +} + +%%% Setup for 'UNinteresting' implementation code blocks +% +\definecolor{uninterestingcodebackgroundcolor}{rgb}{.97,.97,.97} +\definecolor{uninterestingcodelinecolor}{rgb}{.5,.5,.5} +\definecolor{uninterestingcodecolor}{rgb}{.4,.4,.4} +\mdfdefinestyle{uninterestingcode}{ + linecolor = uninterestingcodelinecolor, + backgroundcolor = uninterestingcodebackgroundcolor, +} +\newcommand*{\uninteresting}{% + \def\codestyle{uninterestingcode}% + \def\macro@font{\color{uninterestingcodecolor}\old@macro@font}% + \vskip-\belowdisplayskip% + \vskip-1.05\abovedisplayskip% +} + +\BeforeBeginEnvironment{macrocode}{\vskip.2\abovedisplayskip} + +%%% Actually surround 'macrocode' with the frame +% +\surroundwithmdframed[ + style = \codestyle, + skipabove = 0bp, + skipbelow = 0bp, + splitbottomskip = 4bp, + innertopmargin =-3bp, + innerrightmargin = 1bp, + innerbottommargin = 4bp, + innerleftmargin = 1bp +]{macrocode} + +%%% Start out with 'interesting' code status and +%%% always go back to it after one code block +% +\interesting +\AfterEndEnvironment{macrocode}{\vskip\belowdisplayskip\interesting\NoIndentAfterThis} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Argument Specifiers and such % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\newcommand*{\movarg}[1]{[ \texttt{#1} ]} +\newcommand*{\momarg}[1]{[ \meta{#1} ]} + +\newcommand{\describemacro}[2]{% + \needspace{3\baselineskip}% + \noindent\\\DescribeMacro{#1} #2\\\NoIndentAfterThis% +} + +\newcommand{\describeanymacro}[2]{% + \needspace{3\baselineskip}% + \noindent\\\marginnote{#1} #2\\\NoIndentAfterThis% +} + +\newcommand{\describemetamacro}[2]{% + \describeanymacro{\meta{#1}}{#2}% +} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Other Stuff % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\NoIndentAfterEnv{description} +\NoIndentAfterEnv{itemize} +\NoIndentAfterEnv{enumerate} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Automatic Implementation Docs % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\AtEndDocument{ + \pagebreak + + \section{Implementation} \label{sec:implementation} + + \StopEventually {\PrintChanges} + + We now show and explain the entire implementation from \texttt{\packagename.sty}. + + \DocInput{\packagename.sty} + + \Finale + + \PrintIndex +} diff --git a/Master/texmf-dist/tex/latex/withargs/withargs.sty b/Master/texmf-dist/tex/latex/withargs/withargs.sty new file mode 100644 index 00000000000..408878b7fcc --- /dev/null +++ b/Master/texmf-dist/tex/latex/withargs/withargs.sty @@ -0,0 +1,331 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \iffalse %%%% +% % +% Copyright (c) 2013 - Michiel Helvensteijn (www.mhelvens.net) % +% % +% This work may be distributed and/or modified under the conditions % +% of the LaTeX Project Public License, either version 1.3 of this % +% license or (at your option) 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. % +% % +% This work has the LPPL maintenance status `maintained'. % +% % +% The Current Maintainer of this work is Michiel Helvensteijn. % +% % +% This work consists of the files withargs.tex and withargs.sty. % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \fi %%%% + +% \CheckSum{115} +% +% \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 +% Lower-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 +% Digits \0\1\2\3\4\5\6\7\8\9 +% Exclamation \! Double quote \" Hash (number) \# +% Dollar \$ Percent \% Ampersand \& +% Acute accent \' Left paren \( Right paren \) +% Asterisk \* Plus \+ Comma \, +% Minus \- Point \. Solidus \/ +% Colon \: Semicolon \; Less than \< +% Equals \= Greater than \> Question mark \? +% Commercial at \@ Left bracket \[ Backslash \\ +% Right bracket \] Circumflex \^ Underscore \_ +% Grave accent \` Left brace \{ Vertical bar \| +% Right brace \} Tilde \~} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% \subsection{Package Info} % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% \begin{macrocode} +\NeedsTeXFormat{LaTeX2e} +\RequirePackage{expl3} +\ProvidesExplPackage{withargs}{2013/10/11}{0.0.2} + {an inline construct for passing token lists as TeX parameters} +% \end{macrocode} +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% \subsection{Required Packages} % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% We just need some expl3-ish packages. +% +% \begin{macrocode} +\RequirePackage{xparse} +\RequirePackage{l3regex} +% \end{macrocode} +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% \subsection{\LaTeX3 Functions} % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % \begin{macro}{\withargs:nn,\withargs:nnn,\withargs:nnnn,\withargs:nnnnn,\withargs:nnnnnn, + % \withargs:nnnnnnn,\withargs:nnnnnnnn,\withargs:nnnnnnnnn} + % \(\overbrace{\hbox{\marg1 \marg2 \marg3 \marg4 \marg5 \marg6 \marg7 \marg8}}^{1-8}\) + % \marg{body} +%%% \\[-.5\belowdisplayskip]\nopagebreak +% +% \noindent These are the |expl3| API versions of the |\withargs| command. +% The implementation is quite straight-forward. This technique has to +% be used by any library command that accepts \TeX-style parameters. +% +% \begin{macrocode} +\cs_new_protected:Nn \withargs:nn { + \cs_set:Npn \__withargs:n ##1 {#2} + \__withargs:n {#1} } +\cs_new_protected:Nn \withargs:nnn { + \cs_set:Npn \__withargs:nn ##1##2 {#3} + \__withargs:nn {#1}{#2} } +\cs_new_protected:Nn \withargs:nnnn { + \cs_set:Npn \__withargs:nnn ##1##2##3 {#4} + \__withargs:nnn {#1}{#2}{#3} } +\cs_new_protected:Nn \withargs:nnnnn { + \cs_set:Npn \__withargs:nnnn ##1##2##3##4 {#5} + \__withargs:nnnn {#1}{#2}{#3}{#4} } +\cs_new_protected:Nn \withargs:nnnnnn { + \cs_set:Npn \__withargs:nnnnn ##1##2##3##4##5 {#6} + \__withargs:nnnnn {#1}{#2}{#3}{#4}{#5} } +\cs_new_protected:Nn \withargs:nnnnnnn { + \cs_set:Npn \__withargs:nnnnnn ##1##2##3##4##5##6 {#7} + \__withargs:nnnnnn {#1}{#2}{#3}{#4}{#5}{#6} } +\cs_new_protected:Nn \withargs:nnnnnnnn { + \cs_set:Npn \__withargs:nnnnnnn ##1##2##3##4##5##6##7 {#8} + \__withargs:nnnnnnn {#1}{#2}{#3}{#4}{#5}{#6}{#7} } +\cs_new_protected:Nn \withargs:nnnnnnnnn { + \cs_set:Npn \__withargs:nnnnnnnn ##1##2##3##4##5##6##7##8 {#9} + \__withargs:nnnnnnnn {#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8} } +% \end{macrocode} +% +%%% \end{macro} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% \subsection{Document Level Command} % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % \begin{macro}{\__withargs_var:x} \marg{argument specifier} +%%% \\[-.5\belowdisplayskip]\nopagebreak +% +% \noindent This is a convenience command for generating +% and using a |\withargs:| variant in one go. I only use it +% for the document-level command, since those users can't +% roll their own. +% +% |#1| should be the number of optional |\withargs| arguments +% and |#2| should be a \LaTeX3 argument specification not +% longer than |#1| --- a prefix. +% +% \begin{macrocode} +\cs_new:Nn \__withargs_var:nx { + \cs_generate_variant:cx + { withargs : \prg_replicate:nn{#1}{n} n } + { #2 n } + \use:c { + withargs : + #2 + \prg_replicate:nn{#1-\tl_count:n{#2}}{n} + n + } +} +% \end{macrocode} +% \uninteresting\begin{macrocode} +\cs_generate_variant:Nn \cs_generate_variant:Nn {cx} +% \end{macrocode} +% +%%% \end{macro} \vspace{-2mm} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % \begin{macro}{\__withargs_process_uniquecsname:n} + % \marg{argument} +%%% \\[-.5\belowdisplayskip]\nopagebreak +% +% \noindent An |xparse| processor function to pass a unique +% control sequence name if the argument given was '|\uniquecsname|'. +% +% \begin{macrocode} +\cs_new_protected:Nn\__withargs_process_uniquecsname:n{ + \tl_if_eq:nnTF {#1} {\uniquecsname} { + \int_gincr:N \g__with_unique_int + \tl_set:Nx \ProcessedArgument + { Unique-CS-Name-( \int_use:N\g__with_unique_int ) } + }{ + \tl_set:Nn \ProcessedArgument {#1} + } +} +\int_new:N \g__with_unique_int +% \end{macrocode} +% +%%% \end{macro} \vspace{-2mm} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % \begin{macro}{\__withargs_remove_spaces:n} + % \marg{argument} +%%% \\[-.5\belowdisplayskip]\nopagebreak +% +% \noindent An |xparse| processor function to remove all +% spaces from the argument. +% +% \begin{macrocode} +\cs_new_protected:Nn\__withargs_remove_spaces:n{ + \tl_set:Nn \ProcessedArgument {#1} + \tl_remove_all:Nn\ProcessedArgument {~} +} +% \end{macrocode} +% +%%% \end{macro} \vspace{-2mm} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +% \pagebreak + + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % \begin{macro}{\withargs} + % \texttt{\bfseries(}\meta{argument specification}\texttt{\bfseries)} + % \oarg{1} \oarg{2} \oarg{3} \oarg{4} \oarg{5} \oarg{6} \oarg{7} + % \marg{body} +%%% \\[-.5\belowdisplayskip]\nopagebreak +% +% \noindent This is the document version of the |\withargs| command. +% +% \changes{0.0.2}{2013/10/11} +% {made the first argument optional and delimited by parentheses} +% +% \begin{macrocode} +\NewDocumentCommand {\withargs} + { >{\__withargs_remove_spaces:n} D(){} % argument spec + >{\__withargs_process_uniquecsname:n} +o % up to 7 optional args + >{\__withargs_process_uniquecsname:n} +o + >{\__withargs_process_uniquecsname:n} +o + >{\__withargs_process_uniquecsname:n} +o + >{\__withargs_process_uniquecsname:n} +o + >{\__withargs_process_uniquecsname:n} +o + >{\__withargs_process_uniquecsname:n} +o + +m } { % the body to execute +% \end{macrocode} +% +% We first check if the argument specification is valid. +% It has to be between 0 and 7 characters long and each +% symbol has to be one of `|noxfcv|'. Otherwise: error! +% The variants `|N|' and `|V|' are not supported (yet) because +% they collect arguments differently than the others, and frankly, +% I didn't want to bother. +% +% \begin{macrocode} + \regex_match:nnF {^[nofxcv]{0,7}$} {#1} + { \msg_critical:nnn{withargs}{invalid-parameter-specs}{#1} } +% \end{macrocode} +% +% The next bit counts the number of optional arguments provided +% using binary search. +% If |#1| specifies \emph{more} arguments than were provided: error! +% +% \begin{macrocode} + \int_set:Nn \l__with_arg_int { + \IfNoValueTF {#5} + { \IfNoValueTF {#3} { \IfNoValueTF{#2} 0 1 } + { \IfNoValueTF{#4} 2 3 } } + { \IfNoValueTF {#7} { \IfNoValueTF{#6} 4 5 } + { \IfNoValueTF{#8} 6 7 } } + } + + \int_compare:nNnT {\tl_count:n{#1}} > {\l__with_arg_int} { + \msg_error:nnxxx{withargs}{invalid-parameter-number} + { \tl_count:n{#1} } + { \int_use:N \l__with_arg_int } + { #1 } + } +% \end{macrocode} +% +% We can then call the right variant of |\withargs:|. +% +% \begin{macrocode} + \int_case:nnn {\l__with_arg_int} { + {1} { \__withargs_var:nx1{#1} {#2} {#9} } + {2} { \__withargs_var:nx2{#1} {#2}{#3} {#9} } + {3} { \__withargs_var:nx3{#1} {#2}{#3}{#4} {#9} } + {4} { \__withargs_var:nx4{#1} {#2}{#3}{#4}{#5} {#9} } + {5} { \__withargs_var:nx5{#1} {#2}{#3}{#4}{#5}{#6} {#9} } + {6} { \__withargs_var:nx6{#1} {#2}{#3}{#4}{#5}{#6}{#7} {#9} } + {7} { \__withargs_var:nx7{#1} {#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9} } + }{} +% \end{macrocode} +% \uninteresting\begin{macrocode} +} +\int_new:N \l__with_arg_int +% \end{macrocode} +% +%%% \end{macro} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% \noindent The following is the error message displayed +% if the argument specification is ill-formed: +% +% \begin{macrocode} +\msg_new:nnnn{withargs}{invalid-parameter-specs}{ + The~argument~specification~'#1'~is~not~valid. +}{ + The~argument~specification~should~consist~of~between~one~ + and~seven~of~the~letters~'n',~'o',~'f',~'x',~'c',~'v'. +} +% \end{macrocode} +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% \noindent This is the error message displayed if the +% number of provided optional arguments is inconsistent +% with the provided argument specification. +% +% \begin{macrocode} +\msg_new:nnnn{withargs}{invalid-parameter-number}{ + You~specified~#1~arguments~but~provided~#2. +}{ + Your~argument~specification~is~'#3',~which~means~you~should~ + provide~#1~optional~arguments.~However,~you~provided~#2.~ + You~should~fix~that. +} +% \end{macrocode} +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + |