summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2009-02-15 00:43:17 +0000
committerKarl Berry <karl@freefriends.org>2009-02-15 00:43:17 +0000
commit65f1bea00b6756c4051bd992581aa4b97b84426e (patch)
tree348a56473f5c4ef0b601d1d9574ac93f5699a119
parent6ffb78835e54834c65b3bd1c35e3ad939b61c5d9 (diff)
xstring 1.5a (12feb09)
git-svn-id: svn://tug.org/texlive/trunk@12159 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/generic/xstring/README12
-rw-r--r--Master/texmf-dist/doc/generic/xstring/test_etex.pdfbin56880 -> 56861 bytes
-rw-r--r--Master/texmf-dist/doc/generic/xstring/test_etex.tex2
-rw-r--r--Master/texmf-dist/doc/generic/xstring/test_latex.pdfbin66695 -> 66675 bytes
-rw-r--r--Master/texmf-dist/doc/generic/xstring/test_latex.tex2
-rw-r--r--Master/texmf-dist/doc/generic/xstring/xstring_doc_en.pdfbin233713 -> 309902 bytes
-rw-r--r--Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex1879
-rw-r--r--Master/texmf-dist/doc/generic/xstring/xstring_doc_fr.pdfbin257031 -> 339378 bytes
-rw-r--r--Master/texmf-dist/doc/generic/xstring/xstring_doc_fr.tex1956
-rw-r--r--Master/texmf-dist/tex/generic/xstring/xstring.tex259
10 files changed, 2474 insertions, 1636 deletions
diff --git a/Master/texmf-dist/doc/generic/xstring/README b/Master/texmf-dist/doc/generic/xstring/README
index 49f0f106950..87a793b8459 100644
--- a/Master/texmf-dist/doc/generic/xstring/README
+++ b/Master/texmf-dist/doc/generic/xstring/README
@@ -1,8 +1,8 @@
_________________
xstring package
- v 1.5
- 2008/12/31
+ v 1.5a
+ 2008/02/09
_________________
------------------------------------------------------------------------------
@@ -13,7 +13,7 @@
This package provides macros manipulating strings for programming use.
A "string" is made of TeX code, i.e. chars (catcodes 10, 11 and 12), controls
sequences, groups between braces, tokens with other catcodes, excepted catcodes
-6 and 14 (usually tokens # and %).
+6 and 14 (usually chars # and %).
Main features are:
* tests:
@@ -31,6 +31,7 @@ Main features are:
- find a group with its identifier, etc.
* substitution of all (or the n first) occurrences of a substring
for an other substring;
+ * n times expansion of the tokens of a string;
* calculation of numbers:
- length of a string;
- position of the nth occurrence of a substring;
@@ -61,10 +62,10 @@ répertoire tex/.
------------------------------------------------------------------------------
Cette extension regroupe un ensemble de macros manipulant des chaînes à des
fins de programmation.
-Une "chaine" est du code TeX, c'est-à-dire des caractères (catcodes 10, 11
+Une "chaîne" est du code TeX, c'est-à-dire des caractères (catcodes 10, 11
et 12), des séquences de contrôle, des groupes entre accolades et des lexèmes
ayant d'autres catcodes excepté les catcodes 6 et 14 (habituellement les
-lexèmes # et %).
+caractères # et %).
Les principales fonctionnalités sont :
* des tests :
@@ -82,6 +83,7 @@ Les principales fonctionnalités sont :
- recherche d'un groupe avec son identifiant.
* le remplacement de toutes ou des n premières occurrences d'une
sous-chaîne par une autre sous-chaîne;
+ * n-développement des tokens d'une chaîne;
* des calculs de nombres :
- longueur d'une chaîne;
- position de la la nieme occurrence d'une sous-chaîne;
diff --git a/Master/texmf-dist/doc/generic/xstring/test_etex.pdf b/Master/texmf-dist/doc/generic/xstring/test_etex.pdf
index 91ac4ada3dd..a307c0ef37a 100644
--- a/Master/texmf-dist/doc/generic/xstring/test_etex.pdf
+++ b/Master/texmf-dist/doc/generic/xstring/test_etex.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/generic/xstring/test_etex.tex b/Master/texmf-dist/doc/generic/xstring/test_etex.tex
index 74e389db727..5ad98f0b7fb 100644
--- a/Master/texmf-dist/doc/generic/xstring/test_etex.tex
+++ b/Master/texmf-dist/doc/generic/xstring/test_etex.tex
@@ -8,7 +8,7 @@
% Ceci est test_latex.tex, le fichier de test de xstring à compiler avec LaTeX
% This is test_latex.tex, the test file of xstring to compile with LaTeX
%
-% Christian Tellechea 2008
+% Christian Tellechea 2009
%
% email : unbonpetit@gmail.com
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/Master/texmf-dist/doc/generic/xstring/test_latex.pdf b/Master/texmf-dist/doc/generic/xstring/test_latex.pdf
index c35dbe1f3c9..0f92ee2c5cf 100644
--- a/Master/texmf-dist/doc/generic/xstring/test_latex.pdf
+++ b/Master/texmf-dist/doc/generic/xstring/test_latex.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/generic/xstring/test_latex.tex b/Master/texmf-dist/doc/generic/xstring/test_latex.tex
index e7f698e99ce..b79d23ec17e 100644
--- a/Master/texmf-dist/doc/generic/xstring/test_latex.tex
+++ b/Master/texmf-dist/doc/generic/xstring/test_latex.tex
@@ -1,7 +1,7 @@
% Ceci est test_latex.tex, le fichier de test de xstring à compiler avec LaTeX
% This is test_latex.tex, the test file of xstring to compile with LaTeX
%
-% Christian Tellechea 2008
+% Christian Tellechea 2009
%
% email : unbonpetit@gmail.com
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.pdf b/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.pdf
index 6406ead0bb5..e10b94afdd5 100644
--- a/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.pdf
+++ b/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex b/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex
index 2c09848b6e8..c0c292dadd8 100644
--- a/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex
+++ b/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex
@@ -19,22 +19,67 @@
\usepackage[T1]{fontenc}
\usepackage[dvips,colorlinks=true,hyperfootnotes=false,citecolor=black,filecolor=black,linkcolor=blue,urlcolor=blue,bookmarks=false,pdfauthor={Christian Tellechea},pdftitle={xstring},pdfsubject={package for strings of tokens},pdfkeywords={xstring,latex,string},pdfcreator={LaTeX}]{hyperref}
\usepackage[a4paper,dvips,margin=1.9cm]{geometry}
-\usepackage{amsmath,amssymb}
-\usepackage{textcomp}
-\usepackage{moreverb}
+\usepackage{amsmath,amssymb,amsfonts,textcomp}
+\usepackage{color}
\usepackage{lmodern}
\usepackage{eurosym}
\usepackage{xspace}
+\usepackage{listings}
\usepackage{xstring}
-\usepackage[french,english]{babel}
+\usepackage[french]{babel}
\makeatletter
-\newcommand*\exemple{\@ifstar{\let\frontiere\textbar\@xs@MakeVerb}{\let\frontiere\@empty\@xs@MakeVerb}}
-\def\@xs@afterreadverb#1{%
- \normalexpandarg
- \tokenize\cs@resultat{#1}%
- \fullexpandarg
- \leavevmode\hbox to0.7\linewidth{\hfil\tt#1}\quad\frontiere\cs@resultat\frontiere\hfil\par}
+\definecolor{@xs@bckgcolor}{rgb}{1,1,0.875}
+\definecolor{@xs@keywordsxstring}{rgb}{0.7,0,0}
+\definecolor{@xs@keywordslatex}{rgb}{0,0,1}
+\definecolor{@xs@arguments}{rgb}{0,0,0}
+\definecolor{@xs@comments}{rgb}{0.5,0.5,0.5}
+\definecolor{violet}{rgb}{0.66,0,0.66}
+\lstset{%
+ language=[AlLaTeX]TeX,%
+ morekeywords={numexpr,detokenize},%
+ float=hbp,%
+ basicstyle=\small\ttfamily,%
+ identifierstyle=\color{@xs@arguments},%
+ keywordstyle=\color{@xs@keywordslatex},%
+ commentstyle=\itshape\color{@xs@comments},%
+ columns=fixed,%
+ tabsize=4,%
+ frame=single,%
+ extendedchars=true,%
+ showspaces=false,%
+ showstringspaces=false,%
+ numbers=left,%
+ numberstyle=\tiny\ttfamily,%
+ breaklines=true,%
+ breakindent=3em,%
+ backgroundcolor=\color{@xs@bckgcolor},%
+ breakautoindent=true,%
+ captionpos=t,%
+ xleftmargin=1em,%
+ xrightmargin=1em,%
+ lineskip=0pt,%
+ numbersep=1em,%
+ classoffset=1,%
+ morekeywords={% les macros et commandes de xstring
+ IfSubStr,IfSubStrBefore,IfSubStrBehind,%
+ IfBeginWith,IfEndWith,%
+ IfInteger,IfDecimal,integerpart,decimalpart,%
+ IfStrEq,IfEq,IfStrEqCase,IfEqCase,%
+ StrBefore,StrBehind,StrBetween,%
+ StrSubstitute,StrDel,%
+ StrGobbleLeft,StrGobbleRight,StrRight,StrLeft,StrMid,StrChar,%
+ StrSplit,%
+ StrLen,StrCount,StrPosition,StrCompare,%
+ StrFindGroup,groupID,verbtocs,tokenize,scancs,StrExpand,StrRemoveBraces,%
+ exploregroups,noexploregroups,saveexploremode,restoreexploremode,%
+ comparenormal,comparestrict,savecomparemode,restorecomparemode,%
+ expandarg,noexpandarg,normalexpandarg,fullexpandarg,saveexpandmode,restoreexpandmode,%
+ expandingroups,noexpandingroups,%
+ setverbdelim},%
+ keywordstyle=\color{@xs@keywordsxstring},%
+ classoffset=0}
\makeatother
+
\newcommand\guill[1]{"#1"}
\newcommand\argu[1]{$\langle$\textit{#1}$\rangle$}
\newcommand\ARGU[1]{\texttt{\{}\argu{#1}\texttt{\}}}
@@ -55,8 +100,13 @@
\newcommand\US{syntax unit\xspace}
\newcommand\USs{syntax units\xspace}
\newcommand\Xstring{\textsf{xstring}\xspace}
+\newcommand\styleexemple{\small\vskip4pt}
+\newcommand\styleexercice{\footnotesize}
+\newcommand\verbinline{\lstinline[basicstyle=\normalsize\ttfamily]}
+\newcommand\colorise{\color{violet}}
\begin{document}
+\def:{\string:}
\setlength{\parindent}{0pt}
\begin{titlepage}
\null\par\vfill
@@ -80,7 +130,8 @@
\begin{minipage}{0.85\linewidth}
\noindent
\hfill\textbf{\textit{Abstract}}\hfill{}\medskip\par
- This package which requires $\varepsilon$-\TeX{}, provides macros manipulating strings of tokens. For a basic use, tokens can be alphanumeric chars, but the macros can also be useful for manipulating tokens, i.e. \TeX{} code. Main features are:
+ This package which requires $\varepsilon$-\TeX{}, provides macros manipulating strings of tokens. For a basic use, tokens can be alphanumeric chars, but the macros can also be useful for manipulating tokens, i.e. \TeX{} code. Main features are:\smallskip
+
\parindent1.5em
\begin{itemize}
\item[$\triangleright$] tests:
@@ -122,7 +173,7 @@ This manual is a translation of the french manual. I apologize for my poor engli
\subsection{Description}
This extension\footnote{This extension does not require \LaTeX{} and can be compiled with Plain $\varepsilon$-\TeX{}.} provides macros and tests operating on strings of tokens, i.e. \TeX{} code, as other programmation languages have. They provides the usual strings operations, such as: test if a string contains another, begins or ends with another, extractions of strings, calculation of the position of a substring, of the number of occurrences, etc.\medskip
-\Xstring reads the arguments of the macros \US by \US\footnote{In the \TeX{} code, a \US is a control sequence, a group between brace or a single char. See also page~\pageref{developpementarguments}.} : when \USs are \guill{simple} chars (catcode 10, 11 and 12), \Xstring logically read the argument char by char. \Xstring can also be used for programming purpose, including in arguments other tokens such as control sequences, braces and tokens with other catcodes. See chapter on reading mode and arguments expansion (page~\pageref{developpementarguments}), the command \verb|\verbtocs| (page~\pageref{verbtocs}) and the command \verb|\scancs| (page~\pageref{scancs}).\medskip
+\Xstring reads the arguments of the macros \US by \US\footnote{In the \TeX{} code, a \US is a control sequence, a group between brace or a single char. See also page~\pageref{developpementarguments}.} : when \USs are \guill{simple} chars (catcode 10, 11 and 12), \Xstring logically read the argument char by char. \Xstring can also be used for programming purpose, including in arguments other tokens such as control sequences, braces and tokens with other catcodes. See chapter on reading mode and arguments expansion (page~\pageref{developpementarguments}), the command \verbinline|\verbtocs| (page~\pageref{verbtocs}) and the command \verbinline|\scancs| (page~\pageref{scancs}).\medskip
As the arguments may contain any token, advanced users could have problems with catcodes leading to unexpected behaviours. These behaviours can be controlled: read page~\pageref{macrosetoilees}.\medskip
@@ -134,9 +185,6 @@ I decided to write this package of macros because I have never really found tool
Thus, writing a coherent set of macros forces more discipline and leads to necessary improvements, which took most of the time I spent writing this package. This package is my first one as I recently discoverd \LaTeX{}\footnote{In november 2007, I will be a noob for a long time\ldots}, so my main motivation was to make progress in programming with \TeX, and to tackle its specific methods.
\section{The macros}
-\textbf{Important}: in the following, a \argu{number} can be an integer written with numeric chars, a counter, or the result of an arithmetic operation made with the command \verb|\numexpr|.
-
-\subsection{Presentation of macros}
For a better understanding, let's see first the macros with the simpler arguments possible. No special catcode, no exotic token, no control sequence neither: only alphanumeric chars will be contained in the arguments.\medskip
In the following chapters, all the macros will be presented this plan:
@@ -145,11 +193,15 @@ In the following chapters, all the macros will be presented this plan:
\item a short description of the operation;
\item the operation under special conditions. For each conditions considered, the operation described has priority on that (those) below;
\item finally, several examples\footnote{For much more examples, see the test file.} are given. I tried to find them most easily comprehensible and most representative of the situations met in normal use. If a doubt is possible with spaces in the result, this one will be delimited by \guill{|}, given that an empty string is represented by \guill{||}.
-\end{itemize}
+\end{itemize}\smallskip
+
+\textbf{Important}: in the following, a \argu{number} can be an integer written with numeric chars, a counter, or the result of an arithmetic operation made with the command \verbinline|\numexpr|.\smallskip
+
+In the following, macros of \Xstring are displayed in {\makeatletter\color{@xs@keywordsxstring}red}.
\subsection{The tests}
\subsubsection{\ttfamily\textbackslash IfSubStr}
-\verb|\IfSubStr|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\ARGU{true}\ARGU{false}
+\verbinline|\IfSubStr|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\ARGU{true}\ARGU{false}
\smallskip
The value of the optional argument \argu{number} is 1 by default.\par\smallskip
@@ -161,16 +213,30 @@ Tests if \argu{string} contains at least \argu{number} times \argu{stringA} and
\item If \argu{string} or \argu{stringA} is empty, runs \argu{false}.
\end{Conditions}
-\exemple|\IfSubStr{xstring}{tri}{true}{false}|
-\exemple|\IfSubStr{xstring}{a}{true}{false}|
-\exemple|\IfSubStr{a bc def }{c d}{true}{false}|
-\exemple|\IfSubStr{a bc def }{cd}{true}{false}|
-\exemple|\IfSubStr[2]{1a2a3a}{a}{true}{false}|
-\exemple|\IfSubStr[3]{1a2a3a}{a}{true}{false}|
-\exemple|\IfSubStr[4]{1a2a3a}{a}{true}{false}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfSubStr{xstring}{tri}{true}{false}
+\IfSubStr{xstring}{a}{true}{false}
+\IfSubStr{a bc def }{c d}{true}{false}
+\IfSubStr{a bc def }{cd}{true}{false}
+\IfSubStr[2]{1a2a3a}{a}{true}{false}
+\IfSubStr[3]{1a2a3a}{a}{true}{false}
+\IfSubStr[4]{1a2a3a}{a}{true}{false}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfSubStr{xstring}{tri}{true}{false}\par
+ \IfSubStr{xstring}{a}{true}{false}\par
+ \IfSubStr{a bc def }{c d}{true}{false}\par
+ \IfSubStr{a bc def }{cd}{true}{false}\par
+ \IfSubStr[2]{1a2a3a}{a}{true}{false}\par
+ \IfSubStr[3]{1a2a3a}{a}{true}{false}\par
+ \IfSubStr[4]{1a2a3a}{a}{true}{false}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfSubStrBefore}
-\verb|\IfSubStrBefore|\etoile\arguCC{number1}{number2}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
+\verbinline|\IfSubStrBefore|\etoile\arguCC{number1}{number2}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
\smallskip
The values of the optional arguments \argu{number1} and \argu{number2} are 1 by default.\par\smallskip
@@ -183,19 +249,35 @@ In \argu{string}, tests if the \argu{number1}\th occurrence of \argu{stringA} is
\item If one of the optional arguments is negative or zero, runs \argu{false}.
\end{Conditions}
-\exemple|\IfSubStrBefore{xstring}{st}{in}{true}{false}|
-\exemple|\IfSubStrBefore{xstring}{ri}{s}{true}{false}|
-\exemple|\IfSubStrBefore{LaTeX}{LaT}{TeX}{true}{false}|
-\exemple|\IfSubStrBefore{a bc def }{ b}{ef}{true}{false}|
-\exemple|\IfSubStrBefore{a bc def }{ab}{ef}{true}{false}|
-\exemple|\IfSubStrBefore[2,1]{b1b2b3}{b}{2}{true}{false}|
-\exemple|\IfSubStrBefore[3,1]{b1b2b3}{b}{2}{true}{false}|
-\exemple|\IfSubStrBefore[2,2]{baobab}{a}{b}{true}{false}|
-\exemple|\IfSubStrBefore[2,3]{baobab}{a}{b}{true}{false}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfSubStrBefore{xstring}{st}{in}{true}{false}
+\IfSubStrBefore{xstring}{ri}{s}{true}{false}
+\IfSubStrBefore{LaTeX}{LaT}{TeX}{true}{false}
+\IfSubStrBefore{a bc def }{ b}{ef}{true}{false}
+\IfSubStrBefore{a bc def }{ab}{ef}{true}{false}
+\IfSubStrBefore[2,1]{b1b2b3}{b}{2}{true}{false}
+\IfSubStrBefore[3,1]{b1b2b3}{b}{2}{true}{false}
+\IfSubStrBefore[2,2]{baobab}{a}{b}{true}{false}
+\IfSubStrBefore[2,3]{baobab}{a}{b}{true}{false}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfSubStrBefore{xstring}{st}{in}{true}{false}\par
+ \IfSubStrBefore{xstring}{ri}{s}{true}{false}\par
+ \IfSubStrBefore{LaTeX}{LaT}{TeX}{true}{false}\par
+ \IfSubStrBefore{a bc def }{ b}{ef}{true}{false}\par
+ \IfSubStrBefore{a bc def }{ab}{ef}{true}{false}\par
+ \IfSubStrBefore[2,1]{b1b2b3}{b}{2}{true}{false}\par
+ \IfSubStrBefore[3,1]{b1b2b3}{b}{2}{true}{false}\par
+ \IfSubStrBefore[2,2]{baobab}{a}{b}{true}{false}\par
+ \IfSubStrBefore[2,3]{baobab}{a}{b}{true}{false}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfSubStrBehind}
-\verb|\IfSubStrBehind|\etoile\arguCC{number1}{number2}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
+\verbinline|\IfSubStrBehind|\etoile\arguCC{number1}{number2}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
\smallskip
The values of the optional arguments \argu{number1} and \argu{number2} are 1 by default.\par\smallskip
@@ -208,19 +290,35 @@ In \argu{string}, tests if the \argu{number1}\th occurrence of \argu{stringA} is
\item If one of the optional arguments is negative or zero, runs \argu{false}.
\end{Conditions}
-\exemple|\IfSubStrBehind{xstring}{ri}{xs}{true}{false}|
-\exemple|\IfSubStrBehind{xstring}{s}{i}{true}{false}|
-\exemple|\IfSubStrBehind{LaTeX}{TeX}{LaT}{true}{false}|
-\exemple|\IfSubStrBehind{a bc def }{ d}{a}{true}{false}|
-\exemple|\IfSubStrBehind{a bc def }{cd}{a b}{true}{false}|
-\exemple|\IfSubStrBehind[2,1]{b1b2b3}{b}{2}{true}{false}|
-\exemple|\IfSubStrBehind[3,1]{b1b2b3}{b}{2}{true}{false}|
-\exemple|\IfSubStrBehind[2,2]{baobab}{b}{a}{true}{false}|
-\exemple|\IfSubStrBehind[2,3]{baobab}{b}{a}{true}{false}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfSubStrBehind{xstring}{ri}{xs}{true}{false}
+\IfSubStrBehind{xstring}{s}{i}{true}{false}
+\IfSubStrBehind{LaTeX}{TeX}{LaT}{true}{false}
+\IfSubStrBehind{a bc def }{ d}{a}{true}{false}
+\IfSubStrBehind{a bc def }{cd}{a b}{true}{false}
+\IfSubStrBehind[2,1]{b1b2b3}{b}{2}{true}{false}
+\IfSubStrBehind[3,1]{b1b2b3}{b}{2}{true}{false}
+\IfSubStrBehind[2,2]{baobab}{b}{a}{true}{false}
+\IfSubStrBehind[2,3]{baobab}{b}{a}{true}{false}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfSubStrBehind{xstring}{ri}{xs}{true}{false}\par
+ \IfSubStrBehind{xstring}{s}{i}{true}{false}\par
+ \IfSubStrBehind{LaTeX}{TeX}{LaT}{true}{false}\par
+ \IfSubStrBehind{a bc def }{ d}{a}{true}{false}\par
+ \IfSubStrBehind{a bc def }{cd}{a b}{true}{false}\par
+ \IfSubStrBehind[2,1]{b1b2b3}{b}{2}{true}{false}\par
+ \IfSubStrBehind[3,1]{b1b2b3}{b}{2}{true}{false}\par
+ \IfSubStrBehind[2,2]{baobab}{b}{a}{true}{false}\par
+ \IfSubStrBehind[2,3]{baobab}{b}{a}{true}{false}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfBeginWith}
-\verb|\IfBeginWith|\etoile\ARGU{string}\ARGU{stringA}\ARGU{true}\ARGU{false}
+\verbinline|\IfBeginWith|\etoile\ARGU{string}\ARGU{stringA}\ARGU{true}\ARGU{false}
\smallskip
Tests if \argu{string} begins with \argu{stringA}, and runs \argu{true} if so, and \argu{false} otherwise.\medskip
@@ -229,14 +327,25 @@ Tests if \argu{string} begins with \argu{stringA}, and runs \argu{true} if so, a
\item If \argu{string} or \argu{stringA} is empty, runs \argu{false}.
\end{Conditions}
-\exemple|\IfBeginWith{xstring}{xst}{true}{false}|
-\exemple|\IfBeginWith{LaTeX}{a}{true}{false}|
-\exemple|\IfBeginWith{a bc def }{a b}{true}{false}|
-\exemple|\IfBeginWith{a bc def }{ab}{true}{false}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfBeginWith{xstring}{xst}{true}{false}
+\IfBeginWith{LaTeX}{a}{true}{false}
+\IfBeginWith{a bc def }{a b}{true}{false}
+\IfBeginWith{a bc def }{ab}{true}{false}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfBeginWith{xstring}{xst}{true}{false}\par
+ \IfBeginWith{LaTeX}{a}{true}{false}\par
+ \IfBeginWith{a bc def }{a b}{true}{false}\par
+ \IfBeginWith{a bc def }{ab}{true}{false}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfEndWith}
-\verb|\IfEndWith|\etoile\ARGU{string}\ARGU{stringA}\ARGU{Behind}\ARGU{false}
+\verbinline|\IfEndWith|\etoile\ARGU{string}\ARGU{stringA}\ARGU{Behind}\ARGU{false}
\smallskip
Tests if \argu{string} ends with \argu{stringA}, and runs \argu{true} if so, and \argu{false} otherwise.\medskip
@@ -245,40 +354,69 @@ Tests if \argu{string} ends with \argu{stringA}, and runs \argu{true} if so, and
\item If \argu{string} or \argu{stringA} is empty, runs \argu{false}.
\end{Conditions}
-\exemple|\IfEndWith{xstring}{ring}{true}{false}|
-\exemple|\IfEndWith{LaTeX}{a}{true}{false}|
-\exemple|\IfEndWith{a bc def }{ef }{true}{false}|
-\exemple|\IfEndWith{a bc def }{ef}{true}{false}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfEndWith{xstring}{ring}{true}{false}
+\IfEndWith{LaTeX}{a}{true}{false}
+\IfEndWith{a bc def }{ef }{true}{false}
+\IfEndWith{a bc def }{ef}{true}{false}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfEndWith{xstring}{ring}{true}{false}\par
+ \IfEndWith{LaTeX}{a}{true}{false}\par
+ \IfEndWith{a bc def }{ef }{true}{false}\par
+ \IfEndWith{a bc def }{ef}{true}{false}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfInteger}
-\verb|\IfInteger|\ARGU{number}\ARGU{true}\ARGU{false}
+\verbinline|\IfInteger|\ARGU{number}\ARGU{true}\ARGU{false}
\smallskip
-Tests if \argu{number} is an integer, and runs \argu{true} if so, and \argu{false} otherwise.\smallskip
-
-If test is false because unexpected characters, the control sequence \verb|\@xs@afterinteger| contains the illegal part of \argu{number}.\medskip
-
-\exemple|\IfInteger{13}{true}{false}|
-\exemple|\IfInteger{-219}{true}{false}|
-\exemple|\IfInteger{+9}{true}{false}|
-\exemple|\IfInteger{3.14}{true}{false}|
-\exemple|\IfInteger{0}{true}{false}|
-\exemple|\IfInteger{49a}{true}{false}|
-\exemple|\IfInteger{+}{true}{false}|
-\exemple|\IfInteger{-}{true}{false}|
-\exemple|\IfInteger{0000}{true}{false}|
+Tests if \argu{number} is an integer (i.e whose decimal part is empty or 0), and runs \argu{true} if so, and \argu{false} otherwise.\smallskip
+
+If test is false because unexpected characters, the control sequence \verbinline|\@xs@afterinteger| contains the illegal part of \argu{number}.\medskip
+
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfInteger{13}{true}{false}
+\IfInteger{-219}{true}{false}
+\IfInteger{+9}{true}{false}
+\IfInteger{3.14}{true}{false}
+\IfInteger{8.0}{true}{false}
+\IfInteger{0}{true}{false}
+\IfInteger{49a}{true}{false}
+\IfInteger{+}{true}{false}
+\IfInteger{-}{true}{false}
+\IfInteger{0000}{true}{false}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfInteger{13}{true}{false}\par
+ \IfInteger{-219}{true}{false}\par
+ \IfInteger{+9}{true}{false}\par
+ \IfInteger{3.14}{true}{false}\par
+ \IfInteger{8.0}{true}{false}\par
+ \IfInteger{0}{true}{false}\par
+ \IfInteger{49a}{true}{false}\par
+ \IfInteger{+}{true}{false}\par
+ \IfInteger{-}{true}{false}\par
+ \IfInteger{0000}{true}{false}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfDecimal}\label{ifdecimal}
-\verb|\IfDecimal|\ARGU{number}\ARGU{true}\ARGU{false}
+\verbinline|\IfDecimal|\ARGU{number}\ARGU{true}\ARGU{false}
\smallskip
Tests if \argu{number} is a decimal, and runs \argu{true} if so, and \argu{false} otherwise.\smallskip
-Counters \verb|\integerpart| and \verb|\decimalpart| contain the integer part and decimal part of \argu{number}.
+Counters \verbinline|\integerpart| and \verbinline|\decimalpart| contain the integer part and decimal part of \argu{number}.
-If test is false because unexpected characters, the control sequence \verb|\@xs@afterdecimal| contains the illegal part of \argu{number}, whereas if test is false because decimal part is empty after decimal separator, it contains "X".\medskip
+If test is false because unexpected characters, the control sequence \verbinline|\@xs@afterdecimal| contains the illegal part of \argu{number}, whereas if test is false because decimal part is empty after decimal separator, it contains "X".\medskip
\begin{Conditions}
\item Decimal separator can be a dot or a comma;
@@ -286,68 +424,124 @@ If test is false because unexpected characters, the control sequence \verb|\@xs@
\item If what is on the left of decimal separator (if it exists) is empty, the integer part is assumed to be 0;
\end{Conditions}
-\exemple|\IfDecimal{3.14}{true}{false}|
-\exemple|\IfDecimal{3,14}{true}{false}|
-\exemple|\IfDecimal{-0.5}{true}{false}|
-\exemple|\IfDecimal{.7}{true}{false}|
-\exemple|\IfDecimal{,9}{true}{false}|
-\exemple|\IfDecimal{1..2}{true}{false}|
-\exemple|\IfDecimal{+6}{true}{false}|
-\exemple|\IfDecimal{-15}{true}{false}|
-\exemple|\IfDecimal{1.}{true}{false}|
-\exemple|\IfDecimal{2,}{true}{false}|
-\exemple|\IfDecimal{.}{true}{false}|
-\exemple|\IfDecimal{,}{true}{false}|
-\exemple|\IfDecimal{+}{true}{false}|
-\exemple|\IfDecimal{-}{true}{false}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfDecimal{3.14}{true}{false}
+\IfDecimal{3,14}{true}{false}
+\IfDecimal{-0.5}{true}{false}
+\IfDecimal{.7}{true}{false}
+\IfDecimal{,9}{true}{false}
+\IfDecimal{1..2}{true}{false}
+\IfDecimal{+6}{true}{false}
+\IfDecimal{-15}{true}{false}
+\IfDecimal{1.}{true}{false}
+\IfDecimal{2,}{true}{false}
+\IfDecimal{.}{true}{false}
+\IfDecimal{,}{true}{false}
+\IfDecimal{+}{true}{false}
+\IfDecimal{-}{true}{false}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfDecimal{3.14}{true}{false}\par
+ \IfDecimal{3,14}{true}{false}\par
+ \IfDecimal{-0.5}{true}{false}\par
+ \IfDecimal{.7}{true}{false}\par
+ \IfDecimal{,9}{true}{false}\par
+ \IfDecimal{1..2}{true}{false}\par
+ \IfDecimal{+6}{true}{false}\par
+ \IfDecimal{-15}{true}{false}\par
+ \IfDecimal{1.}{true}{false}\par
+ \IfDecimal{2,}{true}{false}\par
+ \IfDecimal{.}{true}{false}\par
+ \IfDecimal{,}{true}{false}\par
+ \IfDecimal{+}{true}{false}\par
+ \IfDecimal{-}{true}{false}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfStrEq}
-\verb|\IfStrEq|\etoile\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
+\verbinline|\IfStrEq|\etoile\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
\smallskip
Tests if the strings \argu{stringA} and \argu{stringB} are equal, i.e. if they contain successively the same \USs in the same order. Runs \argu{true} if so, and \argu{false} otherwise.\smallskip
-\exemple|\IfStrEq{a1b2c3}{a1b2c3}{true}{false}|
-\exemple|\IfStrEq{abcdef}{abcd}{true}{false}|
-\exemple|\IfStrEq{abc}{abcdef}{true}{false}|
-\exemple|\IfStrEq{3,14}{3,14}{true}{false}|
-\exemple|\IfStrEq{12.34}{12.340}{true}{false}|
-\exemple|\IfStrEq{abc}{}{true}{false}|
-\exemple|\IfStrEq{}{abc}{true}{false}|
-\exemple|\IfStrEq{}{}{true}{false}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfStrEq{a1b2c3}{a1b2c3}{true}{false}
+\IfStrEq{abcdef}{abcd}{true}{false}
+\IfStrEq{abc}{abcdef}{true}{false}
+\IfStrEq{3,14}{3,14}{true}{false}
+\IfStrEq{12.34}{12.340}{true}{false}
+\IfStrEq{abc}{}{true}{false}
+\IfStrEq{}{abc}{true}{false}
+\IfStrEq{}{}{true}{false}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfStrEq{a1b2c3}{a1b2c3}{true}{false}\par
+ \IfStrEq{abcdef}{abcd}{true}{false}\par
+ \IfStrEq{abc}{abcdef}{true}{false}\par
+ \IfStrEq{3,14}{3,14}{true}{false}\par
+ \IfStrEq{12.34}{12.340}{true}{false}\par
+ \IfStrEq{abc}{}{true}{false}\par
+ \IfStrEq{}{abc}{true}{false}\par
+ \IfStrEq{}{}{true}{false}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfEq}
-\verb|\IfEq|\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
+\verbinline|\IfEq|\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
\smallskip
Tests if the strings \argu{stringA} and \argu{stringB} are equal, \emph{except} if both \argu{stringA} and \argu{stringB} contain numbers in which case the macro tests if these numbers are equal. Runs \argu{true} if so, and \argu{false} otherwise.\smallskip
\begin{Conditions}
- \item The definition of \emph{number} is given with the macro \verb|IfDecimal| (see page~\pageref{ifdecimal}), and thus :
+ \item The definition of \emph{number} is given with the macro \verbinline|\IfDecimal| (see page~\pageref{ifdecimal}), and thus :
\item \guill{+} signs are optional;
\item Decimal separator can be a dot or a comma.
\end{Conditions}
-\exemple|\IfEq{a1b2c3}{a1b2c3}{true}{false}|
-\exemple|\IfEq{abcdef}{ab}{true}{false}|
-\exemple|\IfEq{ab}{abcdef}{true}{false}|
-\exemple|\IfEq{12.34}{12,34}{true}{false}|
-\exemple|\IfEq{+12.34}{12.340}{true}{false}|
-\exemple|\IfEq{10}{+10}{true}{false}|
-\exemple|\IfEq{-10}{10}{true}{false}|
-\exemple|\IfEq{+0,5}{,5}{true}{false}|
-\exemple|\IfEq{1.001}{1.01}{true}{false}|
-\exemple|\IfEq{3*4+2}{14}{true}{false}|
-\exemple|\IfEq{\number\numexpr3*4+2}{14}{true}{false}|
-\exemple|\IfEq{0}{-0.0}{true}{false}|
-\exemple|\IfEq{}{}{true}{false}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfEq{a1b2c3}{a1b2c3}{true}{false}
+\IfEq{abcdef}{ab}{true}{false}
+\IfEq{ab}{abcdef}{true}{false}
+\IfEq{12.34}{12,34}{true}{false}
+\IfEq{+12.34}{12.340}{true}{false}
+\IfEq{10}{+10}{true}{false}
+\IfEq{-10}{10}{true}{false}
+\IfEq{+0,5}{,5}{true}{false}
+\IfEq{1.001}{1.01}{true}{false}
+\IfEq{3*4+2}{14}{true}{false}
+\IfEq{\number\numexpr3*4+2}{14}{true}{false}
+\IfEq{0}{-0.0}{true}{false}
+\IfEq{}{}{true}{false}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfEq{a1b2c3}{a1b2c3}{true}{false}\par
+ \IfEq{abcdef}{ab}{true}{false}\par
+ \IfEq{ab}{abcdef}{true}{false}\par
+ \IfEq{12.34}{12,34}{true}{false}\par
+ \IfEq{+12.34}{12.340}{true}{false}\par
+ \IfEq{10}{+10}{true}{false}\par
+ \IfEq{-10}{10}{true}{false}\par
+ \IfEq{+0,5}{,5}{true}{false}\par
+ \IfEq{1.001}{1.01}{true}{false}\par
+ \IfEq{3*4+2}{14}{true}{false}\par
+ \IfEq{\number\numexpr3*4+2}{14}{true}{false}\par
+ \IfEq{0}{-0.0}{true}{false}\par
+ \IfEq{}{}{true}{false}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfStrEqCase}
\begin{minipage}{\textwidth}
- \verb|\IfStrEqCase|\etoile\ARGU{string}\verb|{%|\par
+ \verbinline|\IfStrEqCase|\etoile\ARGU{string}\verb|{%|\par
\qquad\qquad\ARGU{string1}\ARGU{code1}\verb|%|\par
\qquad\qquad\ARGU{string2}\ARGU{code2}\verb|%|\par
\qquad\qquad\verb|etc...|\par
@@ -355,19 +549,32 @@ Tests if the strings \argu{stringA} and \argu{stringB} are equal, \emph{except}
\end{minipage}
\smallskip
-Tests successively if \argu{string} is equal to \argu{string1}, \argu{string2}, etc. Comparison is made with \verb|\IfStrEq| (see above). If the test number $i$ is positive (the \argu{string} matches \argu{string\;$i$}), the macro runs \argu{code\;$i$} and ends. If all tests fail, the macro runs the optional \argu{other cases code}, if present.\smallskip
-
-\exemple|\IfStrEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}|
-\exemple*|\IfStrEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|
-\exemple|\IfStrEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[other]|
-\exemple|\IfStrEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[other]|
-\exemple|\IfStrEqCase{+3}{{1}{one}{2}{two}{3}{three}}[other]|
-\exemple|\IfStrEqCase{0.5}{{0}{zero}{.5}{half}{1}{one}}[other]|
+Tests successively if \argu{string} is equal to \argu{string1}, \argu{string2}, etc. Comparison is made with \verbinline|\IfStrEq| (see above). If the test number $i$ is positive (the \argu{string} matches \argu{string\;$i$}), the macro runs \argu{code\;$i$} and ends. If all tests fail, the macro runs the optional \argu{other cases code}, if present.\smallskip
+
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfStrEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}
+|\IfStrEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|
+\IfStrEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[other]
+\IfStrEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[other]
+\IfStrEqCase{+3}{{1}{one}{2}{two}{3}{three}}[other]
+\IfStrEqCase{0.5}{{0}{zero}{.5}{half}{1}{one}}[other]
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfStrEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}\par
+ |\IfStrEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|\par
+ \IfStrEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[other]\par
+ \IfStrEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[other]\par
+ \IfStrEqCase{+3}{{1}{one}{2}{two}{3}{three}}[other]\par
+ \IfStrEqCase{0.5}{{0}{zero}{.5}{half}{1}{one}}[other]
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfEqCase}
\begin{minipage}{\textwidth}
- \verb|\IfEqCase|\etoile\ARGU{string}\verb|{%|\par
+ \verbinline|\IfEqCase|\etoile\ARGU{string}\verb|{%|\par
\qquad\qquad\ARGU{string1}\ARGU{code1}\verb|%|\par
\qquad\qquad\ARGU{string2}\ARGU{code2}\verb|%|\par
\qquad\qquad\verb|etc...|\par
@@ -375,19 +582,32 @@ Tests successively if \argu{string} is equal to \argu{string1}, \argu{string2},
\end{minipage}
\smallskip
-Tests successively if \argu{string} is equal to \argu{string1}, \argu{string2}, etc. Comparison is made with \verb|\IEq| (see above). If the test number $i$ is positive (the \argu{string} matches \argu{string\;$i$}), the macro runs \argu{code\;$i$} and ends. If all tests fail, the macro runs the optional \argu{other cases code}, if present.\smallskip
-
-\exemple|\IfEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}|
-\exemple*|\IfEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|
-\exemple|\IfEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[other]|
-\exemple|\IfEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[other]|
-\exemple|\IfEqCase{+3}{{1}{one}{2}{two}{3}{three}}[other]|
-\exemple|\IfEqCase{0.5}{{0}{zero}{.5}{half}{1}{one}}[other]|
+Tests successively if \argu{string} is equal to \argu{string1}, \argu{string2}, etc. Comparison is made with \verbinline|\IEq| (see above). If the test number $i$ is positive (the \argu{string} matches \argu{string\;$i$}), the macro runs \argu{code\;$i$} and ends. If all tests fail, the macro runs the optional \argu{other cases code}, if present.\smallskip
+
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}
+|\IfEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|
+\IfEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[other]
+\IfEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[other]
+\IfEqCase{+3}{{1}{one}{2}{two}{3}{three}}[other]
+\IfEqCase{0.5}{{0}{zero}{.5}{half}{1}{one}}[other]
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}\par
+ |\IfEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|\par
+ \IfEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[other]\par
+ \IfEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[other]\par
+ \IfEqCase{+3}{{1}{one}{2}{two}{3}{three}}[other]\par
+ \IfEqCase{0.5}{{0}{zero}{.5}{half}{1}{one}}[other]
+\end{minipage}%
\subsection{Extraction of substrings}
\subsubsection{\ttfamily\textbackslash StrBefore}
-\verb|\StrBefore|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
+\verbinline|\StrBefore|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip
The value of the optional argument \argu{number} is 1 by default.\par\smallskip
@@ -400,18 +620,33 @@ In \argu{string}, returns what is leftwards the \argu{number}\th occurrence of \
\item If the occurrence is not found, an empty string is returned.
\end{Conditions}
-\exemple*|\StrBefore{xstring}{tri}|
-\exemple*|\StrBefore{LaTeX}{e}|
-\exemple*|\StrBefore{LaTeX}{p}|
-\exemple*|\StrBefore{LaTeX}{L}|
-\exemple*|\StrBefore{a bc def }{def}|
-\exemple*|\StrBefore{a bc def }{cd}|
-\exemple*|\StrBefore[1]{1b2b3}{b}|
-\exemple*|\StrBefore[2]{1b2b3}{b}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrBefore{xstring}{tri}
+\StrBefore{LaTeX}{e}
+|\StrBefore{LaTeX}{p}|
+|\StrBefore{LaTeX}{L}|
+|\StrBefore{a bc def }{def}|
+|\StrBefore{a bc def }{cd}|
+\StrBefore[1]{1b2b3}{b}
+\StrBefore[2]{1b2b3}{b}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrBefore{xstring}{tri}\par
+ \StrBefore{LaTeX}{e}\par
+ |\StrBefore{LaTeX}{p}|\par
+ |\StrBefore{LaTeX}{L}|\par
+ |\StrBefore{a bc def }{def}|\par
+ |\StrBefore{a bc def }{cd}|\par
+ \StrBefore[1]{1b2b3}{b}\par
+ \StrBefore[2]{1b2b3}{b}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrBehind}
-\verb|\StrBehind|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
+\verbinline|\StrBehind|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip
The value of the optional argument \argu{number} is 1 by default.\par\smallskip
@@ -424,20 +659,35 @@ In \argu{string}, returns what is rightwards the \argu{number}\th occurrence of
\item If the occurrence is not found, an empty string is returned.
\end{Conditions}
-
-\exemple*|\StrBehind{xstring}{tri}|
-\exemple*|\StrBehind{LaTeX}{e}|
-\exemple*|\StrBehind{LaTeX}{p}|
-\exemple*|\StrBehind{LaTeX}{X}|
-\exemple*|\StrBehind{a bc def }{bc}|
-\exemple*|\StrBehind{a bc def }{cd}|
-\exemple*|\StrBehind[1]{1b2b3}{b}|
-\exemple*|\StrBehind[2]{1b2b3}{b}|
-\exemple*|\StrBehind[3]{1b2b3}{b}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrBehind{xstring}{tri}
+\StrBehind{LaTeX}{e}
+|\StrBehind{LaTeX}{p}|
+|\StrBehind{LaTeX}{X}|
+|\StrBehind{a bc def }{bc}|
+|\StrBehind{a bc def }{cd}|
+\StrBehind[1]{1b2b3}{b}
+\StrBehind[2]{1b2b3}{b}
+|\StrBehind[3]{1b2b3}{b}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrBehind{xstring}{tri}\par
+ \StrBehind{LaTeX}{e}\par
+ |\StrBehind{LaTeX}{p}|\par
+ |\StrBehind{LaTeX}{X}|\par
+ |\StrBehind{a bc def }{bc}|\par
+ |\StrBehind{a bc def }{cd}|\par
+ \StrBehind[1]{1b2b3}{b}\par
+ \StrBehind[2]{1b2b3}{b}\par
+ |\StrBehind[3]{1b2b3}{b}|
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrBetween}
-\verb|\StrBetween|\etoile\arguCC{number1}{number2}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\arguC{name}
+\verbinline|\StrBetween|\etoile\arguCC{number1}{number2}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\arguC{name}
\smallskip
The values of the optional arguments \argu{number1} and \argu{number2} are 1 by default.\par\smallskip
@@ -450,20 +700,37 @@ In \argu{string}, returns the substring between\footnote{In a strict sense, i.e.
\item If one of the optional arguments \argu{number1} ou \argu{number2} is negative or zero, an empty string is returned.
\end{Conditions}
-\exemple*|\StrBetween{xstring}{xs}{ng}|
-\exemple*|\StrBetween{xstring}{i}{n}|
-\exemple*|\StrBetween{xstring}{a}{tring}|
-\exemple*|\StrBetween{a bc def }{a}{d}|
-\exemple*|\StrBetween{a bc def }{a }{f}|
-\exemple*|\StrBetween{a1b1a2b2a3b3}{a}{b}|
-\exemple*|\StrBetween[2,3]{a1b1a2b2a3b3}{a}{b}|
-\exemple*|\StrBetween[1,3]{a1b1a2b2a3b3}{a}{b}|
-\exemple*|\StrBetween[3,1]{a1b1a2b2a3b3}{a}{b}|
-\exemple*|\StrBetween[3,2]{abracadabra}{a}{bra}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrBetween{xstring}{xs}{ng}
+|\StrBetween{xstring}{i}{n}|
+|\StrBetween{xstring}{a}{tring}|
+|\StrBetween{a bc def }{a}{d}|
+|\StrBetween{a bc def }{a }{f}|
+\StrBetween{a1b1a2b2a3b3}{a}{b}
+\StrBetween[2,3]{a1b1a2b2a3b3}{a}{b}
+\StrBetween[1,3]{a1b1a2b2a3b3}{a}{b}
+|\StrBetween[3,1]{a1b1a2b2a3b3}{a}{b}|
+\StrBetween[3,2]{abracadabra}{a}{bra}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrBetween{xstring}{xs}{ng}\par
+ |\StrBetween{xstring}{i}{n}|\par
+ |\StrBetween{xstring}{a}{tring}|\par
+ |\StrBetween{a bc def }{a}{d}|\par
+ |\StrBetween{a bc def }{a }{f}|\par
+ \StrBetween{a1b1a2b2a3b3}{a}{b}\par
+ \StrBetween[2,3]{a1b1a2b2a3b3}{a}{b}\par
+ \StrBetween[1,3]{a1b1a2b2a3b3}{a}{b}\par
+ |\StrBetween[3,1]{a1b1a2b2a3b3}{a}{b}|\par
+ \StrBetween[3,2]{abracadabra}{a}{bra}\par
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrSubstitute}
-\verb|\StrSubstitute|\arguC{number}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\arguC{name}
+\verbinline|\StrSubstitute|\arguC{number}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\arguC{name}
\smallskip
The value of the optional argument \argu{number} is 0 by default.\par\smallskip
@@ -478,20 +745,37 @@ In \argu{string}, substitute the \argu{number} first occurrences of \argu{string
\item If \argu{stringB} is empty, the occurrences of \argu{stringA}, if they exist, are deleted.
\end{Conditions}
-\exemple|\StrSubstitute{xstring}{i}{a}|
-\exemple|\StrSubstitute{abracadabra}{a}{o}|
-\exemple|\StrSubstitute{abracadabra}{br}{TeX}|
-\exemple|\StrSubstitute{LaTeX}{m}{n}|
-\exemple|\StrSubstitute{a bc def }{ }{M}|
-\exemple|\StrSubstitute{a bc def }{ab}{AB}|
-\exemple|\StrSubstitute[1]{a1a2a3}{a}{B}|
-\exemple|\StrSubstitute[2]{a1a2a3}{a}{B}|
-\exemple|\StrSubstitute[3]{a1a2a3}{a}{B}|
-\exemple|\StrSubstitute[4]{a1a2a3}{a}{B}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrSubstitute{xstring}{i}{a}
+\StrSubstitute{abracadabra}{a}{o}
+\StrSubstitute{abracadabra}{br}{TeX}
+\StrSubstitute{LaTeX}{m}{n}
+\StrSubstitute{a bc def }{ }{M}
+\StrSubstitute{a bc def }{ab}{AB}
+\StrSubstitute[1]{a1a2a3}{a}{B}
+\StrSubstitute[2]{a1a2a3}{a}{B}
+\StrSubstitute[3]{a1a2a3}{a}{B}
+\StrSubstitute[4]{a1a2a3}{a}{B}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrSubstitute{xstring}{i}{a}\par
+ \StrSubstitute{abracadabra}{a}{o}\par
+ \StrSubstitute{abracadabra}{br}{TeX}\par
+ \StrSubstitute{LaTeX}{m}{n}\par
+ \StrSubstitute{a bc def }{ }{M}\par
+ \StrSubstitute{a bc def }{ab}{AB}\par
+ \StrSubstitute[1]{a1a2a3}{a}{B}\par
+ \StrSubstitute[2]{a1a2a3}{a}{B}\par
+ \StrSubstitute[3]{a1a2a3}{a}{B}\par
+ \StrSubstitute[4]{a1a2a3}{a}{B}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrDel}
-\verb|\StrDel|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
+\verbinline|\StrDel|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip
The value of the optional argument \argu{number} is 0 by default.\par\smallskip
@@ -505,14 +789,28 @@ Delete the \argu{number} first occurrences of \argu{stringA} in \argu{string}, e
\item If \argu{number}${}<0$ the macro behaves as if \argu{number}${}=0$;
\end{Conditions}
-\exemple|\StrDel{abracadabra}{a}|
-\exemple|\StrDel[1]{abracadabra}{a}|
-\exemple|\StrDel[4]{abracadabra}{a}|
-\exemple|\StrDel[9]{abracadabra}{a}|
-\exemple|\StrDel{a bc def }{ }|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrDel{abracadabra}{a}
+\StrDel[1]{abracadabra}{a}
+\StrDel[4]{abracadabra}{a}
+\StrDel[9]{abracadabra}{a}
+\StrDel{a bc def }{ }
+|\StrDel{a bc def }{def}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrDel{abracadabra}{a}\par
+ \StrDel[1]{abracadabra}{a}\par
+ \StrDel[4]{abracadabra}{a}\par
+ \StrDel[9]{abracadabra}{a}\par
+ \StrDel{a bc def }{ }\par
+ |\StrDel{a bc def }{def}|
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrGobbleLeft}
-\verb|\StrGobbleLeft|\ARGU{string}\ARGU{number}\arguC{name}
+\verbinline|\StrGobbleLeft|\ARGU{string}\ARGU{number}\arguC{name}
\smallskip
In \argu{string}, delete the \argu{number} first characters on the left.\medskip
@@ -523,15 +821,27 @@ In \argu{string}, delete the \argu{number} first characters on the left.\medskip
\item If \argu{number}${}\geqslant{}$\argu{lengthString}, all the characters are deleted.
\end{Conditions}
-\exemple*|\StrGobbleLeft{xstring}{2}|
-\exemple*|\StrGobbleLeft{xstring}{9}|
-\exemple*|\StrGobbleLeft{LaTeX}{4}|
-\exemple*|\StrGobbleLeft{LaTeX}{-2}|
-\exemple*|\StrGobbleLeft{a bc def }{4}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrGobbleLeft{xstring}{2}
+|\StrGobbleLeft{xstring}{9}|
+\StrGobbleLeft{LaTeX}{4}
+\StrGobbleLeft{LaTeX}{-2}
+|\StrGobbleLeft{a bc def }{4}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrGobbleLeft{xstring}{2}\par
+ |\StrGobbleLeft{xstring}{9}|\par
+ \StrGobbleLeft{LaTeX}{4}\par
+ \StrGobbleLeft{LaTeX}{-2}\par
+ |\StrGobbleLeft{a bc def }{4}|
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrLeft}
-\verb|\StrLeft|\ARGU{string}\ARGU{number}\arguC{name}
+\verbinline|\StrLeft|\ARGU{string}\ARGU{number}\arguC{name}
\smallskip
In \argu{string}, returns the \argu{number} first characters on the left.\medskip
@@ -542,41 +852,77 @@ In \argu{string}, returns the \argu{number} first characters on the left.\medski
\item If \argu{number}${}\geqslant{}$\argu{lengthString}, all the characters are returned.
\end{Conditions}
-\exemple*|\StrLeft{xstring}{2}|
-\exemple*|\StrLeft{xstring}{9}|
-\exemple*|\StrLeft{LaTeX}{4}|
-\exemple*|\StrLeft{LaTeX}{-2}|
-\exemple*|\StrLeft{a bc def }{5}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrLeft{xstring}{2}
+\StrLeft{xstring}{9}
+\StrLeft{LaTeX}{4}
+|\StrLeft{LaTeX}{-2}|
+|\StrLeft{a bc def }{5}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrLeft{xstring}{2}\par
+ \StrLeft{xstring}{9}\par
+ \StrLeft{LaTeX}{4}\par
+ |\StrLeft{LaTeX}{-2}|\par
+ |\StrLeft{a bc def }{5}|
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrGobbleRight}
-\verb|\StrGobbleRight|\ARGU{string}\ARGU{number}\arguC{name}
+\verbinline|\StrGobbleRight|\ARGU{string}\ARGU{number}\arguC{name}
\smallskip
In \argu{string}, delete the \argu{number} last characters on the right.\medskip
-\exemple*|\StrGobbleRight{xstring}{2}|
-\exemple*|\StrGobbleRight{xstring}{9}|
-\exemple*|\StrGobbleRight{LaTeX}{4}|
-\exemple*|\StrGobbleRight{LaTeX}{-2}|
-\exemple*|\StrGobbleRight{a bc def }{4}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrGobbleRight{xstring}{2}
+|\StrGobbleRight{xstring}{9}|
+\StrGobbleRight{LaTeX}{4}
+|\StrGobbleRight{LaTeX}{-2}|
+|\StrGobbleRight{a bc def }{4}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrGobbleRight{xstring}{2}\par
+ |\StrGobbleRight{xstring}{9}|\par
+ \StrGobbleRight{LaTeX}{4}\par
+ |\StrGobbleRight{LaTeX}{-2}|\par
+ |\StrGobbleRight{a bc def }{4}|
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrRight}
-\verb|\StrRight|\ARGU{string}\ARGU{number}\arguC{name}
+\verbinline|\StrRight|\ARGU{string}\ARGU{number}\arguC{name}
\smallskip
In \argu{string}, returns the \argu{number} last characters on the right.\medskip
-\exemple*|\StrRight{xstring}{2}|
-\exemple*|\StrRight{xstring}{9}|
-\exemple*|\StrRight{LaTeX}{4}|
-\exemple*|\StrRight{LaTeX}{-2}|
-\exemple*|\StrRight{a bc def }{5}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrRight{xstring}{2}
+\StrRight{xstring}{9}
+\StrRight{LaTeX}{4}
+|\StrRight{LaTeX}{-2}|
+\StrRight{a bc def }{5}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrRight{xstring}{2}\par
+ \StrRight{xstring}{9}\par
+ \StrRight{LaTeX}{4}\par
+ |\StrRight{LaTeX}{-2}|\par
+ \StrRight{a bc def }{5}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrChar}
-\verb|\StrChar|\etoile\ARGU{string}\ARGU{number}\arguC{name}
+\verbinline|\StrChar|\etoile\ARGU{string}\ARGU{number}\arguC{name}
\smallskip
Returns the \US at the position \argu{number} in \argu{string}.\medskip
@@ -586,14 +932,25 @@ Returns the \US at the position \argu{number} in \argu{string}.\medskip
\item If \argu{number}${}\leqslant0$ or if \argu{number}${}>{}$\argu{lengthString}, no character is returned.
\end{Conditions}
-\exemple|\StrChar{xstring}{4}|
-\exemple*|\StrChar{xstring}{9}|
-\exemple*|\StrChar{xstring}{-5}|
-\exemple|\StrChar{a bc def }{6}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrChar{xstring}{4}
+|\StrChar{xstring}{9}|
+|\StrChar{xstring}{-5}|
+\StrChar{a bc def }{6}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrChar{xstring}{4}\par
+ |\StrChar{xstring}{9}|\par
+ |\StrChar{xstring}{-5}|\par
+ \StrChar{a bc def }{6}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrMid}
-\verb|\StrMid|\ARGU{string}\ARGU{numberA}\ARGU{numberB}\arguC{name}
+\verbinline|\StrMid|\ARGU{string}\ARGU{numberA}\ARGU{numberB}\arguC{name}
\smallskip
In \argu{string}, returns the substring between\footnote{In the broad sense, i.e. that the strings characters of the \guill{border} are returned.} the positions \argu{numberA} and \argu{numberB}.\medskip
@@ -607,28 +964,51 @@ In \argu{string}, returns the substring between\footnote{In the broad sense, i.e
\item If \argu{numberB}${}>{}$\argu{lengthString}, the macro behaves as if \argu{numberB}${}={}$\argu{lengthString}.
\end{Conditions}
-\exemple|\StrMid{xstring}{2}{5}|
-\exemple|\StrMid{xstring}{-4}{2}|
-\exemple*|\StrMid{xstring}{5}{1}|
-\exemple|\StrMid{xstring}{6}{15}|
-\exemple|\StrMid{xstring}{3}{3}|
-\exemple*|\StrMid{a bc def }{2}{7}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrMid{xstring}{2}{5}
+\StrMid{xstring}{-4}{2}
+|\StrMid{xstring}{5}{1}|
+\StrMid{xstring}{6}{15}
+\StrMid{xstring}{3}{3}
+|\StrMid{a bc def }{2}{7}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrMid{xstring}{2}{5}\par
+ \StrMid{xstring}{-4}{2}\par
+ |\StrMid{xstring}{5}{1}|\par
+ \StrMid{xstring}{6}{15}\par
+ \StrMid{xstring}{3}{3}\par
+ |\StrMid{a bc def }{2}{7}|
+\end{minipage}%
\subsection{Macros returning a number}
\subsubsection{\ttfamily\textbackslash StrLen}
-\verb|\StrLen|\ARGU{string}\arguC{name}
+\verbinline|\StrLen|\ARGU{string}\arguC{name}
\smallskip
Return the length of \argu{string}.
-\exemple|\StrLen{xstring}|
-\exemple|\StrLen{A}|
-\exemple|\StrLen{a bc def }|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrLen{xstring}
+\StrLen{A}
+\StrLen{a bc def }
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrLen{xstring}\par
+ \StrLen{A}\par
+ \StrLen{a bc def }
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrCount}
-\verb|\StrCount|\ARGU{string}\ARGU{stringA}\arguC{name}
+\verbinline|\StrCount|\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip
Counts how many times \argu{stringA} is contained in \argu{string}.\par\medskip
@@ -637,14 +1017,25 @@ Counts how many times \argu{stringA} is contained in \argu{string}.\par\medskip
\item If one at least of the arguments \argu{string} or \argu{stringA} is empty, the macro return 0.
\end{Conditions}
-\exemple|\StrCount{abracadabra}{a}|
-\exemple|\StrCount{abracadabra}{bra}|
-\exemple|\StrCount{abracadabra}{tic}|
-\exemple|\StrCount{aaaaaa}{aa}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrCount{abracadabra}{a}
+\StrCount{abracadabra}{bra}
+\StrCount{abracadabra}{tic}
+\StrCount{aaaaaa}{aa}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrCount{abracadabra}{a}\par
+ \StrCount{abracadabra}{bra}\par
+ \StrCount{abracadabra}{tic}\par
+ \StrCount{aaaaaa}{aa}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrPosition}
-\verb|\StrPosition|\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
+\verbinline|\StrPosition|\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip
The value of the optional argument \argu{number} is 1 by default.\par\smallskip
@@ -657,70 +1048,114 @@ In \argu{string}, returns the position of the \argu{number}\th occurrence of \ar
\end{Conditions}
\medskip
-\exemple|\StrPosition{xstring}{ring}|
-\exemple|\StrPosition[4]{abracadabra}{a}|
-\exemple|\StrPosition[2]{abracadabra}{bra}|
-\exemple|\StrPosition[9]{abracadabra}{a}|
-\exemple|\StrPosition{abracadabra}{z}|
-\exemple|\StrPosition{a bc def }{d}|
-\exemple|\StrPosition[3]{aaaaaa}{aa}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrPosition{xstring}{ring}
+\StrPosition[4]{abracadabra}{a}
+\StrPosition[2]{abracadabra}{bra}
+\StrPosition[9]{abracadabra}{a}
+\StrPosition{abracadabra}{z}
+\StrPosition{a bc def }{d}
+\StrPosition[3]{aaaaaa}{aa}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrPosition{xstring}{ring}\par
+ \StrPosition[4]{abracadabra}{a}\par
+ \StrPosition[2]{abracadabra}{bra}\par
+ \StrPosition[9]{abracadabra}{a}\par
+ \StrPosition{abracadabra}{z}\par
+ \StrPosition{a bc def }{d}\par
+ \StrPosition[3]{aaaaaa}{aa}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrCompare}
-\verb|\StrCompare|\etoile\ARGU{stringA}\ARGU{stringB}\arguC{name}
+\verbinline|\StrCompare|\etoile\ARGU{stringA}\ARGU{stringB}\arguC{name}
\smallskip
This macro has 2 tolerances: the "normal" tolerance, used by default, and the "strict" tolerance.
\begin{itemize}
- \item The normal tolerance is activated with \verb|\comparenormal|.\par
+ \item The normal tolerance is activated with \verbinline|\comparenormal|.\par
The macro compares characters from left to right in \argu{stringA} and \argu{stringB} until a difference appears or the end of the shortest string is reached. The position of the first difference is returned and if no difference is found, the macro return 0.
- \item The strict tolerance is activated with \verb|\comparestrict|.\par
+ \item The strict tolerance is activated with \verbinline|\comparestrict|.\par
The macro compares the 2 strings. If they are equal, it returns 0. If not, the position of the first difference is returned.
\end{itemize}
\medskip
-It is possible to save the comparison mode with \verb|\savecomparedmode|, then modify this comparison mode and come back to the situation when it was saved with \verb|\restoreecomparemode|.\medskip
-
-Examples with the normal tolerance:\par\comparenormal
-\exemple|\StrCompare{abcd}{abcd}|
-\exemple|\StrCompare{abcd}{abc}|
-\exemple|\StrCompare{abc}{abcd}|
-\exemple|\StrCompare{éùçà}{éùçà}|
-\exemple|\StrCompare{a b c}{abc}|
-\exemple|\StrCompare{aaa}{baaa}|
-\exemple|\StrCompare{abc}{xyz}|
-\exemple|\StrCompare{123456}{123457}|
-\exemple|\StrCompare{abc}{}|
-\medskip
+It is possible to save the comparison mode with \verbinline|\savecomparemode|, then modify this comparison mode and come back to the situation when it was saved with \verbinline|\restorecomparemode|.\medskip
-Examples with the strict tolerance:\par\comparestrict
-\exemple|\StrCompare{abcd}{abcd}|
-\exemple|\StrCompare{abcd}{abc}|
-\exemple|\StrCompare{abc}{abcd}|
-\exemple|\StrCompare{éùçà}{éùçà}|
-\exemple|\StrCompare{a b c}{abc}|
-\exemple|\StrCompare{aaa}{baaa}|
-\exemple|\StrCompare{abc}{xyz}|
-\exemple|\StrCompare{123456}{123457}|
-\exemple|\StrCompare{abc}{}|
+Examples with the normal tolerance:\par\nobreak
+\begin{minipage}[t]{0.65\linewidth}
\comparenormal
+\begin{lstlisting}
+\StrCompare{abcd}{abcd}
+\StrCompare{abcd}{abc}
+\StrCompare{abc}{abcd}
+\StrCompare{a b c}{abc}
+\StrCompare{aaa}{baaa}
+\StrCompare{abc}{xyz}
+\StrCompare{123456}{123457}
+\StrCompare{abc}{}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \comparenormal
+ \StrCompare{abcd}{abcd}\par
+ \StrCompare{abcd}{abc}\par
+ \StrCompare{abc}{abcd}\par
+ \StrCompare{a b c}{abc}\par
+ \StrCompare{aaa}{baaa}\par
+ \StrCompare{abc}{xyz}\par
+ \StrCompare{123456}{123457}\par
+ \StrCompare{abc}{}
+\end{minipage}%
+\medskip
+
+Examples with the strict tolerance:\par\nobreak
+\begin{minipage}[t]{0.65\linewidth}
+\comparestrict
+\begin{lstlisting}
+\StrCompare{abcd}{abcd}
+\StrCompare{abcd}{abc}
+\StrCompare{abc}{abcd}
+\StrCompare{a b c}{abc}
+\StrCompare{aaa}{baaa}
+\StrCompare{abc}{xyz}
+\StrCompare{123456}{123457}
+\StrCompare{abc}{}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \comparestrict
+ \StrCompare{abcd}{abcd}\par
+ \StrCompare{abcd}{abc}\par
+ \StrCompare{abc}{abcd}\par
+ \StrCompare{a b c}{abc}\par
+ \StrCompare{aaa}{baaa}\par
+ \StrCompare{abc}{xyz}\par
+ \StrCompare{123456}{123457}\par
+ \StrCompare{abc}{}
+\end{minipage}%
\section{Operating modes}
\subsection{Expansion of arguments}
\label{devarg}
\subsubsection{The commands {\ttfamily \textbackslash fullexpandarg}, {\ttfamily \textbackslash expandarg} and {\ttfamily \textbackslash noexpandarg}}
-The command \verb|\fullexpandarg| is called by default, so all the arguments are fully expanded (an \verb|\edef| is used) before the the macro works on them. In most of the cases, this expansion mode avoids chains of \verb|\expandafter| and allows lighter code.
+The command \verbinline|\fullexpandarg| is called by default, so all the arguments are fully expanded (an \verbinline|\edef| is used) before the the macro works on them. In most of the cases, this expansion mode avoids chains of \verbinline|\expandafter| and allows lighter code.
-Of course, the expansion of argument can be canceled to find back the usual behaviour of \TeX{} with the comands \verb|\noexpandarg| or \verb|\normalexpandarg|.\medskip
+Of course, the expansion of argument can be canceled to find back the usual behaviour of \TeX{} with the comands \verbinline|\noexpandarg| or \verbinline|\normalexpandarg|.\medskip
-Another expansion mode can be called with \verb|\expandarg|. In this case, the \textbf{first token} of each argument is expanded \emph{one time} while all other tokens are left unchanged (if you want the expansion of all tokens one time, you should call the macro \verb|\scancs*|, see page~\pageref{scancs}).\medskip
+Another expansion mode can be called with \verbinline|\expandarg|. In this case, the \textbf{first token} of each argument is expanded \emph{one time} while all other tokens are left unchanged (if you want the expansion of all tokens one time, you should call the macro \verbinline|\scancs*|, see page~\pageref{scancs}).\medskip
-The commands \verb|\fullexpandarg|, \verb|\noexpandarg|, \verb|\normalexpandarg| and \verb|\expandarg| can be called at any moment in the code; they behave as "switches" and they can be locally used in a group.\medskip
+The commands \verbinline|\fullexpandarg|, \verbinline|\noexpandarg|, \verbinline|\normalexpandarg| and \verbinline|\expandarg| can be called at any moment in the code; they behave as "switches" and they can be locally used in a group.\medskip
-It is possible to save the expansion mode with \verb|\saveexpandmode|, then modify this expansion mode and come back to the situation when it was saved with \verb|\restoreexpandmode|.\medskip
+It is possible to save the expansion mode with \verbinline|\saveexpandmode|, then modify this expansion mode and come back to the situation when it was saved with \verbinline|\restoreexpandmode|.\medskip
-In the following list, for every macro of the previous chapter, the arguments colored in \textcolor{red}{red} will possibly be expanded, according to the expansion mode:\smallskip
+In the following list, for every macro of the previous chapter, the arguments colored in \textcolor{violet}{purple} will possibly be expanded, according to the expansion mode:\smallskip
-\newcommand\colorise{\color{red}}
\parindent3em
\begin{itemize}
\item\verb|\IfSubStr|\etoile{\colorise\arguC{number}\ARGU{string}\ARGU{stringA}}\ARGU{true}\ARGU{false}
@@ -764,7 +1199,7 @@ In the following list, for every macro of the previous chapter, the arguments co
\subsubsection{Chars allowed in arguments}
First of all, whatever be the current expansion mode, \textbf{tokens with catcode 6 and 14 (usually {\ttfamily\#} and {\ttfamily\%}) are forbidden in all the arguments}\footnote{Maybe, the token {\ttfamily\#} will be allowed in a further version.}.\bigskip
-When full expansion mode is activated with \verb|\fullexpandarg|, arguments are expanded with an \verb|\edef| before they are read by the macro. Consequently, are allowed in arguments :
+When full expansion mode is activated with \verbinline|\fullexpandarg|, arguments are expanded with an \verbinline|\edef| before they are read by the macro. Consequently, are allowed in arguments :
\parindent3em
\begin{itemize}
\item letters (uppercase or lowercase, accented\footnote{For a reliable operation with accented letters, the \texttt{\string\fontenc} package with option \texttt{[T1]} and \texttt{\string\inputenc} with appropriated option must be loaded} or not), figures, spaces, and any other character with a catcode of 10, 11 ou 12 (punctuation signs, calculation signs, parenthesis, square bracket, etc).;
@@ -776,7 +1211,7 @@ When full expansion mode is activated with \verb|\fullexpandarg|, arguments are
On the other hand, some chars\footnote{These chars are obtained with the keys \textsf{AtlGr}${}+{}$letter under GNU/Linux distributions.} like \officialeuro, \textcurrency, ¶, etc. will provoke errors.\medskip
-When expansion is not full (\verb|\expandarg| or \verb|\noexpandarg| are active), allowed char in arguments are:\parindent3em
+When expansion is not full (\verbinline|\expandarg| or \verbinline|\noexpandarg| are active), allowed char in arguments are:\parindent3em
\begin{itemize}
\item those cited above;
\item any control sequence or token catocode 13, even undefined;
@@ -786,20 +1221,20 @@ When expansion is not full (\verb|\expandarg| or \verb|\noexpandarg| are active)
\subsection{Expansion of macros, optional argument}
\label{argumentoptionnel}
-The macros of this package are not purely expandable, i.e. they cannot be put in the argument of an \verb|\edef|. Nestling macros is not possible neither.\medskip
+The macros of this package are not purely expandable, i.e. they cannot be put in the argument of an \verbinline|\edef|. Nestling macros is not possible neither.\medskip
-For this reason, all the macros returning a result (i.e. all excepted the tests) have an optional argument in last position. The syntax is \arguC{name}, where \argu{name} is the name of the control sequence that will receive the result of the macro: the assignment is made with an \verb|\edef| which make the result of the macro \argu{name} purely expandable. Of course, if an optional argument is present, the macro does not display anything.\medskip
+For this reason, all the macros returning a result (i.e. all excepted the tests) have an optional argument in last position. The syntax is \arguC{name}, where \argu{name} is the name of the control sequence that will receive the result of the macro: the assignment is made with an \verbinline|\edef| which make the result of the macro \argu{name} purely expandable. Of course, if an optional argument is present, the macro does not display anything.\medskip
-Thus, this structure not allowed, supposed to assign to \verb|\Result| the 4 chars on the left of \verb|xstring|:\par
-\hspace{0.2\linewidth}\verb|\edef\Result{\StrLeft{xstring}{4}}|\par
-\qquad is equivalent to :\par
-\hspace{0.2\linewidth}\verb|\StrLeft{xstring}{4}[\Result]|\medskip
+Thus, this structure not allowed, supposed to assign to \verb|\Result| the 4 chars on the left of \verb|xstring|:\par\nobreak
+\hspace{0.2\linewidth}\verbinline|\edef\Result{\StrLeft{xstring}{4}}|\par\nobreak
+\qquad is equivalent to :\par\nobreak
+\hspace{0.2\linewidth}\verbinline|\StrLeft{xstring}{4}[\Result]|\medskip
-And this not allowed nested structure, supposed to remove the first and last char of \verb|xstring|:\par
-\hspace{0.2\linewidth}\verb|\StrGobbleLeft{\StrGobbleRight{xstring}{1}}{1}|\par
-\qquad should be written like this:\par
-\hspace{0.2\linewidth}\verb|\StrGobbleRight{xstring}{1}[\mystring]|\par
-\hspace{0.2\linewidth}\verb|\StrGobbleleft{\mystring}{1}|\par
+And this nested structure, not allowed neither, supposed to remove the first and last char of \verb|xstring|:\par\nobreak
+\hspace{0.2\linewidth}\verbinline|\StrGobbleLeft{\StrGobbleRight{xstring}{1}}{1}|\par\nobreak
+\qquad should be written like this:\par\nobreak
+\hspace{0.2\linewidth}\verbinline|\StrGobbleRight{xstring}{1}[\mystring]|\par\nobreak
+\hspace{0.2\linewidth}\verbinline|\StrGobbleleft{\mystring}{1}|\par
\subsection{How does \Xstring read the arguments?}
\label{developpementarguments}
@@ -816,117 +1251,113 @@ Let's see what is a \US with an example. Let's take this argument : "\verb|ab\te
It has 6 \USs: "\verb|a|", "\verb|b|", "\verb|\textbf|", "\verb|{xyz}|", "\verb|c|" and "\verb|d|".\medskip
-What will happen if, while \verb|\noexpandarg| is active, we ask \Xstring to find the length of this argument and find its 4\th "char"\medskip
-
-\begin{minipage}[r]{0.6\linewidth}
-\hfill
-\begin{boxedverbatim}
+What will happen if, while \verbinline|\noexpandarg| is active, we ask \Xstring to find the length of this argument and find its 4\th "char"\medskip
+
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\noexpandarg
+\StrLen{ab\textbf{xyz}cd}\par
+\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
+\meaning\mychar
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\noexpandarg
\StrLen{ab\textbf{xyz}cd}\par
\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
\meaning\mychar
-\end{boxedverbatim}
-\hspace*{0.3cm}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \noexpandarg
- \StrLen{ab\textbf{xyz}cd}\par
- \StrChar{ab\textbf{xyz}cd}{4}[\mychar]
- \meaning\mychar
-\end{minipage}
\fullexpandarg
\medskip
-It is necessary to use \verb|\meaning| to see the real expansion of \verb|\mychar|, and not simply call \verb|\mychar| to display it, which make loose informations (braces here). We do not obtain a "char" but a \US, as expected.
+It is necessary to use \verbinline|\meaning| to see the real expansion of \verb|\mychar|, and not simply call \verb|\mychar| to display it, which make loose informations (braces here). We do not obtain a "char" but a \US, as expected.
\subsubsection{Exploration of groups}
-By default, the command \verb|\noexploregroups| is called, so in the argument containing the string of tokens, \Xstring does not look into groups, and simply consider them as a \US.
+By default, the command \verbinline|\noexploregroups| is called, so in the argument containing the string of tokens, \Xstring does not look into groups, and simply consider them as a \US.
-For specific uses, it can be necessary to look into groups: \verb|\exploregroups| changes the exploration mode and forces the macros to look inside groups.\medskip
+For specific uses, it can be necessary to look into groups: \verbinline|\exploregroups| changes the exploration mode and forces the macros to look inside groups.\medskip
What does this exploration mode in the previous example? \Xstring does not count the group as a single \US but looks inside it and counts the \US found inside (\verb|x|, \verb|y| and \verb|z|), and so on if there were several nested groups:\smallskip
-\begin{minipage}[r]{0.6\linewidth}
-\hfill
-\begin{boxedverbatim}
+\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\noexpandarg
+\exploregroups
+\StrLen{ab\textbf{xyz}cd}\par
+\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
+\meaning\mychar
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\noexpandarg
\exploregroups
\StrLen{ab\textbf{xyz}cd}\par
\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
\meaning\mychar
-\end{boxedverbatim}
-\hspace*{0.3cm}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \noexpandarg
- \exploregroups
- \StrLen{ab\textbf{xyz}cd}\par
- \StrChar{ab\textbf{xyz}cd}{4}[\mychar]
- \meaning\mychar
-\end{minipage}
\fullexpandarg\noexploregroups
\medskip
-Exploring the groups can be usefull for counting a substring in a string (\verb|\StrCount|), for the position of a substring in a string (\verb|\StrPosition|) or for tests, but has a severe limitation with macros returning a string: when a string is cut inside a group, \textbf{the result does not take into account what is outside this group}. This exploration mode must be used knowingly this limitation when calling macros returning a string.\smallskip
-
-Let's see what this means with an example. We want to know what is on the left of the second appearance of \verb|\a| in the argument \verb|\a1{\b1\a2}\a3|. As groups are explored, this appearance is inside this group : \verb|{\b1\a2}|. The result will be \verb|\b1|. Let's check:\smallskip
-
-\begin{minipage}[r]{0.6\linewidth}
-\hfill
-\begin{boxedverbatim}
+Exploring the groups can be usefull for counting a substring in a string (\verbinline|\StrCount|), for the position of a substring in a string (\verbinline|\StrPosition|) or for tests, but has a severe limitation with macros returning a string: when a string is cut inside a group, \textbf{the result does not take into account what is outside this group}. This exploration mode must be used knowingly this limitation when calling macros returning a string.\smallskip
+
+Let's see what this means with an example. We want to know what is on the left of the second appearance of \verb|\a| in the argument \verb|\a1{\b1\a2}\a3|. As groups are explored, this appearance is inside this group : \verb|{\b1\a2}|. The result will be \verb|\b1|. Let's check:\par\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\noexpandarg
+\exploregroups
+\StrBefore[2]{\a1{\b1\a2}\a3}{\a}[\mycs]
+\meaning\mycs
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\noexpandarg
\exploregroups
\StrBefore[2]{\a1{\b1\a2}\a3}{\a}[\mycs]
\meaning\mycs
-\end{boxedverbatim}
-\hspace*{0.3cm}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \noexpandarg
- \exploregroups
- \StrBefore[2]{\a1{\b1\a2}\a3}{\a}[\mycs]
- \meaning\mycs
-\end{minipage}
-\fullexpandarg\noexploregroups
\medskip
-Exploring the groups\footnote{The file test of \Xstring has many examples underlining differences between exploration modes.} can change the behaviour of most of the macros of \Xstring, excepted these macros untouched by the exploration mode; their behaviour is the same in any case: \verb|\IfInteger|, \verb|\IfDecimal|, \verb|\IfStrEq|, \verb|\StrEq| et \verb|\StrCompare|.
+Exploring the groups\footnote{The file test of \Xstring has many examples underlining differences between exploration modes.} can change the behaviour of most of the macros of \Xstring, excepted these macros untouched by the exploration mode; their behaviour is the same in any case: \verbinline|\IfInteger|, \verbinline|\IfDecimal|, \verbinline|\IfStrEq|, \verbinline|\StrEq| et \verbinline|\StrCompare|.
-Moreover, 2 macros run in \verb|\noexploregroups| mode, whatever be the current mode: \verb|\StrBetween| et \verb|\StrMid|.\medskip
+Moreover, 2 macros run in \verbinline|\noexploregroups| mode, whatever be the current mode: \verbinline|\StrBetween| et \verbinline|\StrMid|.\medskip
-It is possible to save the exploration mode with \verb|\saveexploremode|, then modify it and come back to the situation when it was saved with \verb|\restoreexploremode|.
+It is possible to save the exploration mode with \verbinline|\saveexploremode|, then modify it and come back to the situation when it was saved with \verbinline|\restoreexploremode|.
\subsection{Catcode and starred macros}
\label{macrosetoilees}
Macros of this package take the catcodes of tokens into account. To avoid unexpected behaviour (particulary with tests), you should keep in mind that tokens \emph{and their catcodes} are examined.\medskip
For instance, these two arguments:\par\medskip
-\hfil\verb|{\string a\string b}|\qquad and\qquad\verb|{ab}|\hfil{}\par\smallskip
-do \emph{not} expand into equal strings for xstring! Because of the command \verb|\string|, the first expands into "\verb|ab|" with catcodes 12 while the second have characters with their natural catcodes 11. Catcodes do not match! It is necessary to be aware of this, particulary with \TeX{} commands like \verb|\string| whose expansions are a strings with chars catcodes 12 and 10 : \verb|\detokenize|, \verb|\meaning|, \verb|\jobname|, \verb|\fontname|, \verb|\romannumeral|, etc.\medskip
+\hfil\verbinline|{\string a\string b}|\qquad and\qquad\verb|{ab}|\hfil{}\par\smallskip
+do \emph{not} expand into equal strings for xstring! Because of the command \verbinline|\string|, the first expands into "\verb|ab|" with catcodes 12 while the second have characters with their natural catcodes 11. Catcodes do not match! It is necessary to be aware of this, particulary with \TeX{} commands like \verbinline|\string| whose expansions are a strings with chars catcodes 12 and 10 : \verbinline|\detokenize|, \verbinline|\meaning|, \verbinline|\jobname|, \verbinline|\fontname|, \verbinline|\romannumeral|, etc.\medskip
Starred macros do not take catcodes into account. They simply convert some arguments into arguments with catcodes 10, 11 and 12, and call the non-starred macros with these modified arguments. The optional arguments are not modified and the catcodes are left unchanged.\medskip
-Here is an example:\par\smallskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \IfStrEq{\string a\string b}{ab}{true}{false}\par
- \IfStrEq*{\string a\string b}{ab}{true}{false}
- \end{boxedverbatim}
- \hspace{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+Here is an example:\par\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\IfStrEq{\string a\string b}{ab}{true}{false}\par
+\IfStrEq*{\string a\string b}{ab}{true}{false}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\IfStrEq{\string a\string b}{ab}{true}{false}\par
\IfStrEq*{\string a\string b}{ab}{true}{false}
-\end{minipage}\smallskip
+\end{minipage}%
+\smallskip
The strings do not match because of catcode differences: the test is negative in the non-starred macro.\bigskip
\textbf{Warning}: the use of a strarred macro has consequences! The arguments are \guill{detokenized}, thus, there is no more control sequences, groups, neither any special char: everything is converted into chars with "harmless" catcodes.\medskip
-For the macros returning a string, if the starred version is used, the result will be a string in which chars have catcodes 12 and 10 for space. For example, after a "\verb|\StrBefore*{a \b c d}{c}[\mytext]|", the control sequence \verb|\mytext| expands to "\verb|a|${}_{12}$\verb*| |${}_{10}$\verb|\|${}_{12}$\verb|b|${}_{12}$\verb*| |${}_{10}$".\medskip
+For the macros returning a string, if the starred version is used, the result will be a string in which chars have catcodes 12 and 10 for space. For example, after a "\verbinline|\StrBefore*{a \b c d}{c}[\mytext]|", the control sequence \verb|\mytext| expands to "\verb|a|${}_{12}$\verb*| |${}_{10}$\verb|\|${}_{12}$\verb|b|${}_{12}$\verb*| |${}_{10}$".\medskip
-The macro with a starred version are listed below. For these macros, if starred version is used, the \textcolor{red}{red} arguments will be detokenized:\smallskip
+The macro with a starred version are listed below. For these macros, if starred version is used, the \textcolor{violet}{purple} arguments will be detokenized:\smallskip
\parindent3em
\begin{itemize}
@@ -958,9 +1389,9 @@ The macro with a starred version are listed below. For these macros, if starred
Though \Xstring is able to read arguments containing \TeX{} or \LaTeX{} code, for some advanced programming needs, it can be insufficient. This chapter presents other macros able to get round some limitations.
\subsection{Finding a group, macros {\ttfamily\textbackslash StrFindGroup} and {\ttfamily\textbackslash groupID}}
-When \verb=\exploregroups= mode is active, the macro \verb=\StrFindGroup= finds a group between braces with its identifier:\smallskip
+When \verbinline=\exploregroups= mode is active, the macro \verbinline=\StrFindGroup= finds a group between braces with its identifier:\smallskip
-\verb|\StrFindGroup|\ARGU{argument}\ARGU{identifier}\arguC{name}\medskip
+\verbinline|\StrFindGroup|\ARGU{argument}\ARGU{identifier}\arguC{name}\medskip
When the group matching the identifier does not exist, an empty string is assigned to \argu{name}. If the group is found, this group \emph{with its braces} is assigned to \argu{name}.\smallskip
@@ -984,70 +1415,66 @@ In this example:\parindent3em
\end{itemize}
\parindent0pt
\medskip
-Here is the full example:\smallskip
-
-\begin{minipage}[r]{0.6\linewidth}
-\hfill
-\begin{boxedverbatim}
+Here is the full example:\par\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\exploregroups
+\expandarg
+\def\mystring{a{{bc}d{efg}}h{{ij}{k}{l{m}{no}}p}}
+\StrFindGroup{\mystring}{1}[\mygroup]
+\meaning\mygroup\par
+\StrFindGroup{\mystring}{2,1}[\mygroup]
+\meaning\mygroup\par
+\StrFindGroup{\mystring}{2,3,2}[\mygroup]
+\meaning\mygroup\par
+\StrFindGroup{\mystring}{2,5}[\mygroup]
+\meaning\mygroup\par
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\exploregroups
\expandarg
- \def\string{a{{bc}d{efg}}h{{ij}{k}{l{m}{no}}p}}
- \StrFindGroup{\string}{1}[\mygroup]
+ \def\mystring{a{{bc}d{efg}}h{{ij}{k}{l{m}{no}}p}}
+ \StrFindGroup{\mystring}{1}[\mygroup]
\meaning\mygroup\par
- \StrFindGroup{\string}{2,1}[\mygroup]
+ \StrFindGroup{\mystring}{2,1}[\mygroup]
\meaning\mygroup\par
- \StrFindGroup{\string}{2,3,2}[\mygroup]
+ \StrFindGroup{\mystring}{2,3,2}[\mygroup]
\meaning\mygroup\par
- \StrFindGroup{\string}{2,5}[\mygroup]
+ \StrFindGroup{\mystring}{2,5}[\mygroup]
\meaning\mygroup\par
-\end{boxedverbatim}
-\hspace*{0.3cm}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \exploregroups
- \expandarg
- \def\string{a{{bc}d{efg}}h{{ij}{k}{l{m}{no}}p}}
- \StrFindGroup{\string}{1}[\mygroup]
- \meaning\mygroup\par
- \StrFindGroup{\string}{2,1}[\mygroup]
- \meaning\mygroup\par
- \StrFindGroup{\string}{2,3,2}[\mygroup]
- \meaning\mygroup\par
- \StrFindGroup{\string}{2,5}[\mygroup]
- \meaning\mygroup\par
-\end{minipage}
\bigskip
-The reverse process exists, and several macros of \Xstring provide the identifier of the group in which they made a cut or they found a substring. These macros are: \verb|\IfSubStr|, \verb|\StrBefore|, \verb|\StrBehind|, \verb|\StrSplit|, \verb|\StrLeft|, \verb|\StrGobbleLeft|, \verb|\StrRight|, \verb|\StrGobbleRight|, \verb|\StrChar|, \verb|\StrPosition|.\medskip
-
-After these macros, the control sequence \verb|\groupID| expands to the identifier of the group where the cut has been done or the search has succeeded. When not cut can be done or the search fails, \verb|\groupID| is empty. Obvioulsly, the use of \verb|\groupID| has sense only when \verb|\exploregroups| mode is acive and when non starred macros are used.\smallskip
-
-Here are some examples with the macro \verb|\StrChar|:\smallskip
-
-\begin{minipage}[r]{0.6\linewidth}
-\hfill
-\begin{boxedverbatim}
+The reverse process exists, and several macros of \Xstring provide the identifier of the group in which they made a cut or they found a substring. These macros are: \verbinline|\IfSubStr|, \verbinline|\StrBefore|, \verbinline|\StrBehind|, \verbinline|\StrSplit|, \verbinline|\StrLeft|, \verbinline|\StrGobbleLeft|, \verbinline|\StrRight|, \verbinline|\StrGobbleRight|, \verbinline|\StrChar|, \verbinline|\StrPosition|.\medskip
+
+After these macros, the control sequence \verbinline|\groupID| expands to the identifier of the group where the cut has been done or the search has succeeded. When not cut can be done or the search fails, \verbinline|\groupID| is empty. Obvioulsly, the use of \verbinline|\groupID| has sense only when \verbinline|\exploregroups| mode is acive and when non starred macros are used.\smallskip
+
+Here are some examples with the macro \verbinline|\StrChar|:\par\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\exploregroups
+char 1 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{1}\qquad
+\string\groupID = \groupID\par
+char 4 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{4}\qquad
+\string\groupID = \groupID\par
+char 6 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{6}\qquad
+\string\groupID = \groupID\par
+char 20 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{20}\qquad
+\string\groupID = \groupID
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\exploregroups
- char no 1 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{1}\qquad
+ char 1 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{1}\qquad
\string\groupID = \groupID\par
- char no 4 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{4}\qquad
+ char 4 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{4}\qquad
\string\groupID = \groupID\par
- char no 6 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{6}\qquad
+ char 6 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{6}\qquad
\string\groupID = \groupID\par
- char no 20 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{20}\qquad
- \string\groupID = \groupID
-\end{boxedverbatim}
-\hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \exploregroups
- char no 1 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{1}\qquad
- \string\groupID = \groupID\par
- char no 4 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{4}\qquad
- \string\groupID = \groupID\par
- char no 6 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{6}\qquad
- \string\groupID = \groupID\par
- char no 20 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{20}\qquad
+ char 20 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{20}\qquad
\string\groupID = \groupID
\end{minipage}
@@ -1055,7 +1482,7 @@ Here are some examples with the macro \verb|\StrChar|:\smallskip
\label{StrSplit}
Here is the syntax:\smallskip
-\verb|\StrSplit|\ARGU{string}\ARGU{number}\ARGU{stringA}\ARGU{stringB}
+\verbinline|\StrSplit|\ARGU{string}\ARGU{number}\ARGU{stringA}\ARGU{stringB}
\smallskip
The \argu{string}, is splitted after the \US at position \argu{number}. The left part is assigned to the control sequence \argu{stringA} and the right part is assigned to \argu{stringB}.\par
@@ -1067,81 +1494,93 @@ This macro returns two strings, so it does \emph{not} display anything. Conseque
\item If \argu{string} is empty, \argu{stringA} and \argu{stringB} are empty, whatever be the integer \argu{number}.
\end{Conditions}
-\setverbdelim{=}
-\exemple=\StrSplit{abcdef}{4}{\aa}{\bb}results: |\aa| and |\bb|=
-\exemple=\StrSplit{a b c }{2}{\aa}{\bb}results: |\aa| and |\bb|=
-\exemple=\StrSplit{abcdef}{1}{\aa}{\bb}results: |\aa| and |\bb|=
-\exemple=\StrSplit{abcdef}{5}{\aa}{\bb}results: |\aa| and |\bb|=
-\exemple=\StrSplit{abcdef}{9}{\aa}{\bb}results: |\aa| and |\bb|=
-\exemple=\StrSplit{abcdef}{-3}{\aa}{\bb}results: |\aa| and |\bb|=
-\setverbdelim{|}\medskip
-
-When the exploration of groups is active and the cut is made at the end of a group, the content of the left string will tbe the entire group while the right string will be empty. The example shows this:\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+
+\begin{lstlisting}
+\def\redsep{{\color{red}|}}%
+\StrSplit{abcdef}{4}{\csA}{\csB}|\csA\redsep\csB|
+\StrSplit{a b c }{2}{\csA}{\csB}|\csA\redsep\csB|
+\StrSplit{abcdef}{1}{\csA}{\csB}|\csA\redsep\csB|
+\StrSplit{abcdef}{5}{\csA}{\csB}|\csA\redsep\csB|
+\StrSplit{abcdef}{9}{\csA}{\csB}|\csA\redsep\csB|
+\StrSplit{abcdef}{-3}{\csA}{\csB}|\csA\redsep\csB|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
+ \def\redsep{{\color{red}|}}%
+ \StrSplit{abcdef}{4}{\csA}{\csB}|\csA\redsep\csB|\par
+ \StrSplit{a b c }{2}{\csA}{\csB}|\csA\redsep\csB|\par
+ \StrSplit{abcdef}{1}{\csA}{\csB}|\csA\redsep\csB|\par
+ \StrSplit{abcdef}{5}{\csA}{\csB}|\csA\redsep\csB|\par
+ \StrSplit{abcdef}{9}{\csA}{\csB}|\csA\redsep\csB|\par
+ \StrSplit{abcdef}{-3}{\csA}{\csB}|\csA\redsep\csB|
+\end{minipage}%
-\begin{minipage}[r]{0.6\linewidth}
+When the exploration of groups is active and the cut is made at the end of a group, the content of the left string will tbe the entire group while the right string will be empty. The example shows this:\par\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
\hfill
-\begin{boxedverbatim}
+\begin{lstlisting}
+\exploregroups
+\StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
+\meaning\strA\par
+\meaning\strB
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\exploregroups
\StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
\meaning\strA\par
\meaning\strB
-\end{boxedverbatim}
-\hspace*{0.3cm}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \exploregroups
- \StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
- \meaning\strA\par
- \meaning\strB
-\end{minipage}
\medskip
-This macro provides a star version: in this case, the cut is made just before the \US which follows the \US at position \argu{number}. Both version give same results, except when the cut is made at the end of a group; in that case, \verb|\StrSplit| closes as many group as necessary until it finds the next \US: the cut is made just before this \US.\smallskip
+This macro provides a star version: in this case, the cut is made just before the \US which follows the \US at position \argu{number}. Both version give same results, except when the cut is made at the end of a group; in that case, \verbinline|\StrSplit| closes as many group as necessary until it finds the next \US: the cut is made just before this \US.\smallskip
-\begin{minipage}[r]{0.6\linewidth}
+\begin{minipage}[c]{0.65\linewidth}
\hfill
-\begin{boxedverbatim}
+\begin{lstlisting}
+\exploregroups
+Use without star :\par
+\StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
+\meaning\strA\par
+\meaning\strB\par
+\string\groupID\ = \groupID\par\medskip
+Use with star :\par
+\StrSplit*{ab{cd{ef}gh}ij}{6}\strA\strB
+\meaning\strA\par
+\meaning\strB\par
+\string\groupID\ = \groupID
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\exploregroups
- With natural macro:\par
+ Use without star :\par
\StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
\meaning\strA\par
\meaning\strB\par
- \string\groupID = \groupID\par
- With star macro:\par
+ \string\groupID\ = \groupID\par\medskip
+ Use with star :\par
\StrSplit*{ab{cd{ef}gh}ij}{6}\strA\strB
\meaning\strA\par
\meaning\strB\par
\string\groupID\ = \groupID
-\end{boxedverbatim}
-\hspace*{0.3cm}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \exploregroups
- With natural macro:\par
- \StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
- \meaning\strA\par
- \meaning\strB\par
- \string\groupID = \groupID\par
- With star macro:\par
- \StrSplit*{ab{cd{ef}gh}ij}{6}\strA\strB
- \meaning\strA\par
- \meaning\strB\par
- \string\groupID\ = \groupID
-\end{minipage}
\subsection{Assign a verb content, the macro \ttfamily\textbackslash verbtocs}
\label{verbtocs}
-The macro \verb|\verbtocs| allow to read the content of a \guill{verb} argument containing special characters: \verb|&|, \verb|~|, \verb|\|, \verb|{|, \verb|}|, \verb|_|, \verb|#|, \verb|$|, \verb|^| and \verb|%|. The catcodes of \guill{normal} characters are left unchanged while special characters take a catcode 12. Then, these characters are assigned to a control sequence. The syntax is:\medskip
-
-\hfill\verb|\verbtocs|\ARGU{name}|\argu{characters}|\hfill{}
+The macro \verbinline|\verbtocs| allow to read the content of a \guill{verb} argument containing special characters: \verb|&|, \verb|~|, \verb|\|, \verb|{|, \verb|}|, \verb|_|, \verb|#|, \verb|$|, \verb|^| and \verb|%|. The catcodes of \guill{normal} characters are left unchanged while special characters take a catcode 12. Then, these characters are assigned to a control sequence. The syntax is:\par\nobreak\medskip
+\hfill\verbinline|\verbtocs|\ARGU{name}|\argu{characters}|\hfill{}
\smallskip
-\argu{name} is the name of the control sequence receiving, with an \verb|\edef|, the \argu{characters}. \argu{name} thus contains tokens with catcodes 12 (or 10 for space).\medskip
+\argu{name} is the name of the control sequence receiving, with an \verbinline|\edef|, the \argu{characters}. \argu{name} thus contains tokens with catcodes 12 (or 10 for space).\medskip
-By default, the token delimiting the verb content is \guill{|}. Obviously, this token cannot be both delimiting and being contained into what it delimits. If you need to verbatimize strings containing \guill{|}, you can change at any time the token delimiting the verb content with the macro:\par\medskip
-\hfill\verb|\setverbdelim|\ARGU{character}\hfill{}\smallskip
+By default, the token delimiting the verb content is \guill{|}. Obviously, this token cannot be both delimiting and being contained into what it delimits. If you need to verbatimize strings containing \guill{|}, you can change at any time the token delimiting the verb content with the macro:\par\nobreak\medskip
+\hfill\verbinline|\setverbdelim|\ARGU{character}\hfill{}\smallskip
-Any \argu{token} can be used\footnote{Several tokens can be used, but the syntax of \texttt{\textbackslash verbtocs} becomes less readable ! For this reason, a warning occurs when the argument of \texttt{\textbackslash setverbdelim} contains more than a single token.}. For example, after \verb|\setverbdelim{=}|, a verb argument look like this: \verb|=|\argu{characters}\verb|=|.\medskip
+Any \argu{token} can be used\footnote{Several tokens can be used, but the syntax of \texttt{\textbackslash verbtocs} becomes less readable ! For this reason, a warning occurs when the argument of \texttt{\textbackslash setverbdelim} contains more than a single token.}. For example, after \verbinline|\setverbdelim{=}|, a verb argument look like this: \verb|=|\argu{characters}\verb|=|.\medskip
About verb arguments, keep in mind that:
\begin{itemize}
@@ -1150,138 +1589,118 @@ About verb arguments, keep in mind that:
\end{itemize}
\medskip
-Example:\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \verbtocs{\result} |a & b{ c% d$ e \f|
- \result
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+Example:\par\nobreak\medskip
+\begin{minipage}[c]{0.65\linewidth}
+\lstset{deletecomment=[l]\%}
+\begin{lstlisting}
+\verbtocs{\result} |a & b{ c% d$ e \f|
+I display the result :\par\result
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\verbtocs{\result} |a & b{ c% d$ e \f|
- \result
-\end{minipage}
+ I display the result :\par\result
+\end{minipage}%
\subsection{Tokenization of a text to a control sequence, the macro \ttfamily\textbackslash tokenize}
-The reverse process of what has been seen above is to transform chars into tokens. This is done by the macro:\medskip
-
-\hfill\verb|\tokenize|\ARGU{name}\ARGU{control sequences}\hfill{}
+The reverse process of what has been seen above is to transform chars into tokens. This is done by the macro:\par\nobreak\medskip
+\hfill\verbinline|\tokenize|\ARGU{name}\ARGU{control sequences}\hfill{}
\smallskip
-\argu{control sequences} is fully expanded if \verb|\fullexpandarg| has been called, and is not expanded if \verb|\noexpandarg| or \verb|\expandarg| are active. After expansion, the chars are tokenized to tokens and assigned to \argu{name} with a \verb|\def|.\medskip
-
-Example:\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \verbtocs{\text}|\textbf{a} $\frac{1}{2}$|
- text: \text
- \tokenize{\result}{\text}
- \par
- result: \result
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \raggedright
+\argu{control sequences} is fully expanded if \verbinline|\fullexpandarg| has been called, and is not expanded if \verbinline|\noexpandarg| or \verbinline|\expandarg| are active. After expansion, the chars are tokenized to tokens and assigned to \argu{name} with a \verbinline|\def|.\medskip
+
+Example:\par\nobreak\medskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\verbtocs{\text}|\textbf{a} $\frac{1}{2}$|
+text : \text
+\tokenize{\result}{\text}\par
+result : \result
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\verbtocs{\text}
|\textbf{a} $\frac{1}{2}$|
- text: \text
- \tokenize{\result}{\text}
- \par
- result: \result
-\end{minipage}
+ text : \text
+ \tokenize{\result}{\text} \par
+ result : \result
+\end{minipage}%
\medskip
Obviously, the control sequence \verb|\result| can be called at the last line since the control sequences it contains are defined.
-\subsection{Expansion of a control sequence before verbatimize, the macro \ttfamily\textbackslash scancs}
+\subsection{Expansion of a control sequence before verbatimize, the macros {\ttfamily\textbackslash StrExpand} and {\ttfamily\textbackslash scancs}}
\label{scancs}
-It is possible to expand a control sequence before converting this expansion into text. This is done by the macro:\medskip
-
-\hfill\verb|\scancs|\arguC{number}\ARGU{name}\ARGU{control sequence}\hfill{}
-\smallskip
-
-\argu{number}${}=1$ by default and represents the number of times \argu{control sequence} will be expanded before being converted in characters with catcodes 12 (or 10 for spaces). These characters are then assigned to \argu{name}.
-
-If necessary, the depth of expansion can be controlled with the optional argument. If the $n$\th expansion is a control sequence, the control sequence is verbatimized into chars catcodes 12. The following shows all the "depths" of expansion, from 0 to 3:\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \def\a{1 z 3}
- \def\b{\a}
- \def\c{\b}
- \scancs[0]{\result}{\c}
- expansion 0 : \result\par
- \scancs[1]{\result}{\c}
- expansion 1 : \result\par
- \scancs[2]{\result}{\c}
- expansion 2 : \result\par
- \scancs[3]{\result}{\c}
- expansion 3 : \result
- \end{boxedverbatim}
- \hspace{0.3cm}
+The macro \verbinline|\StrExpand| expands the tokens of a string:\par\nobreak\medskip
+\verbinline|\StrExpand|\arguC{number}\ARGU{string}\ARGU{name}\smallskip
+
+By default, \argu{number} is 1 and represnts the number of times each token of \argu{string} has to be expanded. The \argu{name} is a control sequence receiving the result of the expansions.\medskip
+
+Macro works sequentially and by pass: in a pass, each token from left to right is replaced by its 1-expansion. After this expansion, if the \argu{number} of expansions is not reached, an other pass starts, and so on.\medskip
+
+Here is an example:\par\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\def\csA{1 2}
+\def\csB{a \csA}
+\def\csC{\csB\space}
+\def\csD{x{\csA y}\csB{\csC z}}
+Expansion of \string\csD\ at\par
+\StrExpand[0]{\csD}{\csE} depth 0 :
+\detokenize\expandafter{\csE}\par
+\StrExpand[1]{\csD}{\csE} depth 1 :
+\detokenize\expandafter{\csE}\par
+\StrExpand[2]{\csD}{\csE} depth 2 :
+\detokenize\expandafter{\csE}\par
+\StrExpand[3]{\csD}{\csE} depth 3 :
+\detokenize\expandafter{\csE}\par
+\StrExpand[4]{\csD}{\csE} depth 4 :
+\detokenize\expandafter{\csE}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
+ \def\csA{1 2}
+ \def\csB{a \csA}
+ \def\csC{\csB\space}
+ \def\csD{x{\csA y}\csB{\csC z}}
+ Expansion of \string\csD\ at\par
+ \StrExpand[0]{\csD}{\csE} depth 0 :
+ \detokenize\expandafter{\csE}\par
+ \StrExpand[1]{\csD}{\csE} depth 1 :
+ \detokenize\expandafter{\csE}\par
+ \StrExpand[2]{\csD}{\csE} depth 2 :
+ \detokenize\expandafter{\csE}\par
+ \StrExpand[3]{\csD}{\csE} depth 3 :
+ \detokenize\expandafter{\csE}\par
+ \StrExpand[4]{\csD}{\csE} depth 4 :
+ \detokenize\expandafter{\csE}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \def\a{1 z 3}
- \def\b{\a}
- \def\c{\b}
- \scancs[0]{\result}{\c}
- expansion 0 : \result\par
- \scancs[1]{\result}{\c}
- expansion 1 : \result\par
- \scancs[2]{\result}{\c}
- expansion 2 : \result\par
- \scancs[3]{\result}{\c}
- expansion 3 : \result
-\end{minipage}
\medskip
-Obviously, it is necessary to ensure that the expansion to the desired depth is possible.\medskip
-
-In normal use, the third argument \argu{control sequence} (or one of its expansions) must contain a single control sequence that will be expanded. If this third argument or one of its expansion contains several control sequences, compilation stops with an error message asking you to use the starred version. This starred version, more difficult to use allows to expand \argu{number} times \emph{all} the control sequences contained in the third argument. It is necessary to keep in mind that if the $n-1$\th expansion contains a group between braces, this group will be expanded at the $n$\th expansion and will loose its braces! It is the same for spaces\footnote{Any call to {\ttfamily\string\scancs*} provoque a warning message warning against this behaviour.}.\medskip
-
-This is an example that shows the deletion of braces during the next expansion:\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \def\a{1 {2}}
- \def\b{\a \a}
- \scancs*[0]{\result}{{A}\b}
- expansion 0 : \result\par
- \scancs*[1]{\result}{{A}\b}
- expansion 1 : \result\par
- \scancs*[2]{\result}{{A}\b}
- expansion 2 : \result\par
- \scancs*[3]{\result}{{A}\b}
- expansion 3 : \result
- \end{boxedverbatim}
- \hspace{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \def\a{1 {2}}
- \def\b{\a \a}
- \scancs*[0]{\result}{{A}\b}
- expansion 0 : \result\par
- \scancs*[1]{\result}{{A}\b}
- expansion 1 : \result\par
- \scancs*[2]{\result}{{A}\b}
- expansion 2 : \result\par
- \scancs*[3]{\result}{{A}\b}
- expansion 3 : \result
-\end{minipage}
+The macro expands each token consecutively, and does not see what follows: tokens whose expansion depends on other tokens cannot be expanded with this macro. For instance, though "\hbox{\verbinline|\iftrue A\else B\fi|}" has a natural expansion ("A"), it cannot be put in the argument of \verbinline|\StrExpand| and:\par\nobreak\smallskip
+\hfil\verbinline|\StrExpand{\iftrue A\else B\fi}\resultat|\hfil{}\par\nobreak\smallskip
+provokes an error because the first token "\verbinline|\iftrue|" is expanded \emph{alone} without seeing its \verbinline-\fi- which makes \TeX{} angry.
+
+Expansion inside groups is \emph{independant} of the exploration mode: this macro has its own command to expand or not what is inside the groups. By default, tokens inside groups are expanded, but this can be changed with \verbinline-\noexpandingroups-. The default behaviour can be recoverd with \verbinline-\expandingroups-.\bigskip
+
+The \verbinline-\scancs- macro returns the detokenized result:\par\nobreak\medskip
+\verbinline|\scancs|\arguC{number}\ARGU{name}\ARGU{string}\par\nobreak\smallskip
+The \argu{number} is 1 by default and represents the number of expansions.\smallskip
+
+\verbinline-\scancs- has been kept for compatibility with older versions of \Xstring. This macro now unnecessry, simply takes the result of \verbinline|\StrExpand| and \verbinline|\detokenize| it.
\subsection{Inside the definition of a macro}
-Some difficulties arise inside the definition of a macro, i.e. between braces following a \verb|\def\macro| or a\\\verb|\newcommand\macro|.\medskip
+Some difficulties arise inside the definition of a macro, i.e. between braces following a \verbinline|\def\macro| or a\\\verbinline|\newcommand\macro|.\medskip
-It is forbidden to use the command \verb|\verb| inside the definition of a macro. For the same reasons:\par\medskip
+It is forbidden to use the command \verbinline|\verb| inside the definition of a macro. For the same reasons:\par\medskip
\hfill\textbf{Do not use \texttt{\textbackslash verbtocs} inside the definition of a macro}.\hfill{}\medskip
But then, how to manipulate special characters and "verbatimize" inside the définition of macros ?\bigskip
-The \verb|\detokenize| primitive of $\varepsilon$-\TeX can be used but it has limitations:
+The \verbinline|\detokenize| primitive of $\varepsilon$-\TeX can be used but it has limitations:
\begin{itemize}
\item braces must be balanced;
\item consecutive spaces make a single space;
@@ -1291,133 +1710,147 @@ The \verb|\detokenize| primitive of $\varepsilon$-\TeX can be used but it has li
\end{itemize}
\medskip
-It is better to use \verb|\scancs| and define \emph{outside the definition of the macros} control sequences containing special characters with \verb|\verbtocs|. It is also possible to use \verb|\tokenize| to transform the final result (which is generaly \texte{10,11,12}) into control sequences. See example using these macros at the end of this manual, page~\pageref{exemples}.\medskip
-
-In the following teaching example\footnote{It is possible to make much more simple using \texttt{\textbackslash detokenize}. The macro becomes:\par\texttt{\textbackslash newcommand\textbackslash bracearg[1]\{\textbackslash detokenize\{\{\#1\}\}\}}}, the macro \verb|\bracearg| adds braces to its argument. To make this possible, 2 control sequences \verb|\Ob| and \verb|\Cb| containing "\verb|{|" and "\verb|}|" are defined outside the definition of \verb|\bracearg|, and expanded inside it:\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \verbtocs{\Ob}|{|
- \verbtocs{\Cb}|}|
- \newcommand\bracearg[1]{%
- \def\text{#1}%
- \scancs*{\result}{\Ob\text\Cb}%
- \result}
- \bracearg{xstring}\par
- \bracearg{\a}
- \end{boxedverbatim}
- \hspace{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+It is better to use \verbinline|\scancs| and define \emph{outside the definition of the macros} control sequences containing special characters with \verbinline|\verbtocs|. It is also possible to use \verbinline|\tokenize| to transform the final result (which is generaly \texte{10,11,12}) into control sequences. See example using these macros at the end of this manual, page~\pageref{exemples}.\medskip
+
+In the following teaching example\footnote{It is possible to make much more simple using \texttt{\textbackslash detokenize}. The macro becomes:\par\texttt{\textbackslash newcommand\textbackslash bracearg[1]\{\textbackslash detokenize\{\{\#1\}\}\}}}, the macro \verb|\bracearg| adds braces to its argument. To make this possible, 2 control sequences \verb|\Ob| and \verb|\Cb| containing "\verb|{|" and "\verb|}|" are defined outside the definition of \verb|\bracearg|, and expanded inside it:\par\nobreak\medskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\verbtocs{\Ob}|{|
+\verbtocs{\Cb}|}|
+\newcommand\bracearg[1]{%
+ \def\text{#1}%
+ \scancs{\result}{\Ob\text\Cb}%
+ \result}
+
+\bracearg{xstring}\par
+\bracearg{\a}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\verbtocs{\Ob}|{|
\verbtocs{\Cb}|}|
\newcommand\bracearg[1]{%
\def\text{#1}%
- \scancs*{\result}{\Ob\text\Cb}%
+ \scancs{\result}{\Ob\text\Cb}%
\result}
+
\bracearg{xstring}\par
\bracearg{\a}
-\end{minipage}
+\end{minipage}%
\subsection{The macro \ttfamily\textbackslash StrRemoveBraces}
Advanced users may need to remove the braces of an argument.
-The macro \verb|\StrRemoveBraces| does this. Its syntax is:\smallskip
+The macro \verbinline|\StrRemoveBraces| does this. Its syntax is:\smallskip
-\verb|\StrRemoveBraces|\ARGU{string}\arguC{name}
+\verbinline|\StrRemoveBraces|\ARGU{string}\arguC{name}
\smallskip
-This macro is sensitive to exploration mode and will remove \emph{all} the braces with \verb|\exploregroups| while it will remove braces of lower level with \verb|\noexploregroups|.\medskip
+This macro is sensitive to exploration mode and will remove \emph{all} the braces with \verbinline|\exploregroups| while it will remove braces of lower level with \verbinline|\noexploregroups|.\medskip
-\exemple|\noexploregroups|
-\exemple|\StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]|
-\exemple|\meaning\mycs|
-\exemple|\exploregroups|
-\exemple|\StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]|
-\exemple|\meaning\mycs|
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
\noexploregroups
+\StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]
+\meaning\mycs
+
+\exploregroups
+\StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]
+\meaning\mycs
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
+ \noexploregroups
+ \StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]
+ \meaning\mycs
+
+ \exploregroups
+ \StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]
+ \meaning\mycs
+\end{minipage}%
+
\subsection{Examples}
\label{exemples}
Here are some very simple examples involving the macros of this package in programming purposes.
\subsubsection{Example 1}
-We want to substitute the 2 first \verb|\textit| by \verb|\textbf| in the control sequence \verb|\myCS| which contains \par\smallskip
-\hfill\verb|\textit{A}\textit{B}\textit{C}|\hfill{}
+We want to substitute the 2 first \verbinline|\textit| by \verbinline|\textbf| in the control sequence \verb|\myCS| which contains \par\smallskip
+\hfill\verbinline|\textit{A}\textit{B}\textit{C}|\hfill{}
\medskip
We expect: \textbf{A}\textbf{B}\textit{C}\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \expandarg
- \def\myCS{\textit{A}\textit{B}\textit{C}}
- \def\pattern{\textit}
- \def\replace{\textbf}
- \StrSubstitute[2]{\myCS}{\pattern}{\replace}
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\expandarg
+\def\myCS{\textit{A}\textit{B}\textit{C}}
+\def\pattern{\textit}
+\def\replace{\textbf}
+\StrSubstitute[2]{\myCS}{\pattern}{\replace}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\expandarg
\def\myCS{\textit{A}\textit{B}\textit{C}}
\def\pattern{\textit}
\def\replace{\textbf}
\StrSubstitute[2]{\myCS}{\pattern}{\replace}
-\end{minipage}\fullexpandarg
+\end{minipage}%
\medskip
-It is possible to avoid to define \verb|\pattern| and \verb|\replace|: a "snare" can be used. It can be a control sequence which expansion is empty, like the famous \verb|\empty|. The code would have been:\par\smallskip
-\hfil\verb|\StrSubstitute[2]{\myCS}{\empty\textit}{\empty\textbf}|\hfil{}\medskip
+It is possible to avoid to define \verb|\pattern| and \verb|\replace|: a "snare" can be used. It can be a control sequence which expansion is empty, like the famous \verbinline|\empty|. The code would have been:\par\nobreak\smallskip
+\hfil\verbinline|\StrSubstitute[2]{\myCS}{\empty\textit}{\empty\textbf}|\hfil{}\medskip
-With this code, in both arguments, the first token \verb|\empty| is expanded to "nothing" and the following significant tokens \verb|\textit| and \verb|textbf| are left unchanged.\smallskip
+With this code, in both arguments, the first token \verbinline|\empty| is expanded to "nothing" and the following significant tokens \verbinline|\textit| and \verbinline|textbf| are left unchanged.\smallskip
-By this way, \verb|\empty| is a way to "hack" \verb|\expandarg|: it allows to avoid the expansion of all the other tokens. The control sequence \verb|\noexpand| can be used instead of \verb|\empty| for the same result.
+By this way, \verbinline|\empty| is a way to "hack" \verbinline|\expandarg|: it allows to avoid the expansion of all the other tokens. The control sequence \verbinline|\noexpand| can be used instead of \verbinline|\empty| for the same result.
\subsubsection{Exemple 2}
Here, we try to write a macro which gobbles \verb|n| \USs in a string from a given position, and assigns the result to a control sequence.
-Let's call this macro \verb|StringDel| and let's give it this syntax:
-
+Let's call this macro \verb|StringDel| and let's give it this syntax:\par\nobreak
\hfil\verb|\StringDel{string}{position}{n}{\name_of_result}|\hfil{}
\medskip
-We can proceed like this: take the string before the position and save it. Then remove \verb|n + position| \USs from the initial string, and add (concatenate) this result to the string previously saved. This gives the following code:\medskip
-
-\begin{minipage}[r]{0.7\linewidth}
- \hfill
- \begin{boxedverbatim}
- \newcommand\StringDel[4]{%
- \begingroup
- \expandarg% local inside this group
- \StrLeft{\empty#1}{\number\numexpr#2-1}[#4]%
- \StrGobbleLeft{\empty#1}{\number\numexpr#2+#3-1}[\StrA]%
- \expandafter\expandafter\expandafter\endgroup
- \expandafter\expandafter\expandafter\def
- \expandafter\expandafter\expandafter#4%
- \expandafter\expandafter\expandafter{\expandafter#4\StrA}%
- }
-
- \noexploregroups
- \StringDel{abcdefgh}{2}{3}{\cmd}
- \meaning\cmd
-
- \StringDel{a\textbf{1}b\textbf{2c}3d}{3}{4}{\cmd}
- \meaning\cmd
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+We can proceed like this: take the string before the position and save it. Then remove \verb|n + position| \USs from the initial string, and add (concatenate) this result to the string previously saved. This gives the following code:\par\nobreak\medskip
+
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\newcommand\StringDel[4]{%
+ \begingroup
+ \expandarg% locally in this group
+ \StrLeft{\empty#1}{\number\numexpr#2-1}[#4]%
+ \StrGobbleLeft{\empty#1}{\numexpr#2+#3-1}[\StrA]%
+ \expandafter\expandafter\expandafter\endgroup
+ \expandafter\expandafter\expandafter\def
+ \expandafter\expandafter\expandafter#4%
+ \expandafter\expandafter\expandafter
+ {\expandafter#4\StrA}%
+}
+
+\noexploregroups
+\StringDel{abcdefgh}{2}{3}{\cmd}
+\meaning\cmd
+
+\StringDel{a\textbf{1}b\textbf{2c}3d}{3}{4}{\cmd}
+\meaning\cmd
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\newcommand\StringDel[4]{%
\begingroup
- \expandarg% local inside this group
+ \expandarg% locally in this group
\StrLeft{\empty#1}{\number\numexpr#2-1}[#4]%
- \StrGobbleLeft{\empty#1}{\number\numexpr#2+#3-1}[\StrA]%
+ \StrGobbleLeft{\empty#1}{\numexpr#2+#3-1}[\StrA]%
\expandafter\expandafter\expandafter\endgroup
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter#4%
\expandafter\expandafter\expandafter{\expandafter#4\StrA}%
- }
+ }
\noexploregroups
\StringDel{abcdefgh}{2}{3}{\cmd}
@@ -1425,69 +1858,66 @@ We can proceed like this: take the string before the position and save it. Then
\StringDel{a\textbf{1}b\textbf{2c}3d}{3}{4}{\cmd}
\meaning\cmd
-\end{minipage}\fullexpandarg
-\bigskip
-
-To concatenate, the \LaTeX{} macro \verb|\g@addto@macro| could have been used, leading to a lighter code without the huge bridge of \verb|\expandafter|. The assignment\footnote{The macro {\ttfamily\string\g@addto@macro} can be used if the catcode of "{\ttfamily\string@}" is temporarily changed with {\ttfamily\string\makeatletter} and restored with {\ttfamily\string\makeatother}} can be written like this:\smallskip
+\end{minipage}%
+\fullexpandarg\bigskip
-\hfil\verb|\expandafter\g@addto@macro\expandafter#4\expandafter{\StrA}\endgroup|\hfil{}
+To concatenate, the \LaTeX{} macro \verb|\g@addto@macro| could have been used, leading to a lighter code without the huge bridge of \verbinline|\expandafter|. The assignment\footnote{The macro {\ttfamily\string\g@addto@macro} can be used if the catcode of "{\ttfamily\string@}" is temporarily changed with {\ttfamily\string\makeatletter} and restored with {\ttfamily\string\makeatother}} can be written like this:\par\nobreak\smallskip
+\hfil\verbinline|\expandafter\g@addto@macro\expandafter#4\expandafter{\StrA}\endgroup|\hfil{}
\subsubsection{Example 3}
Let's try to write a macro \verb|\tofrac| that transforms an argument of this type \guill{a/b} into \guill{$\frac{a}{b}$}.\par\medskip
-First of all, let's cancel the expansion of arguments with \verb|\noexpandarg|, we do not need expansion here. Then, it's easy to cut what is before and behind the first occurrence of \guill{/} (assumed there is a single occurrence) and assign it to \verb|\num| and \verb|\den| and simply call the macro \verb|\frac| :\medskip
-
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \noexpandarg
- \newcommand\tofrac[1]{%
- \StrBefore{#1}{/}[\num]%
- \StrBehind{#1}{/}[\den]%
- $\frac{\num}{\den}$%
- }
- \tofrac{15/9}
- \tofrac{u_{n+1}/u_n}
- \tofrac{a^m/a^n}
- \tofrac{x+\sqrt{x}/\sqrt{x^2+x+1}}
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+First of all, let's cancel the expansion of arguments with \verbinline|\noexpandarg|, we do not need expansion here. Then, it's easy to cut what is before and behind the first occurrence of \guill{/} (assumed there is a single occurrence) and assign it to \verb|\num| and \verb|\den| and simply call the macro \verbinline|\frac| :\par\nobreak\medskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\noexpandarg
+\newcommand\tofrac[1]{%
+ \StrBefore{#1}{/}[\num]%
+ \StrBehind{#1}{/}[\den]%
+ $\frac{\num}{\den}$%
+}
+\tofrac{15/9}
+\tofrac{u_{n+1}/u_n}
+\tofrac{a^m/a^n}
+\tofrac{x+\sqrt{x}/\sqrt{x^2+x+1}}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\noexpandarg
\newcommand\tofrac[1]{%
\StrBefore{#1}{/}[\num]%
\StrBehind{#1}{/}[\den]%
- $\frac{\num}{\den}$}
+ $\frac{\num}{\den}$%
+ }
\tofrac{15/9}
\tofrac{u_{n+1}/u_n}
\tofrac{a^m/a^n}
\tofrac{x+\sqrt{x}/\sqrt{x^2+x+1}}
-\end{minipage}\fullexpandarg
+\end{minipage}%
\subsubsection{Example 4}
Let's try to write a macro \verb|\boldafter| which writes in bold the first word that follows the word contained in the expansion of \verb|\word|.\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \newcommand\boldafter[2]{%
- \noexpandarg
- \StrBehind[1]{#1 }{ #2 }[\word]%
- \expandarg
- \StrBefore{\word}{ }[\word]%
- \StrSubstitute[1]{#1}{\word}{\textbf{\word}}%
- }
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\newcommand\boldafter[2]{%
+ \noexpandarg
+ \StrBehind[1]{#1 }{ #2 }[\word]%
+ \expandarg
+ \StrBefore{\word}{ }[\word]%
+ \StrSubstitute[1]{#1}{\word}{\textbf{\word}}%
+}
- \boldafter{The xstring package is new}{xstring}
+\boldafter{The xstring package is new}{xstring}
- \boldafter{The xstring package is new}{ring}
+\boldafter{The xstring package is new}{ring}
- \boldafter{The xstring package is new}{is}
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+\boldafter{The xstring package is new}{is}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\newcommand\boldafter[2]{%
\noexpandarg
\StrBehind[1]{#1 }{ #2 }[\word]%
@@ -1501,83 +1931,88 @@ Let's try to write a macro \verb|\boldafter| which writes in bold the first word
\boldafter{The xstring package is new}{ring}
\boldafter{The xstring package is new}{is}
-\end{minipage}\fullexpandarg
+\end{minipage}%
+\fullexpandarg
\subsubsection{Example 5}
-A control sequence \verb|\myCS| défined with an \verb|\def| contains control sequences with their possible arguments. How to reverse the order of the 2 first control sequences? For this, a macro \verb|\swaptwofirst| does the job and displays the result. But this time, it is not possible to seek the token \verb|\| (catcode 0) with the macros of \Xstring. This is why the use of \verb|\scancs| is necessary: after the detokenization of the argument, it becomes possible to search the char \verb|\| (catcode 12). After 4 lines, the process made by the macros of \Xstring (\verb|\StrBefore| and \verb|\StrBehind|) is finish, a retokenization is done by \verb|\tokenize| and \verb|\before| and \verb|\after| are swapped at this moment.\medskip
-
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \verbtocs{\antislash}|\|
- \newcommand\swaptwofirst[1]{%
- \fullexpandarg
- \scancs[0]\chaine{#1}%
- \StrBefore[3]{\chaine}{\antislash}[\firsttwo]%
- \StrBehind{\chaine}{\firsttwo}[\others]
- \StrBefore[2]{\firsttwo}{\antislash}[\before]
- \StrBehind{\firsttwo}{\before}[\after]%
- \tokenize\myCS{\after\before\others}%
- \myCS}
-
- \swaptwofirst{\underline{A}\textbf{B}\textit{C}}
-
- \swaptwofirst{\Large\underline{A}\textbf{B}123}
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+How to reverse the order of the 2 first control sequences? For this, a macro \verb|\swaptwofirst| does the job and displays the result. But this time, it is not possible to seek the token \verb|\| (catcode 0) with the macros of \Xstring. This is why the use of \verbinline|\scancs| is necessary: after the detokenization of the argument, it becomes possible to search the char \verb|\| (catcode 12). At line 5, a retokenization is done by \verbinline|\tokenize| and \verb|\before| and \verb|\after| are swapped at this moment.\medskip
+
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\verbtocs{\antislash}|\|
+\newcommand\swaptwofirst[1]{%
+ \begingroup
+ \fullexpandarg
+ \scancs[0]\mystring{#1}%
+ \StrBefore[3]{\mystring}{\antislash}[\firsttwo]%
+ \StrBehind{\mystring}{\firsttwo}[\others]
+ \StrBefore[2]{\firsttwo}{\antislash}[\before]
+ \StrBehind{\firsttwo}{\before}[\after]%
+ \tokenize\myCS{\after\before\others}%
+ \myCS
+ \endgroup
+}
+
+\swaptwofirst{\underline{A}\textbf{B}\textit{C}}
+
+\swaptwofirst{\Large\underline{A}\textbf{B}123}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\verbtocs{\antislash}|\|
\newcommand\swaptwofirst[1]{%
+ \begingroup
\fullexpandarg
- \scancs[0]\chaine{#1}%
- \StrBefore[3]{\chaine}{\antislash}[\firsttwo]%
- \StrBehind{\chaine}{\firsttwo}[\others]
+ \scancs[0]\mystring{#1}%
+ \StrBefore[3]{\mystring}{\antislash}[\firsttwo]%
+ \StrBehind{\mystring}{\firsttwo}[\others]
\StrBefore[2]{\firsttwo}{\antislash}[\before]
\StrBehind{\firsttwo}{\before}[\after]%
\tokenize\myCS{\after\before\others}%
- \myCS}
+ \myCS
+ \endgroup
+ }
\swaptwofirst{\underline{A}\textbf{B}\textit{C}}
\swaptwofirst{\Large\underline{A}\textbf{B}123}
-\end{minipage}
+\end{minipage}%
+
\subsubsection{Example 6}
In a string, we want to find the $n$\th{} word between 2 given delimiters. For this, let's write a macro \verb|\findword| with an optional argument which content is the delimiter (space by default), 1 argument containing the string and an other argument containing the number $n$.\medskip
-The macro \verb|\findword| artfully uses \verb|\StrBetween| and \verb|\numexpr|:\medskip
-
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
+The macro \verb|\findword| artfully uses \verbinline|\StrBetween| and \verbinline|\numexpr|:\par\nobreak\medskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\newcommand\findword[3][ ]{%
+ \StrBetween[#3,\numexpr#3+1]{#1#2#1}{#1}{#1}%
+}
+\noexpandarg
+|\findword{a bc d\textbf{e f} gh}{3}|
+
+|\findword[\nil]{1 \nil 2 3 \nil4\nil5}{2}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\newcommand\findword[3][ ]{%
- \StrBetween[#3,\numexpr#3+1]{#1#2#1}{#1}{#1}}
+ \StrBetween[#3,\numexpr#3+1]{#1#2#1}{#1}{#1}%
+ }
\noexpandarg
- |\findword{a bc d\textit{e f} gh}{3}|
+ |\findword{a bc d\textbf{e f} gh}{3}|
- |\findword[\@nil]{1 \@nil 2 3 \@nil4\@nil5}{2}|
- \end{boxedverbatim}
- \hspace*{0.3cm}
+ |\findword[\nil]{1 \nil 2 3 \nil4\nil5}{2}|
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \newcommand\findword[3][ ]{%
- \StrBetween[#3,\numexpr#3+1]{#1#2#1}{#1}{#1}}
- \noexpandarg
- |\findword{a bc d\textit{e f} gh}{3}|
-
- |\findword[\@nil]{1 \@nil 2 3 \@nil4\@nil5}{2}|
-\end{minipage}
\bigskip\bigskip
\begin{center}
$\star$\par
$\star$\quad$\star$
\end{center}
-\bigskip\bigskip
-
-That's all, I hope you will find this package useful!\par
-Please, send me an \href{mailto:unbonpetit@gmail.com}{email} if you find a bug or if you have any idea of improvement\ldots\medskip
-
+\par\nobreak\bigskip\bigskip
+That's all, I hope you will find this package useful!\par\nobreak
+Please, send me an \href{mailto:unbonpetit@gmail.com}{email} if you find a bug or if you have any idea of improvement\ldots\par\nobreak\medskip
Christian Tellechea
\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/doc/generic/xstring/xstring_doc_fr.pdf b/Master/texmf-dist/doc/generic/xstring/xstring_doc_fr.pdf
index c0e0ed96678..a65c484396f 100644
--- a/Master/texmf-dist/doc/generic/xstring/xstring_doc_fr.pdf
+++ b/Master/texmf-dist/doc/generic/xstring/xstring_doc_fr.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/generic/xstring/xstring_doc_fr.tex b/Master/texmf-dist/doc/generic/xstring/xstring_doc_fr.tex
index 295644470ec..b36d6ea957f 100644
--- a/Master/texmf-dist/doc/generic/xstring/xstring_doc_fr.tex
+++ b/Master/texmf-dist/doc/generic/xstring/xstring_doc_fr.tex
@@ -18,17 +18,67 @@
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
-\usepackage[dvips,colorlinks=true,hyperfootnotes=false,citecolor=black,filecolor=black,linkcolor=blue,urlcolor=blue,bookmarks=false,pdfauthor={Christian TELLECHEA},pdftitle={xstring},pdfsubject={package pour la manipulation de chaines de lexèmes},pdfkeywords={xstring,latex,string,chaine},pdfcreator={LaTeX}]{hyperref}
+\usepackage[a4paper,dvips,colorlinks=true,hyperfootnotes=false,citecolor=black,filecolor=black,linkcolor=blue,urlcolor=blue,bookmarks=false,pdfauthor={Christian TELLECHEA},pdftitle={xstring},pdfsubject={package pour la manipulation de chaines de tokens},pdfkeywords={xstring,latex,tex,string,chaine},pdfcreator={LaTeX}]{hyperref}
\usepackage[a4paper,dvips,margin=1.9cm]{geometry}
\usepackage{amsmath,amssymb,amsfonts,textcomp}
\usepackage{color}
-\usepackage{moreverb}
\usepackage{lmodern}
\usepackage{eurosym}
\usepackage{xspace}
+\usepackage{listings}
\usepackage{xstring}
\usepackage[frenchb]{babel}
\makeatletter
+\definecolor{@xs@bckgcolor}{rgb}{1,1,0.875}
+\definecolor{@xs@keywordsxstring}{rgb}{0.7,0,0}
+\definecolor{@xs@keywordslatex}{rgb}{0,0,1}
+\definecolor{@xs@arguments}{rgb}{0,0,0}
+\definecolor{@xs@comments}{rgb}{0.5,0.5,0.5}
+\definecolor{violet}{rgb}{0.66,0,0.66}
+\lstset{%
+ language=[AlLaTeX]TeX,%
+ morekeywords={numexpr,detokenize},%
+ float=hbp,%
+ basicstyle=\small\ttfamily,%
+ identifierstyle=\color{@xs@arguments},%
+ keywordstyle=\color{@xs@keywordslatex},%
+ commentstyle=\itshape\color{@xs@comments},%
+ columns=fixed,%
+ tabsize=4,%
+ frame=single,%
+ extendedchars=true,%
+ showspaces=false,%
+ showstringspaces=false,%
+ numbers=left,%
+ numberstyle=\tiny\ttfamily,%
+ breaklines=true,%
+ breakindent=3em,%
+ backgroundcolor=\color{@xs@bckgcolor},%
+ breakautoindent=true,%
+ captionpos=t,%
+ xleftmargin=1em,%
+ xrightmargin=1em,%
+ lineskip=0pt,%
+ numbersep=1em,%
+ classoffset=1,%
+ morekeywords={% les macros et commandes de xstring
+ IfSubStr,IfSubStrBefore,IfSubStrBehind,%
+ IfBeginWith,IfEndWith,%
+ IfInteger,IfDecimal,integerpart,decimalpart,%
+ IfStrEq,IfEq,IfStrEqCase,IfEqCase,%
+ StrBefore,StrBehind,StrBetween,%
+ StrSubstitute,StrDel,%
+ StrGobbleLeft,StrGobbleRight,StrRight,StrLeft,StrMid,StrChar,%
+ StrSplit,%
+ StrLen,StrCount,StrPosition,StrCompare,%
+ StrFindGroup,groupID,verbtocs,tokenize,scancs,StrExpand,StrRemoveBraces,%
+ exploregroups,noexploregroups,saveexploremode,restoreexploremode,%
+ comparenormal,comparestrict,savecomparemode,restorecomparemode,%
+ expandarg,noexpandarg,normalexpandarg,fullexpandarg,saveexpandmode,restoreexpandmode,%
+ expandingroups,noexpandingroups,%
+ setverbdelim},%
+ keywordstyle=\color{@xs@keywordsxstring},%
+ classoffset=0}
% redéfinition de l'écriture des textes des footnote
\long\def\@makefntextFB#1{%
\ifx\thefootnote\ftnISsymbol
@@ -39,16 +89,10 @@
\ifdim\wd\@tempboxa>\z@
\kern2em\llap{\@thefnmark.\kern0.5em}%
\fi
- \begingroup\advance\hsize-2em\vtop{#1}\endgroup%
+ \begingroup\advance\hsize-2em\vtop{#1}\endgroup
\fi}
-
-\newcommand*\exemple{\@ifstar{\let\frontiere\textbar\@xs@MakeVerb}{\let\frontiere\@empty\@xs@MakeVerb}}
-\def\@xs@afterreadverb#1{%
- \normalexpandarg
- \tokenize\cs@resultat{#1}%
- \fullexpandarg
- \leavevmode\hbox to0.7\linewidth{\hfil\tt#1}\quad\frontiere\cs@resultat\frontiere\hfil\par}
\makeatother
+
\newcommand\guill[1]{\og{}#1\fg{}}
\newcommand\argu[1]{$\langle$\textit{#1}$\rangle$}
\newcommand\ARGU[1]{\texttt{\color{black}\{}\argu{#1}\texttt{\color{black}\}}}
@@ -64,9 +108,14 @@
\setlength{\topsep}{2ptplus3ptminus2pt}
}}%
{\end{list}}
+
\newcommand\US{unité syntaxique\xspace}
\newcommand\USs{unités syntaxiques\xspace}
\newcommand\Xstring{\textsf{xstring}\xspace}
+\newcommand\styleexemple{\small\vskip4pt}
+\newcommand\styleexercice{\footnotesize}
+\newcommand\verbinline{\lstinline[basicstyle=\normalsize\ttfamily]}
+\newcommand\colorise{\color{violet}}
\begin{document}
\setlength{\parindent}{0pt}
@@ -92,8 +141,9 @@
\begin{minipage}{0.85\linewidth}
\noindent
\hfill\textbf{\textit{Résumé}}\hfill{}\medskip\par
- Cette extension, qui requiert Plain $\varepsilon$-\TeX, regroupe un ensemble de macros manipulant des chaînes de lexèmes (tokens en anglais). Les macros peuvent être utilisées de façon basique dans le traitement des chaînes de caractères mais peuvent également être utiles en programmation \TeX{} pour la manipulation des lexèmes, c'est-à-dire du code \TeX{}. Parmis les fonctionnalités, les principales sont :
- \setlength{\parindent}{1.5em}
+ Cette extension, qui requiert Plain $\varepsilon$-\TeX, regroupe un ensemble de macros manipulant des chaînes de tokens (ou lexèmes en français). Les macros peuvent être utilisées de façon basique dans le traitement des chaînes de caractères mais peuvent également être utiles en programmation \TeX{} pour la manipulation des tokens, c'est-à-dire du code \TeX{}. Parmis les fonctionnalités, les principales sont :\smallskip
+
+ \parindent1.5em
\begin{itemize}
\item[$\triangleright$] des tests :
\begin{itemize}
@@ -121,7 +171,7 @@
\end{itemize}
\setlength{\parindent}{0pt}
\medskip
- D'autres commandes permettent de gérer les lexèmes spéciaux normalement interdits dans les chaînes (\verb|#| et \verb|%|), ainsi que d'éventuelles différences entre catcodes de lexèmes, ce qui devrait permettre de couvrir tous les besoins en matière de programmation.
+ D'autres commandes permettent de gérer les tokens spéciaux normalement interdits dans les chaînes (\verb|#| et \verb|%|), ainsi que d'éventuelles différences entre catcodes de tokens, ce qui devrait permettre de couvrir tous les besoins en matière de programmation.
\end{minipage}
\end{center}
\hrulefill\vfill{}
@@ -131,27 +181,25 @@
\section{Présentation}
\subsection{Description}
-Cette extension\footnote{L'extension ne nécessite pas \LaTeX{} et peut être compilée sous Plain $\varepsilon$-\TeX{}.} regroupe des macros et des tests opérant sur des chaînes de lexèmes, un peu comme en disposent des langages dit \guill{évolués}. On y trouve les opérations habituelles sur les chaînes, comme par exemple : test si une chaîne en contient une autre, commence ou finit par une autre, test si une chaîne est un nombre entier ou décimal, extractions de sous-chaînes, calculs de position d'une sous-chaîne, calculs du nombre d'occurrences, etc.\medskip
+Cette extension\footnote{L'extension ne nécessite pas \LaTeX{} et peut être compilée sous Plain $\varepsilon$-\TeX{}.} regroupe des macros et des tests opérant sur des chaînes de tokens, un peu comme en disposent des langages dit \guill{évolués}. On y trouve les opérations habituelles sur les chaînes, comme par exemple : test si une chaîne en contient une autre, commence ou finit par une autre, test si une chaîne est un nombre entier ou décimal, extractions de sous-chaînes, calculs de position d'une sous-chaîne, calculs du nombre d'occurrences, etc.\medskip
-Les arguments contenant des chaînes de lexèmes sont lus par \Xstring \emph{\US par \US\footnote{Sauf cas particulier, une \US est un caractère lu dans le code à ces exceptions près : une séquence de contrôle est une \US, un groupe entre accolades est aussi une \US. Voir également page~\pageref{developpementarguments}.}}, ce qui revient à les lire caractère par caractère lorsque ceux-ci contiennent des lexèmes \guill{normaux}, c'est-à-dire dont les catcodes sont 10, 11 et 12. On peut également utiliser \Xstring à des fins de programmation en utilisant des arguments contenant des séquences de contrôle et des lexèmes dont les catcodes sont moins inoffensifs. Voir le chapitre sur le mode de lecture et de développement des arguments (page~\pageref{developpementarguments}), la commande \verb|\verbtocs| (page~\pageref{verbtocs}), la commande \verb|\scancs| (page~\pageref{scancs}).\medskip
+Les arguments contenant des chaînes de tokens sont lus par \Xstring \emph{\US par \US\footnote{Sauf cas particulier, une \US est un caractère lu dans le code à ces exceptions près : une séquence de contrôle est une \US, un groupe entre accolades est aussi une \US. Voir également page~\pageref{developpementarguments}.}}, ce qui revient à les lire caractère par caractère lorsque ceux-ci contiennent des tokens \guill{normaux}, c'est-à-dire dont les catcodes sont 10, 11 et 12. On peut également utiliser \Xstring à des fins de programmation en utilisant des arguments contenant des séquences de contrôle et des tokens dont les catcodes sont moins inoffensifs. Voir le chapitre sur le mode de lecture et de développement des arguments (page~\pageref{developpementarguments}), la commande \verbinline|\verbtocs| (page~\pageref{verbtocs}), la commande \verbinline|\scancs| (page~\pageref{scancs}).\medskip
Certes d'autres packages manipulant les chaînes de caractères existent (par exemple \href{http://www.ctan.org/tex-archive/macros/latex/contrib/substr/}{\nolinkurl{substr}} et \href{http://www.ctan.org/tex-archive/macros/latex/contrib/stringstrings/}{\nolinkurl{stringstrings}}), mais outre des différences notables quant aux fonctionnalités, ils ne prennent pas en charge les occurrences des sous-chaînes et me semblent soit trop limités, soit trop difficiles à utiliser pour la programmation.\medskip
-Comme les macros manipulent des chaînes de lexèmes, il peut arriver aux utilisateurs avancés de rencontrer des problèmes de \guill{catcodes\footnote{Codes de catégories, en français.}} conduisant à des comportement inattendus. Ces effets indésirables peuvent être contrôlés. Consulter en particulier le chapitre sur les catcodes des arguments page~\pageref{macrosetoilees}.
+Comme les macros manipulent des chaînes de tokens, il peut arriver aux utilisateurs avancés de rencontrer des problèmes de \guill{catcodes\footnote{Codes de catégories, en français.}} conduisant à des comportement inattendus. Ces effets indésirables peuvent être contrôlés. Consulter en particulier le chapitre sur les catcodes des arguments page~\pageref{macrosetoilees}.
\subsection{Motivation}
J'ai été conduit à écrire ce type de macros car je n'ai jamais vraiment trouvé de d'outils sous \LaTeX{} adaptés à mes besoins concernant le traitement de chaînes. Alors, au fil des mois, et avec l'aide de contributeurs\footnote{Je remercie chaleureusement Manuel alias \guill{\nolinkurl{mpg}} pour son aide précieuse, sa compétence et sa disponibilité.} de \nolinkurl{fr.comp.text.tex}, j'ai écrit quelques macros qui me servaient ponctuellement ou régulièrement. Leur nombre s'étant accru, et celles-ci devenant un peu trop dispersées dans les répertoires de mon ordinateur, je les ai regroupées dans ce package.
-Ainsi, le fait de donner corps à un ensemble cohérent de macros force à davantage de rigueur et induit naturellement de nécessaires améliorations, ce qui a pris la majeure partie du temps que j'ai consacré à ce package. Pour harmoniser le tout, mais à contre-c\oe{}ur, j'ai fini par choisir des noms de macros à consonances anglo-saxonnes.\medskip
+Ainsi, le fait de donner corps à un ensemble cohérent de macros force à davantage de rigueur et induit naturellement de nécessaires améliorations, ce qui a pris la majeure partie du temps que j'ai consacré à ce package. Pour harmoniser le tout, mais à contre-cœur, j'ai fini par choisir des noms de macros à consonances anglo-saxonnes.\medskip
Ensuite, et cela a été ma principale motivation puisque j'ai découvert \LaTeX{} récemment\footnote{En novembre 2007, je suis donc un \og noob\fg{} pour longtemps encore !}, l'écriture de \Xstring qui est mon premier package m'a surtout permis de beaucoup progresser en programmation pure, et aborder des méthodes propres à la programmation sous \TeX.
\section{Les macros}
-\subsection{Présentation des macros}
-Pour bien comprendre les actions de chaque macro, envisageons tout d'abord le fonctionnement et la présentation des macros dans leur mode de fonctionnement le plus simple. Pas de problème de catcode ici, ni de lexèmes spéciaux et encore moins de séquence de contrôle dans les arguments : les arguments contiendront des caractères alphanumériques.\medskip
-
-Dans ce chapitre, la totalité des macros est présentée selon ce plan :\smallskip
+Pour bien comprendre les actions de chaque macro, envisageons tout d'abord le fonctionnement et la présentation des macros dans leur mode de fonctionnement le plus simple. Pas de problème de catcode ici, ni de tokens spéciaux et encore moins de séquence de contrôle dans les arguments : les arguments contiendront des caractères alphanumériques.\medskip
+Dans ce chapitre, la totalité des macros est présentée selon ce plan :\par\nobreak\smallskip
\parindent3em
\begin{itemize}
\item la syntaxe complète\footnote{L'étoile optionnelle après le nom de la macro, et l'argument optionnel entre crochet venant en dernier seront expliqués plus tard. Voir page~\pageref{macrosetoilees} pour les macros étoilées et page~\pageref{argumentoptionnel} pour l'argument optionnel en dernière position.} ainsi que la valeur d'éventuels arguments optionnels;
@@ -161,15 +209,16 @@ Dans ce chapitre, la totalité des macros est présentée selon ce plan :\smalls
\end{itemize}
\parindent0pt\smallskip
-\textbf{Important} : dans les macros qui suivent, sauf cas spécifié, un \argu{nombre} est un nombre entier, un compteur, ou le résultat d'une opération arithmétique effectuée à l'aide de la primitive \verb|\numexpr|.
+\textbf{Important} : dans les macros qui suivent, sauf cas spécifié, un \argu{nombre} est un nombre entier, un compteur, ou le résultat d'une opération arithmétique effectuée à l'aide de la primitive \verb|\numexpr|.\smallskip
+
+Dans le reste du texte, les macros de \Xstring sont affichées en {\makeatletter\color{@xs@keywordsxstring}rouge}.
+
\subsection{Les tests}
\subsubsection{\ttfamily\textbackslash IfSubStr}
-\verb|\IfSubStr|\etoile\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\ARGU{vrai}\ARGU{faux}
-\smallskip
-
-L'argument optionnel \argu{nombre} vaut 1 par défaut.\par
+\verbinline|\IfSubStr|\etoile\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\ARGU{vrai}\ARGU{faux}
\smallskip
+L'argument optionnel \argu{nombre} vaut 1 par défaut.\par\nobreak\smallskip
Teste si \argu{chaine} contient au moins \argu{nombre} fois \argu{chaineA} et exécute \argu{vrai} dans l'affirmative, et \argu{faux} dans le cas contraire.\medskip
\begin{Conditions}
@@ -177,20 +226,33 @@ Teste si \argu{chaine} contient au moins \argu{nombre} fois \argu{chaineA} et ex
\item Si \argu{chaine} ou \argu{chaineA} est vide, exécute \argu{faux}.
\end{Conditions}
-\exemple|\IfSubStr{xstring}{tri}{vrai}{faux}|
-\exemple|\IfSubStr{xstring}{a}{vrai}{faux}|
-\exemple|\IfSubStr{a bc def }{c d}{vrai}{faux}|
-\exemple|\IfSubStr{a bc def }{cd}{vrai}{faux}|
-\exemple|\IfSubStr[2]{1a2a3a}{a}{vrai}{faux}|
-\exemple|\IfSubStr[3]{1a2a3a}{a}{vrai}{faux}|
-\exemple|\IfSubStr[4]{1a2a3a}{a}{vrai}{faux}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfSubStr{xstring}{tri}{vrai}{faux}
+\IfSubStr{xstring}{a}{vrai}{faux}
+\IfSubStr{a bc def }{c d}{vrai}{faux}
+\IfSubStr{a bc def }{cd}{vrai}{faux}
+\IfSubStr[2]{1a2a3a}{a}{vrai}{faux}
+\IfSubStr[3]{1a2a3a}{a}{vrai}{faux}
+\IfSubStr[4]{1a2a3a}{a}{vrai}{faux}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfSubStr{xstring}{tri}{vrai}{faux}\par
+ \IfSubStr{xstring}{a}{vrai}{faux}\par
+ \IfSubStr{a bc def }{c d}{vrai}{faux}\par
+ \IfSubStr{a bc def }{cd}{vrai}{faux}\par
+ \IfSubStr[2]{1a2a3a}{a}{vrai}{faux}\par
+ \IfSubStr[3]{1a2a3a}{a}{vrai}{faux}\par
+ \IfSubStr[4]{1a2a3a}{a}{vrai}{faux}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfSubStrBefore}
-\verb|\IfSubStrBefore|\etoile\arguCC{nombre1}{nombre2}\ARGU{chaine}\ARGU{chaineA}\ARGU{chaineB}\ARGU{vrai}\ARGU{faux}
+\verbinline|\IfSubStrBefore|\etoile\arguCC{nombre1}{nombre2}\ARGU{chaine}\ARGU{chaineA}\ARGU{chaineB}\ARGU{vrai}\ARGU{faux}
\smallskip
-Les arguments optionnels \argu{nombre1} et \argu{nombre2} valent 1 par défaut.\par\smallskip
-
+Les arguments optionnels \argu{nombre1} et \argu{nombre2} valent 1 par défaut.\par\nobreak\smallskip
Dans \argu{chaine}, la macro teste si l'occurrence \no\argu{nombre1} de \argu{chaineA} se trouve à gauche de l'occurrence \no\argu{nombre2} de \argu{chaineB}. Exécute \argu{vrai} dans l'affirmative, et \argu{faux} dans le cas contraire.\medskip
\begin{Conditions}
@@ -199,22 +261,37 @@ Dans \argu{chaine}, la macro teste si l'occurrence \no\argu{nombre1} de \argu{ch
\item Si l'un au moins des deux arguments optionnels est négatif ou nul, exécute \argu{faux}.
\end{Conditions}
-\exemple|\IfSubStrBefore{xstring}{st}{in}{vrai}{faux}|
-\exemple|\IfSubStrBefore{xstring}{ri}{s}{vrai}{faux}|
-\exemple|\IfSubStrBefore{LaTeX}{LaT}{TeX}{vrai}{faux}|
-\exemple|\IfSubStrBefore{a bc def }{ b}{ef}{vrai}{faux}|
-\exemple|\IfSubStrBefore{a bc def }{ab}{ef}{vrai}{faux}|
-\exemple|\IfSubStrBefore[2,1]{b1b2b3}{b}{2}{vrai}{faux}|
-\exemple|\IfSubStrBefore[3,1]{b1b2b3}{b}{2}{vrai}{faux}|
-\exemple|\IfSubStrBefore[2,2]{baobab}{a}{b}{vrai}{faux}|
-\exemple|\IfSubStrBefore[2,3]{baobab}{a}{b}{vrai}{faux}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfSubStrBefore{xstring}{st}{in}{vrai}{faux}
+\IfSubStrBefore{xstring}{ri}{s}{vrai}{faux}
+\IfSubStrBefore{LaTeX}{LaT}{TeX}{vrai}{faux}
+\IfSubStrBefore{a bc def }{ b}{ef}{vrai}{faux}
+\IfSubStrBefore{a bc def }{ab}{ef}{vrai}{faux}
+\IfSubStrBefore[2,1]{b1b2b3}{b}{2}{vrai}{faux}
+\IfSubStrBefore[3,1]{b1b2b3}{b}{2}{vrai}{faux}
+\IfSubStrBefore[2,2]{baobab}{a}{b}{vrai}{faux}
+\IfSubStrBefore[2,3]{baobab}{a}{b}{vrai}{faux}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfSubStrBefore{xstring}{st}{in}{vrai}{faux}\par
+ \IfSubStrBefore{xstring}{ri}{s}{vrai}{faux}\par
+ \IfSubStrBefore{LaTeX}{LaT}{TeX}{vrai}{faux}\par
+ \IfSubStrBefore{a bc def }{ b}{ef}{vrai}{faux}\par
+ \IfSubStrBefore{a bc def }{ab}{ef}{vrai}{faux}\par
+ \IfSubStrBefore[2,1]{b1b2b3}{b}{2}{vrai}{faux}\par
+ \IfSubStrBefore[3,1]{b1b2b3}{b}{2}{vrai}{faux}\par
+ \IfSubStrBefore[2,2]{baobab}{a}{b}{vrai}{faux}\par
+ \IfSubStrBefore[2,3]{baobab}{a}{b}{vrai}{faux}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfSubStrBehind}
-\verb|\IfSubStrBehind|\etoile\arguCC{nombre1}{nombre2}\ARGU{chaine}\ARGU{chaineA}\ARGU{chaineB}\ARGU{vrai}\ARGU{faux}
+\verbinline|\IfSubStrBehind|\etoile\arguCC{nombre1}{nombre2}\ARGU{chaine}\ARGU{chaineA}\ARGU{chaineB}\ARGU{vrai}\ARGU{faux}
\smallskip
-Les arguments optionnels \argu{nombre1} et \argu{nombre2} valent 1 par défaut.\par\smallskip
-
+Les arguments optionnels \argu{nombre1} et \argu{nombre2} valent 1 par défaut.\par\nobreak\smallskip
Dans \argu{chaine}, la macro teste si l'occurrence \no\argu{nombre1} de \argu{chaineA} se trouve après l'occurrence \\\no\argu{nombre2} de \argu{chaineB}. Exécute \argu{vrai} dans l'affirmative, et \argu{faux} dans le cas contraire.\medskip
\begin{Conditions}
@@ -223,19 +300,34 @@ Dans \argu{chaine}, la macro teste si l'occurrence \no\argu{nombre1} de \argu{ch
\item Si l'un au moins des deux arguments optionnels est négatif ou nul, exécute \argu{faux}.
\end{Conditions}
-\exemple|\IfSubStrBehind{xstring}{ri}{xs}{vrai}{faux}|
-\exemple|\IfSubStrBehind{xstring}{s}{i}{vrai}{faux}|
-\exemple|\IfSubStrBehind{LaTeX}{TeX}{LaT}{vrai}{faux}|
-\exemple|\IfSubStrBehind{a bc def }{ d}{a}{vrai}{faux}|
-\exemple|\IfSubStrBehind{a bc def }{cd}{a b}{vrai}{faux}|
-\exemple|\IfSubStrBehind[2,1]{b1b2b3}{b}{2}{vrai}{faux}|
-\exemple|\IfSubStrBehind[3,1]{b1b2b3}{b}{2}{vrai}{faux}|
-\exemple|\IfSubStrBehind[2,2]{baobab}{b}{a}{vrai}{faux}|
-\exemple|\IfSubStrBehind[2,3]{baobab}{b}{a}{vrai}{faux}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfSubStrBehind{xstring}{ri}{xs}{vrai}{faux}
+\IfSubStrBehind{xstring}{s}{i}{vrai}{faux}
+\IfSubStrBehind{LaTeX}{TeX}{LaT}{vrai}{faux}
+\IfSubStrBehind{a bc def }{ d}{a}{vrai}{faux}
+\IfSubStrBehind{a bc def }{cd}{a b}{vrai}{faux}
+\IfSubStrBehind[2,1]{b1b2b3}{b}{2}{vrai}{faux}
+\IfSubStrBehind[3,1]{b1b2b3}{b}{2}{vrai}{faux}
+\IfSubStrBehind[2,2]{baobab}{b}{a}{vrai}{faux}
+\IfSubStrBehind[2,3]{baobab}{b}{a}{vrai}{faux}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfSubStrBehind{xstring}{ri}{xs}{vrai}{faux}\par
+ \IfSubStrBehind{xstring}{s}{i}{vrai}{faux}\par
+ \IfSubStrBehind{LaTeX}{TeX}{LaT}{vrai}{faux}\par
+ \IfSubStrBehind{a bc def }{ d}{a}{vrai}{faux}\par
+ \IfSubStrBehind{a bc def }{cd}{a b}{vrai}{faux}\par
+ \IfSubStrBehind[2,1]{b1b2b3}{b}{2}{vrai}{faux}\par
+ \IfSubStrBehind[3,1]{b1b2b3}{b}{2}{vrai}{faux}\par
+ \IfSubStrBehind[2,2]{baobab}{b}{a}{vrai}{faux}\par
+ \IfSubStrBehind[2,3]{baobab}{b}{a}{vrai}{faux}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfBeginWith}
-
-\verb|\IfBeginWith|\etoile\ARGU{chaine}\ARGU{chaineA}\ARGU{vrai}\ARGU{faux}
+\verbinline|\IfBeginWith|\etoile\ARGU{chaine}\ARGU{chaineA}\ARGU{vrai}\ARGU{faux}
\smallskip
Teste si \argu{chaine} commence par \argu{chaineA}, et exécute \argu{vrai} dans l'affirmative, et \argu{faux} dans le cas contraire.\medskip
@@ -244,14 +336,24 @@ Teste si \argu{chaine} commence par \argu{chaineA}, et exécute \argu{vrai} dans
\item Si \argu{chaine} ou \argu{chaineA} est vide, exécute \argu{faux}.
\end{Conditions}
-\exemple|\IfBeginWith{xstring}{xst}{vrai}{faux}|
-\exemple|\IfBeginWith{LaTeX}{a}{vrai}{faux}|
-\exemple|\IfBeginWith{a bc def }{a b}{vrai}{faux}|
-\exemple|\IfBeginWith{a bc def }{ab}{vrai}{faux}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfBeginWith{xstring}{xst}{vrai}{faux}
+\IfBeginWith{LaTeX}{a}{vrai}{faux}
+\IfBeginWith{a bc def }{a b}{vrai}{faux}
+\IfBeginWith{a bc def }{ab}{vrai}{faux}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfBeginWith{xstring}{xst}{vrai}{faux}\par
+ \IfBeginWith{LaTeX}{a}{vrai}{faux}\par
+ \IfBeginWith{a bc def }{a b}{vrai}{faux}\par
+ \IfBeginWith{a bc def }{ab}{vrai}{faux}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfEndWith}
-
-\verb|\IfEndWith|\etoile\ARGU{chaine}\ARGU{chaineA}\ARGU{vrai}\ARGU{faux}
+\verbinline|\IfEndWith|\etoile\ARGU{chaine}\ARGU{chaineA}\ARGU{vrai}\ARGU{faux}
\smallskip
Teste si \argu{chaine} se termine par \argu{chaineA}, et exécute \argu{vrai} dans l'affirmative, et \argu{faux} dans le cas contraire.\medskip
@@ -260,109 +362,189 @@ Teste si \argu{chaine} se termine par \argu{chaineA}, et exécute \argu{vrai} da
\item Si \argu{chaine} ou \argu{chaineA} est vide, exécute \argu{faux}.
\end{Conditions}
-\exemple|\IfEndWith{xstring}{ring}{vrai}{faux}|
-\exemple|\IfEndWith{LaTeX}{a}{vrai}{faux}|
-\exemple|\IfEndWith{a bc def }{ef }{vrai}{faux}|
-\exemple|\IfEndWith{a bc def }{ef}{vrai}{faux}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfEndWith{xstring}{ring}{vrai}{faux}
+\IfEndWith{LaTeX}{a}{vrai}{faux}
+\IfEndWith{a bc def }{ef }{vrai}{faux}
+\IfEndWith{a bc def }{ef}{vrai}{faux}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfEndWith{xstring}{ring}{vrai}{faux}\par
+ \IfEndWith{LaTeX}{a}{vrai}{faux}\par
+ \IfEndWith{a bc def }{ef }{vrai}{faux}\par
+ \IfEndWith{a bc def }{ef}{vrai}{faux}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfInteger}
-
-\verb|\IfInteger|\ARGU{nombre}\ARGU{vrai}\ARGU{faux}
+\verbinline|\IfInteger|\ARGU{nombre}\ARGU{vrai}\ARGU{faux}
\smallskip
-Teste si \argu{nombre} est un nombre entier relatif, et exécute \argu{vrai} dans l'affirmative, et \argu{faux} dans le cas contraire.\smallskip
-
+Teste si \argu{nombre} est un nombre entier relatif (c'est-à-dire dont la partie décimale est absente ou constituée d'une suite de 0), et exécute \argu{vrai} dans l'affirmative, et \argu{faux} dans le cas contraire.\par\nobreak\smallskip
Si le test est faux pour cause de caractères non autorisés, la séquence de contrôle \verb|\@xs@afterinteger| contient la partie illégale de \argu{nombre}.\medskip
-\exemple|\IfInteger{13}{vrai}{faux}|
-\exemple|\IfInteger{-219}{vrai}{faux}|
-\exemple|\IfInteger{+9}{vrai}{faux}|
-\exemple|\IfInteger{3.14}{vrai}{faux}|
-\exemple|\IfInteger{0}{vrai}{faux}|
-\exemple|\IfInteger{49a}{vrai}{faux}|
-\exemple|\IfInteger{+}{vrai}{faux}|
-\exemple|\IfInteger{-}{vrai}{faux}|
-\exemple|\IfInteger{0000}{vrai}{faux}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfInteger{13}{vrai}{faux}
+\IfInteger{-219}{vrai}{faux}
+\IfInteger{+9}{vrai}{faux}
+\IfInteger{3.14}{vrai}{faux}
+\IfInteger{8.0}{vrai}{faux}
+\IfInteger{0}{vrai}{faux}
+\IfInteger{49a}{vrai}{faux}
+\IfInteger{+}{vrai}{faux}
+\IfInteger{-}{vrai}{faux}
+\IfInteger{0000}{vrai}{faux}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfInteger{13}{vrai}{faux}\par
+ \IfInteger{-219}{vrai}{faux}\par
+ \IfInteger{+9}{vrai}{faux}\par
+ \IfInteger{3.14}{vrai}{faux}\par
+ \IfInteger{8.0}{vrai}{faux}\par
+ \IfInteger{0}{vrai}{faux}\par
+ \IfInteger{49a}{vrai}{faux}\par
+ \IfInteger{+}{vrai}{faux}\par
+ \IfInteger{-}{vrai}{faux}\par
+ \IfInteger{0000}{vrai}{faux}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfDecimal}
\label{ifdecimal}
-\verb|\IfDecimal|\ARGU{nombre}\ARGU{vrai}\ARGU{faux}
+\verbinline|\IfDecimal|\ARGU{nombre}\ARGU{vrai}\ARGU{faux}
\smallskip
-Teste si \argu{nombre} est un nombre décimal, et exécute \argu{vrai} dans l'affirmative, et \argu{faux} dans le cas contraire.\smallskip
-
+Teste si \argu{nombre} est un nombre décimal, et exécute \argu{vrai} dans l'affirmative, et \argu{faux} dans le cas contraire.\par\nobreak\smallskip
Les compteurs \verb|\integerpart| et \verb|\decimalpart| contiennent les parties entières et décimales de \argu{nombre}.
Si le test est faux pour cause de caractères non autorisés, la séquence de contrôle \verb|\@xs@afterdecimal| contient la partie illégale de \argu{nombre}, alors que si le test est faux parce que la partie décimale après le séparateur décimal est vide, elle contient \guill{X}.\medskip
\begin{Conditions}
\item Le séparateur décimal peut être un point ou une virgule;
- \item Si ce qui se trouve à droite du séparateur décimal s'il est présent est vide, le test est faux;
- \item Si ce qui se trouve à gauche du séparateur décimal s'il est présent est vide, la partie entière est considérée comme étant 0.
+ \item Si le \argu{nombre} commence par un séparateur décimal, le test est vrai (lignes 4 et 5) et la partie entière est considérée comme étant 0;
+ \item Si le \argu{nombre} se termine par un séparateur décimal, le test est faux (lignes 9 et 10).
\end{Conditions}
-\exemple|\IfDecimal{3.14}{vrai}{faux}|
-\exemple|\IfDecimal{3,14}{vrai}{faux}|
-\exemple|\IfDecimal{-0.5}{vrai}{faux}|
-\exemple|\IfDecimal{.7}{vrai}{faux}|
-\exemple|\IfDecimal{,9}{vrai}{faux}|
-\exemple|\IfDecimal{1..2}{vrai}{faux}|
-\exemple|\IfDecimal{+6}{vrai}{faux}|
-\exemple|\IfDecimal{-15}{vrai}{faux}|
-\exemple|\IfDecimal{1.}{vrai}{faux}|
-\exemple|\IfDecimal{2,}{vrai}{faux}|
-\exemple|\IfDecimal{.}{vrai}{faux}|
-\exemple|\IfDecimal{,}{vrai}{faux}|
-\exemple|\IfDecimal{+}{vrai}{faux}|
-\exemple|\IfDecimal{-}{vrai}{faux}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfDecimal{3.14}{vrai}{faux}
+\IfDecimal{3,14}{vrai}{faux}
+\IfDecimal{-0.5}{vrai}{faux}
+\IfDecimal{.7}{vrai}{faux}
+\IfDecimal{,9}{vrai}{faux}
+\IfDecimal{1..2}{vrai}{faux}
+\IfDecimal{+6}{vrai}{faux}
+\IfDecimal{-15}{vrai}{faux}
+\IfDecimal{1.}{vrai}{faux}
+\IfDecimal{2,}{vrai}{faux}
+\IfDecimal{.}{vrai}{faux}
+\IfDecimal{,}{vrai}{faux}
+\IfDecimal{+}{vrai}{faux}
+\IfDecimal{-}{vrai}{faux}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfDecimal{3.14}{vrai}{faux}\par
+ \IfDecimal{3,14}{vrai}{faux}\par
+ \IfDecimal{-0.5}{vrai}{faux}\par
+ \IfDecimal{.7}{vrai}{faux}\par
+ \IfDecimal{,9}{vrai}{faux}\par
+ \IfDecimal{1..2}{vrai}{faux}\par
+ \IfDecimal{+6}{vrai}{faux}\par
+ \IfDecimal{-15}{vrai}{faux}\par
+ \IfDecimal{1.}{vrai}{faux}\par
+ \IfDecimal{2,}{vrai}{faux}\par
+ \IfDecimal{.}{vrai}{faux}\par
+ \IfDecimal{,}{vrai}{faux}\par
+ \IfDecimal{+}{vrai}{faux}\par
+ \IfDecimal{-}{vrai}{faux}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfStrEq}
-\verb|\IfStrEq|\etoile\ARGU{chaineA}\ARGU{chaineB}\ARGU{vrai}\ARGU{faux}
+\verbinline|\IfStrEq|\etoile\ARGU{chaineA}\ARGU{chaineB}\ARGU{vrai}\ARGU{faux}
\smallskip
Teste si les chaînes \argu{chaineA} et \argu{chaineB} sont égales, c'est-à-dire si elles contiennent successivement les mêmes \US dans le même ordre. Exécute \argu{vrai} dans l'affirmative, et \argu{faux} dans le cas contraire.\smallskip
-\exemple|\IfStrEq{a1b2c3}{a1b2c3}{vrai}{faux}|
-\exemple|\IfStrEq{abcdef}{abcd}{vrai}{faux}|
-\exemple|\IfStrEq{abc}{abcdef}{vrai}{faux}|
-\exemple|\IfStrEq{3,14}{3,14}{vrai}{faux}|
-\exemple|\IfStrEq{12.34}{12.340}{vrai}{faux}|
-\exemple|\IfStrEq{abc}{}{vrai}{faux}|
-\exemple|\IfStrEq{}{abc}{vrai}{faux}|
-\exemple|\IfStrEq{}{}{vrai}{faux}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfStrEq{a1b2c3}{a1b2c3}{vrai}{faux}
+\IfStrEq{abcdef}{abcd}{vrai}{faux}
+\IfStrEq{abc}{abcdef}{vrai}{faux}
+\IfStrEq{3,14}{3,14}{vrai}{faux}
+\IfStrEq{12.34}{12.340}{vrai}{faux}
+\IfStrEq{abc}{}{vrai}{faux}
+\IfStrEq{}{abc}{vrai}{faux}
+\IfStrEq{}{}{vrai}{faux}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfStrEq{a1b2c3}{a1b2c3}{vrai}{faux}\par
+ \IfStrEq{abcdef}{abcd}{vrai}{faux}\par
+ \IfStrEq{abc}{abcdef}{vrai}{faux}\par
+ \IfStrEq{3,14}{3,14}{vrai}{faux}\par
+ \IfStrEq{12.34}{12.340}{vrai}{faux}\par
+ \IfStrEq{abc}{}{vrai}{faux}\par
+ \IfStrEq{}{abc}{vrai}{faux}\par
+ \IfStrEq{}{}{vrai}{faux}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfEq}
-
-\verb|\IfEq|\etoile\ARGU{chaineA}\ARGU{chaineB}\ARGU{vrai}\ARGU{faux}
+\verbinline|\IfEq|\etoile\ARGU{chaineA}\ARGU{chaineB}\ARGU{vrai}\ARGU{faux}
\smallskip
Teste si les chaînes \argu{chaineA} et \argu{chaineB} sont égales, \emph{sauf} si \argu{chaineA} et \argu{chaineB} contiennent des nombres, auquel cas la macro teste si les nombres sont égaux. Exécute \argu{vrai} dans l'affirmative, et \argu{faux} dans le cas contraire.\smallskip
\begin{Conditions}
- \item La définition de \emph{nombre} est celle évoquée dans la macro \verb|IfDecimal| (voir page~\pageref{ifdecimal}), et donc :
+ \item La définition de \emph{nombre} est celle évoquée dans la macro \verbinline|\IfDecimal| (voir page~\pageref{ifdecimal}), et donc :
\item Les signes \guill{+} sont facultatifs;
\item Le séparateur décimal peut être indifféremment la virgule ou le point.
\end{Conditions}
-\exemple|\IfEq{a1b2c3}{a1b2c3}{vrai}{faux}|
-\exemple|\IfEq{abcdef}{ab}{vrai}{faux}|
-\exemple|\IfEq{ab}{abcdef}{vrai}{faux}|
-\exemple|\IfEq{12.34}{12,34}{vrai}{faux}|
-\exemple|\IfEq{+12.34}{12.340}{vrai}{faux}|
-\exemple|\IfEq{10}{+10}{vrai}{faux}|
-\exemple|\IfEq{-10}{10}{vrai}{faux}|
-\exemple|\IfEq{+0,5}{,5}{vrai}{faux}|
-\exemple|\IfEq{1.001}{1.01}{vrai}{faux}|
-\exemple|\IfEq{3*4+2}{14}{vrai}{faux}|
-\exemple|\IfEq{\number\numexpr3*4+2}{14}{vrai}{faux}|
-\exemple|\IfEq{0}{-0.0}{vrai}{faux}|
-\exemple|\IfEq{}{}{vrai}{faux}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfEq{a1b2c3}{a1b2c3}{vrai}{faux}
+\IfEq{abcdef}{ab}{vrai}{faux}
+\IfEq{ab}{abcdef}{vrai}{faux}
+\IfEq{12.34}{12,34}{vrai}{faux}
+\IfEq{+12.34}{12.340}{vrai}{faux}
+\IfEq{10}{+10}{vrai}{faux}
+\IfEq{-10}{10}{vrai}{faux}
+\IfEq{+0,5}{,5}{vrai}{faux}
+\IfEq{1.001}{1.01}{vrai}{faux}
+\IfEq{3*4+2}{14}{vrai}{faux}
+\IfEq{\number\numexpr3*4+2}{14}{vrai}{faux}
+\IfEq{0}{-0.0}{vrai}{faux}
+\IfEq{}{}{vrai}{faux}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfEq{a1b2c3}{a1b2c3}{vrai}{faux}\par
+ \IfEq{abcdef}{ab}{vrai}{faux}\par
+ \IfEq{ab}{abcdef}{vrai}{faux}\par
+ \IfEq{12.34}{12,34}{vrai}{faux}\par
+ \IfEq{+12.34}{12.340}{vrai}{faux}\par
+ \IfEq{10}{+10}{vrai}{faux}\par
+ \IfEq{-10}{10}{vrai}{faux}\par
+ \IfEq{+0,5}{,5}{vrai}{faux}\par
+ \IfEq{1.001}{1.01}{vrai}{faux}\par
+ \IfEq{3*4+2}{14}{vrai}{faux}\par
+ \IfEq{\number\numexpr3*4+2}{14}{vrai}{faux}\par
+ \IfEq{0}{-0.0}{vrai}{faux}\par
+ \IfEq{}{}{vrai}{faux}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfStrEqCase}
-
\begin{minipage}{\textwidth}
- \verb|\IfStrEqCase|\etoile\ARGU{chaine}\verb|{%|\par
+ \verbinline|\IfStrEqCase|\etoile\ARGU{chaine}\verb|{%|\par
\qquad\qquad\ARGU{chaine1}\ARGU{code1}\verb|%|\par
\qquad\qquad\ARGU{chaine2}\ARGU{code2}\verb|%|\par
\qquad\qquad\verb|etc...|\par
@@ -370,19 +552,31 @@ Teste si les chaînes \argu{chaineA} et \argu{chaineB} sont égales, \emph{sauf}
\end{minipage}
\smallskip
-Teste successivement si \argu{chaine} est égale à \argu{chaine1}, \argu{chaine2}, etc. La comparaison se fait au sens de \verb|\IfStrEq| (voir paragraphes précédents). Si un test est positif, le code correspondant est exécuté et la macro se termine. Si tous les tests sont négatifs, le code optionnel \argu{code alternatif} est exécuté s'il est présent.\smallskip
-
-\exemple|\IfStrEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}|
-\exemple*|\IfStrEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|
-\exemple|\IfStrEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[autre]|
-\exemple|\IfStrEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[autre]|
-\exemple|\IfStrEqCase{+3}{{1}{un}{2}{deux}{3}{trois}}[autre]|
-\exemple|\IfStrEqCase{0.5}{{0}{zero}{.5}{moitié}{1}{un}}[autre]|
+Teste successivement si \argu{chaine} est égale à \argu{chaine1}, \argu{chaine2}, etc. La comparaison se fait au sens de \verbinline|\IfStrEq| (voir paragraphes précédents). Si un test est positif, le code correspondant est exécuté et la macro se termine. Si tous les tests sont négatifs, le code optionnel \argu{code alternatif} est exécuté s'il est présent.\smallskip
+
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfStrEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}
+|\IfStrEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|
+\IfStrEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[autre]
+\IfStrEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[autre]
+\IfStrEqCase{+3}{{1}{un}{2}{deux}{3}{trois}}[autre]
+\IfStrEqCase{0.5}{{0}{zero}{.5}{demi}{1}{un}}[autre]
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfStrEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}\par
+ |\IfStrEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|\par
+ \IfStrEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[autre]\par
+ \IfStrEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[autre]\par
+ \IfStrEqCase{+3}{{1}{un}{2}{deux}{3}{trois}}[autre]\par
+ \IfStrEqCase{0.5}{{0}{zero}{.5}{demi}{1}{un}}[autre]
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash IfEqCase}
-
\begin{minipage}{\textwidth}
- \verb|\IfEqCase|\etoile\ARGU{chaine}\verb|{%|\par
+ \verbinline|\IfEqCase|\etoile\ARGU{chaine}\verb|{%|\par
\qquad\qquad\ARGU{chaine1}\ARGU{code1}\verb|%|\par
\qquad\qquad\ARGU{chaine2}\ARGU{code2}\verb|%|\par
\qquad\qquad\verb|etc...|\par
@@ -390,22 +584,34 @@ Teste successivement si \argu{chaine} est égale à \argu{chaine1}, \argu{chaine
\end{minipage}
\smallskip
-Teste successivement si \argu{chaine} est égale à \argu{chaine1}, \argu{chaine2}, etc. La comparaison se fait au sens de \verb|\IfEq| (voir paragraphes précédents). Si un test est positif, le code correspondant est exécuté et la macro se termine. Si tous les tests sont négatifs, le code optionnel \argu{code alternatif} est exécuté s'il est présent.\smallskip
-
-\exemple|\IfEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}|
-\exemple*|\IfEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|
-\exemple|\IfEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[autre]|
-\exemple|\IfEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[autre]|
-\exemple|\IfEqCase{+3}{{1}{un}{2}{deux}{3}{trois}}[autre]|
-\exemple|\IfEqCase{0.5}{{0}{zero}{.5}{moitié}{1}{un}}[autre]|
+Teste successivement si \argu{chaine} est égale à \argu{chaine1}, \argu{chaine2}, etc. La comparaison se fait au sens de \verbinline|\IfEq| (voir paragraphes précédents). Si un test est positif, le code correspondant est exécuté et la macro se termine. Si tous les tests sont négatifs, le code optionnel \argu{code alternatif} est exécuté s'il est présent.\smallskip
+
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\IfEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}
+|\IfEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|
+\IfEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[autre]
+\IfEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[autre]
+\IfEqCase{+3}{{1}{un}{2}{deux}{3}{trois}}[autre]
+\IfEqCase{0.5}{{0}{zero}{.5}{demi}{1}{un}}[autre]
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \IfEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}\par
+ |\IfEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|\par
+ \IfEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[autre]\par
+ \IfEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[autre]\par
+ \IfEqCase{+3}{{1}{un}{2}{deux}{3}{trois}}[autre]\par
+ \IfEqCase{0.5}{{0}{zero}{.5}{demi}{1}{un}}[autre]
+\end{minipage}%
\subsection{Les macros renvoyant une chaîne}
\subsubsection{\ttfamily\textbackslash StrBefore}
-\verb|\StrBefore|\etoile\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\arguC{nom}
+\verbinline|\StrBefore|\etoile\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\arguC{nom}
\smallskip
-L'argument optionnel \argu{nombre} vaut 1 par défaut.\par\smallskip
-
+L'argument optionnel \argu{nombre} vaut 1 par défaut.\par\nobreak\smallskip
Dans \argu{chaine}, renvoie ce qui se trouve avant l'occurrence \no\argu{nombre} de \argu{chaineA}.\medskip
\begin{Conditions}
@@ -414,21 +620,35 @@ Dans \argu{chaine}, renvoie ce qui se trouve avant l'occurrence \no\argu{nombre}
\item Si l'occurrence n'est pas trouvée, une chaîne vide est renvoyée.
\end{Conditions}
-\exemple*|\StrBefore{xstring}{tri}|
-\exemple*|\StrBefore{LaTeX}{e}|
-\exemple*|\StrBefore{LaTeX}{p}|
-\exemple*|\StrBefore{LaTeX}{L}|
-\exemple*|\StrBefore{a bc def }{def}|
-\exemple*|\StrBefore{a bc def }{cd}|
-\exemple*|\StrBefore[1]{1b2b3}{b}|
-\exemple*|\StrBefore[2]{1b2b3}{b}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrBefore{xstring}{tri}
+\StrBefore{LaTeX}{e}
+|\StrBefore{LaTeX}{p}|
+|\StrBefore{LaTeX}{L}|
+|\StrBefore{a bc def }{def}|
+|\StrBefore{a bc def }{cd}|
+\StrBefore[1]{1b2b3}{b}
+\StrBefore[2]{1b2b3}{b}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrBefore{xstring}{tri}\par
+ \StrBefore{LaTeX}{e}\par
+ |\StrBefore{LaTeX}{p}|\par
+ |\StrBefore{LaTeX}{L}|\par
+ |\StrBefore{a bc def }{def}|\par
+ |\StrBefore{a bc def }{cd}|\par
+ \StrBefore[1]{1b2b3}{b}\par
+ \StrBefore[2]{1b2b3}{b}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrBehind}
-\verb|\StrBehind|\etoile\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\arguC{nom}
+\verbinline|\StrBehind|\etoile\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\arguC{nom}
\smallskip
-L'argument optionnel \argu{nombre} vaut 1 par défaut.\par\smallskip
-
+L'argument optionnel \argu{nombre} vaut 1 par défaut.\par\nobreak\smallskip
Dans \argu{chaine}, renvoie ce qui se trouve après l'occurrence \no\argu{nombre} de \argu{chaineA}.\medskip
\begin{Conditions}
@@ -437,24 +657,38 @@ Dans \argu{chaine}, renvoie ce qui se trouve après l'occurrence \no\argu{nombre
\item Si l'occurrence n'est pas trouvée, une chaîne vide est renvoyée.
\end{Conditions}
-\exemple*|\StrBehind{xstring}{tri}|
-\exemple*|\StrBehind{LaTeX}{e}|
-\exemple*|\StrBehind{LaTeX}{p}|
-\exemple*|\StrBehind{LaTeX}{X}|
-\exemple*|\StrBehind{a bc def }{bc}|
-\exemple*|\StrBehind{a bc def }{cd}|
-\exemple*|\StrBehind[1]{1b2b3}{b}|
-\exemple*|\StrBehind[2]{1b2b3}{b}|
-\exemple*|\StrBehind[3]{1b2b3}{b}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrBehind{xstring}{tri}
+\StrBehind{LaTeX}{e}
+|\StrBehind{LaTeX}{p}|
+|\StrBehind{LaTeX}{X}|
+|\StrBehind{a bc def }{bc}|
+|\StrBehind{a bc def }{cd}|
+\StrBehind[1]{1b2b3}{b}
+\StrBehind[2]{1b2b3}{b}
+|\StrBehind[3]{1b2b3}{b}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrBehind{xstring}{tri}\par
+ \StrBehind{LaTeX}{e}\par
+ |\StrBehind{LaTeX}{p}|\par
+ |\StrBehind{LaTeX}{X}|\par
+ |\StrBehind{a bc def }{bc}|\par
+ |\StrBehind{a bc def }{cd}|\par
+ \StrBehind[1]{1b2b3}{b}\par
+ \StrBehind[2]{1b2b3}{b}\par
+ |\StrBehind[3]{1b2b3}{b}|
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrBetween}
-\verb|\StrBetween|\etoile\arguCC{nombre1}{nombre2}\ARGU{chaine}\ARGU{chaineA}\ARGU{chaineB}\arguC{nom}
+\verbinline|\StrBetween|\etoile\arguCC{nombre1}{nombre2}\ARGU{chaine}\ARGU{chaineA}\ARGU{chaineB}\arguC{nom}
\smallskip
-Les arguments optionnels \argu{nombre1} et \argu{nombre2} valent 1 par défaut.\par\smallskip
-
-Dans \argu{chaine}, renvoie ce qui se trouve entre\footnote{Au sens strict, c'est-à-dire \emph{sans} les chaînes frontière} les occurrences \no\argu{nombre1} de \argu{chaineA} et \no \argu{nombre2} de \argu{chaineB}.
-\medskip
+Les arguments optionnels \argu{nombre1} et \argu{nombre2} valent 1 par défaut.\par\nobreak\smallskip
+Dans \argu{chaine}, renvoie ce qui se trouve entre\footnote{Au sens strict, c'est-à-dire \emph{sans} les chaînes frontière} les occurrences \no\argu{nombre1} de \argu{chaineA} et \no \argu{nombre2} de \argu{chaineB}.\medskip
\begin{Conditions}
\item Si les occurrences ne sont pas dans l'ordre (\argu{chaineA} \emph{puis} \argu{chaineB}) dans \argu{chaine}, une chaîne vide est renvoyée;
@@ -462,23 +696,39 @@ Dans \argu{chaine}, renvoie ce qui se trouve entre\footnote{Au sens strict, c'es
\item Si l'un des arguments optionnels \argu{nombre1} ou \argu{nombre2} est négatif ou nul, une chaîne vide est renvoyée.
\end{Conditions}
-\exemple*|\StrBetween{xstring}{xs}{ng}|
-\exemple*|\StrBetween{xstring}{i}{n}|
-\exemple*|\StrBetween{xstring}{a}{tring}|
-\exemple*|\StrBetween{a bc def }{a}{d}|
-\exemple*|\StrBetween{a bc def }{a }{f}|
-\exemple*|\StrBetween{a1b1a2b2a3b3}{a}{b}|
-\exemple*|\StrBetween[2,3]{a1b1a2b2a3b3}{a}{b}|
-\exemple*|\StrBetween[1,3]{a1b1a2b2a3b3}{a}{b}|
-\exemple*|\StrBetween[3,1]{a1b1a2b2a3b3}{a}{b}|
-\exemple*|\StrBetween[3,2]{abracadabra}{a}{bra}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrBetween{xstring}{xs}{ng}
+|\StrBetween{xstring}{i}{n}|
+|\StrBetween{xstring}{a}{tring}|
+|\StrBetween{a bc def }{a}{d}|
+|\StrBetween{a bc def }{a }{f}|
+\StrBetween{a1b1a2b2a3b3}{a}{b}
+\StrBetween[2,3]{a1b1a2b2a3b3}{a}{b}
+\StrBetween[1,3]{a1b1a2b2a3b3}{a}{b}
+|\StrBetween[3,1]{a1b1a2b2a3b3}{a}{b}|
+\StrBetween[3,2]{abracadabra}{a}{bra}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrBetween{xstring}{xs}{ng}\par
+ |\StrBetween{xstring}{i}{n}|\par
+ |\StrBetween{xstring}{a}{tring}|\par
+ |\StrBetween{a bc def }{a}{d}|\par
+ |\StrBetween{a bc def }{a }{f}|\par
+ \StrBetween{a1b1a2b2a3b3}{a}{b}\par
+ \StrBetween[2,3]{a1b1a2b2a3b3}{a}{b}\par
+ \StrBetween[1,3]{a1b1a2b2a3b3}{a}{b}\par
+ |\StrBetween[3,1]{a1b1a2b2a3b3}{a}{b}|\par
+ \StrBetween[3,2]{abracadabra}{a}{bra}\par
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrSubstitute}
-\verb|\StrSubstitute|\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\ARGU{chaineB}\arguC{nom}
+\verbinline|\StrSubstitute|\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\ARGU{chaineB}\arguC{nom}
\smallskip
-L'argument optionnel \argu{nombre} vaut 0 par défaut.\par\smallskip
-
+L'argument optionnel \argu{nombre} vaut 0 par défaut.\par\nobreak\smallskip
Dans \argu{chaine}, la macro remplace les \argu{nombre} premières occurrences de \argu{chaineA} par \argu{chaineB}, sauf si \argu{nombre}${}=0$ auquel cas, \emph{toutes} les occurrences sont remplacées.
\begin{Conditions}
@@ -489,23 +739,39 @@ Dans \argu{chaine}, la macro remplace les \argu{nombre} premières occurrences d
\item Si \argu{chaineB} est vide, alors les occurrences de \argu{chaineA}, si elles existent, sont supprimées.
\end{Conditions}
-\exemple|\StrSubstitute{xstring}{i}{a}|
-\exemple|\StrSubstitute{abracadabra}{a}{o}|
-\exemple|\StrSubstitute{abracadabra}{br}{TeX}|
-\exemple|\StrSubstitute{LaTeX}{m}{n}|
-\exemple|\StrSubstitute{a bc def }{ }{M}|
-\exemple|\StrSubstitute{a bc def }{ab}{AB}|
-\exemple|\StrSubstitute[1]{a1a2a3}{a}{B}|
-\exemple|\StrSubstitute[2]{a1a2a3}{a}{B}|
-\exemple|\StrSubstitute[3]{a1a2a3}{a}{B}|
-\exemple|\StrSubstitute[4]{a1a2a3}{a}{B}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrSubstitute{xstring}{i}{a}
+\StrSubstitute{abracadabra}{a}{o}
+\StrSubstitute{abracadabra}{br}{TeX}
+\StrSubstitute{LaTeX}{m}{n}
+\StrSubstitute{a bc def }{ }{M}
+\StrSubstitute{a bc def }{ab}{AB}
+\StrSubstitute[1]{a1a2a3}{a}{B}
+\StrSubstitute[2]{a1a2a3}{a}{B}
+\StrSubstitute[3]{a1a2a3}{a}{B}
+\StrSubstitute[4]{a1a2a3}{a}{B}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrSubstitute{xstring}{i}{a}\par
+ \StrSubstitute{abracadabra}{a}{o}\par
+ \StrSubstitute{abracadabra}{br}{TeX}\par
+ \StrSubstitute{LaTeX}{m}{n}\par
+ \StrSubstitute{a bc def }{ }{M}\par
+ \StrSubstitute{a bc def }{ab}{AB}\par
+ \StrSubstitute[1]{a1a2a3}{a}{B}\par
+ \StrSubstitute[2]{a1a2a3}{a}{B}\par
+ \StrSubstitute[3]{a1a2a3}{a}{B}\par
+ \StrSubstitute[4]{a1a2a3}{a}{B}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrDel}
-\verb|\StrDel|\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\arguC{nom}
+\verbinline|\StrDel|\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\arguC{nom}
\smallskip
-L'argument optionnel \argu{nombre} vaut 0 par défaut.\par\smallskip
-
+L'argument optionnel \argu{nombre} vaut 0 par défaut.\par\nobreak\smallskip
Supprime les \argu{nombre} premières occurrences de \argu{chaineA} dans \argu{chaine}, sauf si \argu{nombre}${}=0$ auquel cas, \emph{toutes} les occurrences sont supprimées.\medskip
\begin{Conditions}
@@ -515,15 +781,28 @@ Supprime les \argu{nombre} premières occurrences de \argu{chaineA} dans \argu{c
\item Si \argu{nombre}${}<0$ alors la macro se comporte comme si \argu{nombre}${}=0$;
\end{Conditions}
-\exemple|\StrDel{abracadabra}{a}|
-\exemple|\StrDel[1]{abracadabra}{a}|
-\exemple|\StrDel[4]{abracadabra}{a}|
-\exemple|\StrDel[9]{abracadabra}{a}|
-\exemple|\StrDel{a bc def }{ }|
-\exemple*|\StrDel{a bc def }{def}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrDel{abracadabra}{a}
+\StrDel[1]{abracadabra}{a}
+\StrDel[4]{abracadabra}{a}
+\StrDel[9]{abracadabra}{a}
+\StrDel{a bc def }{ }
+|\StrDel{a bc def }{def}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrDel{abracadabra}{a}\par
+ \StrDel[1]{abracadabra}{a}\par
+ \StrDel[4]{abracadabra}{a}\par
+ \StrDel[9]{abracadabra}{a}\par
+ \StrDel{a bc def }{ }\par
+ |\StrDel{a bc def }{def}|
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrGobbleLeft}
-\verb|\StrGobbleLeft|\ARGU{chaine}\ARGU{nombre}\arguC{nom}
+\verbinline|\StrGobbleLeft|\ARGU{chaine}\ARGU{nombre}\arguC{nom}
\smallskip
Dans \argu{chaine}, enlève les \argu{nombre} premieres \USs de gauche.\medskip
@@ -534,14 +813,26 @@ Dans \argu{chaine}, enlève les \argu{nombre} premieres \USs de gauche.\medskip
\item Si \argu{nombre}${}\geqslant{}$\argu{longueurChaine}, toutes les \USs sont supprimées.
\end{Conditions}
-\exemple*|\StrGobbleLeft{xstring}{2}|
-\exemple*|\StrGobbleLeft{xstring}{9}|
-\exemple*|\StrGobbleLeft{LaTeX}{4}|
-\exemple*|\StrGobbleLeft{LaTeX}{-2}|
-\exemple*|\StrGobbleLeft{a bc def }{4}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrGobbleLeft{xstring}{2}
+|\StrGobbleLeft{xstring}{9}|
+\StrGobbleLeft{LaTeX}{4}
+\StrGobbleLeft{LaTeX}{-2}
+|\StrGobbleLeft{a bc def }{4}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrGobbleLeft{xstring}{2}\par
+ |\StrGobbleLeft{xstring}{9}|\par
+ \StrGobbleLeft{LaTeX}{4}\par
+ \StrGobbleLeft{LaTeX}{-2}\par
+ |\StrGobbleLeft{a bc def }{4}|
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrLeft}
-\verb|\StrLeft|\ARGU{chaine}\ARGU{nombre}\arguC{nom}
+\verbinline|\StrLeft|\ARGU{chaine}\ARGU{nombre}\arguC{nom}
\smallskip
Dans \argu{chaine}, renvoie la sous-chaîne de gauche de longueur \argu{nombre}.\medskip
@@ -552,38 +843,74 @@ Dans \argu{chaine}, renvoie la sous-chaîne de gauche de longueur \argu{nombre}.
\item Si \argu{nombre}${}\geqslant{}$\argu{longueurChaine}, toutes les \USs sont retournées.
\end{Conditions}
-\exemple*|\StrLeft{xstring}{2}|
-\exemple*|\StrLeft{xstring}{9}|
-\exemple*|\StrLeft{LaTeX}{4}|
-\exemple*|\StrLeft{LaTeX}{-2}|
-\exemple*|\StrLeft{a bc def }{5}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrLeft{xstring}{2}
+\StrLeft{xstring}{9}
+\StrLeft{LaTeX}{4}
+|\StrLeft{LaTeX}{-2}|
+|\StrLeft{a bc def }{5}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrLeft{xstring}{2}\par
+ \StrLeft{xstring}{9}\par
+ \StrLeft{LaTeX}{4}\par
+ |\StrLeft{LaTeX}{-2}|\par
+ |\StrLeft{a bc def }{5}|
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrGobbleRight}
-\verb|\StrGobbleRight|\ARGU{chaine}\ARGU{nombre}\arguC{nom}
+\verbinline|\StrGobbleRight|\ARGU{chaine}\ARGU{nombre}\arguC{nom}
\smallskip
-Agit comme \verb|\StrGobbleLeft|, mais enlève les \USs à droite de \argu{chaine}.
-
-\exemple*|\StrGobbleRight{xstring}{2}|
-\exemple*|\StrGobbleRight{xstring}{9}|
-\exemple*|\StrGobbleRight{LaTeX}{4}|
-\exemple*|\StrGobbleRight{LaTeX}{-2}|
-\exemple*|\StrGobbleRight{a bc def }{4}|
+Agit comme \verbinline|\StrGobbleLeft|, mais enlève les \USs à droite de \argu{chaine}.
+
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrGobbleRight{xstring}{2}
+|\StrGobbleRight{xstring}{9}|
+\StrGobbleRight{LaTeX}{4}
+|\StrGobbleRight{LaTeX}{-2}|
+|\StrGobbleRight{a bc def }{4}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrGobbleRight{xstring}{2}\par
+ |\StrGobbleRight{xstring}{9}|\par
+ \StrGobbleRight{LaTeX}{4}\par
+ |\StrGobbleRight{LaTeX}{-2}|\par
+ |\StrGobbleRight{a bc def }{4}|
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrRight}
-\verb|\StrRight|\ARGU{chaine}\ARGU{nombre}\arguC{nom}
+\verbinline|\StrRight|\ARGU{chaine}\ARGU{nombre}\arguC{nom}
\smallskip
-Agit comme \verb|\StrLeft|, mais renvoie les \USs à la droite de \argu{chaine}.
-
-\exemple*|\StrRight{xstring}{2}|
-\exemple*|\StrRight{xstring}{9}|
-\exemple*|\StrRight{LaTeX}{4}|
-\exemple*|\StrRight{LaTeX}{-2}|
-\exemple*|\StrRight{a bc def }{5}|
+Agit comme \verbinline|\StrLeft|, mais renvoie les \USs à la droite de \argu{chaine}.
+
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrRight{xstring}{2}
+\StrRight{xstring}{9}
+\StrRight{LaTeX}{4}
+|\StrRight{LaTeX}{-2}|
+\StrRight{a bc def }{5}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrRight{xstring}{2}\par
+ \StrRight{xstring}{9}\par
+ \StrRight{LaTeX}{4}\par
+ |\StrRight{LaTeX}{-2}|\par
+ \StrRight{a bc def }{5}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrChar}
-\verb|\StrChar|\ARGU{chaine}\ARGU{nombre}\arguC{nom}
+\verbinline|\StrChar|\ARGU{chaine}\ARGU{nombre}\arguC{nom}
\smallskip
Renvoie l'\US à la position \argu{nombre} dans la chaîne \argu{chaine}.\medskip
@@ -593,13 +920,24 @@ Renvoie l'\US à la position \argu{nombre} dans la chaîne \argu{chaine}.\medski
\item Si \argu{nombre}${}\leqslant0$ ou si \argu{nombre}${}>{}$\argu{longueurChaine}, aucune \US n'est renvoyée.
\end{Conditions}
-\exemple|\StrChar{xstring}{4}|
-\exemple*|\StrChar{xstring}{9}|
-\exemple*|\StrChar{xstring}{-5}|
-\exemple|\StrChar{a bc def }{6}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrChar{xstring}{4}
+|\StrChar{xstring}{9}|
+|\StrChar{xstring}{-5}|
+\StrChar{a bc def }{6}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrChar{xstring}{4}\par
+ |\StrChar{xstring}{9}|\par
+ |\StrChar{xstring}{-5}|\par
+ \StrChar{a bc def }{6}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrMid}
-\verb|\StrMid|\ARGU{chaine}\ARGU{nombre1}\ARGU{nombre2}\arguC{nom}
+\verbinline|\StrMid|\ARGU{chaine}\ARGU{nombre1}\ARGU{nombre2}\arguC{nom}
\smallskip
Dans \argu{chaine}, renvoie la sous chaîne se trouvant entre\footnote{Au sens large, c'est-à-dire que les chaînes \guill{frontière} sont renvoyés.} les positions \argu{nombre1} et \argu{nombre2}.\medskip
@@ -613,27 +951,49 @@ Dans \argu{chaine}, renvoie la sous chaîne se trouvant entre\footnote{Au sens l
\item Si \argu{nombre2}${}>{}$\argu{longueurChaine}, alors la macro se comporte comme si \argu{nombre2}${}={}$\argu{longueurChaine}.
\end{Conditions}
-\exemple|\StrMid{xstring}{2}{5}|
-\exemple|\StrMid{xstring}{-4}{2}|
-\exemple*|\StrMid{xstring}{5}{1}|
-\exemple|\StrMid{xstring}{6}{15}|
-\exemple|\StrMid{xstring}{3}{3}|
-\exemple*|\StrMid{a bc def }{2}{7}|
-
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrMid{xstring}{2}{5}
+\StrMid{xstring}{-4}{2}
+|\StrMid{xstring}{5}{1}|
+\StrMid{xstring}{6}{15}
+\StrMid{xstring}{3}{3}
+|\StrMid{a bc def }{2}{7}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrMid{xstring}{2}{5}\par
+ \StrMid{xstring}{-4}{2}\par
+ |\StrMid{xstring}{5}{1}|\par
+ \StrMid{xstring}{6}{15}\par
+ \StrMid{xstring}{3}{3}\par
+ |\StrMid{a bc def }{2}{7}|
+\end{minipage}%
\subsection{Les macros renvoyant des nombres}
\subsubsection{\ttfamily\textbackslash StrLen}
-\verb|\StrLen|\ARGU{chaine}\arguC{nom}
+\verbinline|\StrLen|\ARGU{chaine}\arguC{nom}
\smallskip
Renvoie la longueur de \argu{chaine}.
-\exemple|\StrLen{xstring}|
-\exemple|\StrLen{A}|
-\exemple|\StrLen{a bc def }|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrLen{xstring}
+\StrLen{A}
+\StrLen{a bc def }
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrLen{xstring}\par
+ \StrLen{A}\par
+ \StrLen{a bc def }
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrCount}
-\verb|\StrCount|\ARGU{chaine}\ARGU{chaineA}\arguC{nom}
+\verbinline|\StrCount|\ARGU{chaine}\ARGU{chaineA}\arguC{nom}
\smallskip
Compte combien de fois \argu{chaineA} est contenue dans \argu{chaine}.\par\medskip
@@ -642,17 +1002,27 @@ Compte combien de fois \argu{chaineA} est contenue dans \argu{chaine}.\par\medsk
\item Si l'un au moins des arguments \argu{chaine} ou \argu{chaineA} est vide, la macro renvoie 0.
\end{Conditions}
-\exemple|\StrCount{abracadabra}{a}|
-\exemple|\StrCount{abracadabra}{bra}|
-\exemple|\StrCount{abracadabra}{tic}|
-\exemple|\StrCount{aaaaaa}{aa}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrCount{abracadabra}{a}
+\StrCount{abracadabra}{bra}
+\StrCount{abracadabra}{tic}
+\StrCount{aaaaaa}{aa}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrCount{abracadabra}{a}\par
+ \StrCount{abracadabra}{bra}\par
+ \StrCount{abracadabra}{tic}\par
+ \StrCount{aaaaaa}{aa}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrPosition}
-\verb|\StrPosition|\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\arguC{nom}
+\verbinline|\StrPosition|\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}\arguC{nom}
\smallskip
-L'argument optionnel \argu{nombre} vaut 1 par défaut.\par\smallskip
-
+L'argument optionnel \argu{nombre} vaut 1 par défaut.\par\nobreak\smallskip
Dans \argu{chaine}, renvoie la position de l'occurrence \no\argu{nombre} de \argu{chaineA}.\medskip
\begin{Conditions}
@@ -661,73 +1031,119 @@ Dans \argu{chaine}, renvoie la position de l'occurrence \no\argu{nombre} de \arg
\end{Conditions}
\medskip
-\exemple|\StrPosition{xstring}{ring}|
-\exemple|\StrPosition[4]{abracadabra}{a}|
-\exemple|\StrPosition[2]{abracadabra}{bra}|
-\exemple|\StrPosition[9]{abracadabra}{a}|
-\exemple|\StrPosition{abracadabra}{z}|
-\exemple|\StrPosition{a bc def }{d}|
-\exemple|\StrPosition[3]{aaaaaa}{aa}|
+\begin{minipage}[t]{0.65\linewidth}
+\begin{lstlisting}
+\StrPosition{xstring}{ring}
+\StrPosition[4]{abracadabra}{a}
+\StrPosition[2]{abracadabra}{bra}
+\StrPosition[9]{abracadabra}{a}
+\StrPosition{abracadabra}{z}
+\StrPosition{a bc def }{d}
+\StrPosition[3]{aaaaaa}{aa}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \StrPosition{xstring}{ring}\par
+ \StrPosition[4]{abracadabra}{a}\par
+ \StrPosition[2]{abracadabra}{bra}\par
+ \StrPosition[9]{abracadabra}{a}\par
+ \StrPosition{abracadabra}{z}\par
+ \StrPosition{a bc def }{d}\par
+ \StrPosition[3]{aaaaaa}{aa}
+\end{minipage}%
\subsubsection{\ttfamily\textbackslash StrCompare}
-\verb|\StrCompare|\etoile\ARGU{chaineA}\ARGU{chaineB}\arguC{nom}
+\verbinline|\StrCompare|\etoile\ARGU{chaineA}\ARGU{chaineB}\arguC{nom}
\smallskip
Cette macro peut fonctionner avec 2 tolérances : la tolérance \guill{normale} sélectionnée par défaut, et la tolérance \guill{stricte}.\medskip
\begin{itemize}
- \item La tolérance normale, activée par la commande \verb|\comparenormal|.\par
+ \item La tolérance normale, activée par la commande \verbinline|\comparenormal|.\par
La macro compare successivement les \US de gauche à droite des chaînes \argu{chaineA} et \argu{chaineB} jusqu'à ce qu'une différence apparaisse ou que la fin de la plus courte chaîne soit atteinte. Si aucune différence n'est trouvée, la macro renvoie 0. Sinon, la position de la 1\iere{} différence est renvoyée.
- \item La tolérance stricte, activée par la commande \verb|\comparestrict|.\par
+ \item La tolérance stricte, activée par la commande \verbinline|\comparestrict|.\par
La macro compare les 2 chaînes. Si elles sont égales, elle renvoie 0 sinon la position de la 1\iere{} différence est renvoyée.
\end{itemize}
\smallskip
-L'ordre des 2 chaînes n'a aucune influence sur le comportement de la macro.\medskip
+L'ordre des 2 chaînes n'a aucune influence sur le comportement de la macro.
-On peut également mémoriser le mode de comparaison en cours avec \verb|\savecomparemode|, le modifier par la suite et revenir à la situation lors de la sauvegarde avec \verb|\restoreecomparemode|.\medskip
+\medskip On peut également mémoriser le mode de comparaison en cours avec \verbinline|\savecomparemode|, le modifier par la suite et revenir à la situation lors de la sauvegarde avec \verbinline|\restorecomparemode|.\medskip
-Exemples en tolérance normale :\par\comparenormal
-\exemple|\StrCompare{abcd}{abcd}|
-\exemple|\StrCompare{abcd}{abc}|
-\exemple|\StrCompare{abc}{abcd}|
-\exemple|\StrCompare{éùçà}{éùçà}|
-\exemple|\StrCompare{a b c}{abc}|
-\exemple|\StrCompare{aaa}{baaa}|
-\exemple|\StrCompare{abc}{xyz}|
-\exemple|\StrCompare{123456}{123457}|
-\exemple|\StrCompare{abc}{}|
+Exemples en tolérance normale :\par\nobreak
+\begin{minipage}[t]{0.65\linewidth}
+\comparenormal
+\begin{lstlisting}
+\StrCompare{abcd}{abcd}
+\StrCompare{abcd}{abc}
+\StrCompare{abc}{abcd}
+\StrCompare{a b c}{abc}
+\StrCompare{aaa}{baaa}
+\StrCompare{abc}{xyz}
+\StrCompare{123456}{123457}
+\StrCompare{abc}{}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \comparenormal
+ \StrCompare{abcd}{abcd}\par
+ \StrCompare{abcd}{abc}\par
+ \StrCompare{abc}{abcd}\par
+ \StrCompare{a b c}{abc}\par
+ \StrCompare{aaa}{baaa}\par
+ \StrCompare{abc}{xyz}\par
+ \StrCompare{123456}{123457}\par
+ \StrCompare{abc}{}
+\end{minipage}%
\medskip
-Exemples en tolérance stricte :\par\comparestrict
-\exemple|\StrCompare{abcd}{abcd}|
-\exemple|\StrCompare{abcd}{abc}|
-\exemple|\StrCompare{abc}{abcd}|
-\exemple|\StrCompare{éùçà}{éùçà}|
-\exemple|\StrCompare{a b c}{abc}|
-\exemple|\StrCompare{aaa}{baaa}|
-\exemple|\StrCompare{abc}{xyz}|
-\exemple|\StrCompare{123456}{123457}|
-\exemple|\StrCompare{abc}{}|
-\comparenormal
+Exemples en tolérance stricte :\par\nobreak
+\begin{minipage}[t]{0.65\linewidth}
+\comparestrict
+\begin{lstlisting}
+\StrCompare{abcd}{abcd}
+\StrCompare{abcd}{abc}
+\StrCompare{abc}{abcd}
+\StrCompare{a b c}{abc}
+\StrCompare{aaa}{baaa}
+\StrCompare{abc}{xyz}
+\StrCompare{123456}{123457}
+\StrCompare{abc}{}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[t]{0.35\linewidth}
+ \styleexemple
+ \comparestrict
+ \StrCompare{abcd}{abcd}\par
+ \StrCompare{abcd}{abc}\par
+ \StrCompare{abc}{abcd}\par
+ \StrCompare{a b c}{abc}\par
+ \StrCompare{aaa}{baaa}\par
+ \StrCompare{abc}{xyz}\par
+ \StrCompare{123456}{123457}\par
+ \StrCompare{abc}{}
+\end{minipage}%
\section{Modes de fonctionnement}
\subsection{Développement des arguments}
\label{devarg}
+\lstset{basicstyle=\footnotesize\ttfamily}
\subsubsection{Les macros {\ttfamily \textbackslash fullexpandarg}, {\ttfamily \textbackslash expandarg} et {\ttfamily \textbackslash noexpandarg}}
-La macro \verb|\fullexpandarg| est appelée par défaut, ce qui fait que certains arguments transmis aux macros sont développés le plus possible (pour cela, un \verb|\edef| est utilisé). Ce mode de développement maximal permet dans la plupart des cas d'éviter d'utiliser des chaînes d'\verb|\expandafter|. Le code en est souvent allégé.
+La macro \verbinline|\fullexpandarg| est appelée par défaut, ce qui fait que certains arguments transmis aux macros sont développés le plus possible (pour cela, un \verb|\edef| est utilisé). Ce mode de développement maximal permet dans la plupart des cas d'éviter d'utiliser des chaînes d'\verb|\expandafter|. Le code en est souvent allégé.
-On peut interdire le développement de ces arguments (et ainsi revenir au comportement normal de \TeX) en invoquant \verb|\noexpandarg| ou \verb|\normalexpandarg| qui sont synonymes.\medskip
+On peut interdire le développement de ces arguments (et ainsi revenir au comportement normal de \TeX) en invoquant \verbinline|\noexpandarg| ou \verbinline|\normalexpandarg| qui sont synonymes.\medskip
-Il existe enfin un autre mode de développement de ces arguments que l'on appelle avec \verb|\expandarg|. Dans ce cas, le \textbf{premier lexème} de ces arguments est développé \emph{une fois} avant que la macro ne soit appelée. Si l'argument contient plus d'un lexème, les lexèmes qui suivent le premier ne sont pas développés (on peut contourner cette volontaire limitation et utiliser la macro \verb|\scancs*|, voir page~\pageref{scancs}).\medskip
+Il existe enfin un autre mode de développement de ces arguments que l'on appelle avec \verbinline|\expandarg|. Dans ce cas, le \textbf{premier token} de ces arguments est développé \emph{une fois} avant que la macro ne soit appelée. Si l'argument contient plus d'un token, les tokens qui suivent le premier ne sont pas développés (on peut contourner cette volontaire limitation et utiliser la macro \verbinline|\StrExpand|, voir page~\pageref{scancs}).\medskip
-Les commandes \verb|\fullexpandarg|, \verb|\noexpandarg|, \verb|\normalexpandarg| et \verb|\expandarg| peuvent être appelées à tout moment dans le code et fonctionnent comme des bascules. On peut rendre leur portée locale dans un groupe.\medskip
+Les commandes \verbinline|\fullexpandarg|, \verbinline|\noexpandarg|, \verbinline|\normalexpandarg| et \verbinline|\expandarg| peuvent être appelées à tout moment dans le code et fonctionnent comme des bascules. On peut rendre leur portée locale dans un groupe.\medskip
-On peut également mémoriser le mode de développement en cours avec \verb|\saveexpandmode|, le modifier par la suite et revenir à la situation lors de la sauvegarde avec \verb|\restoreexpandmode|.\medskip
+On peut également mémoriser le mode de développement en cours avec \verbinline|\saveexpandmode|, le modifier par la suite et revenir à la situation lors de la sauvegarde avec \verbinline|\restoreexpandmode|.\medskip
-Dans la liste ci-dessous, on peut voir en \textcolor{red}{rouge} quels arguments sont soumis à l'éventuel développement pour chaque macro vue dans le chapitre précedent :\smallskip
+Dans la liste ci-dessous, on peut voir en \textcolor{violet}{violet} quels arguments sont soumis à l'éventuel développement pour chaque macro vue dans le chapitre précedent :
-\newcommand\colorise{\color{red}}
+\nobreak\smallskip
\parindent3em
\begin{itemize}
\item\verb|\IfSubStr|\etoile{\colorise\arguC{nombre}\ARGU{chaine}\ARGU{chaineA}}\ARGU{vrai}\ARGU{faux}
@@ -769,24 +1185,24 @@ Dans la liste ci-dessous, on peut voir en \textcolor{red}{rouge} quels arguments
\parindent0pt
\subsubsection{Caractères autorisés dans les arguments}
-Tout d'abord, quelque soit le mode de développement choisi, \textbf{les lexèmes de catcode 6 et 14 (habituellement {\ttfamily\#} et {\ttfamily\%}) sont interdits dans tous les arguments}\footnote{Le lexème {\ttfamily\#} sera peut-être autorisé dans une future version !}.\bigskip
+Tout d'abord, quelque soit le mode de développement choisi, \textbf{les tokens de catcode 6 et 14 (habituellement {\ttfamily\#} et {\ttfamily\%}) sont interdits dans tous les arguments}\footnote{Le token {\ttfamily\#} sera peut-être autorisé dans une future version !}.\bigskip
-Lorsque le mode \verb|\fullexpandarg| est activé, les arguments sont évalués à l'aide de la primitive \verb|\edef| avant d'être transmis aux macros. Par conséquent, sont autorisés dans les arguments :
-\smallskip\parindent3em
+Lorsque le mode \verbinline|\fullexpandarg| est activé, les arguments sont évalués à l'aide de la primitive \verb|\edef| avant d'être transmis aux macros. Par conséquent, sont autorisés dans les arguments :
+\nobreak\smallskip\parindent3em
\begin{itemize}
- \item les lettres, majuscules, minuscules, accentuées\footnote{Pour pouvoir utiliser des lettres accentuées de façon fiable, il est nécessaire de charger le packages \texttt{\string\fontenc} avec l'option \texttt{[T1]}, ainsi que \texttt{\string\inputenc} avec l'option correspondant au codage du fichier tex.} ou non, les chiffres, les espaces\footnote{Selon la règle \TeX{}iènne, plusieurs espaces consécutifs n'en font qu'un.} ainsi que tout autre lexème de catcode 10, 11 ou 12 (signes de ponctuation, signes opératoires mathématiques, parenthèses, crochets, etc);
- \item les lexèmes de catcode 1 à 4, qui sont habituellement : \og\verb|{|\fg\quad\og\verb|}|\fg\footnote{Attention : les accolades \textbf{doivent} être équilibrées dans les arguments !}\quad\og\verb|$|\fg\quad\og\verb|&|\fg
- \item les lexèmes de catcode 7 et 8, qui sont habituellement : \og\verb|^|\fg\quad\og\verb|_|\fg
+ \item les lettres, majuscules, minuscules, accentuées\footnote{Pour pouvoir utiliser des lettres accentuées de façon fiable, il est nécessaire de charger le packages \texttt{\string\fontenc} avec l'option \texttt{[T1]}, ainsi que \texttt{\string\inputenc} avec l'option correspondant au codage du fichier tex.} ou non, les chiffres, les espaces\footnote{Selon la règle \TeX{}iènne, plusieurs espaces consécutifs n'en font qu'un.} ainsi que tout autre token de catcode 10, 11 ou 12 (signes de ponctuation, signes opératoires mathématiques, parenthèses, crochets, etc);
+ \item les tokens de catcode 1 à 4, qui sont habituellement : \og\verb|{|\fg\quad\og\verb|}|\fg\footnote{Attention : les accolades \textbf{doivent} être équilibrées dans les arguments !}\quad\og\verb|$|\fg\quad\og\verb|&|\fg
+ \item les tokens de catcode 7 et 8, qui sont habituellement : \og\verb|^|\fg\quad\og\verb|_|\fg
\item toute séquence de contrôle si elle est purement développable\footnote{C'est-à-dire qu'elle peut être mise à l'intérieur d'un {\ttfamily\string\edef}.} et dont le développement maximal donne des caractères autorisés;
- \item un lexème de catcode 13 (caractère actif) s'il est purement développable.
+ \item un token de catcode 13 (caractère actif) s'il est purement développable.
\end{itemize}
\parindent0pt\smallskip
En revanche, sous UTF8, certains caractères\footnote{Ces caractères s'obtiennent avec la touche \textsf{AtlGr}${}+{}$lettre sous les distributions GNU/Linux.} comme \officialeuro, \textcurrency, ¶, etc. généreront des erreurs.
\bigskip
-Lorsque les arguments ne sont plus développés au maximum avec \verb|\expandarg| ou \verb|\noexpandarg|, les caractères autorisés sont ceux cités ci-dessus auxquels il faut rajouter toute séquence de contrôle, même non définie, ainsi que les caractères précédemment cités (\officialeuro, \textcurrency, ¶, etc.).
+Lorsque les arguments ne sont plus développés au maximum avec \verbinline|\expandarg| ou \verbinline|\noexpandarg|, les caractères autorisés sont ceux cités ci-dessus auxquels il faut rajouter toute séquence de contrôle, même non définie, ainsi que les caractères précédemment cités (\officialeuro, \textcurrency, ¶, etc.).
\subsection{Développement des macros, argument optionnel}
\label{argumentoptionnel}
@@ -794,145 +1210,129 @@ Les macros de ce package ne sont pas purement développables et ne peuvent donc
C'est pour cela que les macros renvoyant un résultat, c'est-à-dire toutes sauf les tests, sont dotées d'un argument optionnel venant en dernière position. Cet argument prend la forme de \arguC{nom}, où \argu{nom} est une séquence de contrôle qui recevra (l'assignation se fait avec un \verb|\edef|) le résultat de la macro, ce qui fait que \argu{nom} est purement développable et peut donc se trouver dans l'argument d'un \verb|\edef|. Dans le cas de la présence d'un argument optionnel en dernière position, aucun affichage n'aura lieu. Cela permet donc contourner les limitations évoquées dans les exemples ci dessus.\medskip
-Ainsi cette construction non permise censée assigner à \verb|\Resultat| les 4 caractères de gauche de \verb|xstring| :\par
-\hspace{0.2\linewidth}\verb|\edef\Resultat{\StrLeft{xstring}{4}}|\par
-\qquad est équivalente à :\par
-\hspace{0.2\linewidth}\verb|\StrLeft{xstring}{4}[\Resultat]|\medskip
+Ainsi cette construction non permise censée assigner à \verb|\Resultat| les 4 caractères de gauche de \verb|xstring| :\par\nobreak
+\hspace{0.2\linewidth}\verbinline|\edef\Resultat{\StrLeft{xstring}{4}}|\par\nobreak
+\qquad est équivalente à :\par\nobreak
+\hspace{0.2\linewidth}\verbinline|\StrLeft{xstring}{4}[\Resultat]|\medskip
-Et cette imbrication non permise censée enlever le premier et le dernier caractère de \verb|xstring| :\par
-\hspace{0.2\linewidth}\verb|\StrGobbleLeft{\StrGobbleRight{xstring}{1}}{1}|\par
-\qquad se programme ainsi :\par
-\hspace{0.2\linewidth}\verb|\StrGobbleRight{xstring}{1}[\machaine]|\par
-\hspace{0.2\linewidth}\verb|\StrGobbleleft{\machaine}{1}|\par
+Et cette imbrication non permise censée enlever le premier et le dernier caractère de \verb|xstring| :\par\nobreak
+\hspace{0.2\linewidth}\verbinline|\StrGobbleLeft{\StrGobbleRight{xstring}{1}}{1}|\par\nobreak
+\qquad se programme ainsi :\par\nobreak
+\hspace{0.2\linewidth}\verbinline|\StrGobbleRight{xstring}{1}[\machaine]|\par\nobreak
+\hspace{0.2\linewidth}\verbinline|\StrGobbleLeft{\machaine}{1}|\par
\subsection{Traitement des arguments}
\label{developpementarguments}
\subsubsection{Traitement à l'\US prés}
-Les macros de \Xstring traitent les arguments \US par \US. Dans le code \TeX{}, une \US\footnote{Pour les utilisateurs familiers avec la programmation \LaTeX, une \US est ce qui est supprimé par la macro \texttt{\string\@gobble} dont le code, d'une grande simplicité, est :\quad{\ttfamily\string\def\string\@gobble\string#1\string{\string}}} est soit :\smallskip\parindent3em
-
+Les macros de \Xstring traitent les arguments \US par \US. Dans le code \TeX{}, une \US\footnote{Pour les utilisateurs familiers avec la programmation \LaTeX, une \US est ce qui est supprimé par la macro \texttt{\string\@gobble} dont le code, d'une grande simplicité, est : {\ttfamily\string\def\string\@gobble\string#1\string{\string}}} est soit :\par\nobreak\smallskip\parindent3em
\begin{itemize}
\item une séquence de contrôle;
- \item un groupe, c'est à dire une suite de lexèmes située entre deux accolades équilibrées;
+ \item un groupe, c'est à dire une suite de tokens située entre deux accolades équilibrées;
\item un caractère ne faisant pas partie des 2 espèces ci dessus.
\end{itemize}
\medskip\parindent0pt
Voyons ce qu'est la notion d'\US sur un exemple. Prenons cet argument : \og\verb|ab\textbf{xyz}cd|\fg
-Il contient 6 \USs qui sont : \og\verb|a|\fg, \og\verb|b|\fg, \og\verb|\textbf|\fg, \og\verb|{xyz}|\fg, \og\verb|c|\fg{} et \og\verb|d|\fg.\medskip
+\nobreak Il contient 6 \USs qui sont : \og\verb|a|\fg, \og\verb|b|\fg, \og\verb|\textbf|\fg, \og\verb|{xyz}|\fg, \og\verb|c|\fg{} et \og\verb|d|\fg.
-Que va t-il arriver si l'on se place sous \verb|\noexpandarg| et que l'on demande à \Xstring de trouver la longueur de cet argument et d'en trouver le 4\ieme{} \guill{caractère} ?\medskip
+\nobreak\medskip Que va t-il arriver si l'on se place sous \verbinline|\noexpandarg| et que l'on demande à \Xstring de trouver la longueur de cet argument et d'en trouver le 4\ieme{} \guill{caractère} ?\medskip
-\begin{minipage}[r]{0.6\linewidth}
-\hfill
-\begin{boxedverbatim}
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\noexpandarg
+\StrLen{ab\textbf{xyz}cd}\par
+\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
+\meaning\mychar
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\noexpandarg
\StrLen{ab\textbf{xyz}cd}\par
\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
\meaning\mychar
-\end{boxedverbatim}
-\hspace*{0.3cm}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \noexpandarg
- \StrLen{ab\textbf{xyz}cd}\par
- \StrChar{ab\textbf{xyz}cd}{4}[\mychar]
- \meaning\mychar
-\end{minipage}
\fullexpandarg
\medskip
Il est nécessaire d'utiliser \verb|\meaning| pour bien visualiser le véritable contenu de \verb|\mychar| et non pas de simplement d'appeler cette séquence de contrôle, ce qui fait perdre des informations ---~les accolades ici. On voit qu'on n'obtient pas vraiment un \guill{caractère}, mais cela était prévisible : il s'agit d'une \US.
\subsubsection{Exploration des groupes}
-Par défaut, la commande \verb|\noexploregroups| est appelée et donc dans l'argument à examiner qui contient la chaîne de lexèmes, \Xstring considère les groupes entre accolades comme \USs fermées dans lesquelles \Xstring ne regarde pas.
-
-Pour certains besoins spécifiques, il peut être nécessaire de modifier le mode de lecture des arguments et d'explorer l'intérieur des groupes entre accolades. Pour cela on peut invoquer \verb|\exploregroups|.\medskip
-
-Que va donner ce nouveau mode d'exploration sur l'exemple précédent ? \Xstring ne va plus compter le groupe comme une seule \US mais va compter les \USs se trouvant à l'intérieur, et ainsi de suite s'il y avait plusieurs niveaux d'imbrication de groupes:\smallskip
-
-\begin{minipage}[r]{0.6\linewidth}
-\hfill
-\begin{boxedverbatim}
+Par défaut, la commande \verbinline|\noexploregroups| est appelée et donc dans l'argument à examiner qui contient la chaîne de tokens, \Xstring considère les groupes entre accolades comme \USs fermées dans lesquelles \Xstring ne regarde pas.
+
+Pour certains besoins spécifiques, il peut être nécessaire de modifier le mode de lecture des arguments et d'explorer l'intérieur des groupes entre accolades. Pour cela on peut invoquer \verbinline|\exploregroups|.\medskip
+
+Que va donner ce nouveau mode d'exploration sur l'exemple précédent ? \Xstring ne va plus compter le groupe comme une seule \US mais va compter les \USs se trouvant à l'intérieur, et ainsi de suite s'il y avait plusieurs niveaux d'imbrication de groupes:
+
+\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\noexpandarg
+\exploregroups
+\StrLen{ab\textbf{xyz}cd}\par
+\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
+\meaning\mychar
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\noexpandarg
\exploregroups
\StrLen{ab\textbf{xyz}cd}\par
\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
\meaning\mychar
-\end{boxedverbatim}
-\hspace*{0.3cm}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \noexpandarg
- \exploregroups
- \StrLen{ab\textbf{xyz}cd}\par
- \StrChar{ab\textbf{xyz}cd}{4}[\mychar]
- \meaning\mychar
-\end{minipage}
\fullexpandarg\noexploregroups
\medskip
L'exploration des groupes peut se réveler utile pour le comptage, le calcul de position ou les tests, mais comporte une limitation lorsque l'on appelle des macros renvoyant des chaînes : lorsqu'un argument est coupé à l'intérieur d'un groupe, alors \textbf{le résultat ne tient pas compte de ce qui se trouve à l'extérieur de ce groupe}. Il faut donc utiliser ce mode en connaissance de cause lorsque l'on utilise les macros renvoyant des chaînes.
-Voyons ce que cela signifie sur un exemple : mettons que l'on veuille renvoyer ce qui se trouve à droite de la 2\ieme{} occurrence de \verb|\a| dans l'argument \verb|\a1{\b1\a2}\a3|. Comme l'on explore les groupes, cette occurrence se trouve à l'intérieur du groupe \verb|{\b1\a2}|. Le résultat renvoyé sera donc : \verb|\b1|. Vérifions-le :\smallskip
+Voyons ce que cela signifie sur un exemple : mettons que l'on veuille renvoyer ce qui se trouve à droite de la 2\ieme{} occurrence de \verb|\a| dans l'argument \verb|\a1{\b1\a2}\a3|. Comme l'on explore les groupes, cette occurrence se trouve à l'intérieur du groupe \verb|{\b1\a2}|. Le résultat renvoyé sera donc : \verb|\b1|. Vérifions-le :
-\begin{minipage}[r]{0.6\linewidth}
-\hfill
-\begin{boxedverbatim}
- \noexpandarg
- \exploregroups
- \StrBefore[2]{\a1{\b1\a2}\a3}{\a}[\mycs]
- \meaning\mycs
-\end{boxedverbatim}
-\hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \noexpandarg
- \exploregroups
- \StrBefore[2]{\a1{\b1\a2}\a3}{\a}[\mycs]
- \meaning\mycs
-\end{minipage}
-\medskip
-L'exploration des groupes\footnote{On peut consulter le fichier de test de \Xstring qui comporte de nombreux exemples et met en évidence les différences selon le mode d'exploration des groupes.} peut ainsi changer le comportement de la plupart des macros de \Xstring, à l'exception de \verb|\IfInteger|, \verb|\IfDecimal|, \verb|\IfStrEq|, \verb|\IfEq| et \verb|\StrCompare| qui sont insensibles au mode d'exploration en cours.
-De plus, pour des raison d'équilibrage d'accolades, 2 macros n'opèrent qu'en mode \verb|\noexploregroups|, quelque soit le mode d'exploration en cours : \verb|\StrBetween| et \verb|\StrMid|.\medskip
+L'exploration des groupes\footnote{On peut consulter le fichier de test de \Xstring qui comporte de nombreux exemples et met en évidence les différences selon le mode d'exploration des groupes.} peut ainsi changer le comportement de la plupart des macros de \Xstring, à l'exception de \verbinline|\IfInteger|, \verbinline|\IfDecimal|, \verbinline|\IfStrEq|, \verbinline|\IfEq| et \verbinline|\StrCompare| qui sont insensibles au mode d'exploration en cours.
-On peut mémoriser le mode de d'exploration en cours avec \verb|\saveexploremode|, le modifier par la suite et revenir à la situation lors de la sauvegarde avec \verb|\restoreexploremode|.
+De plus, pour des raison d'équilibrage d'accolades, 2 macros n'opèrent qu'en mode \verbinline|\noexploregroups|, quelque soit le mode d'exploration en cours : \verbinline|\StrBetween| et \verbinline|\StrMid|.\medskip
+
+On peut mémoriser le mode de d'exploration en cours avec \verbinline|\saveexploremode|, le modifier par la suite et revenir à la situation lors de la sauvegarde avec \verbinline|\restoreexploremode|.
\subsection{Catcodes et macros étoilées}
\label{macrosetoilees}
-Les macros de \Xstring tiennent compte des catcodes des lexèmes constituant les arguments. Il faut donc garder à l'esprit, particulièrement lors des tests, que les lexèmes \emph{et leurs catcodes} sont examinés.\medskip
+Les macros de \Xstring tiennent compte des catcodes des tokens constituant les arguments. Il faut donc garder à l'esprit, particulièrement lors des tests, que les tokens \emph{et leurs catcodes} sont examinés.\medskip
-Par exemple, ces 2 arguments :\par\smallskip
+Par exemple, ces 2 arguments :\par\nobreak\smallskip
\hfil\verb|{\string a\string b}|\qquad et\qquad\verb|{ab}|\hfil{}\par\smallskip
ne se développent pas en 2 arguments égaux aux yeux de \Xstring. Dans le premier cas, à cause de l'emploi de la primitive \verb|\string|, les caractères \og\verb|ab|\fg{} ont un catcode de 12 alors que dans l'autre cas, ils ont leurs catcodes naturels de 11. Il convient donc d'être conscient de ces subtilités lorsque l'on emploie des primitives dont les résultats sont des chaînes de caractères ayant des catcodes de 12 et 10. Ces primitives sont par exemple : \verb|\string|, \verb|\detokenize|, \verb|\meaning|, \verb|\jobname|, \verb|\fontname|, \verb|\romannumeral|, etc.\medskip
Pour demander aux macros de ne pas tenir compte des catcodes, on peut utiliser les macros étoilées. Après l'éventuel développement des arguments en accord avec le mode de développement, celles-ci convertissent (à l'aide d'un \verb|\detokenize|) leur arguments en chaînes de caractères dont les catcodes sont 12 et 10 pour l'espace, avant que la macro non étoilée travaille sur ces arguments ainsi modifiés. Il faut noter que les arguments optionnels ne sont pas concernés par ces modifications et gardent leur catcode.\smallskip
-Voici un exemple :\par\smallskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \IfStrEq{\string a\string b}{ab}{vrai}{faux}\par
- \IfStrEq*{\string a\string b}{ab}{vrai}{faux}
- \end{boxedverbatim}
- \hspace{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+Voici un exemple :\par\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\IfStrEq{\string a\string b}{ab}{vrai}{faux}\par
+\IfStrEq*{\string a\string b}{ab}{vrai}{faux}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\IfStrEq{\string a\string b}{ab}{vrai}{faux}\par
\IfStrEq*{\string a\string b}{ab}{vrai}{faux}
-\end{minipage}\smallskip
+\end{minipage}%
+\smallskip
Les chaînes n'étant pas égales à cause des catcodes, le test est bien \emph{négatif} dans la version non étoilée.\bigskip
\textbf{Attention} : utiliser une macro étoilée a des conséquenses ! Les arguments sont \guill{détokénisés}, il n'y a donc plus de séquence de contrôle, plus de goupes, ni aucun caractère de catcode spécial puisque tout est converti en caractères \guill{inoffensifs} ayant le même catcode.\medskip
-Ainsi, pour les macros renvoyant une chaîne, si on emploie les versions étoilées, le résultat sera une chaîne de caractères dont les catcodes sont 12, et 10 pour l'espace. Ainsi après un \og\verb|\StrBefore*{a \b c d}{c}[\montexte]|\fg{}, la séquence de contrôle \verb|\montexte| se développera en \og{}\verb|a|${}_{12}$\verb*| |${}_{10}$\verb|\|${}_{12}$\verb|b|${}_{12}$\verb*| |${}_{10}$\fg{}.\medskip
+Ainsi, pour les macros renvoyant une chaîne, si on emploie les versions étoilées, le résultat sera une chaîne de caractères dont les catcodes sont 12, et 10 pour l'espace.
-Les macros détokenisant leur arguments par l'utilisation de l'étoile sont présentées dans la liste ci-dessous. Pour chacune d'entre elles, on peut voir en \textcolor{red}{rouge} quels arguments seront détokenisé lorsque l'étoile sera employée :\smallskip
+Et donc, après un \og\verbinline|\StrBefore*{a \b c d}{c}[\montexte]|\fg{}, la séquence de contrôle \verb|\montexte| se développera en \og{}\verb|a|${}_{12}$\verb*| |${}_{10}$\verb|\|${}_{12}$\verb|b|${}_{12}$\verb*| |${}_{10}$\fg{}.\medskip
-\parindent3em
+Les macros détokenisant leur arguments par l'utilisation de l'étoile sont présentées dans la liste ci-dessous. Pour chacune d'entre elles, on peut voir en \textcolor{violet}{violet} quels arguments seront détokenisé lorsque l'étoile sera employée :
+
+\nobreak\smallskip\parindent3em
\begin{itemize}
\item\verb|\IfSubStr|\etoile\arguC{nombre}{\colorise\ARGU{chaine}\ARGU{chaineA}}\ARGU{vrai}\ARGU{faux}
\item\verb|\IfSubStrBefore|\etoile\arguCC{nombre1}{nombre2}{\colorise\ARGU{chaine}\ARGU{chaineA}\ARGU{chaineB}}\ARGU{vrai}\ARGU{faux}
@@ -958,12 +1358,13 @@ Les macros détokenisant leur arguments par l'utilisation de l'étoile sont pré
\end{itemize}
\parindent0pt
-\section{Macros avancées la programmation}
+\section{Macros avancées pour la programmation}
Bien que \Xstring ait la possibilité de lire et traiter des arguments contenant du code \TeX{} ou \LaTeX{} ce qui devrait couvrir la plupart des besoins en programmation, il peut arriver pour des besoins très spécifiques que les macros décritesz précédemment ne suffisent pas. Ce chapitre présente d'autres macros qui permettent d'aller plus loin ou de contourner certaines limitations.
\subsection{Recherche d'un groupe, les macros {\ttfamily\textbackslash StrFindGroup} et {\ttfamily\textbackslash groupID}}
-Lorsque le mode \verb=\exploregroups= est actif, la macro \verb=\StrFindGroup= permet de trouver un groupe entre accolades explicites en spécifiant son identifiant :\smallskip
+Lorsque le mode \verbinline=\exploregroups= est actif, la macro \verbinline=\StrFindGroup= permet de trouver un groupe entre accolades explicites en spécifiant son identifiant :
-\verb|\StrFindGroup|\ARGU{argument}\ARGU{identifiant}\arguC{nom}\medskip
+\nobreak\smallskip
+\verbinline|\StrFindGroup|\ARGU{argument}\ARGU{identifiant}\arguC{nom}\medskip
Lorsque le groupe caractérisé par l'identifiant n'existe pas, une chaîne vide sera assignée à la séquence de contrôle \argu{nom}. Si le groupe existe, ce groupe \emph{avec ses accolades} sera assigné à \argu{nom}.\smallskip
@@ -978,7 +1379,9 @@ Prenons par exemple l'argument suivant où l'on a 3 niveaux d'imbrication de gro
\[\texte{a}{\color{red}\underbrace{\AccO{red}{\color{blue}\underbrace{\decalbrace\AccO{blue}\texte{bc}\AccF{blue}}_{\color{blue}1}}\texte{d}{\color{blue}\underbrace{\decalbrace\AccO{blue}\texte{efg}\AccF{blue}}_{\color{blue}2}}\AccF{red}}_{\color{red}1}}\texte{h}{\color{red}\underbrace{\AccO{red}{\color{blue}\underbrace{\decalbrace\AccO{blue}\texte{ij}\AccF{blue}}_{\color{blue}1}}{\color{blue}\underbrace{\decalbrace\AccO{blue}\texte{k}\AccF{blue}}_{\color{blue}2}}{\color{blue}\underbrace{\AccO{blue}\texte{l}{\color{green}\underbrace{\AccO{green}\texte{m}\AccF{green}}_{\color{green}1}}{\color{green}\underbrace{\AccO{green}\texte{no}\AccF{green}}_{\color{green}2}}\AccF{blue}}_{\color{blue}3}}\texte{p}\AccF{red}}_{\color{red}2}}\]
\endgroup
\smallskip
-Dans cet exemple :\parindent3em
+Dans cet exemple :
+
+\nobreak\parindent3em
\begin{itemize}
\item le groupe \verb={{bc}d{efg}}= a donc pour identifiant \texttt{\color{red}1};
\item le groupe \verb={ij}= a pour identifiant \texttt{{\color{red}2},\color{blue}1};
@@ -987,12 +1390,24 @@ Dans cet exemple :\parindent3em
\end{itemize}
\parindent0pt
\medskip
-
-Voici l'exemple complet :\smallskip
-
-\begin{minipage}[r]{0.6\linewidth}
-\hfill
-\begin{boxedverbatim}
+Voici l'exemple complet :\par\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\exploregroups
+\expandarg
+\def\chaine{a{{bc}d{efg}}h{{ij}{k}{l{m}{no}}p}}
+\StrFindGroup{\chaine}{1}[\mongroupe]
+\meaning\mongroupe\par
+\StrFindGroup{\chaine}{2,1}[\mongroupe]
+\meaning\mongroupe\par
+\StrFindGroup{\chaine}{2,3,2}[\mongroupe]
+\meaning\mongroupe\par
+\StrFindGroup{\chaine}{2,5}[\mongroupe]
+\meaning\mongroupe\par
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\exploregroups
\expandarg
\def\chaine{a{{bc}d{efg}}h{{ij}{k}{l{m}{no}}p}}
@@ -1004,62 +1419,44 @@ Voici l'exemple complet :\smallskip
\meaning\mongroupe\par
\StrFindGroup{\chaine}{2,5}[\mongroupe]
\meaning\mongroupe\par
-\end{boxedverbatim}
-\hspace*{0.3cm}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \exploregroups
- \expandarg
- \def\chaine{a{{bc}d{efg}}h{{ij}{k}{l{m}{no}}p}}
- \StrFindGroup{\chaine}{1}[\mongroupe]
- \meaning\mongroupe\par
- \StrFindGroup{\chaine}{2,1}[\mongroupe]
- \meaning\mongroupe\par
- \StrFindGroup{\chaine}{2,3,2}[\mongroupe]
- \meaning\mongroupe\par
- \StrFindGroup{\chaine}{2,5}[\mongroupe]
- \meaning\mongroupe\par
-\end{minipage}
\bigskip
-Le processus inverse existe, et plusieurs macros de \Xstring donnent aussi comme information l'identifiant du groupe dans lequel elles ont fait une coupure ou trouvé une recherche. Ces macros sont : \verb|\IfSubStr|, \verb|\StrBefore|, \verb|\StrBehind|, \verb|\StrSplit|, \verb|\StrLeft|, \verb|\StrGobbleLeft|, \verb|\StrRight|, \verb|\StrGobbleRight|, \verb|\StrChar|, \verb|\StrPosition|.\medskip
-
-Après l'appel à ces macros, la commande \verb|\groupID| se développe en l'identifiant du groupe dans lequel la coupure s'est faite ou la recherche d'un argument a abouti. Lorsque la coupure ne peut avoir lieu ou que la recherche n'a pas abouti, \verb|\groupID| est vide. Évidemment, l'utilisation de \verb|\groupID| n'a de sens que lorsque le mode \verb|\exploregroups| est actif, et quand les macros ne sont pas étoilées.\smallskip
-
-Voici quelques exemples avec la macro \verb|\StrChar| :\smallskip
-
-\begin{minipage}[r]{0.6\linewidth}
-\hfill
-\begin{boxedverbatim}
- \exploregroups
- char no 1 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{1}\qquad
- \string\groupID = \groupID\par
- char no 4 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{4}\qquad
- \string\groupID = \groupID\par
- char no 6 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{6}\qquad
- \string\groupID = \groupID\par
- char no 20 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{20}\qquad
- \string\groupID = \groupID
-\end{boxedverbatim}
-\hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+Le processus inverse existe, et plusieurs macros de \Xstring donnent aussi comme information l'identifiant du groupe dans lequel elles ont fait une coupure ou trouvé une recherche. Ces macros sont : \verbinline|\IfSubStr|, \verbinline|\StrBefore|, \verbinline|\StrBehind|, \verbinline|\StrSplit|, \verbinline|\StrLeft|, \verbinline|\StrGobbleLeft|, \verbinline|\StrRight|, \verbinline|\StrGobbleRight|, \verbinline|\StrChar|, \verbinline|\StrPosition|.\medskip
+
+Après l'appel à ces macros, la commande \verbinline|\groupID| se développe en l'identifiant du groupe dans lequel la coupure s'est faite ou la recherche d'un argument a abouti. Lorsque la coupure ne peut avoir lieu ou que la recherche n'a pas abouti, \verbinline|\groupID| est vide. Évidemment, l'utilisation de \verbinline|\groupID| n'a de sens que lorsque le mode \verbinline|\exploregroups| est actif, et quand les macros ne sont pas étoilées.\smallskip
+
+Voici quelques exemples avec la macro \verbinline|\StrChar| :\par\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\exploregroups
+char 1 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{1}\qquad
+\string\groupID = \groupID\par
+char 4 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{4}\qquad
+\string\groupID = \groupID\par
+char 6 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{6}\qquad
+\string\groupID = \groupID\par
+char 20 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{20}\qquad
+\string\groupID = \groupID
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\exploregroups
- char no 1 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{1}\qquad
+ char 1 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{1}\qquad
\string\groupID = \groupID\par
- char no 4 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{4}\qquad
+ char 4 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{4}\qquad
\string\groupID = \groupID\par
- char no 6 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{6}\qquad
+ char 6 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{6}\qquad
\string\groupID = \groupID\par
- char no 20 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{20}\qquad
+ char 20 = \StrChar{a{b{cd}{e{f}g}h}ijkl}{20}\qquad
\string\groupID = \groupID
\end{minipage}
\subsection{Coupure d'une chaîne, la macro {\ttfamily\textbackslash StrSplit}}
\label{StrSplit}
-Voici la syntaxe de cette macro :\smallskip
-
-\verb|\StrSplit|\ARGU{chaine}\ARGU{nombre}\ARGU{chaineA}\ARGU{chaineB}
+Voici la syntaxe de cette macro :\par\nobreak\smallskip
+\verbinline|\StrSplit|\ARGU{chaine}\ARGU{nombre}\ARGU{chaineA}\ARGU{chaineB}
\smallskip
La \argu{chaine}, est coupée en deux chaînes juste après l'\US se situant à la position \argu{nombre}. La partie gauche est assigné à la séquence de contrôle \argu{chaineA} et la partie droite à \argu{chaineB}.\par
@@ -1071,363 +1468,373 @@ Cette macro renvoie \emph{deux chaînes} et donc \textbf{n'affiche rien}. Par co
\item Si \argu{chaine} est vide \argu{chaineA} et \argu{chaineB} seront vides, quelque soit l'entier \argu{nombre}.
\end{Conditions}
-\setverbdelim{=}
-\exemple=\StrSplit{abcdef}{4}{\csA}{\csB}résultats : |\csA| et |\csB|=
-\exemple=\StrSplit{a b c }{2}{\csA}{\csB}résultats : |\csA| et |\csB|=
-\exemple=\StrSplit{abcdef}{1}{\csA}{\csB}résultats : |\csA| et |\csB|=
-\exemple=\StrSplit{abcdef}{5}{\csA}{\csB}résultats : |\csA| et |\csB|=
-\exemple=\StrSplit{abcdef}{9}{\csA}{\csB}résultats : |\csA| et |\csB|=
-\exemple=\StrSplit{abcdef}{-3}{\csA}{\csB}résultats : |\csA| et |\csB|=
-\setverbdelim{|}\medskip
+\begin{minipage}[c]{0.65\linewidth}
+\hfill
+\begin{lstlisting}
+ \def\seprouge{{\color{red}|}}
+ \StrSplit{abcdef}{4}{\csA}{\csB}|\csA\seprouge\csB|\par
+ \StrSplit{a b c }{2}{\csA}{\csB}|\csA\seprouge\csB|\par
+ \StrSplit{abcdef}{1}{\csA}{\csB}|\csA\seprouge\csB|\par
+ \StrSplit{abcdef}{5}{\csA}{\csB}|\csA\seprouge\csB|\par
+ \StrSplit{abcdef}{9}{\csA}{\csB}|\csA\seprouge\csB|\par
+ \StrSplit{abcdef}{-3}{\csA}{\csB}|\csA\seprouge\csB|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
+ \def\seprouge{{\color{red}|}}
+ \StrSplit{abcdef}{4}{\csA}{\csB}|\csA\seprouge\csB|\par
+ \StrSplit{a b c }{2}{\csA}{\csB}|\csA\seprouge\csB|\par
+ \StrSplit{abcdef}{1}{\csA}{\csB}|\csA\seprouge\csB|\par
+ \StrSplit{abcdef}{5}{\csA}{\csB}|\csA\seprouge\csB|\par
+ \StrSplit{abcdef}{9}{\csA}{\csB}|\csA\seprouge\csB|\par
+ \StrSplit{abcdef}{-3}{\csA}{\csB}|\csA\seprouge\csB|
+\end{minipage}%
-Lorsque l'exploration des groupes est activée, et que l'on demande une coupure en fin de groupe, alors une chaîne contiendra la totalité du groupe tansque l'autre sera vide comme on le voit sur cet exemple :\smallskip
+\setverbdelim{|}\medskip
-\begin{minipage}[r]{0.6\linewidth}
+Lorsque l'exploration des groupes est activée, et que l'on demande une coupure en fin de groupe, alors une chaîne contiendra la totalité du groupe tansque l'autre sera vide comme on le voit sur cet exemple :\par\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
\hfill
-\begin{boxedverbatim}
+\begin{lstlisting}
+\exploregroups
+\StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
+\meaning\strA\par
+\meaning\strB
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\exploregroups
\StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
\meaning\strA\par
\meaning\strB
-\end{boxedverbatim}
-\hspace*{0.3cm}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \exploregroups
- \StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
- \meaning\strA\par
- \meaning\strB
-\end{minipage}
\medskip
-Une version étoilée de cette macro existe : dans ce cas, la coupure se fait juste avant la prochaine \US qui suit l'\US désirée. La version étoilée ne donne des résultats différents de la version normale que lorsque la $n$\ieme{} \US est à la fin d'un groupe auquel cas, la coupure intervient non pas après cette \US mais \emph{avant} la prochaine \US, que \verb|StrSplit| atteint en fermant autant de groupes que nécessaire.\smallskip
+Une version étoilée de cette macro existe : dans ce cas, la coupure se fait juste avant la prochaine \US qui suit l'\US désirée. La version étoilée ne donne des résultats différents de la version normale que lorsque la $n$\ieme{} \US est à la fin d'un groupe auquel cas, la coupure intervient non pas après cette \US mais \emph{avant} la prochaine \US, que \verbinline|\StrSplit| atteint en fermant autant de groupes que nécessaire.\smallskip
-\begin{minipage}[r]{0.6\linewidth}
+\begin{minipage}[c]{0.65\linewidth}
\hfill
-\begin{boxedverbatim}
+\begin{lstlisting}
+\exploregroups
+Utilisation sans \'etoile :\par
+\StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
+\meaning\strA\par
+\meaning\strB\par
+\string\groupID\ = \groupID\par\medskip
+Utilisation avec \'etoile :\par
+\StrSplit*{ab{cd{ef}gh}ij}{6}\strA\strB
+\meaning\strA\par
+\meaning\strB\par
+\string\groupID\ = \groupID
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\exploregroups
- Macro non étoilée :\par
+ Utilisation sans étoile :\par
\StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
\meaning\strA\par
\meaning\strB\par
- \string\groupID = \groupID\par
- Macro étoilée :\par
+ \string\groupID\ = \groupID\par\medskip
+ Utilisation avec \'etoile :\par
\StrSplit*{ab{cd{ef}gh}ij}{6}\strA\strB
\meaning\strA\par
\meaning\strB\par
\string\groupID\ = \groupID
-\end{boxedverbatim}
-\hspace*{0.3cm}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \exploregroups
- Macro non étoilée :\par
- \StrSplit{ab{cd{ef}gh}ij}{6}\strA\strB
- \meaning\strA\par
- \meaning\strB\par
- \string\groupID = \groupID\par
- Macro étoilée :\par
- \StrSplit*{ab{cd{ef}gh}ij}{6}\strA\strB
- \meaning\strA\par
- \meaning\strB\par
- \string\groupID\ = \groupID
-\end{minipage}
\subsection{Assigner un contenu verb, la macro \ttfamily\textbackslash verbtocs}
\label{verbtocs}
-La macro \verb|\verbtocs| permet le lire le contenu d'un \guill{verb} qui peut contenir tous les caractères spéciaux : \verb|&|, \verb|~|, \verb|\|, \verb|{|, \verb|}|, \verb|_|, \verb|#|, \verb|$|, \verb|^| et \verb|%|. Les caractères \guill{normaux} gardent leur catcodes naturels, sauf les caractères spéciaux qui prennent un catcode de 12. Ensuite, ces caractères sont assignés à une séquence de contrôle. La syntaxe complète est :\medskip
-
-\hfill\verb|\verbtocs|\ARGU{nom}|\argu{caractères}|\hfill{}
+La macro \verbinline|\verbtocs| permet le lire le contenu d'un \guill{verb} qui peut contenir tous les caractères spéciaux : \verb|&|, \verb|~|, \verb|\|, \verb|{|, \verb|}|, \verb|_|, \verb|#|, \verb|$|, \verb|^| et \verb|%|. Les caractères \guill{normaux} gardent leur catcodes naturels, sauf les caractères spéciaux qui prennent un catcode de 12. Ensuite, ces caractères sont assignés à une séquence de contrôle. La syntaxe complète est :\par\nobreak\medskip
+\hfill\verbinline|\verbtocs|\ARGU{nom}|\argu{caractères}|\hfill{}
\smallskip
\argu{nom} est le nom d'une séquence de contrôle qui recevra à l'aide d'un \verb|\edef| les \argu{caractères}. \argu{nom} contiendra donc des caractères de catcodes 12 ou 10 pour l'espace.\medskip
-Par défaut, le lexème délimitant le contenu verb est \guill{|}, étant entendu que ce lexème ne peut être à la fois le délimiteur et être contenu dans ce qu'il délimite. Au cas où on voudrait lire un contenu verb contenant \guill{|}, on peut changer à tout moment le lexème délimitant le contenu verb par la macro :\par\medskip
-\hfill\verb|\setverbdelim|\ARGU{lexème}\hfill{}\smallskip
+Par défaut, le token délimitant le contenu verb est \guill{|}, étant entendu que ce token ne peut être à la fois le délimiteur et être contenu dans ce qu'il délimite. Au cas où on voudrait lire un contenu verb contenant \guill{|}, on peut changer à tout moment le token délimitant le contenu verb par la macro :\par\medskip
+\hfill\verbinline|\setverbdelim|\ARGU{token}\hfill{}\smallskip
-Tout \argu{lexème} peut être utilisé\footnote{Plusieurs lexèmes peuvent être utilisés au risque d'alourdir la syntaxe de \texttt{\string\verbtocs} ! Pour cette raison, avertissement sera émis si l'argument de \texttt{\string\setverbdelim} contient plusieurs lexèmes.}.\medskip
+Tout \argu{token} de catcode 12 peut être utilisé\footnote{Plusieurs tokens peuvent être utilisés au risque d'alourdir la syntaxe de \texttt{\string\verbtocs} ! Pour cette raison, avertissement sera émis si l'argument de \texttt{\string\setverbdelim} contient plusieurs tokens.}.\medskip
Concernant ces arguments verb, il faut tenir compte des deux points suivants :
+
+\nobreak
\begin{itemize}
\item tous les caractères se trouvant avant |\argu{caractères}| seront ignorés;
\item à l'intérieur des délimiteurs, tous les espaces sont comptabilisés même s'ils sont consécutifs.
\end{itemize}
\medskip
-Exemple :\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \verbtocs{\resultat} |a & b{ c% d$ e \f|
- J'affiche le résultat :\par\resultat
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+Exemple :\par\nobreak\medskip
+\begin{minipage}[c]{0.65\linewidth}
+\lstset{deletecomment=[l]\%}
+\begin{lstlisting}
+\verbtocs{\resultat} |a & b{ c% d$ e \f|
+J'affiche le r\'esultat :\par\resultat
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\verbtocs{\resultat} |a & b{ c% d$ e \f|
- J'affiche le résultat :\par\resultat
-\end{minipage}
+ J'affiche le r\'esultat :\par\resultat
+\end{minipage}%
\subsection{Tokenisation d'un texte vers une séquence de contrôle, la macro \ttfamily\textbackslash tokenize}
-Le processus inverse de ce qui a été vu au dessus consiste à interpréter une suite de caractères en lexèmes. Pour cela, on dispose de la macro :\medskip
-
-\hfill\verb|\tokenize|\ARGU{nom}\ARGU{séquences de contrôle}\hfill{}
+Le processus inverse de ce qui a été vu au dessus consiste à interpréter une suite de caractères en tokens. Pour cela, on dispose de la macro :\par\nobreak\medskip
+\hfill\verbinline|\tokenize|\ARGU{nom}\ARGU{texte}\hfill{}
\smallskip
-\argu{séquences de contrôle} est développée le plus possible si l'on a invoqué \verb|\fullexpandarg|; elle n'est pas développée si l'on a invoqué \verb|\normalexpandarg| ou \verb|\expandarg|. Après développement éventuel, la suite de caractères est transformeé en lexèmes puis assigné à l 'aide d'un \verb|\def| à la séquence de contrôle \argu{nom}.\medskip
-
-Voici un exemple où l'on détokenise un argument, on affiche le texte obtenu, puis on transforme ce texte en ce que l'argument était au début; enfin, on affiche le résultat de la tokenisation :\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \verbtocs{\text}|\textbf{a} $\frac{1}{2}$|
- texte : \text
- \tokenize{\resultat}{\text}
- \par
- résultat : \resultat
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \raggedright
+\argu{texte} est développé le plus possible si l'on a invoqué \verbinline|\fullexpandarg|; il n'est pas développé si l'on a invoqué \verbinline|\noexpandarg| ou \verbinline|\expandarg|. Après développement éventuel, le \argu{texte} est transformé en tokens puis assigné à l'aide d'un \verb|\def| à la séquence de contrôle \argu{nom}.\medskip
+
+Voici un exemple où l'on détokenise un argument, on affiche le texte obtenu, puis on transforme ce texte en ce que l'argument était au début; enfin, on affiche le résultat de la tokenisation :\par\nobreak\medskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\verbtocs{\text}|\textbf{a} $\frac{1}{2}$|
+texte : \text
+\tokenize{\resultat}{\text}\par
+r\'esultat : \resultat
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\verbtocs{\text}
|\textbf{a} $\frac{1}{2}$|
texte : \text
- \tokenize{\resultat}{\text}
- \par
- résultat : \resultat
-\end{minipage}
+ \tokenize{\resultat}{\text} \par
+ r\'esultat : \resultat
+\end{minipage}%
\medskip
Il est bien évident à la dernière ligne, que l'appel à la séquence de contrôle \verb|\resultat| est ici possible puisque les séquences de contrôle qu'elle contient sont définies.\medskip
-\subsection{Développement d'une séquence de contrôle avant une conversion en verb, la macro \ttfamily\textbackslash scancs}
+\subsection{Développement contrôlé, les macros {\ttfamily\textbackslash StrExpand} et {\ttfamily\textbackslash scancs}}
\label{scancs}
-On peut souhaiter développer une séquence de contrôle avant de convertir ce développement en texte. Pour cela existe la macro :\medskip
-
-\hfill\verb|\scancs|\etoile\arguC{nombre}\ARGU{nom}\ARGU{séquence(s) de contrôle}\hfill{}
-\smallskip
-
-Le \argu{nombre} vaut 1 par défaut et représente la profondeur à laquelle va être développée la \argu{séquence de contrôle} avant d'être verbatimisée en caractères de catcode 12 ou 10 pour l'espace, puis assignée à la séquence de contrôle \argu{nom}.\bigskip
-
-Si cela s'avère nécessaire, on peut aussi contrôler la profondeur de développement avec l'argument optionnel. Si le $n$-développement donne une séquence de contrôle, alors cette séquence de contrôle est verbatimisée en caractères de catcode 12. L'exemple montre toutes les profondeurs de développement de la séquence de contrôle \verb|\c| de la profondeur 0 jusqu'à la profondeur 3 :\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \def\a{1 z 3}
- \def\b{\a}
- \def\c{\b}
- \scancs[0]{\resultat}{\c}
- développement 0 : \resultat\par
- \scancs[1]{\resultat}{\c}
- développement 1 : \resultat\par
- \scancs[2]{\resultat}{\c}
- développement 2 : \resultat\par
- \scancs[3]{\resultat}{\c}
- développement 3 : \resultat
- \end{boxedverbatim}
- \hspace{0.3cm}
+La macro \verbinline|\StrExpand| développe les tokens de la chaîne passée en argument. Voici sa syntaxe :\par\nobreak\medskip
+\verbinline|\StrExpand|\arguC{nombre}\ARGU{chaine}\ARGU{nom}\smallskip
+
+Le \argu{nombre} vaut 1 par défaut et représente le nombre de développement(s) que doit subir la \argu{chaine} de tokens. Le \argu{nom} est le nom d'une séquence de contrôle à laquelle est assigné le résultat, une fois que tous les tokens aient été développé le nombre de fois demandé.\medskip
+
+La macro opère séquentiellement et par passe : chaque token est remplacé par son 1-dévelopement, et le token suivant subit le même traitement jusqu'à ce que la chaîne ait été parcourue. Ensuite, s'il reste des niveaux de développement à faire, une nouvelle passe est initiée, et ainsi de suite jusqu'à ce que le nombre de développements voulu aient été exécutés.\medskip
+
+Voici un exemple :\par\nobreak\smallskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\def\csA{1 2}
+\def\csB{a \csA}
+\def\csC{\csB\space}
+\def\csD{x{\csA y}\csB{\csC z}}
+D\'eveloppement de \string\csD\ au\par
+\StrExpand[0]{\csD}{\csE} niveau 0 :
+\detokenize\expandafter{\csE}\par
+\StrExpand[1]{\csD}{\csE} niveau 1 :
+\detokenize\expandafter{\csE}\par
+\StrExpand[2]{\csD}{\csE} niveau 2 :
+\detokenize\expandafter{\csE}\par
+\StrExpand[3]{\csD}{\csE} niveau 3 :
+\detokenize\expandafter{\csE}\par
+\StrExpand[4]{\csD}{\csE} niveau 4 :
+\detokenize\expandafter{\csE}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
+ \def\csA{1 2}
+ \def\csB{a \csA}
+ \def\csC{\csB\space}
+ \def\csD{x{\csA y}\csB{\csC z}}
+ Développement de \string\csD\ au\par
+ \StrExpand[0]{\csD}{\csE} niveau 0 :
+ \detokenize\expandafter{\csE}\par
+ \StrExpand[1]{\csD}{\csE} niveau 1 :
+ \detokenize\expandafter{\csE}\par
+ \StrExpand[2]{\csD}{\csE} niveau 2 :
+ \detokenize\expandafter{\csE}\par
+ \StrExpand[3]{\csD}{\csE} niveau 3 :
+ \detokenize\expandafter{\csE}\par
+ \StrExpand[4]{\csD}{\csE} niveau 4 :
+ \detokenize\expandafter{\csE}
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \def\a{1 z 3}
- \def\b{\a}
- \def\c{\b}
- \scancs[0]{\resultat}{\c}
- développement 0 : \resultat\par
- \scancs[1]{\resultat}{\c}
- développement 1 : \resultat\par
- \scancs[2]{\resultat}{\c}
- développement 2 : \resultat\par
- \scancs[3]{\resultat}{\c}
- développement 3 : \resultat
-\end{minipage}
\medskip
-Il est bien évident qu'il faut s'assurer que le développement à la profondeur souhaitée soit possible, sous peine d'erreur à la compilation.\medskip
-
-En toute rigueur, le 3\ieme{} argument \argu{séquence de contrôle} (ou l'un de ses développements) doit contenir une seule et unique séquence de contrôle qui elle seule sera développée. Si ce 3\ieme{} argument ou l'un ses développements contient plusieurs séquences de contrôle, la compilation s'arrête avec un message d'erreur invitant à utiliser la version étoilée. La macro étoilée, d'utilisation plus délicate et qu'il convient donc d'utiliser avec attention, permet en effet de développer \emph{toutes} les séquences de contrôle contenues dans le 3\ieme{} argument à la profondeur spécifiée dans le 1\ier{} argument. Il faut garder à l'esprit que si le $n$-développement contient un groupe entre accolades, ce groupe sera développé au développement $n+1$, et perdra ses accolades ! Il en est de même pour les espaces\footnote{Tout appel à la macro {\ttfamily\string\scancs} est accompagné d'un message d'attention mettant en grade sur ces inconvénients.}.
-
-Voici un exemple :\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \def\a{1 {2}}
- \def\b{\a \a}
- \scancs*[0]{\resultat}{{A}\b}
- développement 0 : \resultat\par
- \scancs*[1]{\resultat}{{A}\b}
- développement 1 : \resultat\par
- \scancs*[2]{\resultat}{{A}\b}
- développement 2 : \resultat\par
- \scancs*[3]{\resultat}{{A}\b}
- développement 3 : \resultat
- \end{boxedverbatim}
- \hspace{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \def\a{1 {2}}
- \def\b{\a \a}
- \scancs*[0]{\resultat}{{A}\b}
- développement 0 : \resultat\par
- \scancs*[1]{\resultat}{{A}\b}
- développement 1 : \resultat\par
- \scancs*[2]{\resultat}{{A}\b}
- développement 2 : \resultat\par
- \scancs*[3]{\resultat}{{A}\b}
- développement 3 : \resultat
-\end{minipage}
+La macro opère séquentiellement et chaque token est développé isolément sans tenir compte de ce qui suit. On ne peut donc développer que des tokens se suffisant à eux même et n'en nécessitant aucun autre. Ainsi, \og\hbox{\verbinline|\iftrue A\else B\fi|}\fg, bien que se développant en \guill{A} ne peut être mis dans l'argument de \verbinline|\StrExpand|, et l'instruction :\par\nobreak\smallskip
+\hfil\verbinline|\StrExpand{\iftrue A\else B\fi}\resultat|\hfil{}\par\nobreak\smallskip
+fera échouer la compilation puisque le premier token \og\verbinline|\iftrue|\fg{} sera développé \emph{seul}, c'est-à-dire sans son \verbinline-\fi- correspondant, ce qui fâchera \TeX{} !\smallskip
+
+Les règles habituelles de lecture des arguments sont en vigueur, à savoir qu'un espace suivant une séquence de contrôle est ignoré, et plusieurs espaces consécutifs n'en font qu'un. Ces règles ne s'appliquent pas pour des espaces explicitement demandés avec \verb-\space- ou \verb*-\ -\footnote{À ce propos, \texttt{\string\space} n'a pas la même signification que \texttt{\string\ }. La première séquence de contrôle se \emph{développe} en un espace tandis que la deuxième est une primitive \TeX{} qui \emph{affiche} une espace. Comme toutes les primitives, cette dernière est son propre développement.}.\smallskip
+
+Le développement de ce qui se trouve à l'intérieur des groupes est \emph{indépendant} du mode d'exploration des groupes : cette macro possède ses propres commandes pour développer ce qui est dans les groupes ou pas. Par défaut, les tokens se trouvant à l'intérieur des groupes sont développés, mais on peut demander à ce que ce développement ne se fasse pas en invoquant \verbinline-\noexpandingroups- et revenir au comportement par defaut par \verbinline-\expandingroups-.\bigskip
+
+On peut détokeniser le résultat obtenu par la macro \verbinline-\StrExpand- avec la macro \verbinline-\scancs- dont la syntaxe est :\par\nobreak\medskip
+\verbinline|\scancs|\arguC{nombre}\ARGU{nom}\ARGU{chaine}\par\nobreak\smallskip
+Le \argu{nombre} vaut 1 par défaut et représente le nombre de développement(s) que doit subir chaque token constituant la \argu{chaine}. Le \argu{nom} est le nom d'une séquence de contrôle à laquelle est assigné le résultat, une fois que tous les tokens aient été développés le nombre de fois demandé et ensuite détokénisés.\smallskip
+
+\verbinline-\scancs- a été conservée pour garder une compatibilité avec des précédentes versions de \Xstring. Pour les mêmes raisons, sa syntaxe n'est pas cohérente avec la syntaxe des autres macros. Cette macro, devenue triviale, prend le résultat de \verbinline|\StrExpand| et lui applique simplement un \verbinline|\detokenize|.
\subsection{À l'intérieur d'une définition de macro}
-Certaines difficultés surviennent lorsque l'on se trouve à l'intérieur de la définition d'une macro, c'est-à-dire entre les accolades suivant un \verb|\def\macro| ou un \verb|\newcommand\macro|.\medskip
+Avec le verbatim, certaines difficultés surviennent lorsque l'on se trouve à l'intérieur de la définition d'une macro, c'est-à-dire entre les accolades suivant un \verb|\def\macro| ou un \verb|\newcommand\macro|.\medskip
-Pour les mêmes raison qu'il est interdit d'employer la commande \verb|\verb| à l'intérieur de la définition d'une macro, les arguments textuels verb du type |\argu{caractères}| sont également interdits, ce qui disqualifie la macro \verb|\verbtocs|. Il faut donc observer la règle suivante :\par\medskip
-\hfill \textbf{Ne pas utiliser la macro {\ttfamily\string\verbtocs} à l'intérieur de la définition d'une macro}.\hfill{}\bigskip
+Pour les mêmes raison qu'il est interdit d'employer la commande \verb|\verb| à l'intérieur de la définition d'une macro, les arguments verb du type |\argu{caractères}| sont également interdits, ce qui disqualifie la macro \verbinline|\verbtocs|. Il faut donc observer la règle suivante :\par\medskip
+\hfill{\bfseries Ne pas utiliser la macro \verbinline-\verbtocs- à l'intérieur de la définition d'une macro}.\hfill{}\bigskip
Mais alors, comment faire pour manipuler des arguments textuels verb et \guill{verbatimiser} dans les définitions de macro ?\bigskip
Il y a la primitive \verb|\detokenize| de $\varepsilon$-\TeX, mais elle comporte des restrictions, entre autres :
+
+\nobreak
\begin{itemize}
\item les accolades doivent être équilibrées;
\item les espaces consécutifs sont ignorés;
\item les signes \verb|%| sont interdits;
- \item une espace est ajoutée après chaque séquence de contrôle;
- \item les caractères \verb|#| sont doublés.
+ \item une espace est ajoutée après chaque séquence de contrôle.
\end{itemize}
\medskip
-Il est préférable d'utiliser la macro \verb|\scancs|, et définir avec \verb|\verbtocs| à l'extérieur des définitions de macros, des séquences de contrôle contenant des caractères spéciaux détokénisés. On pourra aussi utiliser la macro \verb|\tokenize| pour transformer le résultat final (qui est une chaîne de caractères) en une séquence de contrôle. On peut voir des exemples utilisant ces macros page~\pageref{exemples}, à la fin de ce manuel.\medskip
-
-Dans l'exemple artificiel\footnote{On peut agir beaucoup plus simplement en utilisant la commande \texttt{\string\detokenize}. Il suffit de définir la macro ainsi :\par\texttt{\string\newcommand\string\bracearg[1]\{\string\detokenize\{\{\#1\}\}\}}} qui suit, on écrit une macro qui met son argument entre accolades. Pour cela, on définit en dehors de la définition de la macro 2 séquences de contrôles \verb|\Ob| et \verb|\Cb| contenant une accolade ouvrante et une accolade fermante de catcodes 12. Ces séquences de contrôle sont ensuite développées et utilisées à l'intérieur de la macro pour obtenir le résultat voulu :\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \verbtocs{\Ob}|{|
- \verbtocs{\Cb}|}|
- \newcommand\bracearg[1]{%
- \def\text{#1}%
- \scancs*{\result}{\Ob\text\Cb}%
- \result%
- }
- \bracearg{xstring}\par
- \bracearg{\a}
- \end{boxedverbatim}
- \hspace{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+Il est préférable d'utiliser la macro \verbinline|\scancs|, et définir avec \verbinline|\verbtocs| à l'extérieur des définitions de macros, des séquences de contrôle contenant des caractères spéciaux détokénisés. On pourra aussi utiliser la macro \verbinline|\tokenize| pour transformer le résultat final (qui est une chaîne de caractères) en une séquence de contrôle. On peut voir des exemples utilisant ces macros page~\pageref{exemples}, à la fin de ce manuel.\medskip
+
+Dans l'exemple artificiel\footnote{On peut agir beaucoup plus simplement en utilisant la commande \texttt{\string\detokenize}. Il suffit de définir la macro ainsi :\par\texttt{\string\newcommand\string\bracearg[1]\{\string\detokenize\{\{\#1\}\}\}}} qui suit, on écrit une macro qui met son argument entre accolades. Pour cela, on définit en dehors de la définition de la macro 2 séquences de contrôles \verb|\Ob| et \verb|\Cb| contenant une accolade ouvrante et une accolade fermante de catcodes 12. Ces séquences de contrôle sont ensuite développées et utilisées à l'intérieur de la macro pour obtenir le résultat voulu :\par\nobreak\medskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\verbtocs{\Ob}|{|
+\verbtocs{\Cb}|}|
+\newcommand\bracearg[1]{%
+ \def\text{#1}%
+ \scancs{\result}{\Ob\text\Cb}%
+ \result}
+
+\bracearg{xstring}\par
+\bracearg{\a}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\verbtocs{\Ob}|{|
\verbtocs{\Cb}|}|
\newcommand\bracearg[1]{%
\def\text{#1}%
- \scancs*{\result}{\Ob\text\Cb}%
+ \scancs{\result}{\Ob\text\Cb}%
\result}
+
\bracearg{xstring}\par
\bracearg{\a}
-\end{minipage}
+\end{minipage}%
\subsection{La macro \ttfamily\textbackslash StrRemoveBraces}
Pour des utilisations spéciales, on peut désirer retirer les accolades délimitant les groupes dans un argument.
-On peut utiliser la macro \verb|\StrRemoveBraces| dont voici la syntaxe :\smallskip
-
-\verb|\StrRemoveBraces|\ARGU{chaine}\arguC{nom}
+On peut utiliser la macro \verbinline|\StrRemoveBraces| dont voici la syntaxe :\par\nobreak\smallskip
+\verbinline|\StrRemoveBraces|\ARGU{chaine}\arguC{nom}
\smallskip
-Cette macro est sensible au mode d'exploration, et retirera \emph{toutes} les accolades avec \verb|\exploregroups| alors qu'elle ne retirera que les accolades des groupes de plus bas niveau avec \verb|\noexploregroups|.\medskip
+Cette macro est sensible au mode d'exploration, et retirera \emph{toutes} les accolades avec \verbinline|\exploregroups| alors qu'elle ne retirera que les accolades des groupes de plus bas niveau avec \verbinline|\noexploregroups|.\medskip
+
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\noexploregroups
+\StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]
+\meaning\mycs
+
+\exploregroups
+\StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]
+\meaning\mycs
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
+ \noexploregroups
+ \StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]
+ \meaning\mycs
-\vbox{%
-\exemple|\noexploregroups|
-\exemple|\StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]|
-\exemple|\meaning\mycs|
-\exemple|\exploregroups|
-\exemple|\StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]|
-\exemple|\meaning\mycs|}
+ \exploregroups
+ \StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]
+ \meaning\mycs
+\end{minipage}%
\subsection{Exemples d'utilisation en programmation}
\label{exemples}
Voici quelques exemples très simples d'utilisation des macros comme on pourrait en rencontrer en programmation.
\subsubsection{Exemple 1}
-On cherche à remplacer les deux premiers \verb|\textit| par \verb|\textbf| dans la séquence de contrôle \verb|\myCS| qui contient :\par\smallskip
+On cherche à remplacer les deux premiers \verb|\textit| par \verb|\textbf| dans la séquence de contrôle \verb|\myCS| qui contient :\par\nobreak\smallskip
\hfill\verb|\textit{A}\textit{B}\textit{C}|\hfill{}
\medskip
-On cherche évidemment à obtenir \verb|\textbf{A}\textbf{B}\textit{C}| qui donne : \textbf{A}\textbf{B}\textit{C}\medskip
+On cherche évidemment à obtenir \verb|\textbf{A}\textbf{B}\textit{C}| qui affiche : \textbf{A}\textbf{B}\textit{C}\medskip
-Pour cela, on va développer les arguments des macros une fois avant qu'elles les traitent, en invoquant la commande \verb|\expandarg|.
+Pour cela, on va développer les arguments des macros une fois avant qu'elles les traitent, en invoquant la commande \verbinline|\expandarg|.
-Ensuite, on définit \verb|\pattern| qui est le motif à remplacer, et \verb|\replace| qui est le motif de substitution. On travaille token par token puisque \verb|\expandarg| a été appelé, il suffit d'invoquer \verb|\StrSubstitute| pour faire les 2 substitutions.\medskip
+Ensuite, on définit \verb|\pattern| qui est le motif à remplacer, et \verb|\replace| qui est le motif de substitution. On travaille token par token puisque \verbinline|\expandarg| a été appelé, il suffit d'invoquer \verbinline|\StrSubstitute| pour faire les 2 substitutions.\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \expandarg
- \def\myCS{\textit{A}\textit{B}\textit{C}}
- \def\pattern{\textit}
- \def\replace{\textbf}
- \StrSubstitute[2]{\myCS}{\pattern}{\replace}
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\expandarg
+\def\myCS{\textit{A}\textit{B}\textit{C}}
+\def\pattern{\textit}
+\def\replace{\textbf}
+\StrSubstitute[2]{\myCS}{\pattern}{\replace}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\expandarg
\def\myCS{\textit{A}\textit{B}\textit{C}}
\def\pattern{\textit}
\def\replace{\textbf}
\StrSubstitute[2]{\myCS}{\pattern}{\replace}
-\end{minipage}\fullexpandarg
+\end{minipage}%
\medskip
Pour éviter de définir les séquences de contrôle \verb|\pattern| et \verb|\replace|, on aurait pu utiliser un leurre comme par exemple une séquence de contrôle qui se développe en \guill{rien} comme \verb|\empty|, et coder de cette façon :\par\smallskip
-\hfil\verb|\StrSubstitute[2]{\myCS}{\empty\textit}{\empty\textbf}|\hfil{}\medskip
+\hfil\verbinline|\StrSubstitute[2]{\myCS}{\empty\textit}{\empty\textbf}|\hfil{}\medskip
Ainsi, \verb|\empty| est développée en \guill{rien} et il reste dans les 2 derniers arguments les séquences de contrôles significatives \verb|\textit| et \verb|textbf|.\smallskip
-La séquence de contrôle \verb|\empty| est donc un \guill{hack} pour \verb|\expandarg| : elle permet de bloquer le développement du 1\ier{} lexème ! On aurait d'ailleurs pu utiliser \verb|\noexpand| au lieu de \verb|\empty| pour obtenir le même résultat.
+La séquence de contrôle \verbinline|\empty| est donc un \guill{hack} pour \verbinline|\expandarg| : elle permet de bloquer le développement du 1\ier{} token ! On aurait d'ailleurs pu utiliser \verbinline|\noexpand| au lieu de \verbinline|\empty| pour obtenir le même résultat.
\subsubsection{Exemple 2}
On cherche ici à écrire une commande qui efface \verb|n| unités syntaxiques dans une chaîne à partir d'une position donnée, et affecte le résultat dans une séquence de contrôle dont on peut choisir le nom.
-On va appeler cette macro \verb|StringDel| et lui donner la syntaxe :
-
+On va appeler cette macro \verb|StringDel| et lui donner la syntaxe :\par\nobreak\smallskip
\hfil\verb|\StringDel{chaine}{position}{n}{\nom_resultat}|\hfil{}
\medskip
-On peut procéder ainsi : prendre la chaîne se trouvant juste avant la position, la sauvegarder. Ensuite enlever \verb|n + position| \USs à la chaîne, et concaténer ce résultat à ce qui a été sauvegardé auparavant. Cela donne le code suivant :\medskip
-
-\begin{minipage}[r]{0.7\linewidth}
- \hfill
- \begin{boxedverbatim}
- \newcommand\StringDel[4]{%
- \begingroup
- \expandarg% portée locale au groupe
- \StrLeft{\empty#1}{\number\numexpr#2-1}[#4]%
- \StrGobbleLeft{\empty#1}{\number\numexpr#2+#3-1}[\StrA]%
- \expandafter\expandafter\expandafter\endgroup
- \expandafter\expandafter\expandafter\def
- \expandafter\expandafter\expandafter#4%
- \expandafter\expandafter\expandafter{\expandafter#4\StrA}%
- }
-
- \noexploregroups
- \StringDel{abcdefgh}{2}{3}{\cmd}
- \meaning\cmd
-
- \StringDel{a\textbf{1}b\textbf{2c}3d}{3}{4}{\cmd}
- \meaning\cmd
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+On peut procéder ainsi : prendre la chaîne se trouvant juste avant la position, la sauvegarder. Ensuite enlever \verb|n + position| \USs à la chaîne initiale, et concaténer ce résultat à ce qui a été sauvegardé auparavant. Cela donne le code suivant :\par\nobreak\medskip
+
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\newcommand\StringDel[4]{%
+ \begingroup
+ \expandarg% portee locale au groupe
+ \StrLeft{\empty#1}{\number\numexpr#2-1}[#4]%
+ \StrGobbleLeft{\empty#1}{\numexpr#2+#3-1}[\StrA]%
+ \expandafter\expandafter\expandafter\endgroup
+ \expandafter\expandafter\expandafter\def
+ \expandafter\expandafter\expandafter#4%
+ \expandafter\expandafter\expandafter
+ {\expandafter#4\StrA}%
+}
+
+\noexploregroups
+\StringDel{abcdefgh}{2}{3}{\cmd}
+\meaning\cmd
+
+\StringDel{a\textbf{1}b\textbf{2c}3d}{3}{4}{\cmd}
+\meaning\cmd
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\newcommand\StringDel[4]{%
\begingroup
\expandarg% portée locale au groupe
\StrLeft{\empty#1}{\number\numexpr#2-1}[#4]%
- \StrGobbleLeft{\empty#1}{\number\numexpr#2+#3-1}[\StrA]%
+ \StrGobbleLeft{\empty#1}{\numexpr#2+#3-1}[\StrA]%
\expandafter\expandafter\expandafter\endgroup
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter#4%
\expandafter\expandafter\expandafter{\expandafter#4\StrA}%
- }
+ }
\noexploregroups
\StringDel{abcdefgh}{2}{3}{\cmd}
@@ -1435,71 +1842,68 @@ On peut procéder ainsi : prendre la chaîne se trouvant juste avant la position
\StringDel{a\textbf{1}b\textbf{2c}3d}{3}{4}{\cmd}
\meaning\cmd
-\end{minipage}\fullexpandarg
-\bigskip
-
-Pour la concaténation, on aurait pu procéder différemment en utilisant la macro \verb|\g@addto@macro| de \LaTeX{}. Cela évite aussi de laborieux \guill{ponts} d'\verb|\expandafter|. Il suffit alors de remplacer l'assignation par\footnote{À condition d'avoir provisoirement changé le code de catégorie de \og{\ttfamily\string@}\fg{} en écrivant la macro entre les commandes {\ttfamily\string\makeatletter} et {\ttfamily\string\makeatother}} :\smallskip
+\end{minipage}%
+\fullexpandarg\bigskip
-\hfil\verb|\expandafter\g@addto@macro\expandafter#4\expandafter{\StrA}\endgroup|\hfil{}
+Pour la concaténation, on aurait pu procéder différemment en utilisant la macro \verb|\g@addto@macro| de \LaTeX{}. Cela évite aussi ces laborieux \guill{ponts} d'\verbinline|\expandafter|. Il suffit alors de remplacer l'assignation et la sortie du groupe se trouvant entre les lignes 6 à 10 par\footnote{À condition d'avoir provisoirement changé le code de catégorie de \og{\ttfamily\string@}\fg{} en écrivant la macro entre les commandes {\ttfamily\string\makeatletter} et {\ttfamily\string\makeatother}} :\par\nobreak\smallskip
+\hfil\verbinline|\expandafter\g@addto@macro\expandafter#4\expandafter{\StrA}\endgroup|\hfil{}
\subsubsection{Exemple 3}
Cherchons à écrire une macro \verb|\tofrac| qui transforme une écriture du type \guill{a/b} par \guill{$\frac{a}{b}$}.\medskip
-Tout d'abord, annulons le développement des arguments avec \verb|\noexpandarg| : nous n'avons pas besoin de développement ici. Il suffit d'isoler ce qui se trouve avant et après la 1\iere{} occurrence de \guill{/} (on suppose qu'il n'y a qu'une seule occurrence), le mettre dans les séquences de contrôle \verb|\avant| et \verb|\apres| et simplement appeler la macro \verb|\frac| :\medskip
-
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \noexpandarg
- \newcommand\tofrac[1]{%
- \StrBefore{#1}{/}[\num]%
- \StrBehind{#1}{/}[\den]%
- $\frac{\num}{\den}$%
- }
- \tofrac{15/9}
- \tofrac{u_{n+1}/u_n}
- \tofrac{a^m/a^n}
- \tofrac{x+\sqrt{x}/\sqrt{x^2+x+1}}
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+Tout d'abord, annulons le développement des arguments avec \verbinline|\noexpandarg| : nous n'avons pas besoin de développement ici. Il suffit d'isoler ce qui se trouve avant et après la 1\iere{} occurrence de \guill{/} (on suppose qu'il n'y a qu'une seule occurrence), le mettre dans les séquences de contrôle \verb|\num| et \verb|\den| et simplement appeler la macro \TeX{} \verb|\frac| :\par\nobreak\medskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\noexpandarg
+\newcommand\tofrac[1]{%
+ \StrBefore{#1}{/}[\num]%
+ \StrBehind{#1}{/}[\den]%
+ $\frac{\num}{\den}$%
+}
+\tofrac{15/9}
+\tofrac{u_{n+1}/u_n}
+\tofrac{a^m/a^n}
+\tofrac{x+\sqrt{x}/\sqrt{x^2+x+1}}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\noexpandarg
\newcommand\tofrac[1]{%
\StrBefore{#1}{/}[\num]%
\StrBehind{#1}{/}[\den]%
- $\frac{\num}{\den}$}
+ $\frac{\num}{\den}$%
+ }
\tofrac{15/9}
\tofrac{u_{n+1}/u_n}
\tofrac{a^m/a^n}
\tofrac{x+\sqrt{x}/\sqrt{x^2+x+1}}
-\end{minipage}\fullexpandarg
+\end{minipage}%
\subsubsection{Exemple 4}
Soit une phrase composée de texte. Dans cette phrase, essayons construire une macro qui mette en gras le 1\ier{} mot qui suit un mot donné. On entend par mot une suite de caractère ne commençant ni ne finissant par un espace. Si le mot n'existe pas dans la phrase, rien n'est fait.\medskip
-On va écrire une macro \verb|\grasapres| qui effectue ce travail. On appelle \verb|\StrBehind| qui assigne à \verb|\mot| ce qui se trouve après la 1\iere{} occurrence du mot (précédé et suivi de son espace). Ensuite, le mot à mettre en gras est ce qui se trouve avant le 1\ier{} espace dans la séquence de contrôle \verb|\mot|. Remarquons que ceci reste vrai même si le mot à mettre en gras est le dernier de l'argument car un espace a été rajouté à la fin de l'argument par \verb|{#1 }| lors de l'appel à \verb|\StrBehind|. Remarquons aussi que \verb|\expandarg| a été appelé et donc, le premier lexème de l'argument \verb|\textbf{\mot}| est développé 1 fois, \emph{lui aussi} ! Cela est possible (heureusement sinon, il aurait fallu faire autrement et utiliser le hack de l'exemple précédent) puisque le 1-développement de cette macro de \LaTeX{} est \og\verb|\protect\textbf|\fg{}\footnote{En toute rigueur, il aurait fallu écrire :\par\hspace{2em}{\ttfamily\string\StrSubstitute[1]\{\string#1\}\{\string\mot\}\{\string\expandafter\string\textbf\string\expandafter\{\string\mot\}\}}\newline De cette façon, dans {\ttfamily\{\string\expandafter\string\textbf\string\expandafter\{\string\mot\}\}}, la séquence de contrôle {\ttfamily\string\mot} est développée \textbf{avant} que l'appel à la macro ne se fasse. Cela est dû à l'{\ttfamily\string\expandafter} placé en début d'argument qui est développé à cause de {\ttfamily\string\expandarg} et grace à l'autre {\ttfamily\string\expandafter}, provoque le développement de {\ttfamily\string\mot}}.\medskip
+On va écrire une macro \verb|\grasapres| qui effectue ce travail. On appelle \verbinline|\StrBehind| qui assigne à \verb|\mot| ce qui se trouve après la 1\iere{} occurrence du mot (précédé et suivi de son espace). Ensuite, le mot à mettre en gras est ce qui se trouve avant le 1\ier{} espace dans la séquence de contrôle \verb|\mot|. Remarquons que ceci reste vrai même si le mot à mettre en gras est le dernier de l'argument car un espace a été rajouté à la fin de l'argument par \verb|{#1 }| lors de l'appel à \verbinline|\StrBehind|. Remarquons aussi que \verbinline|\expandarg| a été appelé et donc, le premier token de l'argument \verb|\textbf{\mot}| est développé 1 fois, \emph{lui aussi} ! Cela est possible (heureusement sinon, il aurait fallu faire autrement et utiliser le hack de l'exemple précédent) puisque le 1-développement de cette macro de \LaTeX{} est \og\verb|\protect\textbf|\fg{}\footnote{En toute rigueur, il aurait fallu écrire :\par\hspace{2em}{\ttfamily\string\StrSubstitute[1]\{\string#1\}\{\string\mot\}\{\string\expandafter\string\textbf\string\expandafter\{\string\mot\}\}}\newline De cette façon, dans {\ttfamily\{\string\expandafter\string\textbf\string\expandafter\{\string\mot\}\}}, la séquence de contrôle {\ttfamily\string\mot} est développée \textbf{avant} que l'appel à la macro ne se fasse. Cela est dû à l'{\ttfamily\string\expandafter} placé en début d'argument qui est développé à cause de {\ttfamily\string\expandarg} et grace à l'autre {\ttfamily\string\expandafter}, provoque le développement de {\ttfamily\string\mot}}.\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \newcommand\grasapres[2]{%
- \noexpandarg
- \StrBehind[1]{#1 }{ #2 }[\mot]%
- \expandarg
- \StrBefore{\mot}{ }[\mot]%
- \StrSubstitute[1]{#1}{\mot}{\textbf{\mot}}%
- }
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\newcommand\grasapres[2]{%
+ \noexpandarg
+ \StrBehind[1]{#1 }{ #2 }[\mot]%
+ \expandarg
+ \StrBefore{\mot}{ }[\mot]%
+ \StrSubstitute[1]{#1}{\mot}{\textbf{\mot}}%
+}
- \grasapres{Le package xstring est nouveau}{package}
+\grasapres{Le package xstring est nouveau}{package}
- \grasapres{Le package xstring est nouveau}{ckage}
+\grasapres{Le package xstring est nouveau}{ckage}
- \grasapres{Le package xstring est nouveau}{est}
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+\grasapres{Le package xstring est nouveau}{est}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\newcommand\grasapres[2]{%
\noexpandarg
\StrBehind[1]{#1 }{ #2 }[\mot]%
@@ -1513,36 +1917,40 @@ On va écrire une macro \verb|\grasapres| qui effectue ce travail. On appelle \v
\grasapres{Le package xstring est nouveau}{ckage}
\grasapres{Le package xstring est nouveau}{est}
-\end{minipage}\fullexpandarg
+\end{minipage}%
+\fullexpandarg
\subsubsection{Exemple 5}
-Soit un argument commençant par au moins 3 séquences de contrôles avec leurs éventuels arguments. Comment intervertir les 2 premières séquences de contrôle de telle sorte qu'elles gardent leurs arguments ? On va pour cela écrire une macro \verb|swaptwofirst|.
-
-Cette fois ci, on ne peut pas chercher le seul caractère \og\verb|\|\fg{} (de catcode 0) dans un argument. Nous serons obligé de détokeniser l'argument, c'est ce que fait \verb|\scancs[0]\chaine{#1}| qui met le résultat dans \verb|\chaine|. Ensuite, on cherchera dans cette séquence de contrôle les occurrences de \verb|\antislash| qui contient le caractère \og\verb|\|\fg{} de catcode 12, assigné avec un \verb|\verbtocs| écrit \emph{en dehors\footnote{En effet, la macro {\tt\string\verbtocs} et son argument verb est interdite à l'intérieur de la définition d'une macro.}} du corps de la macro. La macro se termine par une retokenisation, une fois que les chaînes \verb|\avant| et \verb|\apres| aient été échangées.\medskip
-
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \verbtocs{\antislash}|\|
- \newcommand\swaptwofirst[1]{%
- \fullexpandarg
- \scancs[0]\chaine{#1}%
- \StrBefore[3]{\chaine}{\antislash}[\firsttwo]%
- \StrBehind{\chaine}{\firsttwo}[\others]
- \StrBefore[2]{\firsttwo}{\antislash}[\avant]
- \StrBehind{\firsttwo}{\avant}[\apres]%
- \tokenize\myCS{\apres\avant\others}%
- \myCS}
-
- \swaptwofirst{\underline{A}\textbf{B}\textit{C}}
-
- \swaptwofirst{\Large\underline{A}\textbf{B}123}
- \end{boxedverbatim}
- \hspace*{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
+Soit un argument commençant par au moins 3 séquences de contrôles avec leurs éventuels arguments. Comment intervertir les 2 premières séquences de contrôle de telle sorte qu'elles gardent leurs arguments ? On va pour cela écrire une macro \verb|\swaptwofirst|.
+
+Cette fois ci, on ne peut pas chercher le seul caractère \og\verb|\|\fg{} (de catcode 0) dans un argument. Nous serons obligé de détokeniser l'argument, c'est ce que fait \verbinline|\scancs[0]\chaine{#1}| qui met le résultat dans \verb|\chaine|. Ensuite, on cherchera dans cette séquence de contrôle les occurrences de \verb|\antislash| qui contient le caractère \og\verb|\|\fg{} de catcode 12, assigné avec un \verbinline|\verbtocs| écrit \emph{en dehors\footnote{En effet, la macro {\tt\string\verbtocs} et son argument verb est interdite à l'intérieur de la définition d'une macro.}} du corps de la macro. La macro se termine par une retokenisation, une fois que les chaînes \verb|\avant| et \verb|\apres| aient été échangées.\medskip
+
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\verbtocs{\antislash}|\|
+\newcommand\swaptwofirst[1]{%
+ \begingroup
+ \fullexpandarg
+ \scancs[0]\chaine{#1}%
+ \StrBefore[3]{\chaine}{\antislash}[\firsttwo]%
+ \StrBehind{\chaine}{\firsttwo}[\others]
+ \StrBefore[2]{\firsttwo}{\antislash}[\avant]
+ \StrBehind{\firsttwo}{\avant}[\apres]%
+ \tokenize\myCS{\apres\avant\others}%
+ \myCS
+ \endgroup
+}
+
+\swaptwofirst{\underline{A}\textbf{B}\textit{C}}
+
+\swaptwofirst{\Large\underline{A}\textbf{B}123}
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\verbtocs{\antislash}|\|
\newcommand\swaptwofirst[1]{%
+ \begingroup
\fullexpandarg
\scancs[0]\chaine{#1}%
\StrBefore[3]{\chaine}{\antislash}[\firsttwo]%
@@ -1550,39 +1958,42 @@ Cette fois ci, on ne peut pas chercher le seul caractère \og\verb|\|\fg{} (de c
\StrBefore[2]{\firsttwo}{\antislash}[\avant]
\StrBehind{\firsttwo}{\avant}[\apres]%
\tokenize\myCS{\apres\avant\others}%
- \myCS}
+ \myCS
+ \endgroup
+ }
\swaptwofirst{\underline{A}\textbf{B}\textit{C}}
\swaptwofirst{\Large\underline{A}\textbf{B}123}
-\end{minipage}
+\end{minipage}%
\subsubsection{Exemple 6}
Dans une chaîne, on cherche ici à isoler le n\ieme{} mot se trouvant entre 2 délimiteurs précis. Pour cela on écrira une macro \verb|\findword| admettant comme argument optionnel le délimiteur de mot (l'espace par défaut), 1 argument contenant la chaîne, 1 argument contenant le nombre correspondant au n\ieme{} mot cheché.\medskip
-La macro \verb|\findword| utilise \verb|\StrBetween| et \verb|\numexpr| de façon astucieuse :\medskip
-
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
+La macro \verb|\findword| utilise \verbinline|\StrBetween| et \verb|\numexpr| de façon astucieuse, et profite du fait que \verbinline-\StrBetween- n'explore pas les groupes :\par\nobreak\medskip
+\begin{minipage}[c]{0.65\linewidth}
+\begin{lstlisting}
+\newcommand\findword[3][ ]{%
+ \StrBetween[#3,\numexpr#3+1]{#1#2#1}{#1}{#1}%
+}
+\noexpandarg
+|\findword{a bc d\textbf{e f} gh}{3}|
+
+|\findword[\nil]{1 \nil 2 3 \nil4\nil5}{2}|
+\end{lstlisting}%
+\end{minipage}\hfill
+\begin{minipage}[c]{0.35\linewidth}
+ \styleexercice
\newcommand\findword[3][ ]{%
- \StrBetween[#3,\numexpr#3+1]{#1#2#1}{#1}{#1}}
+ \StrBetween[#3,\numexpr#3+1]{#1#2#1}{#1}{#1}%
+ }
\noexpandarg
- |\findword{a bc d\textit{e f} gh}{3}|
+ |\findword{a bc d\textbf{e f} gh}{3}|
- |\findword[\@nil]{1 \@nil 2 3 \@nil4\@nil}{2}|
- \end{boxedverbatim}
- \hspace*{0.3cm}
+ |\findword[\nil]{1 \nil 2 3 \nil4\nil5}{2}|
\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \newcommand\findword[3][ ]{%
- \StrBetween[#3,\numexpr#3+1]{#1#2#1}{#1}{#1}}
- \noexpandarg
- |\findword{a bc d\textit{e f} gh}{3}|
-
- |\findword[\@nil]{1 \@nil 2 3 \@nil4\@nil}{2}|
-\end{minipage}
+On peut observer que le résultat de la ligne 7 qui est \og\verb*|2 3 |\fg{} ne commence \emph{pas} par une espace puisque dans le code, cet espace suit une séquence de contrôle~---~ici \verb|\nil|.
\bigskip\bigskip
\begin{center}
$\star$\par
@@ -1590,8 +2001,7 @@ $\star$\quad$\star$
\end{center}
\bigskip\bigskip
-C'est tout, j'espère que ce package vous sera utile !\par
-Merci de me signaler par \href{mailto:unbonpetit@gmail.com}{email} tout bug ou toute proposition d'amélioration\ldots\medskip
-
-Christian Tellechea
+C'est tout, j'espère que ce package vous sera utile !\par\nobreak
+Merci de me signaler par \href{mailto:unbonpetit@gmail.com}{email} tout bug ou toute proposition d'amélioration\ldots\par\nobreak\bigskip
+Christian \textsc{Tellechea}
\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/tex/generic/xstring/xstring.tex b/Master/texmf-dist/tex/generic/xstring/xstring.tex
index 7e2b35779e5..48320845680 100644
--- a/Master/texmf-dist/tex/generic/xstring/xstring.tex
+++ b/Master/texmf-dist/tex/generic/xstring/xstring.tex
@@ -1,9 +1,9 @@
% __________________________________________________
% | |
% | |
-% | xstring v1.5 |
+% | xstring v1.5a |
% | |
-% | December 31 2008 |
+% | February 9 2009 |
% | |
% |__________________________________________________|
%
@@ -18,7 +18,7 @@
% test_latex.tex, test_latex.pdf (test file with LaTeX)
% test_etex.tex, test_etex.pdf (test file with Plain eTeX)
%
-% Christian Tellechea 2008-2009
+% Christian Tellechea 2009
% email : unbonpetit@gmail.com
% -------------------------------------------------------------------
% This work may be distributed and/or modified under the
@@ -35,16 +35,14 @@
%
% The Current Maintainer of this work is Christian Tellechea
% -------------------------------------------------------------------
-\def\xstringversion {1.5}
-\def\xstringdate {2008/12/31}
-\def\xstringfrenchdate {31 d\'ecembre 2008}
-\def\xstringenglishdate{December $31^{\mathrm{st}}$ 2008}
-\edef\CurrentAtCatcode{\the\catcode`\@}
+\def\xstringversion {1.5a}
+\def\xstringdate {2009/02/09}
+\def\xstringfrenchdate {9 f\'evrier 2009}
+\def\xstringenglishdate {February $9^{\mathrm{th}}$ 2009}
+\edef\CurrentAtCatcode {\the\catcode`\@}
\catcode`\@=11
-\newwrite\@xs@unused% pour les messages
-\newcount\@xs@count
-\newcount\integerpart% pour les tests sur les nombres
-\newcount\decimalpart
+\newwrite\@xs@message% canal pour les messages
+\newcount\integerpart\newcount\decimalpart% compteurs utilis\'es par xstring
\expandafter\ifx\csname @latexerr\endcsname\relax% on n'utilise pas LaTeX ?
\immediate\write\m@ne{Package: xstring \xstringdate\space\space v\xstringversion\space\space String manipulations (C Tellechea)}%
@@ -73,35 +71,6 @@
\def\@empty{}
\fi% fin des d\'efinitions LaTeX
-% Gestion des messages d'erreur
-\def\@xs@linenumber{on input line \the\inputlineno}
-
-\def\@xs@errorwrite#1#2{%
- \begingroup
- \newlinechar`\^^J%
- \errhelp{#2}%
- \errmessage{Package xstring Error: \@xs@linenumber\space#1^^J%
- See user manual for further information.^^J%
- Type \space H <return> \space for immediate help.}%
- \endgroup}
-
-\def\@xs@warningwrite#1{%
- \begingroup
- \newlinechar`\^^J%
- \immediate\write\@xs@unused{Package xstring Warning: #1 \@xs@linenumber^^J}%
- \endgroup}
-
-\def\@xs@infowrite#1{%
- \begingroup
- \newlinechar`\^^J%
- \immediate\write\m@ne{Package xstring Info: #1}%
- \endgroup}
-
-% Messages d'information pour situations particuli\`eres
-\def\@xs@BadNumArg {\@xs@infowrite{numerical argument out of range}}
-\def\@xs@ArgNotFound {\@xs@infowrite{substring not found in string}}
-\def\@xs@ArgEmpty {\@xs@infowrite{empty argument}}
-
% Ouvre un groupe o\`u les catcodes sont \`a 12 et \`a 10 pour les espaces
% ensuite, appelle \@xs@ReadVerb qui lit un argument entre d\'elimiteurs verb
\def\@xs@MakeVerb{% lit 1 argument et le transforme en verb
@@ -115,63 +84,21 @@
\def\setverbdelim#1{% d\'efinit quel est le d\'elimiteur de verb
\expandafter\ifx\expandafter\@empty\detokenize\expandafter{\@xs@gobblefirstchar#1}\@empty
\else
- \@xs@warningwrite{verb delimiter is not a single char}%
+ \begingroup
+ \newlinechar`\^^J%
+ \immediate\write\@xs@message
+ {Package xstring Warning: verb delimiter is not a single token on input line \the\inputlineno^^J}%
+ \endgroup
\fi
\def\@xs@ReadVerb##1#1##2#1{% lit ##2 qui est entre les d\'elimiteurs de verb
\endgroup% on ferme le groupe
\@xs@afterreadverb{##2}}}% on appelle l'ex\'ecution de fin
-% Assigne l'argument entre d\'elimiteur verb dans la sc #1
+% Assigne l'argument entre d\'elimiteur verb dans la sc #1' +
\def\verbtocs#1{%
- \def\@xs@afterreadverb##1{\edef#1{##1}}%
+ \def\@xs@afterreadverb##1{\def#1{##1}}%
\@xs@MakeVerb}
-% D\'eveloppe d'un niveau toutes les unit\'es syntaxiques
-% de #1 puis et assigne le r\'esultat \`a \@xs@reserved@A
-\def\@xs@expandallonelevel#1#2\@xs@nil{%
- \expandafter\@xs@addtomacro\expandafter\@xs@reserved@A\expandafter{#1}%
- \ifx\@empty#2\@empty
- \else
- \def\@xs@next{\@xs@expandallonelevel#2\@xs@nil}%
- \expandafter\@xs@next
- \fi}% s'il reste des sc, on boucle
-
-\def\@xs@notestcs#1\@xs@nil{\relax}%
-\def\@xs@testcs#1#2\@xs@nil{%
- \ifx\@empty#2\@empty
- \else% si la s\'equence de contr\^ole n'est pas seule, on gueule
- \@xs@errorwrite{third argument or its expansion^^Jis not a single control sequence! Use \string\scancs* instead of \string\scancs (see manual).}{With \scancs, the third argument (or one of its expansion) cannot contain^^Jmore than one control sequence. If so, use the starred version \scancs*,^^Jand read manual for more information about this starred version...}%
- \fi}
-
-% \scancs d\'eveloppe #3 autant de fois que sp\'ecifi\'e en #1
-% puis le d\'eveloppement obtenu est verbatimis\'e.
-% On utilise \@xs@expandalltodepth autant de fois que #1 le sp\'ecifie
-% puis on invoque \detokenize \`a la fin
-\def\scancs{%
- \@ifstar%
- {\@xs@warningwrite{\string\scancs* has limitations: ^^Jif third argument or its expansion have braces or spaces,^^Jthey will be removed when scanned}%
- \def\@xs@testornot{\@xs@notestcs}%
- \@xs@scancs}%
- {\def\@xs@testornot{\@xs@testcs}%
- \@xs@scancs}}
-\def\@xs@scancs{\@ifnextchar[{\@xs@scancs@}{\@xs@scancs@[1]}}
-\def\@xs@scancs@[#1]#2#3{%
-% #1 : profondeur \`a d\'evelopper avant de verbatimiser
-% #2 : nom de la sc recevant la chaine verb
-% #3 : nom de la sc \`a d\'evelopper et \`a transformer en verb
- \def\@xs@expandalltodepth##1{% d\'eveloppe de #1 niveaux toutes les sc de #3 et l'assigne \`a \@xs@reserved@B
- \let\@xs@reserved@A\@empty%
- \ifnum##1<#1\relax% tant que la profondeur de d\'eveloppement n'est pas atteinte
- \expandafter\@xs@testornot\@xs@reserved@B\@xs@nil% on teste \'eventuellement si le d\'eveloppement comporte 1 seule sc
- \expandafter\@xs@expandallonelevel\@xs@reserved@B\@xs@nil% on d\'eveloppe tout d'un niveau
- \let\@xs@reserved@B\@xs@reserved@A%
- \def\@xs@next{\expandafter\@xs@expandalltodepth\expandafter{\number\numexpr##1+1}}%
- \expandafter\@xs@next% et on recommence
- \fi}%
- \def\@xs@reserved@B{#3}%
- \@xs@expandalltodepth\z@
- \expandafter\def\expandafter#2\expandafter{\detokenize\expandafter{\@xs@reserved@B}}}
-
% Cette macro d\'eveloppe \'eventuellement #2
% puis le transforme en token et l'assigne \`a #1
\begingroup% on ouvre un groupe o\`u...
@@ -190,10 +117,10 @@
% Macro tr\`es simple qui assigne ou affiche le r\'esultat, selon la pr\'esence
% ou non de #2 qui est l'argument optionnel venant en derni\`ere position des macros
\def\@xs@ReturnResult#1#2{%
- \expandafter\ifx\expandafter\@empty\detokenize{#2}\@empty% pas de nom ?
- #1% on affiche #1
- \else% il y a un nom donc
- \def#2{#1}% on assigne #1 dans #2 avec edef
+ \expandafter\ifx\expandafter\@empty\detokenize{#2}\@empty
+ #1%
+ \else
+ \def#2{#1}%
\fi}
% Pas d'expansion des arguments
@@ -308,9 +235,9 @@
% #4 : nombre d'arguments obligatoires
% #5 : utilisation de testopt (1 si oui, 0 si non)
% #6 : code de la macro
-\def\@xs@newmacro@#1#2#3#4#5#6{%
+\def\@xs@newmacro@#1#2#3#4#5{%
\edef\@xs@reserved@A{@xs@\expandafter\@xs@gobblefirstchar\string#2}%
- \edef\@xs@reserved@C{\csname\@xs@reserved@A @\ifx\@empty#3\@empty @\fi\endcsname}%
+ \edef\@xs@reserved@C{\expandafter\noexpand\csname\@xs@reserved@A @\ifx\@empty#3\@empty @\fi\endcsname}%
\edef\@xs@reserved@B{%
\ifx\@empty\@xs@reserved@D
\def\noexpand#2{\noexpand\@ifstar
@@ -322,7 +249,7 @@
\ifx\@empty#3\@empty
\else
\def\expandafter\noexpand\@xs@reserved@C{%
- \noexpand\@testopt{\csname\@xs@reserved@A @@\endcsname}{\ifx\@xs@def\edef#3\else\unexpanded{#3}\fi}}%
+ \noexpand\@testopt{\expandafter\noexpand\csname\@xs@reserved@A @@\endcsname}{\ifx\@xs@def\edef#3\else\unexpanded{#3}\fi}}%
\fi}%
% Que fait \@xs@reserved@B ? Il d\'efinit :
% si #3 est vide : \NOM{\@ifstar{\let\@xs@assign\@xs@expand@and@detokenize\@xs@NOM@@}{\let\@xs@assign\@xs@expand@and@assign\@xs@NOM@@}}
@@ -336,9 +263,9 @@
\expandafter\@xs@BuildLines\expandafter1\expandafter{\number\numexpr#4+1}{#3}{#1}%
\@xs@DefArg@{#4}%
\fi
- \edef\@xs@reserved@B{\def\csname\@xs@reserved@A @@\endcsname\@xs@myarg}%
+ \edef\@xs@reserved@B{\def\expandafter\noexpand\csname\@xs@reserved@A @@\endcsname\@xs@myarg}%
\edef\@xs@reserved@C{\unexpanded\expandafter{\@xs@newlines}\edef\noexpand\@xs@call}%
- \edef\@xs@reserved@D{\noexpand\noexpand\csname\@xs@reserved@A\endcsname\unexpanded\expandafter{\@xs@newargs}}%
+ \edef\@xs@reserved@D{\noexpand\noexpand\expandafter\noexpand\csname\@xs@reserved@A\endcsname\unexpanded\expandafter{\@xs@newargs}}%
\ifnum#5=\@ne\edef\@xs@reserved@D{\noexpand\noexpand\noexpand\@testopt{\unexpanded\expandafter{\@xs@reserved@D}}\unexpanded{{}}}\fi
\@xs@expand@and@addtomacro\@xs@reserved@C{{\unexpanded\expandafter{\@xs@reserved@D}}\noexpand\@xs@call}%
\@xs@expand@and@addtomacro\@xs@reserved@B{{\unexpanded\expandafter{\@xs@reserved@C}}}%
@@ -349,12 +276,12 @@
% si #5=1: \edef\@xs@call{\noexpand\@testopt{\noexpand\@xs@NOM[\@xs@expand\@xs@arg@i]{\@xs@expand\@xs@arg@i}{\@xs@expand\@xs@arg@ii}{\@xs@expand\@xs@arg@iii}{\@xs@expand\@xs@arg@iv}}{}}%
% \@xs@call}
\@xs@reserved@B
- \edef\@xs@reserved@B{\def\expandafter\noexpand\csname\@xs@reserved@A\endcsname\@xs@myarg\ifnum#5=\@ne[\unexpanded{##}\number\numexpr\ifx\@empty#3\@empty#4+1\else#4+2\fi]\fi{\unexpanded{#6}}}%
+ \edef\@xs@reserved@B{\def\expandafter\noexpand\csname\@xs@reserved@A\endcsname\@xs@myarg\ifnum#5=\@ne[\unexpanded{##}\number\numexpr\ifx\@empty#3\@empty#4+1\else#4+2\fi]\fi}%
% Que fait \@xs@reserved@B ? Il d\'efinit par exemple pour 3 arguments obligatoires et 1 facultatif :
% \def \@xs@NOM[##2]##3##4##5[##6]{#6}
\@xs@reserved@B}
-% macro g\'en\'erique qui lit \@xs@reserved@C lex\`eme par lex\`eme
+% macro g\'en\'erique qui lit \@xs@reserved@C us par us
% 3 sous-routines sont appel\'ees \`a des moments cl\'e :
% \@xs@atendofgroup (un groupe se finit, appel r\'ecursif)
% \@xs@atbegingroup (un groupe vient d'être ouvert)
@@ -380,7 +307,7 @@
\integerpart\z@
\@xs@atbegingroup
\else
- \global\advance\@xs@count\@ne
+ \global\advance\decimalpart\@ne
\@xs@atnextsyntaxunit
\fi
\fi
@@ -399,7 +326,7 @@
\fi
\else
\expandafter\expandafter\expandafter\@xs@IfBeginWith@i\expandafter\expandafter\expandafter{\expandafter\@xs@reserved@D\expandafter}\expandafter{\@xs@reserved@E}%
- {\global\advance\@xs@count\@ne
+ {\global\advance\decimalpart\@ne
\let\@xs@reserved@D\@xs@reserved@A
\@xs@atoccurfound}%
{\expandafter\@xs@returnfirstsyntaxunit\expandafter{\@xs@reserved@D}\@xs@reserved@A
@@ -454,8 +381,6 @@
\fi
\@xs@next}
-\def\@xs@strip@delimit#1\@delimit#2\@xs@nil{#1}
-
% \@xs@cutafteroccur coupe l'argument #1 apr\`es la #3\`eme occurrence de #2
% \@xs@reserved@C : contient ce qui se trouve avant cette occurrence
% \@xs@reserved@D : contient ce qui se trouve avant cette occurrence y compris cette occurrence
@@ -463,13 +388,13 @@
% si l'occurrence n'existe pas ou qu'un des arguments est vide, toutes les chaines renvoy\'ees sont vides
\def\@xs@cutafteroccur#1#2#3{%
\def\@xs@reserved@D{#1}\let\@xs@reserved@C\@empty\def\@xs@reserved@E{#2}%
- \@xs@count\z@\integerpart\z@\decimalpart#3\def\groupID{0}\let\@xs@nestlevel\z@
+ \decimalpart\z@\integerpart\z@\def\groupID{0}\let\@xs@nestlevel\z@
\def\@xs@atendofgroup{%
\expandafter\endgroup
\expandafter\@xs@addtomacro\expandafter\@xs@reserved@C\expandafter{\expandafter{\@xs@reserved@C}}%
\@xs@read@reserved@D}%
\def\@xs@atoccurfound{%
- \ifnum\@xs@count=\decimalpart
+ \ifnum\decimalpart=#3
\global\let\@xs@reserved@D\@xs@reserved@D
\global\let\@xs@reserved@C\@xs@reserved@C
\global\let\groupID\groupID
@@ -480,7 +405,7 @@
\let\@xs@next\@xs@read@reserved@D
\fi}%
\@xs@read@reserved@D
- \ifnum\@xs@count=\decimalpart% occurrence trouv\'ee ?
+ \ifnum\decimalpart=#3% occurrence trouv\'ee ?
\let\@xs@reserved@E\@xs@reserved@D
\expandafter\def\expandafter\@xs@reserved@D\expandafter{\@xs@reserved@C#2}%
\else
@@ -514,7 +439,7 @@
\ifx\@xs@reserved@A\@xs@reserved@B% il y a \'egalit\'e...
\@xs@removefirstsyntaxunit{#1}\@xs@reserved@A% on enl\`eve les 1ere unit\'es syntaxiques
\@xs@removefirstsyntaxunit{#2}\@xs@reserved@B
- \def\@xs@next{% et on recommence avec ces arguments racourcis d'1 token
+ \def\@xs@next{% et on recommence avec ces arguments racourcis d'1 unit\'e syntaxique
\expandafter\expandafter\expandafter\@xs@IfBeginWith@i
\expandafter\expandafter\expandafter{\expandafter\@xs@reserved@A\expandafter}\expandafter{\@xs@reserved@B}}%
\else
@@ -588,12 +513,12 @@
\expandafter\@xs@formatnumber\expandafter{\detokenize{#1}}\@xs@reserved@A
\decimalpart\z@
\afterassignment\@xs@defafterinteger\integerpart\@xs@reserved@A\relax\@xs@nil
- \ifx\@empty\@xs@afterinteger
- \expandafter\@firstoftwo
- \else
- \expandafter\tokenize\expandafter\@xs@afterinteger\expandafter{\@xs@afterinteger}%
- \expandafter\@secondoftwo
- \fi}
+ \expandafter\@xs@testdot\@xs@afterinteger\@xs@nil
+ \let\@xs@next\@secondoftwo
+ \ifx\@empty\@xs@afterdecimal
+ \ifnum\decimalpart=\z@\let\@xs@next\@firstoftwo\fi
+ \fi
+ \@xs@next}
\@xs@newmacro\IfDecimal{}{1}{0}{%
\expandafter\@xs@formatnumber\expandafter{\detokenize{#1}}\@xs@reserved@A
@@ -693,16 +618,16 @@
% par la chaine #4 dans la chaine #2
\@xs@newmacro\StrSubstitute{0}{3}{1}{%
\def\@xs@reserved@D{#2}\let\@xs@reserved@C\@empty\def\@xs@reserved@E{#3}%
- \@xs@count\z@\integerpart\z@\def\groupID{0}\let\@xs@nestlevel\z@
+ \decimalpart\z@\integerpart\z@\def\groupID{0}\let\@xs@nestlevel\z@
\def\@xs@atendofgroup{%
\expandafter\endgroup
\expandafter\@xs@addtomacro\expandafter\@xs@reserved@C\expandafter{\expandafter{\@xs@reserved@C}}%
\@xs@read@reserved@D}%
\def\@xs@atoccurfound{%
- \ifnum#1=\z@
+ \ifnum#1<\@ne
\def\@xs@reserved@A{#4}%
\else
- \ifnum\@xs@count>#1
+ \ifnum\decimalpart>#1
\def\@xs@reserved@A{#3}%
\else
\def\@xs@reserved@A{#4}%
@@ -725,14 +650,14 @@
% Compte combien d'unit\'es syntaxiques contient la chaine #1 ?
\@xs@newmacro\StrLen{}{1}{1}{%
\def\@xs@reserved@C{#1}%
- \@xs@count\z@
+ \decimalpart\z@
\let\@xs@nestlevel\z@
\def\groupID{0}%
\let\@xs@atbegingroup\relax
\def\@xs@atendofgroup{\endgroup\@xs@read@reserved@C}%
\let\@xs@atnextsyntaxunit\relax
\@xs@read@reserved@C
- \expandafter\@xs@ReturnResult\expandafter{\number\@xs@count}{#2}}
+ \expandafter\@xs@ReturnResult\expandafter{\number\decimalpart}{#2}}
% Macro interne fermant autant de groupes que n\'ecessaire pour trouver une unit\'e syntaxique derri\`ere
\def\@xs@continuetonext{%
@@ -759,7 +684,7 @@
\def\@xs@StrSplit@i#1#2{%
\def\@xs@reserved@D{#1}\def\@xs@reserved@C{#2}\let\@xs@reserved@B\@empty\let\groupID\@empty
\ifnum#1>\z@
- \@xs@count\z@\integerpart\z@\def\groupID{0}\let\@xs@nestlevel\z@
+ \decimalpart\z@\integerpart\z@\def\groupID{0}\let\@xs@nestlevel\z@
\def\@xs@atendofgroup{%
\expandafter\endgroup
\expandafter\@xs@addtomacro\expandafter\@xs@reserved@B\expandafter{\expandafter{\@xs@reserved@B}}%
@@ -767,7 +692,7 @@
\def\@xs@atbegingroup{\let\@xs@reserved@B\@empty}%
\def\@xs@atnextsyntaxunit{%
\expandafter\@xs@addtomacro\expandafter\@xs@reserved@B\expandafter{\@xs@reserved@A}%
- \ifnum\@xs@count=\@xs@reserved@D\relax
+ \ifnum\decimalpart=\@xs@reserved@D\relax
\ifx\@xs@reserved@C\@empty\@xs@reserved@E\fi
\global\let\@xs@reserved@B\@xs@reserved@B
\global\let\@xs@reserved@C\@xs@reserved@C
@@ -784,8 +709,10 @@
\@xs@newmacro\StrMid{}{3}{1}{%
\begingroup
\noexploregroups
+ \let\@xs@reserved@E\relax
\@xs@StrSplit@i{#3}{#1}%
\edef\@xs@reserved@C{\number\numexpr#2-1}%
+ \let\@xs@reserved@E\relax
\expandafter\expandafter\expandafter\@xs@StrSplit@i\expandafter\expandafter\expandafter{\expandafter\@xs@reserved@C\expandafter}\expandafter{\@xs@reserved@B}%
\expandafter\endgroup
\expandafter\@xs@ReturnResult\expandafter{\@xs@reserved@C}{#4}%
@@ -793,35 +720,39 @@
% supprime #2 unit\'es syntaxiques \`a gauche dans la chaine #1
\@xs@newmacro\StrGobbleLeft{}{2}{1}{%
+ \let\@xs@reserved@E\relax
\@xs@StrSplit@i{#2}{#1}%
\expandafter\@xs@ReturnResult\expandafter{\@xs@reserved@C}{#3}}
% extrait de #1 la chaine \`a gauche de longueur #2
\@xs@newmacro\StrLeft{}{2}{1}{%
+ \let\@xs@reserved@E\relax
\@xs@StrSplit@i{#2}{#1}%
\expandafter\@xs@ReturnResult\expandafter{\@xs@reserved@B}{#3}}
% supprime #2 unit\'es syntaxiques \`a droite dans la chaine #1
\@xs@newmacro\StrGobbleRight{}{2}{1}{%
- \@xs@StrLen{#1}[\@xs@reserved@E]%
- \expandafter\@xs@StrSplit@i\expandafter{\number\numexpr\@xs@reserved@E-#2}{#1}%
+ \@xs@StrLen{#1}[\@xs@reserved@D]%
+ \let\@xs@reserved@E\relax
+ \expandafter\@xs@StrSplit@i\expandafter{\number\numexpr\@xs@reserved@D-#2}{#1}%
\expandafter\@xs@ReturnResult\expandafter{\@xs@reserved@B}{#3}}
% renvoie #2 unit\'es syntaxiques \`a la droite de la chaine #1
\@xs@newmacro\StrRight{}{2}{1}{%
- \@xs@StrLen{#1}[\@xs@reserved@E]%
- \expandafter\@xs@StrSplit@i\expandafter{\number\numexpr\@xs@reserved@E-#2}{#1}%
+ \@xs@StrLen{#1}[\@xs@reserved@D]%
+ \let\@xs@reserved@E\relax
+ \expandafter\@xs@StrSplit@i\expandafter{\number\numexpr\@xs@reserved@D-#2}{#1}%
\expandafter\@xs@ReturnResult\expandafter{\@xs@reserved@C}{#3}}
\@xs@newmacro\StrChar{}{2}{1}{%
\let\@xs@reserved@B\@empty
\ifnum#2>\z@
- \def\@xs@reserved@C{#1}\def\@xs@reserved@D{#2}\@xs@count\z@
+ \def\@xs@reserved@C{#1}\def\@xs@reserved@D{#2}\decimalpart\z@
\def\groupID{0}\let\@xs@nestlevel\z@\integerpart\z@
\let\@xs@atbegingroup\relax
\def\@xs@atendofgroup{\endgroup\@xs@read@reserved@C}%
\def\@xs@atnextsyntaxunit{%
- \ifnum\@xs@count=\@xs@reserved@D% la n i\`eme US est atteinte ?
+ \ifnum\decimalpart=\@xs@reserved@D% la n i\`eme US est atteinte ?
\global\let\@xs@reserved@B\@xs@reserved@A% on capture l'US en cours qui est celle cherch\'ee
\global\let\groupID\groupID
\@xs@exitallgroups
@@ -838,14 +769,14 @@
\@xs@ReturnResult{0}{#3}%
\else
\def\@xs@reserved@D{#1}\def\@xs@reserved@E{#2}\let\@xs@reserved@C\@empty
- \@xs@count\z@\integerpart\z@\def\groupID{0}\let\@xs@nestlevel\z@
+ \decimalpart\z@\integerpart\z@\def\groupID{0}\let\@xs@nestlevel\z@
\def\@xs@atendofgroup{%
\expandafter\endgroup
\expandafter\@xs@addtomacro\expandafter\@xs@reserved@C\expandafter{\expandafter{\@xs@reserved@C}}%
\@xs@read@reserved@D}%
\def\@xs@atoccurfound{\let\@xs@reserved@C\@empty\@xs@read@reserved@D}%
\@xs@read@reserved@D
- \expandafter\@xs@ReturnResult\expandafter{\number\@xs@count}{#3}%
+ \expandafter\@xs@ReturnResult\expandafter{\number\decimalpart}{#3}%
\fi}
% renvoie la position de l'occurrence #1 de la sous chaine #3 dans la chaine #2
@@ -916,8 +847,8 @@
\else
\expandafter\@xs@returnfirstsyntaxunit\expandafter{\@xs@reserved@C}\@xs@reserved@D
\ifx\bgroup\@xs@toks% si la 1\`ere unit\'e syntaxique est un groupe explicite
- \advance\@xs@count\@ne% on augmente le compteur
- \ifnum\@xs@count=\@xs@reserved@A% on est au groupe cherch\'e lors de la profondeur courante ?
+ \advance\decimalpart\@ne% on augmente le compteur
+ \ifnum\decimalpart=\@xs@reserved@A% on est au groupe cherch\'e lors de la profondeur courante ?
\ifx\@empty\@xs@reserved@B% on est \`a la profondeur maximale ?
\def\@xs@next{\expandafter\@xs@ReturnResult\expandafter{\@xs@reserved@D}{#3}}% on renvoie ce groupe
\else% sinon
@@ -935,7 +866,7 @@
\fi
\@xs@next}%
\@xs@extractgroupnumber{#2}\@xs@reserved@A\@xs@reserved@B
- \@xs@count\z@
+ \decimalpart\z@
\ifnum\@xs@reserved@A>\z@\def\@xs@reserved@C{#1}\else\let\@xs@reserved@C\@empty\fi
\@xs@StrFindGroup@ii}
@@ -944,6 +875,49 @@
\@xs@extractgroupnumber@i#1,\@xs@nil
\ifx\@empty#3\else\@xs@extractgroupnumber@i#1\@xs@nil\fi}
+\def\expandingroups{\let\@xs@expandingroups\exploregroups}
+\def\noexpandingroups{\let\@xs@expandingroups\noexploregroups}
+\def\StrExpand{\@testopt{\@xs@StrExpand}{1}}
+\def\@xs@StrExpand[#1]#2#3{%
+ \begingroup
+ \@xs@expandingroups
+ \ifnum#1>\z@
+ \integerpart#1\relax
+ \decimalpart\z@\def\groupID{0}\let\@xs@nestlevel\z@
+ \def\@xs@atendofgroup{%
+ \expandafter\endgroup
+ \expandafter\@xs@addtomacro\expandafter\@xs@reserved@B\expandafter{\expandafter{\@xs@reserved@B}}%
+ \@xs@read@reserved@C}%
+ \def\@xs@atbegingroup{\let\@xs@reserved@B\@empty}%
+ \def\@xs@atnextsyntaxunit{%
+ \expandafter\expandafter\expandafter\@xs@addtomacro
+ \expandafter\expandafter\expandafter\@xs@reserved@B
+ \expandafter\expandafter\expandafter{\@xs@reserved@A}}%
+ \def\@xs@reserved@C{#2}%
+ \@xs@StrExpand@i{#1}% Appel de la macro r\'ecursive
+ \else
+ \def\@xs@reserved@B{#2}%
+ \fi
+ \global\let\@xs@reserved@B\@xs@reserved@B
+ \endgroup
+ \let#3\@xs@reserved@B
+ \let\groupID\@empty}
+\def\@xs@StrExpand@i#1{%
+ \ifnum#1>\z@
+ \let\@xs@reserved@B\@empty
+ \@xs@read@reserved@C
+ \let\@xs@reserved@C\@xs@reserved@B
+ \def\@xs@reserved@A{\expandafter\@xs@StrExpand@i\expandafter{\number\numexpr#1-1}}%
+ \else
+ \let\@xs@reserved@A\relax
+ \fi
+ \@xs@reserved@A}
+
+\def\scancs{\@testopt{\@xs@scancs}{1}}
+\def\@xs@scancs[#1]#2#3{%
+ \@xs@StrExpand[#1]{#3}{#2}%
+ \edef#2{\detokenize\expandafter{#2}}}
+
% Restaure le code de @
\catcode`\@=\CurrentAtCatcode\relax
% D\'efinit le d\'elimiteur verb
@@ -952,6 +926,7 @@
\fullexpandarg\saveexpandmode
\comparenormal\savecomparemode
\noexploregroups\saveexploremode
+\expandingroups
\endinput
%
% Historique
@@ -1053,4 +1028,20 @@
% d\'etok\'enis\'e \`a tort dans les macros \'etoil\'ees.
% - Dans \@xs@newmacro, on doit choisir le num\'ero du dernier argument devant
% être d\'etok\'enis\'e dans le cas d'une macro \'etoil\'ee (sachant que
-% l'argument optionnel ne l'est jamais) \ No newline at end of file
+% l'argument optionnel ne l'est jamais)
+%------------------------------------------------------------------------------
+% v1.5a 09/2/2009
+% - Nouvelle macro \StrExpand, sensible au mode d'exploration. La macro est
+% indépendante du mode d'exploration et dispose de ses propres commandes
+% d'exploration : \expandingroups et \noexpandingroups
+% - R\'e-\'ecriture de \scancs, qui devient triviale puisque d\'ependant de
+% \StrExpand. Il n'y a plus de version \'étoil\'ee et d\'esormais, \scancs
+% est sensible au mode d'exploration.
+% - Correction d'un bug dans \IfInteger : \IfInteger{2.0}{V}{F} affichait F
+% - Correction de bugs : mettre \let\@xs@reserved@E\relax avant d'appeler
+% \@xs@StrSplit@i
+% - Suppression des messages d'erreur, de warning et d'info. xstring devient
+% donc silencieux ;)
+% - Passage de 3 \'a 2 compteurs
+% - Le manuel est d\'esormais plus color\'e, en esp\'erant qu'il sera un peu
+% plus agr\'eable \`a lire ! \ No newline at end of file