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.tex92
1 files changed, 53 insertions, 39 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 aa1dae5525c..0dd3ecaa4ec 100644
--- a/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex
+++ b/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex
@@ -1,8 +1,9 @@
-% This is xtring_doc_en.tex, the manual of xstring
+% This is xtring_doc_en.tex, the english manual of xstring
+%
% Christian Tellechea 2008
%
% email : unbonpetit@gmail.com
-%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
@@ -12,12 +13,12 @@
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
-%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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 for strings},pdfkeywords={xstring,latex,string},pdfcreator={LaTeX}]{hyperref}
-\usepackage[a4paper,dvips,margin=1.9cm]{geometry}
+\usepackage[a4paper,dvips,margin=2cm]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{textcomp}
\usepackage{moreverb}
@@ -25,7 +26,6 @@
\usepackage{eurosym}
\usepackage{xspace}
\usepackage{xstring}
-\usepackage{xstring}
\usepackage[french,english]{babel}
\makeatletter
\newcommand*\exemple{\@ifstar{\def\frontiere{|}\@xs@MakeVerb}{\def\frontiere{}\@xs@MakeVerb}}
@@ -778,7 +778,7 @@ And this not allowed nested structure, supposed to remove the first and last cha
\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?}
+\subsection{How does \Xstring read 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
@@ -1141,6 +1141,14 @@ We expect: \textbf{A}\textbf{B}\textit{C}\medskip
\def\replace{\textbf}
\StrSubstitute[2]{\myCS}{\pattern}{\replace}
\end{minipage}\fullexpandarg
+\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
+
+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
+
+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.
\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
@@ -1260,6 +1268,7 @@ A control sequence \verb|\myCS| defined with an \verb|\edef| contains control se
\begin{minipage}[r]{0.6\linewidth}
\hfill
\begin{boxedverbatim}
+ \fullexpandarg
\newcount\occurr
\newcount\nbgroup
\newcommand\findgroup[2]{%
@@ -1277,10 +1286,12 @@ A control sequence \verb|\myCS| defined with an \verb|\edef| contains control se
\ifnum\nbgroup<#1% not the good group ?
\StrBehind{\text}{\group}[\text]%
\occurr=0% initialise \text & \occur
+ \expandafter\expandafter\expandafter
\findthegroup% do it again
\fi
\else% unbalanced braces ?
% look for next "}"
+ \expandafter
\findthegroup
\fi}
\findthegroup
@@ -1297,39 +1308,42 @@ A control sequence \verb|\myCS| defined with an \verb|\edef| contains control se
\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
- \newcount\occurr
- \newcount\nbgroup
- \newcommand\findgroup[2]{%
- \scancs[1]{\text}{#2}%
- \occurr=0
- \nbgroup=0
- \def\findthegroup{%
- \StrBehind{\text}{\Obr}[\remain]%
- \advance\occurr by 1% next "{"
- \StrBefore[\the\occurr]{\remain}{\Cbr}[\group]%
- \StrCount{\group}{\Obr}[\nbA]%
- \StrCount{\group}{\Cbr}[\nbB]%
- \ifnum\nbA=\nbB% balanced braces ?
- \advance\nbgroup by 1
- \ifnum\nbgroup<#1% if it's not the sought group
- \StrBehind{\text}{\group}[\text]%
- \occurr=0% initialization of \text & \occur
- \findthegroup% do it again
- \fi
- \else% unbalanced braces ?
- % look for next "}"
- \findthegroup
- \fi}
- \findthegroup
- \group}
-
- \verbtocs{\Obr}|{|
- \verbtocs{\Cbr}|}|
- \def\myCS{\a{1\b{2}}\c{3}\d{4\e{5}\f{6{7}}}}
-
- groupe 1: \findgroup{1}{\myCS}\par
- groupe 2: \findgroup{2}{\myCS}\par
- groupe 3: \findgroup{3}{\myCS}
+ \fullexpandarg
+ \newcount\occurr
+ \newcount\nbgroup
+ \newcommand\findgroup[2]{%
+ \scancs[1]{\text}{#2}%
+ \occurr=0
+ \nbgroup=0
+ \def\findthegroup{%
+ \StrBehind{\text}{\Obr}[\remain]%
+ \advance\occurr by 1% next "{"
+ \StrBefore[\the\occurr]{\remain}{\Cbr}[\group]%
+ \StrCount{\group}{\Obr}[\nbA]%
+ \StrCount{\group}{\Cbr}[\nbB]%
+ \ifnum\nbA=\nbB% balanced braces ?
+ \advance\nbgroup by 1
+ \ifnum\nbgroup<#1% not the good group ?
+ \StrBehind{\text}{\group}[\text]%
+ \occurr=0% initialise \text & \occur
+ \expandafter\expandafter\expandafter
+ \findthegroup\expandafter% do it again
+ \fi
+ \else% unbalanced braces ?
+ % look for next "}"
+ \expandafter
+ \findthegroup
+ \fi}
+ \findthegroup
+ \group}
+
+ \verbtocs{\Obr}|{|
+ \verbtocs{\Cbr}|}|
+ \def\myCS{\a{1\b{2}}\c{3}\d{4\e{5}\f{6{7}}}}
+
+ group 1: \findgroup{1}{\myCS}\par
+ group 2: \findgroup{2}{\myCS}\par
+ group 3: \findgroup{3}{\myCS}
\end{minipage}
\medskip