%%
%% This is file `etextools-examples.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% etextools.dtx  (with options: `example')
%% 
%% This is a generated file.
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 of this license or (at your option) any later
%% version. The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% 
%% This work consists of the main source file etextools.dtx
%% and the derived files
%%       etextools.sty, etextools.pdf, etextools.ins,
%% and   etextools-examples.tex
%% 
\ProvidesFile{etextools-examples}
\documentclass[11pt,french,a4paper,oneside]{scrartcl}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{geometry,doc,ltxdockit,txfonts,fancyhdr,stmaryrd,graphicx,enumitem}
\usepackage{etextools}
\usepackage{fancyvrb}
\makeatletter
\let\org@newif\newif
\def\newif#1{\ifx#1\ifnotempty\else\expandafter\org@newif\fi}
\usepackage{umrand}
\renewcommand\ifne[1]{\csname @\ifcat $\detokenize{#1}$first\else second\fi oftwo\endcsname\iffalse\iftrue}
\let\newif\org@newif
\font\umranda=umranda \def\Ch{\char'}
\def\textvb#1{{\usefont{T1}{txtt}{m}{n}#1}}
\newrobustcmd\thispackage{\xpackage{\spot etextools}\xspace}
\newrobustcmd\xpackage[1]{{\usefont{T1}{lmss}{bx}{n}\db\mbox{#1}}}
\hypersetup{colorlinks,pdfstartview={FitH}}
\geometry{top=1.5cm,bottom=1.2cm,left=2.5cm,right=1cm}
\fancyhf{}
\fancyhead[L]{Examples for the \thispackage package}
\pagestyle{fancy}
\DefineShortVerb{\|}
\catcode`\^^a7 \active\def^^a7{\par\nobreak\vskip-\parskip}
\DefineVerbatimEnvironment{VerbLines}{Verbatim}
   {gobble=1,commandchars=!(),frame=lines,framesep=6pt,fontfamily=txtt,fontseries=m}
\apptocmd\@list@extra{\parsep\parskip\topsep\z@\itemsep\z@}{}{}
\def\smex{\leavevmode\hb@xt@2em{\hfil$\longrightarrow$\hfil}}
\def\FE{\setbox8\hbox{$\m@th\bindnasrepma$}%
         \textcolor{fecc}{\scalebox{2}{$\copy8\mkern-13.5mu\copy8\mkern-13.5mu\copy8$}}}
\def\pdfFE{\setbox8\hbox{$\m@th\bindnasrepma$}%
         \textcolor{fecc}{\llap{\textsf{pdf}\TeX{}\,}\scalebox{2}{$\copy8\mkern-13.5mu\copy8\mkern-13.5mu\copy8$}}}
\definecolor{fecc}{rgb}{.2,.6,.2}
\definecolor{dg}{rgb}{0.00,0.37,0.00} \newrobustcmd\dg{\color{dg}}   \newrobustcmd\dgbf{\dg\bfseries}
\definecolor{spot}{rgb}{1.00,0.33,0.00} \newrobustcmd\spot{\color{spot}}
\definecolor{db}{rgb}{0.00,0.00,0.25}   \newrobustcmd\db{\color{db}}
\newrobustcmd\blue{\color{blue}}
\newrobustcmd\nnn{\normalfont\mdseries\upshape}
\newrobustcmd\ClearPage{\@ifstar\clearpage{}}
\def\make@macro#1{\string\def\string#1\parameters@meaning#1\string{\strip@meaning#1\string}}
\newcommand\preline{\@ifstar{\@preline}{\hrulefill\par\@preline}}
\newcommand\@preline[2][1.5ex]{\noindent\hskip6pt\textvb{\make@macro#2}\par\ifblank{#1}{}{\vskip#1}}
\ifdef\pdfstrcmp{\let\ifpdfTeX\iffalse}{\let\ifpdfTeX\iftrue}
\newcommand*\test{\@ifstar{\let\fe\pdfFE\testi}{\let\fe\FE\testi}}
\newcommand\testi[1]{%
   \csname test#1\endcsname
   \edef\usercmd{\strip@meaningcs{test#1}}\edef\result{\meaningcs{#1Test}}\noindent
   \begin{tabular}{lp{15cm}}
   \multicolumn{2}{l}{\textcolor{blue}{\llap{\fe\,\smex}\tt \usercmd}} \\[1.5ex]
   \cmd{#1Test}= & \tt\bfseries\result
   \end{tabular}\par\nobreak\hrulefill\null\goodbreak}
\begin{document}
\title{\vskip-2cm\thispackage\ examples}
\subtitle{Examples for some macros provided by the \thispackage package}
\author{\small<FC -- December 12, 2010>}
\date{}
\newsavebox\helpbox \newsavebox\helpboxx
\newrobustcmd*\mydotleader[2][\z@]{\leavevmode\xleaders\hbox to\dimexpr1.7pt+#1{\hss\raise#2\hbox{$\scriptscriptstyle\cdotp$}\hss}}
\begingroup\let\clearpage\@empty
\setbox\helpbox\hbox to13cm{\hss\lower3cm\vbox to1.8cm{\maketitle\vss}\hss}
\fboxsep\z@
\newrobustcmd\corner[2][\spot\umranda]{\hbox{#1\rlap{\char'115}\char'#2}}
\null\vskip-1cm\hskip-1cm\null\hfil\RandBox {\fbox{\copy\helpbox}}
   font {\umranda} [0pt]
   (\corner{17}) ([\Ch111]) (\corner{14})
   ([\Ch112])         ([\Ch112])
   (\corner{21}) ([\Ch111]) (\corner{11})
\endgroup
\tableofcontents\hyperdef{ettlex}{toc}{}
\section{\cmd{expandnext} examples}
\subsection{Test if the replacement text of  macro is really empty}
\def\xx{   }
\def\testexpandnext{%
   \edef\expandnextTest{\string\xx\ is \expandnext\ifempty{\xx}{}{not} empty}
}
\preline\xx
\test{expandnext}
\def\xx{}
\preline\xx
\test{expandnext}
\ClearPage*
\subsection{Test if the replacement text of a macro is blank (empty or spaces)}
\def\xx{something}
\def\testexpandnext{%
   \edef\expandnextTest{\string\xx\ is \expandnext\ifblank{\xx}{}{not} blank}
}
\preline\xx
\test{expandnext}
\def\xx{    }
\preline\xx
\test{expandnext}
\section{\cmd{ExpandNext} examples}
Example of the main documentation file to reverse the order of the characters in a string:
\def\swap#1#2{{#2#1}}   \def\do[#1]#2{\swap #2}% \do{abcdef}   -> \swap ab + cdef   -> {ba}cdef
                                               % \do{{ba}cdef} -> \swap {ba}c + def -> {cba}def
\edef\result{\naturalloop[\do]{4}{12345}}
\ExpandNext{\def\RESULT}{\naturalloop[\do]{4}{12345}}
\begin{VerbLines}
\def\swap#1#2{{#2#1}}   \def\do[#1]#2{\swap #2}
\edef\result{\naturalloop[\do]{4}{12345}}
\meaning\result = !bfseries!meaning!result
\ExpandNext{\def\RESULT}{\naturalloop[\do]{4}{12345}}
\meaning\RESULT = !bfseries!meaning!RESULT
\end{VerbLines}
\subsection{Test the parameter string of a macro}
The following commands create the filter for the string: "\textvb{[\#1]\#2"}":^^a7
\begin{VerbLines}[commandchars=!()]
\ExpandNext{(!blue\DeclareStringFilter\ParaFilt)}
      {\ExpandAftercmds\@gobblescape{\expandafter\string\csname(!blue[#1]#2)\endcsname}}
\end{VerbLines}
\ExpandNext{\DeclareStringFilter\ParaFilt}
      {\ExpandAftercmds\@gobblescape{\expandafter\string\csname[#1]#2\endcsname}}
\begin{enumerate}[label=\arabic*)~,noitemsep,nolistsep]
\item |\csname[#1]#2\endcsname| is expanded first
\item Immediately after: |\string|
\item At this stage: |\[#1]#2| (everything in category code other) is no more expandable
\item Then |\ExpandAftercmds| expands |\@gobblescape|
\item |[#1]#2| is no more expandable
\item Then |\ExpandNext| expands its first argument: |\DeclareStringFilter\ParaFilt{[#1]#2}|
\end{enumerate}
Remark: |\detokenize| would have doubled the \# characters. Another possibility is to temporarily change the
category code of \# to 12 (other):
\begin{VerbLines}[commandchars=!()]
\begingroup\catcode`\#=12
  (!blue\DeclareStringFilter\ParaFilt{[#1]#2})     !nnn global declaration
\endgroup
\end{VerbLines}
\def\macroA#1#2{Something to do with #1 and #2}
\def\macroB[#1]#2{Something to do with #1 and #2}
\preline[]\macroA
\preline*[]\macroB
\begin{Verbatim}[commandchars=!()]
 !blue\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroA}{macro complies with [\#1]\#2}
                                                     !blue{macro does not comply }
\end{Verbatim}
\hfill\textvb{\dgbf\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroA}{macro complies with [\#1]\#2}
                                                     {macro does not comply }}
\begin{Verbatim}[commandchars=!()]
 !blue\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroB}{macro complies with [\#1]\#2}
                                                     !blue{macro does not comply }
\end{Verbatim}
\hfill\textvb{\dgbf\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroB}{macro complies with [\#1]\#2}
                                                     {macro does not comply }}
\par\hrulefill\par
\ClearPage*
\section{Testing characters}
\subsection{\cmd{ifsinglechar} versus \cmd{iffirstchar}}
\def\testifsinglechar{%
   \edef\ifsinglecharTest{\ifsinglechar *{*hello*}{ single star }{ something else }}
}\hrulefill\par
\test{ifsinglechar}
\def\testifsinglechar{%
   \edef\ifsinglecharTest{\ifsinglechar *{  *}{ single star }{ something else }}
}\hrulefill\par
\test{ifsinglechar}
\def\testifsinglechar{%
   \edef\ifsinglecharTest{\ifsinglechar *{ *  }{ single star }{ something else }}
}\hrulefill\par
\test{ifsinglechar}
{\small Note the space \textbf{after} the star $\uparrow$.}
\def\testiffirstchar{%
   \edef\iffirstcharTest{\iffirstchar *{*hello*}{ first char is star }{ something else }}
}\hrulefill\par
\test{iffirstchar}
\subsection{Fully Expandable starred macros}
\def\starmacro#1{\FE@ifstar{#1}\starred\notstarred}
\def\starred#1{your "#1" will be processed by the  STAR form}
\def\notstarred#1{your "#1" will be processed by the  NORMAL form}
\def\testFE@ifstar{%
   \edef\FE@ifstarTest{\starmacro{sample text}}}
\preline\starmacro
\preline*\starred
\preline*\notstarred
\test{FE@ifstar}
\def\testFE@ifstar{%
   \edef\FE@ifstarTest{\starmacro*{sample text}}}
\hrulefill\par
\test{FE@ifstar}
\subsection{Fully Expandable macros with options}
\def\optmacro#1{\FE@testopt{#1}\OPTmacro{Mr.}}
\def\OPTmacro[#1]#2{#1 #2}
\def\testFE@testopt{%
   \edef\FE@testoptTest{\optmacro{Woody Allen}}}
\preline\optmacro
\preline*\OPTmacro
\test{FE@testopt}
\def\testFE@testopt{%
   \edef\FE@testoptTest{\optmacro[Ms.]{Vanessa Paradis}}}
\hrulefill\par
\test{FE@testopt}
\ClearPage*
\section{Lists management}
\subsection{\cmd{csvloop} and \cmd{csvloop*} examples}
\subsubsection{\cmd{makequotes}}
\def\makequotes#1{"#1"\space}
\def\testcsvloop{%
   \edef\csvloopTest{\csvloop*[\makequotes]{hello,world}}
}
\preline\makequotes
\test{csvloop}
\subsubsection{\cmd{detokenize}}
\def\testcsvloop{%
   \edef\csvloopTest{\csvloop*[\detokenize]{\un,\deux}}
}\hrulefill\par
\test{csvloop}
\subsubsection{\cmd{numexpr}}
\def\mylist{1,2,3,4,5}\def\BySeven#1{$#1\times 7 = \number\numexpr#1*7\relax$\par}
\def\testcsvloop{%
   \edef\csvloopTest{\csvloop[\BySeven]\mylist}}
\preline\mylist
\preline*\BySeven
\test{csvloop}
\subsubsection{protected \cmd{textbf}}
\def\testcsvloop{%
   \protected@edef\csvloopTest{\csvloop*[\textbf]{hello ,my ,friends}}
}\hrulefill\par
\test{csvloop}
\subsection{Index in lists and items by index}
\subsubsection{\cmd{listloop}: getting specific item}
\csvtolist*[\mylist]{one,two,three,four,five,alpha,beta,gamma}
\def\testgetlistitem{%
   \edef\getlistitemTest{\listloop[4]\mylist}
}\hrulefill\par
\noindent\hskip6pt|\csvtolist*[\mylist]{one,two,three,four,five,alpha,beta,gamma}|\par\vskip1.5ex
\test{getlistitem}
\ClearPage*
\subsubsection{\cmd{getlistindex}}
\ifpdfTeX
\leavevmode\vadjust{\textsl{Require the }\string\pdfstrcmp\ \textsl{primitive (pdf\TeX{}) :}}
\def\testgetlistindex{%
   \edef\getlistindexTest{\getlistindex{alpha}\mylist}
}\hrulefill\par
\noindent\hskip6pt|\csvtolist*[\mylist]{one,two,three,four,five,alpha,beta,gamma}|\par\vskip1.5ex
\test*{getlistindex}
\leavevmode\vadjust{\textsl{Require the }\string\pdfstrcmp\ \textsl{primitive (pdf\TeX{}) :}}
\def\testgetlistindex{%
   \edef\getlistindexTest{\getcsvlistindex*{alpha}{one,two,three,four,five,alpha,beta}}
}\hrulefill\par
\test*{getlistindex}
\fi
\hrulefill\par
\getlistindex[\myindex]{alpha}\mylist
{\color{blue}\noindent\hskip6pt\llap\smex|\getlistindex[\myindex]{alpha}\mylist|\par\vskip1.5ex}
{\tt\string\myindex=\quad\textbf{\meaning\myindex}}
\par\hrulefill\par\vskip.5ex
\hrulefill\par
\newcount\myindex
\getcsvlistindex*[\myindex]{alpha}{one,two,three,four,five,alpha,beta}
\noindent\hskip6pt|\newcount\myindex|\par
{\color{blue}\noindent\hskip6pt\llap\smex|\getcsvlistindex*[\myindex]{alpha}{one,two,three,four,five,alpha,beta}|}\par\vskip.5ex
{\tt\string\the\string\myindex=\qquad\textbf{\the\myindex}}
\par\hrulefill\par\vskip.5ex
\ClearPage
\subsubsection{\cmd{gettokslistindex} with \cmd{ifcase}}
\hrulefill\par\vskip2ex\noindent
\llap{\FE\,\smex}\par\vskip-2.5\baselineskip\strut
\leavevmode\vadjust{Always purely expandable (no need of |\pdfstrcmp|, comparison done by |\ifx|):}
\begin{Verbatim}
      \ifcase  \gettokslistindex{D}{LRDF\relax O}
            What do to if L
      \or   What do to if R
      \or   What do to if D
      \or   What do to if F
      \or   What do to if \relax
      \or   What do to if O
      \else Problem
      \fi
\end{Verbatim}
{\tt Result=\qquad\bfseries
\ifcase\gettokslistindex{D}{LRDF}
      What do to if L
\or   What do to if R
\or   What do to if D
\or   What do to if F
\else Problem
\fi}\par
\hrulefill\par\vskip.5ex
\end{document}\endinput

\endinput
%%
%% End of file `etextools-examples.tex'.
