summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex')
-rw-r--r--Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex820
1 files changed, 387 insertions, 433 deletions
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 7cbb5a76425..aa1dae5525c 100644
--- a/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex
+++ b/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex
@@ -17,11 +17,14 @@
\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 for strings},pdfkeywords={xstring,latex,string},pdfcreator={LaTeX}]{hyperref}
-\usepackage[a4paper,dvips,margin=2cm]{geometry}
+\usepackage[a4paper,dvips,margin=1.9cm]{geometry}
\usepackage{amsmath,amssymb}
+\usepackage{textcomp}
\usepackage{moreverb}
\usepackage{lmodern}
\usepackage{eurosym}
+\usepackage{xspace}
+\usepackage{xstring}
\usepackage{xstring}
\usepackage[french,english]{babel}
\makeatletter
@@ -30,7 +33,7 @@
\normalexpandarg
\tokenize\cs@resultat{#1}%
\fullexpandarg
- \hbox to\linewidth{\hbox to0.7\linewidth{\hfil\tt#1}\quad\frontiere\cs@resultat\frontiere\hfil}\par}
+ \leavevmode\hbox to0.7\linewidth{\hfil\tt#1}\quad\frontiere\cs@resultat\frontiere\hfil\par}
\makeatother
\newcommand\guill[1]{"#1"}
\newcommand\argu[1]{$\langle$\textit{#1}$\rangle$}
@@ -39,7 +42,6 @@
\newcommand\arguCC[2]{\texttt{[}\argu{#1}{,}\argu{#2}\texttt{]}}
\newcommand\texte[1]{\texttt{text}${}_{#1}$}
\newcommand\etoile{$\langle$\texttt{[*]}$\rangle$}
-\newcommand\voirdeftexte{~(see \ref{deftexte})}
\newenvironment{Conditions}[1][1cm]%
{\begin{list}%
{$\vartriangleright$}%
@@ -49,7 +51,10 @@
\setlength{\topsep}{2ptplus3ptminus2pt}
}}%
{\end{list}}
-\renewcommand\th{${}^\text{th}$}
+\renewcommand\th{${}^\text{th}$\xspace}
+\newcommand\US{syntax unit\xspace}
+\newcommand\USs{syntax units\xspace}
+\newcommand\Xstring{\textsf{xstring}\xspace}
\begin{document}
\setlength{\parindent}{0pt}
@@ -75,8 +80,8 @@
\begin{minipage}{0.85\linewidth}
\noindent
\hfill\textbf{\textit{Abstract}}\hfill{}\medskip\par
- This package which requires $\varepsilon-\TeX{}$ groups together macros manipulating strings, such as:
- \setlength{\parindent}{1.5em}
+ This package which requires $\varepsilon$-\TeX{}, provides macros manipulating strings contaning chars, control sequences, groups between braces and other special tokens so that the macros may be used for programming purposes. Main features are
+ \parindent1.5em
\begin{itemize}
\item[$\triangleright$] tests:
\begin{itemize}
@@ -87,7 +92,7 @@
\end{itemize}
\item[$\triangleright$] extractions of substrings:
\begin{itemize}
- \item what is on the left (or the right) of the $n$\th{} occurrence of a substring;
+ \item what is on the left (or the right) of the $n$\th occurrence of a substring;
\item what is between the occurrences of 2 substrings;
\item substring between 2 positions, etc.
\end{itemize}
@@ -95,14 +100,14 @@
\item[$\triangleright$] calculation of numbers:
\begin{itemize}
\item length of a string;
- \item position of the $n$\th{} occurrence of a substring;
+ \item position of the $n$\th occurrence of a substring;
\item how many times a string contains a substring?
\item comparison of 2 strings: position of the first difference.
\end{itemize}
\end{itemize}
- \setlength{\parindent}{0pt}
+ \parindent0pt
\medskip
- For programming purposes, other macros allow to use special characters (\verb|&|, \verb|~|, \verb|\|, \verb|{|, \verb|}|, \verb|_|, \verb|#|, \verb|$|, \verb|^| and \verb|%|) with the macros manipulating strings.
+ Other macros allow to use special characters forbiden in arguments (\verb|#| and \verb|%|) and manage differences between catcodes for advanced programming purposes.
\end{minipage}
\end{center}
\hrulefill\vfill{}
@@ -111,108 +116,35 @@
\tableofcontents
\pagebreak
-This manual is a translation of the french manual. I apologize for my poor english but I did my best, and I hope that the following is comprehensible!
+This manual is a translation of the french manual. I apologize for my poor english but I did my best\footnote{Any email to tell me errors would be appreciated!}, and I hope that the following is comprehensible!
\section{Presentation}
\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, 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
-
-Certainly, other packages exist (for example \href{http://www.ctan.org/tex-archive/macros/latex/contrib/substr/}{\nolinkurl{substr}} and \href{http://www.ctan.org/tex-archive/macros/latex/contrib/stringstrings/}{\nolinkurl{stringstrings}}), but as well as differences on features, they do not take into account occurrences so I found them too limited and difficult to use for programming.\medskip
-
-There are 2 forms of each command of this package : the regular one and the starred one. The difference is that the regular \emph{do take care of catcodes} of the characters in the string, while the starred ones, \emph{less strict}, don't. For most users, both should behave the same way (for advanced user, read more at page~\pageref{catcodesarguments} and page~\pageref{macrosetoilees}).
-
-\subsection{Motivation}
-I decided to write this package of macros because I have never really found tools in \LaTeX{} suiting my needs for strings. So, over the last few months,I wrote a few macros that I occasionally or regularly used. Their numbers have increased and become a little too dispersed in directories in my computer, so I have grouped them together in this package.
-
-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.\medskip
+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 \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
-This package is my first one as I discoverd \LaTeX{} less than a year ago, so my main motivation was to make progress in programming with \TeX, and to tackle its specific methods.
-\subsection{Operation}
-\label{deftexte}
-In the following, \guill{\texte{10,11,12}} means a string made of characters whose catcodes are 10, 11 or 12.
-\subsubsection{Expansion of arguments}
-\label{devarg}
-All the arguments of the macros operating on strings\footnote{Excepted the 2 last arguments of the tests.} are supposed, after a number of times of expansion, to expand to \texte{10,11,12}. By \emph{default}, to avoid many \verb|\expandafter| and to ease the use of macros, all the arguments are fully expanded before being taken into account by the macro: for this, \verb|\fullexpandarg| is called by default.\bigskip
+\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
-For example, if \verb|\macro| is a macro of this package requiring 2 arguments (text for the first and a number for the second), the following structures are equivalent:\medskip
+As the arguments may contain chars, advanced users could have problems with catcodes leading to unexpected behaviours. These behaviours can be controlled: read page~\pageref{macrosetoilees}.\medskip
-\begin{minipage}[t]{0.35\linewidth}
- Structure with \verb|\fullexpandarg|\par\hrulefill\par
- \verb|\def\aa{some text}|\par
- \verb|\def\nn{2}|\par
- \verb|\macro{\aa}{\nn}|
-\end{minipage}
-\hfill
-\begin{minipage}[t]{0.6\linewidth}
- Usual structure with \LaTeX{} or with \verb|\normalexpandarg|\par\hrulefill\par
- \verb|\def\aa{some text}|\par
- \verb|\def\nn{2}|\par
- \verb|\expandafter\expandafter\expandafter\macro|\par
- \verb| \expandafter\expandafter\expandafter|\par
- \verb| {\expandafter\aa\expandafter}\expandafter{\nn}|
-\end{minipage}\hfill{}\medskip
-
-The structure on the left allow to forget the order of expansion and avoid writing many \verb|\expandafter|. On the other hand, the arguments must be purely expandable into \texte{10,11,12} containing what is expected by the macro (number or string).\medskip
-
-However, at any time, you can find the usual order of expansion with the macro \verb|\normalexpandarg|, and use again \verb|\fullexpandarg| if you want a full expansion of the arguments.
-
-\subsubsection{Textual arguments}
-The macros operating on strings require one or several arguments containing --~or whose expansion contains~-- \texte{10,11,12}\voirdeftexte{}, using the usual syntax \verb|{|\texte{10,11,12}\verb|}|, and for optional arguments \verb|[|\texte{10,11,12}\verb|]|.\medskip
-
-The following rules shoud be observed for the expansion of textual arguments:
-
-\begin{itemize}
- \item they can contain letters (uppercase or lowercase, accented\footnote{For a reliable operation with accented letters, the \texttt{\textbackslash fontenc} package with option \texttt{[T1]} and \texttt{\textbackslash 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). On the other hand, the \officialeuro{} sign is not allowed.
- \item spaces are taken into account as normal characters, except if several spaces follows in which case the \LaTeX{} rule prevails and they become a single space;
- \item no special character is allowed, i.e. the 10 following characters are strictly forbiden: \verb|&|, \verb|~|, \verb|\|, \verb|{|, \verb|}|, \verb|_|, \verb|#|, \verb|$|, \verb|^| and \verb|%|.
-\end{itemize}\medskip
+Certainly, other packages exist (for example \href{http://www.ctan.org/tex-archive/macros/latex/contrib/substr/}{\nolinkurl{substr}} and \href{http://www.ctan.org/tex-archive/macros/latex/contrib/stringstrings/}{\nolinkurl{stringstrings}}), but as well as differences on features, they do not take into account occurrences so I found them too limited and difficult to use for programming.
-To circumvent some of these rules and to go further in the use of the macros operating on strings, this package provides special macros that enable special characters in textual arguments. See the detailed description of this modus operandi in chapter~\ref{programmation}, page~\pageref{programmation}.
-
-\subsubsection{Expansion of macros, optional argument}
-The macros of this package are not purely expandable, i.e. they cannot be put in the argument of an \verb|\edef|. Consequently, some structures are not allowed and lead to errors when compiling. If, for example, \verb|\command{argument}| is a macro of this package operating on strings and returning a string, the following structures are not allowed:\smallskip
-
-\hspace{0.2\linewidth}\verb|\edef\Result{\command{argument}}|\par
-\qquad or this nested structure\par
-\hspace{0.2\linewidth}\verb|\commandA{\commandB{\commandC{argument}}}|\smallskip
-
-For this reason, all the macros returning a result (i.e. all excepted the tests and \verb|\StrSplit|) 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
-
-Thus, this structure not allowed, already seen above:\par
-\hspace{0.2\linewidth}\verb|\edef\Result{\command{arguments}}|\par
-\qquad is equivalent to:\par
-\hspace{0.2\linewidth}\verb|\command{argument}[\Result]|\medskip
-
-And this nested one:\par
-\hspace{0.2\linewidth}\verb|\commandA{\commandB{\commandC{arguments}}}|\par
-\qquad can be replaced by:\par
-\hspace{0.2\linewidth}\verb|\commandC{arguments}[\MyString]|\par
-\hspace{0.2\linewidth}\verb|\commandB{\MyString}[\MyString]|\par
-\hspace{0.2\linewidth}\verb|\commandA{\MyString}|
-
-\subsubsection{Catcode of arguments}\label{catcodesarguments}
-Macros of this package take the catcodes of characters into account. To avoid unexpected behaviour (particulary with tests), you should keep in mind that characters \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 command like \verb|\string| which expansion is a string with catcodes 12 and 10 : \verb|\detokenize|, \verb|\meaning|, \verb|\jobname|, \verb|\fontname|, \verb|\romannumeral|, etc.\medskip
+\subsection{Motivation}
+I decided to write this package of macros because I have never really found tools in \LaTeX{} suiting my needs for strings. So, over the last few months, I wrote a few macros that I occasionally or regularly used. Their numbers have increased and become a little too dispersed in directories in my computer, so I have grouped them together in this package.
-Starred macros do not take catcodes into account. They simply convert their textual arguments into arguments with catcodes 12 and 10, and call the non-starred macros with these modified arguments. For more information about this, read page~\pageref{macrosetoilees}.
+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}
-\label{listemacros}
\subsection{Presentation of macros}
-In the following chapters, all the macros will be presented this plan:\smallskip
-
+In the following chapters, all the macros will be presented this plan:
\begin{itemize}
- \item the syntax and the value of optional arguments
+ \item the syntax\footnote{The optional star, the optional argument in last position will be explained later. See page~\pageref{macrosetoilees} for starred macros and page~\pageref{argumentoptionnel} for the optional argument.} and the value of optional arguments
\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 are given. I tried to find them most easily comprehensible and most representative of the situations met in normal use\footnote{For more examples, see the test file.}. 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{||}.
+ \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}
\subsection{The tests}
-\subsubsection{IfSubStr}
+\subsubsection{\ttfamily\textbackslash IfSubStr}
\verb|\IfSubStr|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\ARGU{true}\ARGU{false}
\smallskip
@@ -233,13 +165,13 @@ Tests if \argu{string} contains at least \argu{number} times \argu{stringA} and
\exemple|\IfSubStr[3]{1a2a3a}{a}{true}{false}|
\exemple|\IfSubStr[4]{1a2a3a}{a}{true}{false}|
-\subsubsection{IfSubStrBefore}
+\subsubsection{\ttfamily\textbackslash IfSubStrBefore}
\verb|\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
-In \argu{string}, tests if the \argu{number1}\th{} occurrence of \argu{stringA} is on the left of the \argu{number2}\th{} occurrence of \argu{stringB}. Runs \argu{true} if so, and \argu{false} otherwise.\medskip
+In \argu{string}, tests if the \argu{number1}\th occurrence of \argu{stringA} is on the left of the \argu{number2}\th occurrence of \argu{stringB}. Runs \argu{true} if so, and \argu{false} otherwise.\medskip
\begin{Conditions}
\item If one of the occurrences is not found, it runs \argu{false};
@@ -257,14 +189,14 @@ In \argu{string}, tests if the \argu{number1}\th{} occurrence of \argu{stringA}
\exemple|\IfSubStrBefore[2,2]{baobab}{a}{b}{true}{false}|
\exemple|\IfSubStrBefore[2,3]{baobab}{a}{b}{true}{false}|
-\subsubsection{IfSubStrBehind}
+\subsubsection{\ttfamily\textbackslash IfSubStrBehind}
\verb|\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
-In \argu{string}, tests if the \argu{number1}\th{} occurrence of \argu{stringA} is on the right of the \argu{number2}\th{} occurrence of \argu{stringB}. Runs \argu{true} if so, and \argu{false} otherwise.\medskip
+In \argu{string}, tests if the \argu{number1}\th occurrence of \argu{stringA} is on the right of the \argu{number2}\th occurrence of \argu{stringB}. Runs \argu{true} if so, and \argu{false} otherwise.\medskip
\begin{Conditions}
\item If one of the occurrences is not found, it runs \argu{false};
@@ -282,7 +214,7 @@ In \argu{string}, tests if the \argu{number1}\th{} occurrence of \argu{stringA}
\exemple|\IfSubStrBehind[2,2]{baobab}{b}{a}{true}{false}|
\exemple|\IfSubStrBehind[2,3]{baobab}{b}{a}{true}{false}|
-\subsubsection{IfBeginWith}
+\subsubsection{\ttfamily\textbackslash IfBeginWith}
\verb|\IfBeginWith|\etoile\ARGU{string}\ARGU{stringA}\ARGU{true}\ARGU{false}
\smallskip
@@ -298,7 +230,7 @@ Tests if \argu{string} begins with \argu{stringA}, and runs \argu{true} if so, a
\exemple|\IfBeginWith{a bc def }{a b}{true}{false}|
\exemple|\IfBeginWith{a bc def }{ab}{true}{false}|
-\subsubsection{IfEndWith}
+\subsubsection{\ttfamily\textbackslash IfEndWith}
\verb|\IfEndWith|\etoile\ARGU{string}\ARGU{stringA}\ARGU{Behind}\ARGU{false}
\smallskip
@@ -314,7 +246,7 @@ Tests if \argu{string} ends with \argu{stringA}, and runs \argu{true} if so, and
\exemple|\IfEndWith{a bc def }{ef }{true}{false}|
\exemple|\IfEndWith{a bc def }{ef}{true}{false}|
-\subsubsection{IfInteger}
+\subsubsection{\ttfamily\textbackslash IfInteger}
\verb|\IfInteger|\etoile\ARGU{number}\ARGU{true}\ARGU{false}
\smallskip
@@ -333,7 +265,7 @@ If test is false because unexpected characters, the control sequence \verb|\@xs@
\exemple|\IfInteger{-}{true}{false}|
\exemple|\IfInteger{0000}{true}{false}|
-\subsubsection{IfDecimal}\label{ifdecimal}
+\subsubsection{\ttfamily\textbackslash IfDecimal}\label{ifdecimal}
\verb|\IfDecimal|\etoile\ARGU{number}\ARGU{true}\ARGU{false}
\smallskip
@@ -342,7 +274,7 @@ Tests if \argu{number} is a decimal, and runs \argu{true} if so, and \argu{false
Counters \verb|\integerpart| and \verb|\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 \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
\begin{Conditions}
\item Decimal separator can be a dot or a comma;
@@ -365,7 +297,7 @@ If test is false because unexpected characters, the control sequence \verb|\@xs@
\exemple|\IfDecimal{+}{true}{false}|
\exemple|\IfDecimal{-}{true}{false}|
-\subsubsection{IfStrEq}
+\subsubsection{\ttfamily\textbackslash IfStrEq}
\verb|\IfStrEq|\etoile\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
\smallskip
@@ -381,7 +313,7 @@ Tests if the strings \argu{stringA} and \argu{stringB} are equal, i.e. if they c
\exemple|\IfStrEq{}{abc}{true}{false}|
\exemple|\IfStrEq{}{}{true}{false}|
-\subsubsection{IfEq}
+\subsubsection{\ttfamily\textbackslash IfEq}
\verb|\IfEq|\etoile\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
\smallskip
@@ -409,7 +341,7 @@ Tests if the strings \argu{stringA} and \argu{stringB} are equal, \emph{except}
\exemple|\IfEq{0}{-0.0}{true}{false}|
\exemple|\IfEq{}{}{true}{false}|
-\subsubsection{IfStrEqCase}
+\subsubsection{\ttfamily\textbackslash IfStrEqCase}
\begin{minipage}{\textwidth}
\verb|\IfStrEqCase|\etoile\ARGU{string}\verb|{%|\par
@@ -429,7 +361,7 @@ Tests successively if \argu{string} is equal to \argu{string1}, \argu{string2},
\exemple|\IfStrEqCase{+3}{{1}{one}{2}{two}{3}{three}}[other]|
\exemple|\IfStrEqCase{0.5}{{0}{zero}{.5}{half}{1}{one}}[other]|
-\subsubsection{IfEqCase}
+\subsubsection{\ttfamily\textbackslash IfEqCase}
\begin{minipage}{\textwidth}
\verb|\IfEqCase|\etoile\ARGU{string}\verb|{%|\par
@@ -450,14 +382,14 @@ Tests successively if \argu{string} is equal to \argu{string1}, \argu{string2},
\exemple|\IfEqCase{0.5}{{0}{zero}{.5}{half}{1}{one}}[other]|
\subsection{Extraction of substrings}
-\subsubsection{StrBefore}
+\subsubsection{\ttfamily\textbackslash StrBefore}
\verb|\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
-In \argu{string}, returns what is leftwards the \argu{number}\th{} occurrence of \argu{stringA}.\medskip
+In \argu{string}, returns what is leftwards the \argu{number}\th occurrence of \argu{stringA}.\medskip
\begin{Conditions}
\item If \argu{string} or \argu{stringA} is empty, an empty string is returned;
@@ -474,14 +406,14 @@ In \argu{string}, returns what is leftwards the \argu{number}\th{} occurrence of
\exemple*|\StrBefore[1]{1b2b3}{b}|
\exemple*|\StrBefore[2]{1b2b3}{b}|
-\subsubsection{StrBehind}
+\subsubsection{\ttfamily\textbackslash StrBehind}
\verb|\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
-In \argu{string}, returns what is rightwards the \argu{number}\th{} occurrence of \argu{stringA}.\medskip
+In \argu{string}, returns what is rightwards the \argu{number}\th occurrence of \argu{stringA}.\medskip
\begin{Conditions}
\item If \argu{string} or \argu{stringA} is empty, an empty string is returned;
@@ -500,14 +432,14 @@ In \argu{string}, returns what is rightwards the \argu{number}\th{} occurrence o
\exemple*|\StrBehind[2]{1b2b3}{b}|
\exemple*|\StrBehind[3]{1b2b3}{b}|
-\subsubsection{StrBetween}
+\subsubsection{\ttfamily\textbackslash StrBetween}
\verb|\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
-In \argu{string}, returns the substring between\footnote{In a strict sense, i.e. \emph{without} the strings \argu{stringA} and \argu{stringB}} the \argu{number1}\th{} occurrence of \argu{stringA} and \argu{number2}\th{} occurrence of \argu{stringB}.\medskip
+In \argu{string}, returns the substring between\footnote{In a strict sense, i.e. \emph{without} the strings \argu{stringA} and \argu{stringB}} the \argu{number1}\th occurrence of \argu{stringA} and \argu{number2}\th occurrence of \argu{stringB}.\medskip
\begin{Conditions}
\item If the occurrences are not in this order ---~\argu{stringA} \emph{followed by} \argu{stringB}~--- in \argu{string}, an empty string is returned;
@@ -526,12 +458,12 @@ In \argu{string}, returns the substring between\footnote{In a strict sense, i.e.
\exemple*|\StrBetween[3,1]{a1b1a2b2a3b3}{a}{b}|
\exemple*|\StrBetween[3,2]{abracadabra}{a}{bra}|
-\subsubsection{StrSubstitute}
+\subsubsection{\ttfamily\textbackslash StrSubstitute}
\verb|\StrSubstitute|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\arguC{name}
\smallskip
-The value of the optional argument \argu{number} is 1 by default.\par\smallskip
+The value of the optional argument \argu{number} is 0 by default.\par\smallskip
In \argu{string}, substitute the \argu{number} first occurrences of \argu{stringA} for \argu{stringB}, except if \argu{number}${}=0$ in which case \emph{all} the occurrences are substituted.
@@ -554,12 +486,12 @@ In \argu{string}, substitute the \argu{number} first occurrences of \argu{string
\exemple|\StrSubstitute[3]{a1a2a3}{a}{B}|
\exemple|\StrSubstitute[4]{a1a2a3}{a}{B}|
-\subsubsection{StrDel}
+\subsubsection{\ttfamily\textbackslash StrDel}
\verb|\StrDel|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip
-The value of the optional argument \argu{number} is 1 by default.\par\smallskip
+The value of the optional argument \argu{number} is 0 by default.\par\smallskip
Delete the \argu{number} first occurrences of \argu{stringA} in \argu{string}, except if \argu{number}${}=0$ in which case \emph{all} the occurrences are deleted.\medskip
@@ -576,7 +508,7 @@ Delete the \argu{number} first occurrences of \argu{stringA} in \argu{string}, e
\exemple|\StrDel[9]{abracadabra}{a}|
\exemple|\StrDel{a bc def }{ }|
-\subsubsection{StrSplit}
+\subsubsection{\ttfamily\textbackslash StrSplit}
\verb|\StrSplit|\etoile\ARGU{string}\ARGU{number}\ARGU{csA}\ARGU{csB}
\smallskip
@@ -598,7 +530,7 @@ This macro returns two strings, so it does \emph{not} display anything. Conseque
\exemple=\StrSplit{abcdef}{-3}{\aa}{\bb}results: |\aa| and |\bb|=
\setverbdelim{|}
-\subsubsection{StrGobbleLeft}
+\subsubsection{\ttfamily\textbackslash StrGobbleLeft}
\verb|\StrGobbleLeft|\etoile\ARGU{string}\ARGU{number}\arguC{name}
\smallskip
@@ -617,7 +549,7 @@ In \argu{string}, delete the \argu{number} first characters on the left.\medskip
\exemple*|\StrGobbleLeft{LaTeX}{-2}|
\exemple*|\StrGobbleLeft{a bc def }{4}|
-\subsubsection{StrLeft}
+\subsubsection{\ttfamily\textbackslash StrLeft}
\verb|\StrLeft|\etoile\ARGU{string}\ARGU{number}\arguC{name}
\smallskip
@@ -636,7 +568,7 @@ In \argu{string}, returns the \argu{number} first characters on the left.\medski
\exemple*|\StrLeft{LaTeX}{-2}|
\exemple*|\StrLeft{a bc def }{5}|
-\subsubsection{StrGobbleRight}
+\subsubsection{\ttfamily\textbackslash StrGobbleRight}
\verb|\StrGobbleRight|\etoile\ARGU{string}\ARGU{number}\arguC{name}
\smallskip
@@ -649,7 +581,7 @@ In \argu{string}, delete the \argu{number} last characters on the right.\medskip
\exemple*|\StrGobbleRight{LaTeX}{-2}|
\exemple*|\StrGobbleRight{a bc def }{4}|
-\subsubsection{StrRight}
+\subsubsection{\ttfamily\textbackslash StrRight}
\verb|\StrRight|\etoile\ARGU{string}\ARGU{number}\arguC{name}
\smallskip
@@ -662,7 +594,7 @@ In \argu{string}, returns the \argu{number} last characters on the right.\medski
\exemple*|\StrRight{LaTeX}{-2}|
\exemple*|\StrRight{a bc def }{5}|
-\subsubsection{StrChar}
+\subsubsection{\ttfamily\textbackslash StrChar}
\verb|\StrChar|\etoile\ARGU{string}\ARGU{number}\arguC{name}
\smallskip
@@ -679,7 +611,7 @@ Returns the character at the position \argu{number} in \argu{string}.\medskip
\exemple*|\StrChar{xstring}{-5}|
\exemple|\StrChar{a bc def }{6}|
-\subsubsection{StrMid}
+\subsubsection{\ttfamily\textbackslash StrMid}
\verb|\StrMid|\etoile\ARGU{string}\ARGU{numberA}\ARGU{numberB}\arguC{name}
\smallskip
@@ -703,7 +635,7 @@ In \argu{string}, returns the substring between\footnote{In the broad sense, i.e
\exemple*|\StrMid{a bc def }{2}{7}|
\subsection{Number results}
-\subsubsection{StrLen}
+\subsubsection{\ttfamily\textbackslash StrLen}
\verb|\StrLen|\etoile\ARGU{string}\arguC{name}
\smallskip
@@ -714,7 +646,7 @@ Return the length of \argu{string}.
\exemple|\StrLen{A}|
\exemple|\StrLen{a bc def }|
-\subsubsection{StrCount}
+\subsubsection{\ttfamily\textbackslash StrCount}
\verb|\StrCount|\etoile\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip
@@ -730,14 +662,14 @@ Counts how many times \argu{stringA} is contained in \argu{string}.\par\medskip
\exemple|\StrCount{abracadabra}{tic}|
\exemple|\StrCount{aaaaaa}{aa}|
-\subsubsection{StrPosition}
+\subsubsection{\ttfamily\textbackslash StrPosition}
\verb|\StrPosition|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip
The value of the optional argument \argu{number} is 1 by default.\par\smallskip
-In \argu{string}, returns the position of the \argu{number}\th{} occurrence of \argu{stringA}.\medskip
+In \argu{string}, returns the position of the \argu{number}\th occurrence of \argu{stringA}.\medskip
\begin{Conditions}
\item If \argu{number} is greater than the number of occurrences of \argu{stringA}, then the macro returns 0;
@@ -753,19 +685,20 @@ In \argu{string}, returns the position of the \argu{number}\th{} occurrence of \
\exemple|\StrPosition{a bc def }{d}|
\exemple|\StrPosition[3]{aaaaaa}{aa}|
-\subsubsection{StrCompare}
+\subsubsection{\ttfamily\textbackslash StrCompare}
\verb|\StrCompare|\etoile\ARGU{stringA}\ARGU{stringB}\arguC{name}
\smallskip
-This macro has 2 tolerances: the ''normal`` tolerance, used bu default, and the ''strict`` tolerance.\medskip
-
+This macro has 2 tolerances: the "normal" tolerance, used bu default, and the "strict" tolerance.
\begin{itemize}
\item The normal tolerance, activated with \verb|\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, activated with \verb|\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}
-\smallskip
+\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}|
@@ -791,17 +724,198 @@ Examples with the strict tolerance:\par\comparestrict
\exemple|\StrCompare{abc}{}|
\comparenormal
-\section{Using the macros for programming purposes}
-\label{programmation}
-\subsection{Verbatimize to a control sequence}
+\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 is called. In most of the cases, this expansion mode avoids chains of \verb|\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
+
+An other 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 (for the expansion of all tokens one time, you should call the macro \verb|\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". 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|.
+
+\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 :
+\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).;
+ \item tokens with catcode 1 to 4, usually : \verb|{|\quad\verb|}|\footnote{Warning : braces \textbf{must} be balanced in arguments !}\quad\verb|$|\quad\verb|&|
+ \item tokens with catcode 7 and 8, usually : \verb|^|\quad\verb|_|
+ \item any purely expandable control sequence\footnote{i.e. this control sequence can be {\ttfamily\string\edef}ed.} or tokens with catcode 13 (active chars) whose expansion is allowed chars.
+\end{itemize}\parindent0pt
+\smallskip
+
+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
+\begin{itemize}
+ \item those cited above;
+ \item any control sequence or token catocode 13, even undefined;
+ \item the special chars (\officialeuro, \textcurrency, ¶, etc.).
+\end{itemize}
+\parindent0pt
+
+\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, even with \verb|\expandafter|.\medskip
+
+For this reason, all the macros returning a result (i.e. all excepted the tests and \verb|\StrSplit|) 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
+
+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
+
+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 can be written like this:\par
+\hspace{0.2\linewidth}\verb|\StrGobbleRight{xstring}{1}[\mystring]|\par
+\hspace{0.2\linewidth}\verb|\StrGobbleleft{\mystring}{1}|\par
+
+\subsection{How \Xstring reads the arguments?}
+\label{developpementarguments}
+\subsubsection{Syntax unit by \US}
+The macros of \Xstring read their arguments \US par \US. In the \TeX{} code, a \US is either:\parindent3em
+\begin{itemize}
+ \item a control sequence;
+ \item a group, i.e. what is between 2 balanced braces;
+ \item a char.
+\end{itemize}
+\medskip\parindent0pt
+
+Let's see what is a \US with an example. Let's take this argument : "\verb|ab\textbf{xyz}cd|"
+
+It has 6 \USs: "\verb|a|", "\verb|b|", "\verb|\textbf|", "\verb|{xyz}|", "\verb|c|" and "\verb|d|".\medskip
+
+What will happen 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}
+ \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| 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 main argument, \Xstring does not look into groups, and simply consider them as \US.
+
+For specific uses, it can be necessary to look into groups: \verb|\exploregroups| changes the exploration mode an makes the macros look inside groups.\medskip
+
+What does this exploration mode in the preceding example? \Xstring does not count the group as a single \US but look 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}
+ \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 an argument 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}
+ \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|.
+
+Moreover, 2 macros run in \verb|\noexploregroups| mode, whatever be the current mode: \verb|\StrBetween| et \verb|\StrMid|.\medskip
+
+It is possible to save the "explore mode" with \verb|\saveexploremode|, then modify this "explore mode" and come back to the situation when it was saved with \verb|\restoreexploremode|.
+
+\subsection{Catcode of arguments, starred macros}
+\label{macrosetoilees}
+Macros of this package take the catcodes of characters into account. To avoid unexpected behaviour (particulary with tests), you should keep in mind that characters \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 char catcodes 12 and 10 : \verb|\detokenize|, \verb|\meaning|, \verb|\jobname|, \verb|\fontname|, \verb|\romannumeral|, etc.\medskip
+
+Starred macros do not take catcodes into account. They simply convert their textual arguments into arguments with catcodes 10, 11 and 12, and call the non-starred macros with these modified arguments.\medskip
+
+\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
+
+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}
+ \IfStrEq{\string a\string b}{ab}{true}{false}\par
+ \IfStrEq*{\string a\string b}{ab}{true}{false}
+\end{minipage}\smallskip
+
+In the example above, after expansion (assumed that \verb|\fullexpandarg| is active), the first argument contains \verb|{ab}| where, because of \verb|\string|, both chars have catcode 12. The second argument is \verb|{ab}| where both chars have their natural catcode 11. Strings are not equal because of the catcode and the test is negative, if the unstarred version is used.\bigskip
+
+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}$".
+
+\section{Other macros for assistance in programming}
+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{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|^| et \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{}
\smallskip
-\argu{name} is the name of the control sequence receiving, with an \verb|\edef|, the \argu{characters}. Consequently, \argu{name} contains \texte{10,11,12}\voirdeftexte.\medskip
+\argu{name} is the name of the control sequence receiving, with an \verb|\edef|, the \argu{characters}. \argu{name} thus contains char with catcodes 12 or 10 for space.\medskip
-By default, the character delimiting the verb content is \guill{|}. Obviously, this character cannot be both delimiting and being contained into what it delimits. If you need to verbatimize characters containing \guill{|}, you can change at any time the character delimiting the verb content with the macro:\par\medskip
+By default, the character delimiting the verb content is \guill{|}. Obviously, this character 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 character delimiting the verb content with the macro:\par\medskip
\hfill\verb|\setverbdelim|\ARGU{character}\hfill{}\smallskip
Any \argu{character} with a catcode 11 or 12 can be used\footnote{Several characters 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 character.}. For example, after \verb|\setverbdelim{=}|, a verb argument look like this: \verb|=|\argu{characters}\verb|=|.\medskip
@@ -827,14 +941,13 @@ Example:\par\medskip
\result
\end{minipage}
-\subsection{Tokenization of a text to a control sequence}
-
-The reverse process of what has been seen above is to transform a \texte{10,11,12} into control sequences. This is done by the macro:\medskip
+\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 sequence}\hfill{}
+\hfill\verb|\tokenize|\ARGU{name}\ARGU{control sequences}\hfill{}
\smallskip
-\argu{control sequence} is fully expanded if \verb|\fullexpandarg| has been called (see page~\pageref{devarg}), and is not expanded if \verb|\normalexpandarg| has benn called. In both cases, the expansion must be \texte{10,11,12}. Then, this \texte{10,11,12} is converted into tokens and assigned with a \verb|\def| to the control sequence \argu{name}.\medskip
+\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}
@@ -861,66 +974,30 @@ Example:\par\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}
-\subsubsection{The scancs macro}
-It is possible to expand $n$ times a control sequence before converting this expansion into text. This is done by the macro:\medskip
+\subsection{Expansion of a control sequence before verbatimize, the macro \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}.
-\subsubsection{Mind the catcodes !}
-Let's take a simple example where \argu{control sequence} expands to text:\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \def\test{a b1 d}
- \scancs{\result}{\test}
- \resultat
- \end{boxedverbatim}
- \hspace{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \def\test{a b1 d}
- \scancs{\result}{\test}
- \result
-\end{minipage}
-\medskip
-
-But mind the catcodes !
-
-In this example, \verb|\scancs{\result}{\test}| is not equivalent to \verb|\edef\result{\test}|.\medskip
-
-Indeed, with \verb|\scancs{\resultat}{\test}|, \verb|\result| contains \texte{10,12} and expands to:\par
-\hfill\verb|a|${}_{12}$\ \verb*| |${}_{10}$\ \verb|b|${}_{12}$\ \verb|1|${}_{12}$\ \verb*| |${}_{10}$\ \verb|d|${}_{12}$\hfill{}
-\medskip
-
-With \verb|\edef\resultat{\test}|, \verb|\resultat| contains \texte{10,11,12}, i.e. characters whose catcodes are 11 (the letters), 12 (the figure 1) and 10 (the spaces). It expands to:\par
-\hfill\verb|a|${}_{11}$\ \verb*| |${}_{10}$\ \verb|b|${}_{11}$\ \verb|1|${}_{12}$\ \verb*| |${}_{10}$\ \verb|d|${}_{11}$\hfill{}
-
-\subsubsection{Depth of expansion}
-If necessary, the number of expansions can be controled with the optional argument.
-In the following example, when \verb|\scancs| is called the first time, \verb|\c| is expanded 3 times and gives "\verb|1|${}_{12}$\ \verb*| |${}_{10}$\ \verb|z|${}_{11}$\ \verb*| |${}_{10}$\ \verb|3|${}_{12}$" which is converted into "\verb|1|${}_{12}$\ \verb*| |${}_{10}$\ \verb|z|${}_{12}$\ \verb*| |${}_{10}$\ \verb|3|${}_{12}$".\smallskip
-
-On the other hand, if after $n$ expansions, the result is a control sequence, this control sequence is transformed into characters with catcodes 12.
-In the example above, when \verb|\scancs| is called the second time, \verb|\scancs[2]{\resultat}{\c}| expands \verb|\c| 2 times: this gives the control sequence \fbox{\texttt{\textbackslash a}} which is converted into "\verb|\|${}_{12}$~\verb|a|${}_{12}$".\medskip
-
-This example show all the "depths" of expansion, from 3 to 0:\par\medskip
+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[3]{\result}{\c}
- \result\par
- \scancs[2]{\result}{\c}
- \result\par
- \scancs[1]{\result}{\c}
- \result\par
\scancs[0]{\result}{\c}
- \result
+ 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}
\end{minipage}%
@@ -928,150 +1005,49 @@ This example show all the "depths" of expansion, from 3 to 0:\par\medskip
\def\a{1 z 3}
\def\b{\a}
\def\c{\b}
- \scancs[3]{\result}{\c}
- \result\par
- \scancs[2]{\result}{\c}
- \result\par
- \scancs[1]{\result}{\c}
- \result\par
\scancs[0]{\result}{\c}
- \result
-\end{minipage}
-\medskip
-
-Obviously, it is necessary to ensure that the expansion to the desired depth is possible.
-
-\subsubsection{Expansion of several control sequences}
-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. Let's see this with this example:\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \def\a{LaTeX}
- \def\b{is powerful}
- \scancs*[1]{\result}{\a \b}
- \result\par
- \scancs*[2]{\result}{\a\space\b}
- \result
- \end{boxedverbatim}
- \hspace{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \def\a{LaTeX}
- \def\b{is powerful}
- \scancs*[1]{\result}{\a \b}
- \result\par
- \scancs*[2]{\result}{\a\space\b}
- \result
+ 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
-First of all, a warning message has been sent to log: "if third argument or its expansion have braces or spaces, they will be removed when scanned! Use starred \verb|\scancs*| macro with care". Let's see what it means\ldots\medskip
-
-In the first result, a space is missing between the words \guill{LaTeX} and \guill{is}, though a space was present in the code between the 2 control sequences \verb|\a| and \verb|\b|. Indeed, \TeX{} ignores spaces that follow control sequences. Consequently, \verb|{\a \b}| is read as \verb|{\a\b}|, whatever be the number of spaces in the code between \verb|\a| and \verb|\b|. To obtain a space between \guill{LaTeX} and \guill{is}, we could have used the control sequence \verb|\space| whose expansion is a space, and write for the third argument: \verb|{\a\space\b}|. We could also have modified the defintion of \verb|\a| with a space after the word "LaTeX" like this: \verb|\def\a{LaTeX }|.\medskip
+Obviously, it is necessary to ensure that the expansion to the desired depth is possible.\medskip
-However, it is necessary to be carfull when expanding control sequences more than one time: if a control sequence is expanded $n$ times and gives \texte{10,11,12}, the next expansion gobbles spaces. The second result shows that the second expansion gobbled all the spaces and consequently, \verb|\result| contains \guill{LaTeXispowerful}!\medskip
-
-Moreover, it's also the meaning of the warning message, if the $n$\th{} expansion of a control sequence contains braces, they will be gobbled, like spaces.\medskip
-
-Finaly, when using \verb|\scancs| a space is inserted after each control sequence. Indeed, \verb|\detokenize| (an $\varepsilon$-\TeX{} command) called by \verb|\scancs| inserts a space after each control sequence. There is no way to avoid this.
-
-\subsubsection{Examples}
-In the following example, control sequences are expanded 2 times: \verb|\d| gives \verb|\b|, and \verb|\b| gives\\\verb|\textbf{a}\textit{b}|. Notice that a space is inserted after each control sequence.\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \def\a{\textbf{a}\textit{b}}
- \def\b{\a}
- \def\c{\b}
- \def\d{\c}
- \scancs*[2]{\result}{\d\b}
- \result
- \end{boxedverbatim}
- \hspace{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \def\a{\textbf{a}\textit{b}}
- \def\b{\a}
- \def\c{\b}
- \def\d{\c}
- \scancs*[2]{\result}{\d\b}
- \result
-\end{minipage}
-\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}
- \scancs*[1]{\result}{\b{A}}
- \result\par
- \scancs*[2]{\result}{\b{A}}
- \result\par
- \scancs*[3]{\result}{\b{A}}
- \result\par
+ \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}
- \scancs*[1]{\result}{\b{A}}
- \result\par
- \scancs*[2]{\result}{\b{A}}
- \result\par
- \scancs*[3]{\result}{\b{A}}
- \result\par
-\end{minipage}
-\medskip
-
-Finaly, here is an example where we take advantage of the space inserted after each sequence control to find the $n$\th{} control sequence in the expansion of a control sequence.\medskip
-
-In the example above, we find the fourth control sequence in \verb|\myCS| whose expansion is:\par\medskip
-\hfill\verb|\a xy{3 2}\b7\c123 {m}\d{8}\e|\hfill{}
-\medskip
-
-Obviously, we expect: \verb|\d|\par\medskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \verbtocs{\antislash}|\|
- \newcommand\findcs[2]{%
- \scancs[1]{\theCS}{#2}%
- \tokenize{\theCS}{\theCS}%
- \scancs[1]{\theCS}{\theCS}%
- \StrBehind[#1]{\theCS}{\antislash}[\theCS]%
- \StrBefore{\theCS}{ }[\theCS]%
- \edef\theCS{\antislash\theCS}}
- \verbtocs{\myCS}|\a xy{3 2}\b7\c123 {m}\d{8}\e|
- % here, \myCS contains text
- \findcs{4}{\myCS}
- \theCS\par
- \def\myCS{\a xy{3 2}\b7\c123 {m}\d{8}\e}
- % here, \myCS contains control sequences
- \findcs{4}{\myCS}
- \theCS
- \end{boxedverbatim}
- \hspace{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \verbtocs{\antislash}|\|
- \newcommand\findcs[2]{%
- \scancs[1]{\theCS}{#2}%
- \tokenize{\theCS}{\theCS}%
- \scancs[1]{\theCS}{\theCS}%
- \StrBehind[#1]{\theCS}{\antislash}[\theCS]%
- \StrBefore{\theCS}{ }[\theCS]%
- \edef\theCS{\antislash\theCS}}
- \verbtocs{\myCS}|\a xy{3 2}\b7\c123 {m}\d{8}\e|
- % here, \myCS contains text
- \findcs{4}{\myCS}
- \theCS\par
- \def\myCS{\a xy{3 2}\b7\c123 {m}\d{8}\e}
- % here, \myCS contains control sequences
- \findcs{4}{\myCS}
- \theCS
+ \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}
\subsection{Inside the definition of a macro}
@@ -1120,51 +1096,28 @@ In the following teaching example\footnote{It is possible to make much more simp
\bracearg{\a}
\end{minipage}
-\subsection{Starred macros}\label{macrosetoilees}
-Commands manipulating strings take catcodes of characters into account. To prevent any differences between catcode and then avoid unexpected results, all these macros have starred version. Starred macros convert their textual arguments into arguments with catcode 12 and 10 and call the non-starred macros with these modified arguments.\medskip
+\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
-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}
- \IfStrEq{\string a\string b}{ab}{true}{false}\par
- \IfStrEq*{\string a\string b}{ab}{true}{false}
-\end{minipage}\smallskip
-
-In this example, the first argument expands into \verb|{ab}| where, because of \verb|\string|, both characters have a catcode 12. The second argument is \verb|{ab}| where characters have their natural catcode 11. The strings are \emph{not equal} because of unmatching catcodes. Therefore, the test is negative. It is positive only with the starred macro.\medskip
-
-Here is an other ewample :\par\smallskip
-\begin{minipage}[r]{0.6\linewidth}
- \hfill
- \begin{boxedverbatim}
- \scancs[0]\mytext{abc}
- \StrPosition{\mytext}{b}\par
- \StrPosition*{\mytext}{b}\par
- \end{boxedverbatim}
- \hspace{0.3cm}
-\end{minipage}%
-\begin{minipage}[r]{0.3\linewidth}
- \scancs[0]\mytext{abc}
- \StrPosition{\mytext}{b}\par
- \StrPosition*{\mytext}{b}\par
-\end{minipage}\medskip
+\verb|\StrRemoveBraces|\ARGU{stringe}\arguC{name}
+\smallskip
-The control sequence \verb|\mytext| contains \verb|{abc}| with catcodes 12 : indeed, \verb|\scancs| returns strings with catcodes 12 and 10 for space. Logically, the non-starred macro return 0 which means that it considers that the character ''\verb|b|${}_{11}$`` is not contained in the string ''\verb|a|${}_{12}$\verb|b|${}_{12}$\verb|c|${}_{12}$``. The starred macro behaves as expected and returns the correct position.\bigskip
+This macro is sensitive to exploration mode and will remove \emph{all} the braces with \verb|\exploregroups| while it will remove braces of higher level with \verb|\noexploregroups|.\medskip
-For the macros returning a string, if the starred version is used, the result will be a string with characters' catcode 12 and 10 fot space. For example, after ''\verb|\StrBefore*{a b c d}{c}[\mytext]|``, the expansion of the control sequence \verb|\mytext| will be ''\verb|a|${}_{12}$\verb*| |${}_{10}$\verb|b|${}_{12}$\verb*| |${}_{10}$``.
+\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|
\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| winch contains \par\smallskip
+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{}
\medskip
@@ -1173,36 +1126,36 @@ 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}}
- \scancs[1]{\text}{\myCS}
- \StrSubstitute*[2]{\text}{textit}{textbf}[\text]
- \tokenize{\myCS}{\text}
- \myCS
+ \def\pattern{\textit}
+ \def\replace{\textbf}
+ \StrSubstitute[2]{\myCS}{\pattern}{\replace}
\end{boxedverbatim}
\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
+ \expandarg
\def\myCS{\textit{A}\textit{B}\textit{C}}
- \scancs[1]{\text}{\myCS}
- \StrSubstitute*[2]{\text}{textit}{textbf}[\text]
- \tokenize{\myCS}{\text}
- \myCS
-\end{minipage}
+ \def\pattern{\textit}
+ \def\replace{\textbf}
+ \StrSubstitute[2]{\myCS}{\pattern}{\replace}
+\end{minipage}\fullexpandarg
\subsubsection{Example 2}
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}
- \verbtocs{\csfrac}|\frac|%
- \verbtocs{\Ob}|{|%
- \verbtocs{\Cb}|}|%
+ \noexpandarg
\newcommand\tofrac[1]{%
- \scancs[0]{\myfrac}{#1}%
- \StrBefore{\myfrac}{/}[\num]%
- \StrBehind{\myfrac}{/}[\den]%
- \tokenize\myfrac{\csfrac\Ob\num\Cb\Ob\den\Cb}%
- $\myfrac$}
+ \StrBefore{#1}{/}[\num]%
+ \StrBehind{#1}{/}[\den]%
+ $\frac{\num}{\den}$%
+ }
\tofrac{15/9}
\tofrac{u_{n+1}/u_n}
\tofrac{a^m/a^n}
@@ -1211,96 +1164,97 @@ Let's try to write a macro \verb|\tofrac| that transforms an argument of this ty
\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
- \verbtocs{\csfrac}|\frac|%
- \verbtocs{\Ob}|{|%
- \verbtocs{\Cb}|}|%
+ \noexpandarg
\newcommand\tofrac[1]{%
- \scancs[0]{\myfrac}{#1}%
- \StrBefore{\myfrac}{/}[\num]%
- \StrBehind{\myfrac}{/}[\den]%
- \tokenize\myfrac{\csfrac\Ob\num\Cb\Ob\den\Cb}%
- $\myfrac$}
+ \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{minipage}
+\end{minipage}\fullexpandarg
\subsubsection{Example 3}
-In a control sequence \verb|\text|, let's try to write in bold the first word that follows the word "new". In this example, \verb|\text| contains:\par\medskip
-\hfill\verb|Try the new package xstring !|\hfill{}\bigskip
-\setverbdelim{|}
+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}
- \def\text{Try the new package xstring !}
- \def\word{new}
- \StrBehind[1]{\text}{\word}[\name]
- \IfBeginWith{\name}{ }%
- {\StrGobbleLeft{\name}{1}[\name]}%
- {}%
- \StrBefore{\name}{ }[\name]
- \verbtocs{\before}|\textbf{|
- \verbtocs{\after}|}|
- \StrSubstitute[1]%
- {\text}{\name}{\before\name\after}[\text]
- \tokenize{\text}{\text}
- \text
+ \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}{ring}
+
+ \boldafter{The xstring package is new}{is}
\end{boxedverbatim}
\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
- \def\text{Try the new package xstring !}
- \def\word{new}
- \StrBehind[1]{\text}{\word}[\name]
- \IfBeginWith{\name}{ }%
- {\StrGobbleLeft{\name}{1}[\name]}%
- {}%
- \StrBefore{\name}{ }[\name]
- \verbtocs{\before}|\textbf{|
- \verbtocs{\after}|}|
- \StrSubstitute[1]%
- {\text}{\name}{\before\name\after}[\text]
- \tokenize{\text}{\text}
- \text
-\end{minipage}
+ \newcommand\boldafter[2]{%
+ \noexpandarg
+ \StrBehind[1]{#1 }{ #2 }[\word]%
+ \expandarg
+ \StrBefore{\word}{ }[\word]%
+ \StrSubstitute[1]{#1}{\word}{\textbf{\word}}%
+ }
-\subsubsection{Example 4}
-A control sequence \verb|\myCS| défined with an \verb|\edef| contains control sequences with their possible arguments. How to reverse the order of the 2 first control sequences? In this example, \verb|\myCS| contains:\par\medskip
-\hfill\verb|\textbf{A}\textit{B}\texttt{C}|\hfill{}\bigskip
+ \boldafter{The xstring package is new}{xstring}
-We expect a final result containing \verb|\textit{B}\textbf{A}\texttt{C}| and displaying \textit{B}\textbf{A}\texttt{C}\medskip
+ \boldafter{The xstring package is new}{ring}
+
+ \boldafter{The xstring package is new}{is}
+\end{minipage}\fullexpandarg
+
+\subsubsection{Example 4}
+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}
- \def\myCS{\textbf{A}\textit{B}\texttt{C}}
- \scancs[1]{\text}{\myCS}
\verbtocs{\antislash}|\|
- \StrBefore[3]{\text}{\antislash}[\firsttwo]
- \StrBehind{\text}{\firsttwo}[\others]
- \StrBefore[2]{\firsttwo}{\antislash}[\avant]
- \StrBehind{\firsttwo}{\avant}[\apres]%
- \tokenize{\myCS}{\apres\avant\others}%
- result: \myCS
+ \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}
- \def\myCS{\textbf{A}\textit{B}\texttt{C}}
- \scancs[1]{\text}{\myCS}
\verbtocs{\antislash}|\|
- \StrBefore[3]{\text}{\antislash}[\firsttwo]
- \StrBehind{\text}{\firsttwo}[\others]
- \StrBefore[2]{\firsttwo}{\antislash}[\avant]
- \StrBehind{\firsttwo}{\avant}[\apres]%
- \tokenize{\myCS}{\apres\avant\others}%
- result: \myCS
+ \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{minipage}
\subsubsection{Example 5}
-A control sequence \verb|\myCS| defined with an \verb|\edef| contains control sequences and "groups" between braces. Let's try to find the $n$\th{} group, i.e. what is between the $n$\th{} pair of balanced braces. In this example, \verb|\myCS| contains:\par\medskip
+A control sequence \verb|\myCS| defined with an \verb|\edef| contains control sequences and "groups" between braces. Let's try to find the $n$\th group, i.e. what is between the $n$\th pair of balanced braces. In this example, \verb|\myCS| contains:\par\medskip
\hfill\verb|\a{1\b{2}}\c{3}\d{4\e{5}\f{6{7}}}|\hfill{}\medskip
\begin{minipage}[r]{0.6\linewidth}