| 1 |
%% |
| 2 |
%% This is file `etextools-examples.tex', |
| 3 |
%% generated with the docstrip utility. |
| 4 |
%% |
| 5 |
%% The original source files were: |
| 6 |
%% |
| 7 |
%% etextools.dtx (with options: `example') |
| 8 |
%% |
| 9 |
%% This is a generated file. |
| 10 |
%% |
| 11 |
%% This work may be distributed and/or modified under the |
| 12 |
%% conditions of the LaTeX Project Public License, either |
| 13 |
%% version 1.3 of this license or (at your option) any later |
| 14 |
%% version. The latest version of this license is in |
| 15 |
%% http://www.latex-project.org/lppl.txt |
| 16 |
%% |
| 17 |
%% This work consists of the main source file etextools.dtx |
| 18 |
%% and the derived files |
| 19 |
%% etextools.sty, etextools.pdf, etextools.ins, |
| 20 |
%% and etextools-examples.tex |
| 21 |
%% |
| 22 |
\ProvidesFile{etextools-examples} |
| 23 |
\documentclass[11pt,french,a4paper,oneside]{scrartcl} |
| 24 |
\usepackage[latin1]{inputenc} |
| 25 |
\usepackage[T1]{fontenc} |
| 26 |
\usepackage[american]{babel} |
| 27 |
\usepackage{geometry,doc,ltxdockit,txfonts,fancyhdr,stmaryrd,graphicx,enumitem} |
| 28 |
\usepackage{etextools} |
| 29 |
\usepackage{fancyvrb} |
| 30 |
\makeatletter |
| 31 |
\let\org@newif\newif |
| 32 |
\def\newif#1{\ifx#1\ifnotempty\else\expandafter\org@newif\fi} |
| 33 |
\usepackage{umrand} |
| 34 |
\renewcommand\ifne[1]{\csname @\ifcat $\detokenize{#1}$first\else second\fi oftwo\endcsname\iffalse\iftrue} |
| 35 |
\let\newif\org@newif |
| 36 |
\font\umranda=umranda \def\Ch{\char'} |
| 37 |
\def\textvb#1{{\usefont{T1}{txtt}{m}{n}#1}} |
| 38 |
\newrobustcmd\thispackage{\xpackage{\spot etextools}\xspace} |
| 39 |
\newrobustcmd\xpackage[1]{{\usefont{T1}{lmss}{bx}{n}\db\mbox{#1}}} |
| 40 |
\hypersetup{colorlinks,pdfstartview={FitH}} |
| 41 |
\geometry{top=1.5cm,bottom=1.2cm,left=2.5cm,right=1cm} |
| 42 |
\fancyhf{} |
| 43 |
\fancyhead[L]{Examples for the \thispackage package} |
| 44 |
\pagestyle{fancy} |
| 45 |
\DefineShortVerb{\|} |
| 46 |
\catcode`\^^a7 \active\def^^a7{\par\nobreak\vskip-\parskip} |
| 47 |
\DefineVerbatimEnvironment{VerbLines}{Verbatim} |
| 48 |
{gobble=1,commandchars=!(),frame=lines,framesep=6pt,fontfamily=txtt,fontseries=m} |
| 49 |
\apptocmd\@list@extra{\parsep\parskip\topsep\z@\itemsep\z@}{}{} |
| 50 |
\def\smex{\leavevmode\hb@xt@2em{\hfil$\longrightarrow$\hfil}} |
| 51 |
\def\FE{\setbox8\hbox{$\m@th\bindnasrepma$}% |
| 52 |
\textcolor{fecc}{\scalebox{2}{$\copy8\mkern-13.5mu\copy8\mkern-13.5mu\copy8$}}} |
| 53 |
\def\pdfFE{\setbox8\hbox{$\m@th\bindnasrepma$}% |
| 54 |
\textcolor{fecc}{\llap{\textsf{pdf}\TeX{}\,}\scalebox{2}{$\copy8\mkern-13.5mu\copy8\mkern-13.5mu\copy8$}}} |
| 55 |
\definecolor{fecc}{rgb}{.2,.6,.2} |
| 56 |
\definecolor{dg}{rgb}{0.00,0.37,0.00} \newrobustcmd\dg{\color{dg}} \newrobustcmd\dgbf{\dg\bfseries} |
| 57 |
\definecolor{spot}{rgb}{1.00,0.33,0.00} \newrobustcmd\spot{\color{spot}} |
| 58 |
\definecolor{db}{rgb}{0.00,0.00,0.25} \newrobustcmd\db{\color{db}} |
| 59 |
\newrobustcmd\blue{\color{blue}} |
| 60 |
\newrobustcmd\nnn{\normalfont\mdseries\upshape} |
| 61 |
\newrobustcmd\ClearPage{\@ifstar\clearpage{}} |
| 62 |
\def\make@macro#1{\string\def\string#1\parameters@meaning#1\string{\strip@meaning#1\string}} |
| 63 |
\newcommand\preline{\@ifstar{\@preline}{\hrulefill\par\@preline}} |
| 64 |
\newcommand\@preline[2][1.5ex]{\noindent\hskip6pt\textvb{\make@macro#2}\par\ifblank{#1}{}{\vskip#1}} |
| 65 |
\ifdef\pdfstrcmp{\let\ifpdfTeX\iffalse}{\let\ifpdfTeX\iftrue} |
| 66 |
\newcommand*\test{\@ifstar{\let\fe\pdfFE\testi}{\let\fe\FE\testi}} |
| 67 |
\newcommand\testi[1]{% |
| 68 |
\csname test#1\endcsname |
| 69 |
\edef\usercmd{\strip@meaningcs{test#1}}\edef\result{\meaningcs{#1Test}}\noindent |
| 70 |
\begin{tabular}{lp{15cm}} |
| 71 |
\multicolumn{2}{l}{\textcolor{blue}{\llap{\fe\,\smex}\tt \usercmd}} \\[1.5ex] |
| 72 |
\cmd{#1Test}= & \tt\bfseries\result |
| 73 |
\end{tabular}\par\nobreak\hrulefill\null\goodbreak} |
| 74 |
\begin{document} |
| 75 |
\title{\vskip-2cm\thispackage\ examples} |
| 76 |
\subtitle{Examples for some macros provided by the \thispackage package} |
| 77 |
\author{\small<FC -- December 12, 2010>} |
| 78 |
\date{} |
| 79 |
\newsavebox\helpbox \newsavebox\helpboxx |
| 80 |
\newrobustcmd*\mydotleader[2][\z@]{\leavevmode\xleaders\hbox to\dimexpr1.7pt+#1{\hss\raise#2\hbox{$\scriptscriptstyle\cdotp$}\hss}} |
| 81 |
\begingroup\let\clearpage\@empty |
| 82 |
\setbox\helpbox\hbox to13cm{\hss\lower3cm\vbox to1.8cm{\maketitle\vss}\hss} |
| 83 |
\fboxsep\z@ |
| 84 |
\newrobustcmd\corner[2][\spot\umranda]{\hbox{#1\rlap{\char'115}\char'#2}} |
| 85 |
\null\vskip-1cm\hskip-1cm\null\hfil\RandBox {\fbox{\copy\helpbox}} |
| 86 |
font {\umranda} [0pt] |
| 87 |
(\corner{17}) ([\Ch111]) (\corner{14}) |
| 88 |
([\Ch112]) ([\Ch112]) |
| 89 |
(\corner{21}) ([\Ch111]) (\corner{11}) |
| 90 |
\endgroup |
| 91 |
\tableofcontents\hyperdef{ettlex}{toc}{} |
| 92 |
\section{\cmd{expandnext} examples} |
| 93 |
\subsection{Test if the replacement text of macro is really empty} |
| 94 |
\def\xx{ } |
| 95 |
\def\testexpandnext{% |
| 96 |
\edef\expandnextTest{\string\xx\ is \expandnext\ifempty{\xx}{}{not} empty} |
| 97 |
} |
| 98 |
\preline\xx |
| 99 |
\test{expandnext} |
| 100 |
\def\xx{} |
| 101 |
\preline\xx |
| 102 |
\test{expandnext} |
| 103 |
\ClearPage* |
| 104 |
\subsection{Test if the replacement text of a macro is blank (empty or spaces)} |
| 105 |
\def\xx{something} |
| 106 |
\def\testexpandnext{% |
| 107 |
\edef\expandnextTest{\string\xx\ is \expandnext\ifblank{\xx}{}{not} blank} |
| 108 |
} |
| 109 |
\preline\xx |
| 110 |
\test{expandnext} |
| 111 |
\def\xx{ } |
| 112 |
\preline\xx |
| 113 |
\test{expandnext} |
| 114 |
\section{\cmd{ExpandNext} examples} |
| 115 |
Example of the main documentation file to reverse the order of the characters in a string: |
| 116 |
\def\swap#1#2{{#2#1}} \def\do[#1]#2{\swap #2}% \do{abcdef} -> \swap ab + cdef -> {ba}cdef |
| 117 |
% \do{{ba}cdef} -> \swap {ba}c + def -> {cba}def |
| 118 |
\edef\result{\naturalloop[\do]{4}{12345}} |
| 119 |
\ExpandNext{\def\RESULT}{\naturalloop[\do]{4}{12345}} |
| 120 |
\begin{VerbLines} |
| 121 |
\def\swap#1#2{{#2#1}} \def\do[#1]#2{\swap #2} |
| 122 |
\edef\result{\naturalloop[\do]{4}{12345}} |
| 123 |
\meaning\result = !bfseries!meaning!result |
| 124 |
\ExpandNext{\def\RESULT}{\naturalloop[\do]{4}{12345}} |
| 125 |
\meaning\RESULT = !bfseries!meaning!RESULT |
| 126 |
\end{VerbLines} |
| 127 |
\subsection{Test the parameter string of a macro} |
| 128 |
The following commands create the filter for the string: "\textvb{[\#1]\#2"}":^^a7 |
| 129 |
\begin{VerbLines}[commandchars=!()] |
| 130 |
\ExpandNext{(!blue\DeclareStringFilter\ParaFilt)} |
| 131 |
{\ExpandAftercmds\@gobblescape{\expandafter\string\csname(!blue[#1]#2)\endcsname}} |
| 132 |
\end{VerbLines} |
| 133 |
\ExpandNext{\DeclareStringFilter\ParaFilt} |
| 134 |
{\ExpandAftercmds\@gobblescape{\expandafter\string\csname[#1]#2\endcsname}} |
| 135 |
\begin{enumerate}[label=\arabic*)~,noitemsep,nolistsep] |
| 136 |
\item |\csname[#1]#2\endcsname| is expanded first |
| 137 |
\item Immediately after: |\string| |
| 138 |
\item At this stage: |\[#1]#2| (everything in category code other) is no more expandable |
| 139 |
\item Then |\ExpandAftercmds| expands |\@gobblescape| |
| 140 |
\item |[#1]#2| is no more expandable |
| 141 |
\item Then |\ExpandNext| expands its first argument: |\DeclareStringFilter\ParaFilt{[#1]#2}| |
| 142 |
\end{enumerate} |
| 143 |
Remark: |\detokenize| would have doubled the \# characters. Another possibility is to temporarily change the |
| 144 |
category code of \# to 12 (other): |
| 145 |
\begin{VerbLines}[commandchars=!()] |
| 146 |
\begingroup\catcode`\#=12 |
| 147 |
(!blue\DeclareStringFilter\ParaFilt{[#1]#2}) !nnn global declaration |
| 148 |
\endgroup |
| 149 |
\end{VerbLines} |
| 150 |
\def\macroA#1#2{Something to do with #1 and #2} |
| 151 |
\def\macroB[#1]#2{Something to do with #1 and #2} |
| 152 |
\preline[]\macroA |
| 153 |
\preline*[]\macroB |
| 154 |
\begin{Verbatim}[commandchars=!()] |
| 155 |
!blue\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroA}{macro complies with [\#1]\#2} |
| 156 |
!blue{macro does not comply } |
| 157 |
\end{Verbatim} |
| 158 |
\hfill\textvb{\dgbf\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroA}{macro complies with [\#1]\#2} |
| 159 |
{macro does not comply }} |
| 160 |
\begin{Verbatim}[commandchars=!()] |
| 161 |
!blue\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroB}{macro complies with [\#1]\#2} |
| 162 |
!blue{macro does not comply } |
| 163 |
\end{Verbatim} |
| 164 |
\hfill\textvb{\dgbf\ExpandNext{\ParaFilt=.}{\parameters@meaning\macroB}{macro complies with [\#1]\#2} |
| 165 |
{macro does not comply }} |
| 166 |
\par\hrulefill\par |
| 167 |
\ClearPage* |
| 168 |
\section{Testing characters} |
| 169 |
\subsection{\cmd{ifsinglechar} versus \cmd{iffirstchar}} |
| 170 |
\def\testifsinglechar{% |
| 171 |
\edef\ifsinglecharTest{\ifsinglechar *{*hello*}{ single star }{ something else }} |
| 172 |
}\hrulefill\par |
| 173 |
\test{ifsinglechar} |
| 174 |
\def\testifsinglechar{% |
| 175 |
\edef\ifsinglecharTest{\ifsinglechar *{ *}{ single star }{ something else }} |
| 176 |
}\hrulefill\par |
| 177 |
\test{ifsinglechar} |
| 178 |
\def\testifsinglechar{% |
| 179 |
\edef\ifsinglecharTest{\ifsinglechar *{ * }{ single star }{ something else }} |
| 180 |
}\hrulefill\par |
| 181 |
\test{ifsinglechar} |
| 182 |
{\small Note the space \textbf{after} the star $\uparrow$.} |
| 183 |
\def\testiffirstchar{% |
| 184 |
\edef\iffirstcharTest{\iffirstchar *{*hello*}{ first char is star }{ something else }} |
| 185 |
}\hrulefill\par |
| 186 |
\test{iffirstchar} |
| 187 |
\subsection{Fully Expandable starred macros} |
| 188 |
\def\starmacro#1{\FE@ifstar{#1}\starred\notstarred} |
| 189 |
\def\starred#1{your "#1" will be processed by the STAR form} |
| 190 |
\def\notstarred#1{your "#1" will be processed by the NORMAL form} |
| 191 |
\def\testFE@ifstar{% |
| 192 |
\edef\FE@ifstarTest{\starmacro{sample text}}} |
| 193 |
\preline\starmacro |
| 194 |
\preline*\starred |
| 195 |
\preline*\notstarred |
| 196 |
\test{FE@ifstar} |
| 197 |
\def\testFE@ifstar{% |
| 198 |
\edef\FE@ifstarTest{\starmacro*{sample text}}} |
| 199 |
\hrulefill\par |
| 200 |
\test{FE@ifstar} |
| 201 |
\subsection{Fully Expandable macros with options} |
| 202 |
\def\optmacro#1{\FE@testopt{#1}\OPTmacro{Mr.}} |
| 203 |
\def\OPTmacro[#1]#2{#1 #2} |
| 204 |
\def\testFE@testopt{% |
| 205 |
\edef\FE@testoptTest{\optmacro{Woody Allen}}} |
| 206 |
\preline\optmacro |
| 207 |
\preline*\OPTmacro |
| 208 |
\test{FE@testopt} |
| 209 |
\def\testFE@testopt{% |
| 210 |
\edef\FE@testoptTest{\optmacro[Ms.]{Vanessa Paradis}}} |
| 211 |
\hrulefill\par |
| 212 |
\test{FE@testopt} |
| 213 |
\ClearPage* |
| 214 |
\section{Lists management} |
| 215 |
\subsection{\cmd{csvloop} and \cmd{csvloop*} examples} |
| 216 |
\subsubsection{\cmd{makequotes}} |
| 217 |
\def\makequotes#1{"#1"\space} |
| 218 |
\def\testcsvloop{% |
| 219 |
\edef\csvloopTest{\csvloop*[\makequotes]{hello,world}} |
| 220 |
} |
| 221 |
\preline\makequotes |
| 222 |
\test{csvloop} |
| 223 |
\subsubsection{\cmd{detokenize}} |
| 224 |
\def\testcsvloop{% |
| 225 |
\edef\csvloopTest{\csvloop*[\detokenize]{\un,\deux}} |
| 226 |
}\hrulefill\par |
| 227 |
\test{csvloop} |
| 228 |
\subsubsection{\cmd{numexpr}} |
| 229 |
\def\mylist{1,2,3,4,5}\def\BySeven#1{$#1\times 7 = \number\numexpr#1*7\relax$\par} |
| 230 |
\def\testcsvloop{% |
| 231 |
\edef\csvloopTest{\csvloop[\BySeven]\mylist}} |
| 232 |
\preline\mylist |
| 233 |
\preline*\BySeven |
| 234 |
\test{csvloop} |
| 235 |
\subsubsection{protected \cmd{textbf}} |
| 236 |
\def\testcsvloop{% |
| 237 |
\protected@edef\csvloopTest{\csvloop*[\textbf]{hello ,my ,friends}} |
| 238 |
}\hrulefill\par |
| 239 |
\test{csvloop} |
| 240 |
\subsection{Index in lists and items by index} |
| 241 |
\subsubsection{\cmd{listloop}: getting specific item} |
| 242 |
\csvtolist*[\mylist]{one,two,three,four,five,alpha,beta,gamma} |
| 243 |
\def\testgetlistitem{% |
| 244 |
\edef\getlistitemTest{\listloop[4]\mylist} |
| 245 |
}\hrulefill\par |
| 246 |
\noindent\hskip6pt|\csvtolist*[\mylist]{one,two,three,four,five,alpha,beta,gamma}|\par\vskip1.5ex |
| 247 |
\test{getlistitem} |
| 248 |
\ClearPage* |
| 249 |
\subsubsection{\cmd{getlistindex}} |
| 250 |
\ifpdfTeX |
| 251 |
\leavevmode\vadjust{\textsl{Require the }\string\pdfstrcmp\ \textsl{primitive (pdf\TeX{}) :}} |
| 252 |
\def\testgetlistindex{% |
| 253 |
\edef\getlistindexTest{\getlistindex{alpha}\mylist} |
| 254 |
}\hrulefill\par |
| 255 |
\noindent\hskip6pt|\csvtolist*[\mylist]{one,two,three,four,five,alpha,beta,gamma}|\par\vskip1.5ex |
| 256 |
\test*{getlistindex} |
| 257 |
\leavevmode\vadjust{\textsl{Require the }\string\pdfstrcmp\ \textsl{primitive (pdf\TeX{}) :}} |
| 258 |
\def\testgetlistindex{% |
| 259 |
\edef\getlistindexTest{\getcsvlistindex*{alpha}{one,two,three,four,five,alpha,beta}} |
| 260 |
}\hrulefill\par |
| 261 |
\test*{getlistindex} |
| 262 |
\fi |
| 263 |
\hrulefill\par |
| 264 |
\getlistindex[\myindex]{alpha}\mylist |
| 265 |
{\color{blue}\noindent\hskip6pt\llap\smex|\getlistindex[\myindex]{alpha}\mylist|\par\vskip1.5ex} |
| 266 |
{\tt\string\myindex=\quad\textbf{\meaning\myindex}} |
| 267 |
\par\hrulefill\par\vskip.5ex |
| 268 |
\hrulefill\par |
| 269 |
\newcount\myindex |
| 270 |
\getcsvlistindex*[\myindex]{alpha}{one,two,three,four,five,alpha,beta} |
| 271 |
\noindent\hskip6pt|\newcount\myindex|\par |
| 272 |
{\color{blue}\noindent\hskip6pt\llap\smex|\getcsvlistindex*[\myindex]{alpha}{one,two,three,four,five,alpha,beta}|}\par\vskip.5ex |
| 273 |
{\tt\string\the\string\myindex=\qquad\textbf{\the\myindex}} |
| 274 |
\par\hrulefill\par\vskip.5ex |
| 275 |
\ClearPage |
| 276 |
\subsubsection{\cmd{gettokslistindex} with \cmd{ifcase}} |
| 277 |
\hrulefill\par\vskip2ex\noindent |
| 278 |
\llap{\FE\,\smex}\par\vskip-2.5\baselineskip\strut |
| 279 |
\leavevmode\vadjust{Always purely expandable (no need of |\pdfstrcmp|, comparison done by |\ifx|):} |
| 280 |
\begin{Verbatim} |
| 281 |
\ifcase \gettokslistindex{D}{LRDF\relax O} |
| 282 |
What do to if L |
| 283 |
\or What do to if R |
| 284 |
\or What do to if D |
| 285 |
\or What do to if F |
| 286 |
\or What do to if \relax |
| 287 |
\or What do to if O |
| 288 |
\else Problem |
| 289 |
\fi |
| 290 |
\end{Verbatim} |
| 291 |
{\tt Result=\qquad\bfseries |
| 292 |
\ifcase\gettokslistindex{D}{LRDF} |
| 293 |
What do to if L |
| 294 |
\or What do to if R |
| 295 |
\or What do to if D |
| 296 |
\or What do to if F |
| 297 |
\else Problem |
| 298 |
\fi}\par |
| 299 |
\hrulefill\par\vskip.5ex |
| 300 |
\end{document}\endinput |
| 301 |
|
| 302 |
\endinput |
| 303 |
%% |
| 304 |
%% End of file `etextools-examples.tex'. |