diff options
author | Karl Berry <karl@freefriends.org> | 2012-03-29 23:20:23 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-03-29 23:20:23 +0000 |
commit | 84c2b4bf9bf9fa99638f75dd5c81041d7e8705cf (patch) | |
tree | 08001c80f59e16e691575822fde1669bf8fccc44 /Master | |
parent | 9fc033895f0466fc3ad09b515d588d61ea42f960 (diff) |
new generic package bitelist (29mar12)
git-svn-id: svn://tug.org/texlive/trunk@25779 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r-- | Master/texmf-dist/doc/generic/bitelist/README | 64 | ||||
-rw-r--r-- | Master/texmf-dist/doc/generic/bitelist/bitelist.pdf | bin | 0 -> 405448 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/generic/bitelist/bitelist.tex | 319 | ||||
-rw-r--r-- | Master/texmf-dist/source/generic/bitelist/srcfiles.tex | 15 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/bitelist/bitedemo.tex | 43 | ||||
-rw-r--r-- | Master/texmf-dist/tex/generic/bitelist/bitelist.sty | 240 | ||||
-rwxr-xr-x | Master/tlpkg/bin/tlpkg-ctan-check | 2 | ||||
-rw-r--r-- | Master/tlpkg/tlpsrc/bitelist.tlpsrc | 0 | ||||
-rw-r--r-- | Master/tlpkg/tlpsrc/collection-genericextra.tlpsrc | 1 |
9 files changed, 683 insertions, 1 deletions
diff --git a/Master/texmf-dist/doc/generic/bitelist/README b/Master/texmf-dist/doc/generic/bitelist/README new file mode 100644 index 00000000000..81331006413 --- /dev/null +++ b/Master/texmf-dist/doc/generic/bitelist/README @@ -0,0 +1,64 @@ + + README for the `bitelist' package + "Split list at list inside in TeX's Mouth" + (C) Uwe Lueck 2012/03/28 + + +`bitelist.sty' provides commands for "splitting" a token list +at the first occurrence of a contained token list. I.e., for given +token lists s, t return b and shortest a, such that t = a s b. +As opposed to other packages providing similar features, + (i) the method uses TeX's mechanism of reading delimited macro + parameters; + (ii) the splitting macros work by pure expansion, without + assignments, provided the macro doing the search has been + defined before processing (e.g., a file); +(iii) instead of using one macro for a "substring" test and another + one to replace the "substring"--which includes extracting + corresponding prefix and suffix--, the *same* macro that + detects the occurrence returns the split; + (iv) e-TeX is not required. +(And LaTeX is not required.) This improves `fifinddo.sty' (v0.51). + +An elaborated approach (additionally to a simpler one) is provided +that does not loose outer braces of prefix/suffix. + +"Substring" detection and "string" replacement are (implicitly) +included with respect to certain representations of characters by tokens. +Counting occurrences and "global" replacement could be achieved +by applying the operation to earlier results, etc.--so +this approach seems to be "fundamental" for a certain larger +set of list analysis tasks. + +The documentation aims to prove the correctness of the methods +with mathematical rigour. + +KEYWORDs: macro programming, text filtering, substrings + +RELATEd PACKAGEs: datatool, stringstrings, ted, texapi, xstring + +The package file `bitelist.sty' and the documentation files +`bitelist.pdf' and `bitelist.tex' can be redistributed and/or +modified under the terms of the LaTeX Project Public License; +either version 1.3c of the License, or any later version, see + + http://www.latex-project.org/lppl.txt + +We did our best to help you, but there is NO WARRANTY. + +The `bitelist' package is author-maintained in the sense of +this license. + +The latest public version of the package is available at + + http://mirror.ctan.org/macros/latex/contrib/bitelist/ + +A TDS version of the package is available as + + http://mirror.ctan.org/install/macros/generic/bitelist.tds.zip + +Please report bugs, problems, and suggestions via + + http://www.contact-ednotes.sty.de.vu + + diff --git a/Master/texmf-dist/doc/generic/bitelist/bitelist.pdf b/Master/texmf-dist/doc/generic/bitelist/bitelist.pdf Binary files differnew file mode 100644 index 00000000000..5608e6e5e89 --- /dev/null +++ b/Master/texmf-dist/doc/generic/bitelist/bitelist.pdf diff --git a/Master/texmf-dist/source/generic/bitelist/bitelist.tex b/Master/texmf-dist/source/generic/bitelist/bitelist.tex new file mode 100644 index 00000000000..7f6ec25c570 --- /dev/null +++ b/Master/texmf-dist/source/generic/bitelist/bitelist.tex @@ -0,0 +1,319 @@ +\ProvidesFile{bitelist.tex}[2012/03/29 documenting bitelist.sty] +\title{\textsf{\huge bitelist.sty %% \huge 2012/03/19 + }\\---\\``Splitting" a List at a List Inside + \\in \TeX's Mouth\thanks{This + document describes version + \textcolor{blue}{\UseVersionOf{\jobname.sty}} + of \textsf{\jobname.sty} as of \UseDateOf{\jobname.sty}.}} +% \listfiles +{ \RequirePackage{makedoc} \ProcessLineMessage{} + \MakeJobDoc{17} + {\SectionLevelTwoParseInput} } +\documentclass[fleqn]{article}%% TODO paper dimensions!? +\input{makedoc.cfg} %% shared formatting settings +% \ReadPackageInfos{bitelist} +\usepackage{bitelist} +\sloppy +\MDkeywords{macro programming, text filtering, substrings} +\begin{document} +\maketitle +\begin{MDabstract} +'bitelist.sty' provides commands for ``splitting" a token list +at the first occurrence of a contained token list +(i.e., for given $\sigma$, $\tau$, + return $\beta$ and shortest $\alpha$ s.t.\ $\tau=\alpha\sigma\beta$). + As opposed to other packages providing similar features, +\ (\textit{i})\enspace the method uses \TeX's mechanism of reading +delimited macro parameters; +\ (\textit{ii})\enspace the splitting macros work by pure expansion, +without assignments, provided the macro doing the search has been +defined before processing (e.g., a file); +\ (\textit{iii})\enspace instead of using one macro for a ``substring" +test and another one to replace the ``substring"---which includes +extracting corresponding prefix and suffix---, +the \emph{same} macro that detects the occurrence returns +the split; +\ (\textit{iv})\enspace +\httpref{ctan.org/pkg/e-tex}{$\varepsilon$\hbox{-}\TeX} is not required. +\ (And \LaTeX\ is not required.) + +This improves the author's \CtanPkgRef{fifinddo}{fifinddo.sty} +(v0.51---and may once be used there). An elaborated approach +(additionally to a simpler one) is provided that does not loose +outer braces of prefix/suffix. + +``Substring" detection and ``string" replacement are (implicitly) included +with respect to certain representations of characters by tokens. +Counting occurrences and ``global" replacement could be achieved +by applying the operation to earlier results, etc.---so +this approach seems to be ``fundamental" for a certain larger +set of list analysis tasks. + +The documentation aims to prove the correctness of the methods +with mathematical rigour. +\par\smallskip\noindent +\strong{Related packages:}\quad +\ctanpkgref{datatool}, \ctanpkgref{stringstrings}, \ctanpkgref{ted}, +\ctanpkgref{texapi}, \ctanpkgref{xstring} +\end{MDabstract} +\newpage +\tableofcontents + +\section{Task, Background Reasoning, and Usage} +\subsection{The Task Quite Precisely} +\label{sec:task} + +Perhaps I should not have written ``splitting" before, +see Section~\ref{sec:name} why I did so though. +Actually: + +At first we are dealing with token lists $\tau$ and $\sigma$ +without braces +(unless their category code has been changed appropriately) +that can be stored as macros without parameter or in token list registers. +We want to find out whether $\tau$ contains $\sigma$ (``as a subword") +in the sense that there are such token lists $\alpha$ and $\beta$ that +$\tau$ is composed as $\alpha\sigma\beta$, i.e., +\[\tau=\alpha\sigma\beta\] +and in this case +we want to get $\alpha$ and $\beta$ of this kind with +$\alpha$ being the \emph{shortest} possible. +I.e., if there are such $\gamma$ and $\delta$ that $\tau$ +is composed as $\gamma\sigma\delta$, $\alpha$ must be contained +as a ``prefix" in $\gamma$, +i.e., $\gamma$ is composed as $\alpha\eta$ for some token list $\eta$. +The token lists $\alpha$, $\beta$, $\gamma$, $\delta$, $\eta$, +$\sigma$, and $\tau$ are allowed to be empty throughout. + +The task will be extended for some braces in Section~\ref{sec:braces}. + +\subsection{Idea of Solution} + +\TeX's mechanism of expanding macros (\TeX book Chapter~20) +at least has a built-in mechanism to return such $\alpha$ and $\beta$ +\emph{provided} $\tau$ contains $\sigma$. Define +\[`\def<cmd>#1'\sigma`#2'\theta`{<replace-def>}'\] +where $\theta$ must be a token list (maybe of a single token) +that won't occur in $\tau$.\footnote{I am still following others in confusing + source code and tokens. I have better ideas, but must expand on them + elsewhere. Writing `&\def' rather indicates that it is source code, + then $\sigma$ etc. should be replaced by strings that are converted + into tokens $\sigma$ etc. + <cmd> sometimes is a \emph{string} starting with an escape character, + or it is an active character; but sometimes it rather is an ``active" + \emph{token} converted from such an escape string or an active character.} +This is a \strong{limitation} of the approach: +It works for sets of such $\tau$ only that do not contain +any of a small set of tokens or combinations of them. +('bitelist' will use `\BiteSep', `\BiteStop', and `\BiteCrit', + or any other three that can be chosen.) + +On the other hand, \TeX's \emph{category codes} +(\TeX book Chapter~7) can ensure this quite well. +E.g., we may assume that input ``letters" always have category code 11 +(or 12, or one of them), and for $\theta$ we can choose letters +with \emph{different} category codes such as 3. +Without such tricks, you may often assume that nobody will input +certain ``silly" commands such as `\BiteStop'. +(But it may become difficult when you use a package for + replacement macros for generating its own documentation \dots) + +With a <cmd> as defined above, \TeX\ will +\[\mbox{expand\quad} + `<cmd>'\tau\theta + \quad\mbox{to}\quad + <replace>,\] +where <replace> will be the result of replacing +\ (a)\enspace all occurrences of `#1' in <replace-def> by $\alpha$ as wanted and +\ (b)\enspace all occurrences of `#2' in <replace-def> by $\beta$ as wanted. +\ +I.e., <cmd> returns $\alpha$ as its first argument and $\beta$ as its second argument. +The reason is that <cmd>'s first parameter is delimited by $\sigma$ and the second one by +$\theta$ in the sense of The~\TeX book p.~203. +Our requirement to get the \emph{shortest} $\alpha$ for the composition of $\tau$ as +$\alpha\sigma\beta$ is met because \TeX\ indeed looks for the \emph{first} occurrence of +$\sigma$ at the right of <cmd>. + + +\subsection{When We Don't Know \dots} +When $\sigma$ does \emph{not} occur in $\tau$ and we present $\tau\theta$ to <cmd> as +before, \TeX\ will throw an error saying +``Use of <cmd> doesn't match its definition." +When the purpose is ``substring detection" only, without returning $\beta$, +many packages have solved the problem by issuing something like +\[`<cmd>'\tau\sigma\theta\] +Then (still provided $\theta$ does not occurr in $\tau$) +<cmd>'s second argument is empty \emph{exactly} if $\sigma$ occurs in $\tau$. +This method has, e.g., been employed in \LaTeX's internal &\in@ mechanism +(e.g., for dealing with package options) and by the \ctanpkgref{substr} package. +\ctanpkgref{datatool} has used the latter's substring test (for $\sigma$) +before calling a macro for replacing +($\sigma$ by another token list, perhaps thinking of character tokens). + +This way you get the wanted $\alpha$ as the first macro argument immediately indeed. +An obstacle for getting $\beta$ is that <cmd>'s \emph{second} argument now contains +an occurrence of $\sigma$ that is not an occurrence in $\tau$. +In \CtanPkgRef{fifinddo}{fifinddo.sty} I didn't have a better idea than using +another macro to remove the ``dummy text" from the second argument. +I considered it an advantage as compared with 'datatool' that +\emph{one} macro could do this for \emph{all} replacement jobs, +while 'datatool' uses \emph{two} macros with $\sigma$ as a delimiter +for each $\sigma$ to be replaced. + +But still, 'fifinddo' has used \emph{two} macros for each replacement, +the extra one being for presenting $\tau$ to <cmd>, using a job identifier. +This could be improved within 'fifinddo', but I could never afford +to take the time for this. + +\subsection{The Trick} +\label{sec:trick} + +The solution presented here is not very ingenious, +many students would have found it in an exercise for a math course. +My personal approach was looking at &\GetFileInfo from \LaTeX's +\ctanpkgref{doc} package. There they try to get \emph{two} occurrences +of a space token this way:\footnote{We are undoubling the hash marks + inside the definition text of + &\GetFileInfo.} +\[`\def\@tempb#1 #2 #3\relax#4\relax{%'\] +and &\@tempb is called as +\[`\@tempb'\tau`\relax? ? \relax\relax'\] +or with $\tau=<list>$ +\[`\@tempb<list>\relax? ? \relax\relax'\] +The final &\relax may not be removed, but for 'doc' it doesn't harm. +It harms for \emph{me} when I don't want to have a `\relax' in a `.log' file list. +`\empty' would be better, however \dots + +The idea is to use a \emph{three}-parameter macro for that \emph{single} occurrence +of $\sigma$. We introduce a +``dummy separator" $\zeta$ (or <sep>, `\BiteSep') +between $\tau$ and the ``dummy text" and a +``criterion" $\rho$ ($=<crit>$, `\BiteCrit') +for determining occurrence of $\sigma$ ($=<find>$) in $\tau$ ($=<list>$). +Neither $\zeta$ nor $\rho$ must occur in $\tau$. +We will have definitions about as +\[`\def<cmd>#1'\sigma`#2'\zeta`#3'\theta`{<replace-def>}'\] +or +\[`\def<cmd>#1<find>#2<sep>#3<stop>{<replace-def>}'\] +and $\tau$ will be presented with context +\[`<cmd>'\tau\zeta\sigma\rho\zeta\theta + \quad\mbox{or}\quad + <cmd><list><sep><find><crit><sep><stop> + \] +This ensures that <cmd> finds its parameter delimiters $\sigma$, $\zeta$, +and $\theta$, in this order. $\sigma$ occurs in $\tau$ exactly if the second +argument of <cmd> is $\rho$, and in this case the first occurrence +of the second parameter delimiter $\zeta$ delimits $\tau$. +Then <cmd>'s first argument is $\alpha$, and the second one is $\beta$, +as wanted. + +<cmd>'s \emph{third} parameter is delimited by the final $\theta$ (`\BiteStop'). +When $\sigma$ occurs in $\tau$, <cmd>'s third argument starts after the first +of the two $\zeta$, so it is $\sigma\rho\zeta$. +It is just ignored, this way <cmd> removes all the ``dummy" material +after $\tau$. When $\sigma$ does \emph{not} occur in $\tau$, +we ignore all of its arguments, and the macro that invoked <cmd> +must decide what to do next, e.g., keeping $\tau$ elsewhere +for presenting it to another parsing macro resembling <cmd>. + + +\subsection{Installing and Calling} +The file 'bitelist.sty' is provided ready, installation only requires +putting it somewhere where \TeX\ finds it +(which may need updating the filename data + base).\urlfoot{ukfaqref}{inst-wlcf} %% corr. 2011/02/08 + +Below the `\documentclass' line(s) and above `\begin{document}', +you load 'bitelist.sty' (as usually) by +\begin{verbatim} + \usepackage{bitelist} +\end{verbatim} +between the `\documentclass' line and `\begin{document}'; +or by +\begin{verbatim} + \RequirePackage{bitelist} +\end{verbatim} +within a package file, or above or without the `\documentclass' line. +Moreover, the package should work \emph{without} \LaTeX\ and may be +loaded by +\begin{verbatim} + \input bitelist.sty +\end{verbatim} +Actually, using the package for macro programming requires understanding +of pp.~20f.\ of The~\TeX book. On the other hand, the package may be loaded +(without the user noticing it) automatically by a different package that +uses programming tools from the present package. + +\section{Implementation Part I} +\subsection{Package File Header (Legalize)} +\input{bitelist.doc} + +\section{Examples/Tests} +\label{sec:demo} +You should find a separate file `bitedemo.tex' +with examples. It may be run separately with `tex' +(Plain \TeX)---demonstrating that 'bitelist' is ``\strong{generic}", +then finish by entering `\bye'. +With ```latex bitedemo.tex'", end the job by entering `\stop'. +\strong{Expandability} is demonstrated by the `\BiteFind' commands +running with `\typeout'. +\medskip +\noNiceVerb +\hrule +\verbatiminput{bitedemo.tex} +\hrule +\useNiceVerb + +\section{The Package's Name} +\label{sec:name} + +This package deals with \TeX's expansion mechanism. +In Knuth's metaphor, this is \TeX's mouth. +I am not entirely sure, I have never understood it, +or I have understood it only for a few days or hours. +However, the package deals with ``Lists in \TeX's Mouth" +as described in Alan Jeffrey's 1990 +\tugbartref{tb11-2/tb28jeffrey}{\acro{TUG}boat paper} +(Volume~11, No.~2, pp.~237--245).\foothttpurlref{% + tug.org/TUGboat/tb11-2/tb28jeffrey.pdf} + +``Splitting" in title and abstract is an attempt to describe +the package brief{}ly without speaking Mathematicalese. +It roughly refers to certain \Wikienref{string functions} +in various programming languages\foothttpurlref{% + en.wikipedia.org/wiki/String\string_functions\string#split} +with ```split'" in their name. +However, there strings are splitted at separators such as commas. +I am thinking here that a comma is a certain string ```,'", +and this can be generalized to ``splitting" at any substring. +With \TeX, the analogues are (a)~the token with the character code +of the comma and category code 12, or the token list consisting of this +single token,---and (b)~other lists of tokens~\dots + +Anyway, calling a triple $(\alpha,\sigma,\beta)$ of token lists +such that $\tau=\alpha\sigma\beta$ a ``split" of $\tau$ +is not necessarily a bad idea. +Moreover, the blank space example (Section~\ref{sec:space}) +is very close to the original idea of splitting at separators, +a blank space is about as common as a separator as the comma is. + +Finally, according to \urlhttpref{en.wiktionary.org}, +the Proto-Indo-European origin of +\httpref{en.wiktionary.org/wiki/bite}{``to bite"} +just means ``to split."\foothttpurlref{en.wiktionary.org/wiki/bite\string#Etymology} +So in \TeX's mouth, splitting and biting is the same. + + +\end{document} + +VERSION HISTORY + +2012/03/26 for v0.1 started +2012/03/27 pages of motivation etc. +2012/03/28 abstract: "mathematical rigour"; + \section{Implementation}, \section{Task, ...}; + \newpage, \LaTeX\; reference to sec:braces; + "Examples/Tests" halfway; "Package's"; + LaTeX not required, ... +2012/03/29 "Implementation Part I", label sec:demo; + keywords etc. diff --git a/Master/texmf-dist/source/generic/bitelist/srcfiles.tex b/Master/texmf-dist/source/generic/bitelist/srcfiles.tex new file mode 100644 index 00000000000..78ff6be62ae --- /dev/null +++ b/Master/texmf-dist/source/generic/bitelist/srcfiles.tex @@ -0,0 +1,15 @@ +\ProvidesFile{srcfiles.tex}[2012/03/29 file infos -> SrcFILEs.txt] +\RequirePackage{nicefilelist} +\MFfieldtemplate{f-base}{xxbitelist} +\RequirePackage{myfilist} +\EmptyFileList %%% [readprov.sty,myfilist.sty] +%% packages: +\ReadPackageInfos{bitelist} +%% documentation, demo: +\ReadFileInfos{bitelist,bitedemo} +%% documentation settings and auxiliaries: +%\ReadPackageInfos{fifinddo,makedoc,niceverb} +%\ReadFileInfos{makedoc.cfg,mdoccorr.cfg} +\ReadFileInfos{srcfiles} +\ListInfos[SrcFILEs.txt] + diff --git a/Master/texmf-dist/tex/generic/bitelist/bitedemo.tex b/Master/texmf-dist/tex/generic/bitelist/bitedemo.tex new file mode 100644 index 00000000000..6c4f9ed1038 --- /dev/null +++ b/Master/texmf-dist/tex/generic/bitelist/bitedemo.tex @@ -0,0 +1,43 @@ +\def\filename{bitedemo.tex} \def\filedate{2012/03/29} +\def\fileinfo{demonstrating/testing bitelist.sty (UL)} +\expandafter\ifx\csname ProvidesPackage\endcsname\relax \else + \edef\bitedemolatexstart{% + \noexpand\ProvidesFile{\filename}% + [\filedate\space\fileinfo]% + \noexpand\RequirePackage{bitelist}} + \expandafter\bitedemolatexstart +\fi +\ifx\BiteMakeIf\undefined \input bitelist.sty \fi +\ifx\typeout\undefined + \def\typeout{\immediate\write17} + \newlinechar`^^J +\fi +\def\splitted #1#2#3{>>#1|#2|#3<<} +\def\unsplitted#1{>>#1<<} +\def\spacetocomma#1#2{>>#1,#2<<} +\BiteMakeIfOnly {\def}{\occursyesno}{no} +\BiteMakeIf {\def}{\noshowsplit}{no} +\BiteMakeIfBraces{\def}{\noShowSplit}{no} +\typeout{^^J + \BiteFindByIn {no}{\occursyesno} + {bonobo}{YES!}{NO!} + \BiteFindByIn {no}{\noshowsplit} + {bonobo}{bonobo}{\splitted}{\unsplitted} + \BiteFindByInIn{no}{\noshowsplit} + {bonobo}{\splitted}{\unsplitted} + ^^J + \BiteFindByIn {no}{\occursyesno} + {bobobo}{YES!}{NO!} + \BiteFindByIn {no}{\noshowsplit} + {bobobo}{bobobo}{\splitted}{\unsplitted} + \BiteFindByInIn{no}{\noshowsplit} + {bobobo}{\splitted}{\unsplitted} + ^^J + \BiteFindByInBraces{no}{\noShowSplit} + {{bo}no{bo}}{\splitted}{\unsplitted} + ^^J + \BiteGetNextWord{bo no bo}{\spacetocomma}{\unsplitted} + \BiteGetNextWord{bo nobo} {\spacetocomma}{\unsplitted} + \BiteGetNextWord{bonobo} {\spacetocomma}{\unsplitted} + ^^J} +\endinput diff --git a/Master/texmf-dist/tex/generic/bitelist/bitelist.sty b/Master/texmf-dist/tex/generic/bitelist/bitelist.sty new file mode 100644 index 00000000000..219008d6938 --- /dev/null +++ b/Master/texmf-dist/tex/generic/bitelist/bitelist.sty @@ -0,0 +1,240 @@ +\def\filename{bitelist} \def\filedate{2012/03/29} +\def\fileversion{v0.1} \def\fileinfo{split lists in TeX's mouth (UL)} +%% Copyright (C) 2012 Uwe Lueck, +%% http://www.contact-ednotes.sty.de.vu +%% -- author-maintained in the sense of LPPL below -- +%% +%% This file can be redistributed and/or modified under +%% the terms of the LaTeX Project Public License; either +%% version 1.3c of the License, or any later version. +%% The latest version of this license is in +%% http://www.latex-project.org/lppl.txt +%% There is NO WARRANTY - this rather is somewhat experimental. +%% +%% Please report bugs, problems, and suggestions via +%% +%% http://www.contact-ednotes.sty.de.vu +%% +%% === Proceeding without \LaTeX === +%% Some tricks from Bernd Raichle's \CtanPkgRef{ngerman}{ngerman.sty}---I +%% need \LaTeX's `\Provides'\-`Package' for \ctanpkgref{fileinfo}, +%% my package version tools. With 'readprov.sty', it issues `\endinput', +%% close conditional before: +\begingroup\expandafter\expandafter\expandafter\endgroup +\expandafter\ifx\csname ProvidesPackage\endcsname\relax \else + \edef\fileinfo{\noexpand\ProvidesPackage{\filename}% + [\filedate\space \fileversion\space \fileinfo]} + \expandafter\fileinfo +\fi +\chardef\atcode=\catcode`\@ +\catcode`\@=11 % \makeatletter +%% Providing \LaTeX's `\@firstoftwo' and `\@secondoftwo': +\long\def\@firstoftwo #1#2{#1} +\long\def\@secondoftwo#1#2{#2} +%% +%% === Basic Parsing (No Braces) === +%% +%% |\BiteMake{<def>}{<cmd>}{<find>}| provides the parameter text +%% (\TeX book p.~203) for defining (by <def>) a macro <cmd> that will +%% search for <find>: +\def\BiteMake#1#2#3{#1#2##1#3##2\BiteSep##3\BiteStop} +%% With |\BiteFindByIn{<find>}{<cmd>}{<list>}|, +%% you can use a <cmd> (perhaps defined by &\BiteMake) +%% in order to search <find> in <list>. +%% This is expandable as promised: +\def\BiteFindByIn#1#2#3{% + #2#3\BiteSep#1\BiteCrit\BiteSep\BiteStop} +%% Preparing a possible &\edef as <def>: +\let\BiteSep\relax \let\BiteStop\relax +%% And this is important in any case for correct testing of +%% occurrence:\footnote{The idea for the ``funny `Q'" +%% is from the \ctanpkgref{ifmtarg} package.} +\catcode`\Q=7 \let\BiteCrit=Q \catcode`\Q=11 +%% Perhaps you could increase safety of tests by using something similar to the funny `Q' +%% for &\BiteSep and &\BiteStop. +%% %% 2012/03/28: +%% However, this would additionally require reimplementation of +%% the macros for keeping braces (Section~\ref{sec:braces}) using `\edef'. +%% % It appears to me, however, that expandable tests like this one +%% % never are perfectly safe; you only can say that it is safe with a +%% % source meeting certain conditions. \ctanpkgref{fifinddo} originally +%% % was made for ``plain text," to be read from files without assigning +%% % \TeX's special category codes. \emph{Here} we assume that the source +%% % (text in \cs{Provides.\empty..} arguments) will never contain such a +%% % ``funny `Q'". +%% +%% === Simple Conditionals === +%% By |\BiteMakeIfOnly{<def>}{<cmd>}{<find>}|, you can make a command <cmd> +%% that with +%% \[|\BiteFindByIn{<find>}{<cmd>}{<list>}{<yes>}{<no>}|\] +%% chooses <yes> if <find> occurs in <list> and <no> otherwise. +\def\BiteMakeIfOnly#1#2#3{\BiteMake{#1}{#2}{#3}{\BiteIfCrit{##2}}} +%% |\BiteIfCrit{<suffix>}{<yes>}{<no>}| +%% is the basic test for occurrence of <find> in <list>: +\def\BiteIfCrit#1{\ifx\BiteCrit#1\expandafter\@secondoftwo +%% If <cmd>'s second argument---same as &\BiteIfCrit's first argument---is +%% empty, &\BiteCrit is compared with &\expandafter, so <yes> is chosen. +%% That is correct, it happens when <find> is a suffix of <list>. + \else \expandafter\@firstoftwo \fi } +%% +%% === Passing Results Completely---No Braces === +%% So the previous `\BiteMakeIfOnly' generates pure tests on occurrence, +%% giving away information about prefix and suffix. +%% It may be considered a didactical step fostering understanding of the following. +%% % \medskip\noindent +%% % ** Generic Fundamental Splitter---No Braces ** +%% %% Wrong: +%% % With the above `\BiteMakeIfOnly', the user can choose on her own +%% % information about the composition of <list> to use. +%% % Perhaps it is not easy to understand. +%% % `\BiteMakeIfOnlySplit{<def>}{<cmd>}{<find>}' by contrast, +%% % should satisfy ``all needs" by providing \emph{all} the information +%% % about splitting a <list>. It may also be a template for using +%% % `\BiteMakeIfOnly'. +%% When, by contrast \[|\BiteMakeIf{<def>}{<cmd>}{<find>}|\] +%% has been issued, a later +%% $$|\BiteFindByIn{<find>}{<cmd>}{<list>}{<list>}{<yes>}{<no>}|\eqno(*)$$ +%% will expand to +%% \[`<yes>{<prefix>}{<find>}{<suffix>}'\] +%% if <list> is composed as <prefix><find><suffix> +%% and <prefix> is the shortest $\alpha$ such that there is some $\beta$ +%% with $<list>=\alpha<find>\beta$. Otherwise, $(*)$ will expand to +%% \[`<no>{<list>}'\] +%% This gives all the information available. +%% For actual applications, it may be too much, and the macro programmer +%% may do something in between of `\BiteMakeIfOnly' and `\BiteMakeIf': +\def\BiteMakeIf#1#2#3{% + \BiteMake{#1}{#2}{#3}##4##5##6{% +%% In the replacement text, we first do the same as with `\BiteMakeIfOnly': + \BiteIfCrit{##2}% +%% What follows is new. <cmd>'s third argument is ignored. +%% The fourth keeps the original <list>. +%% <yes> is <cmd>'s fifth and <no> is its sixth argument. + {##5{##1}{#3}{##2}}% %% if #3 in ##4 + {##6{##4}}% %% otherwise + }% +} +%% In $(*)$, <list> has been doubled. That was no mistake. +%% It is due to a shortcoming of `\BiteFindByIn'. +%% With +%% \[|\BiteFindByInIn{<find>}{<cmd>}{<list>}{<yes>}{<no>}|\] +%% you get the same result as with $(*)$: +\def\BiteFindByInIn#1#2#3{\BiteFindByIn{#1}{#2}{#3}{#3}} +%% TODO not sure about command names yet +%% +%% == Example Applications == +%% === Splitting at Space === +%% \label{sec:space} +%% This work actually arose from modifying `\GetFileInfo' +%% as provided by \LaTeX's \ctanpkgref{doc} package +%% so that it would deal reasonably with ``incomplete" file info---for +%% the \ctanpkgref{nicefilelist} package. +%% `\GetFileInfo' works best when the file info contains +%% at least \emph{two} blank spaces. But how many are there indeed?---And +%% I wanted to do it \emph{expandably:} while `\GetFileInfo' issues +%% \emph{definitions} of `\filedate', `\fileversion', and `\fileinfo', +%% date, version, and info should be passed as \emph{macro arguments}. +%% \medbreak\noindent +%% |\BiteIfSpace| tries splitting at the next blank space passes results: +\BiteMake{\def}{\BiteIfSpace}{ }#4#5#6{% + \BiteIfCrit{#2}{#5{#1}{#2}}{#6{#4}}} +%% The difference to the `\BiteMakeIf' construction is that we do not +%% pass <find>, the space---it's not essential. +%% (TODO names may change ...) +%% +%% Now \[|\BiteFindByInIn{ }{\BiteIfSpace}{<list>}{<yes>}{<no>}|\] +%% will pass prefix/suffix to <yes> or <list> to <no>. +%% If this is needed frequently, here is a shorthand +%% |\BiteGetNextWord{<list>}{<yes>}{<no>}|: +\def\BiteGetNextWord{\BiteFindByInIn{ }\BiteIfSpace} +%% See a test in `bitedemo.tex' (Section~\ref{sec:demo}). +%% +%% === Splitting at Comma === +%% ... left as an exercise to the reader ... +%% +%% == Keeping Braces: Reasoning == +%% \label{sec:braces} +%% Now we want to generalize task (Section~\ref{sec:task}) +%% and solution (Section~\ref{sec:trick}) for the case that +%% $\tau=<list>$ has (balanced) braces +%% (with category codes for argument delimiters), +%% while $\sigma=<find>$ still has not (does not work with our method). +%% So with $\tau=\alpha\sigma\beta$, +%% $\alpha$ (``prefix") or $\beta$ (``suffix") or both +%% may contain braces. But we consider another restriction: +%% braces must be balanced in $\alpha$ and in $\beta$, +%% we don't try parsing inside braces +%% (as opposed to the search for asterisks in Appendix~D +%% of The~\TeX book). +%% +%% According to \TeX book p.~204, when a macro <cmd> finds an argument +%% formed as `{<tokens>}', in <cmd>'s replacement text only <tokens> +%% is used, i.e., outer braces are removed. +%% So when $\alpha=`{<tokens>}'$, a parser <cmd> as defined by our +%% methods above will return <tokens> instead of `{<tokens>}'---likewise +%% for $\beta$. We are now trying to \emph{keep} outer braces in prefix/suffix +%% by a more elaborate method. +%% +%% The idea is to present $\tau=<list>$ with context\footnote{Perhaps +%% I am confusing `&\empty' and the token list containing just `&\empty' here?} +%% \[`<cmd>\empty<list><stop><sep><find><crit><sep><stop>'\] +%% or in the notation of Section~\ref{sec:trick} +%% \[`<cmd>\empty'\tau\theta\zeta\sigma\rho\zeta\theta\] +%% Then, if <find> occurs in <list>, we must remove the `\empty' +%% from the prefix that we get with the earlier method (easy) +%% and <stop> from the suffix (tricky, similar problem recurs). +%% Using old $\theta$ for a new purpose works here because +%% <cmd> will look for $\theta$ only when it has found $\zeta$ before. +%% +%% Mere testing for occurrence is not affected. +%% \[`\BiteMakeIfOnly' \quad \mbox{and} \quad `\BiteFindByIn'\] +%% still can be used. +%% We provide an improved version of +%% \[`\BiteMakeIf' \quad (`\BiteMakeIfBraces')\] and of +%% \[`\BiteFindInIn' \quad (`\BiteFindInBraces').\] +%% +%% == Implementation Part II == +%% === Keeping Braces === +%% \[|\BiteFindByInBraces{<find>}{<cmd>}{<list>}{<yes>}{<no>}|\] +%% varies `\BiteFindByInIn' according to the previous: +\def\BiteFindByInBraces#1#2#3{% + #2\empty#3\BiteStop\BiteSep#1\BiteCrit\BiteSep\BiteStop{#3}} +%% Such a <cmd> can be made by |\BiteMakeIfBraces{<def>}{<cmd>}{<find>}|: +\def\BiteMakeIfBraces#1#2#3{% + \BiteMake{#1}{#2}{#3}##4##5##6{% + \BiteIfCrit{##2}% +%% <no> works as before. For <yes>, first the `\empty' in the prefix +%% is expanded for vanishing. +%% `\BiteTidyI' and `\BiteTidyII' continue tidying. + {\expandafter \BiteTidyI %% if #3 in ##4 + \expandafter{##1}% %% prefix +%% Another `\empty' avoids that removal of `\BiteStop' in suffix +%% by `\BiteTideII' removes outer braces: + {\BiteTidyII\empty##2}% %% suffix + {#3}% %% find + {##5}}% %% yes + {##6{##4}}% %% otherwise + }% +} +%% |\BiteTidyI{<prefix>}{<suffix>}| \ first expands `\BiteTidyII' +%% for removing `\BiteStop' in <suffix>. +%% `\empty' from `\BiteFindByInBraces' remains and is expanded next +%% for vanishing. Finally, `\BiteTidied' reorders arguments +%% for operation of <yes>: +\def\BiteTidyI#1#2{% + \expandafter\expandafter\expandafter \BiteTidied + \expandafter\expandafter\expandafter {#2}{#1}} +\def\BiteTidyII#1\BiteStop{#1} +\def\BiteTidied#1#2#3#4{#4{#2}{#3}{#1}} +%% +%% === Leaving the Package File === +\catcode`\@=\atcode +\endinput +%% +%% === VERSION HISTORY === + +v0.1 2012/03/26 started + 2012/03/27 continued, restructured + 2012/03/28 continued, separate sections for "Mere Occurrence" + vs. ...; keeping braces, \BiteIfCrit + 2012/03/29 proceeding without LaTeX corrected, restructured diff --git a/Master/tlpkg/bin/tlpkg-ctan-check b/Master/tlpkg/bin/tlpkg-ctan-check index a4f063ba2c2..c286111ce6d 100755 --- a/Master/tlpkg/bin/tlpkg-ctan-check +++ b/Master/tlpkg/bin/tlpkg-ctan-check @@ -63,7 +63,7 @@ my @TLP_working = qw( bibleref-parse biblist bibtex bibtopic bibtopicprefix bibexport bibunits - bidi bigfoot bigints binomexp biocon bizcard + bidi bigfoot bigints binomexp biocon bitelist bizcard blacklettert1 blindtext blkarray block blockdraw_mp bloques blowup bodegraph boisik bold-extra boites boldtensors bondgraph bookest bookhands booklet diff --git a/Master/tlpkg/tlpsrc/bitelist.tlpsrc b/Master/tlpkg/tlpsrc/bitelist.tlpsrc new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/Master/tlpkg/tlpsrc/bitelist.tlpsrc diff --git a/Master/tlpkg/tlpsrc/collection-genericextra.tlpsrc b/Master/tlpkg/tlpsrc/collection-genericextra.tlpsrc index 40bb73995a5..6b96c6949a8 100644 --- a/Master/tlpkg/tlpsrc/collection-genericextra.tlpsrc +++ b/Master/tlpkg/tlpsrc/collection-genericextra.tlpsrc @@ -5,6 +5,7 @@ longdesc TeX and LaTeX. depend abbr depend abstyles depend barr +depend bitelist depend borceux depend c-pascal depend chronosys |