summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/etextools/etextools-examples.tex
blob: a8b96ae1837c1bc26ca92cd52c884d818616a8fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
%%
%% 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.
%% 
%% Copyright (C) 2009 by Florent Chervet <florent.chervet@free.fr>
%% 
%% 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
%% 
%%% etextools : more e-TeX useful tools for LaTeX package writers
%%% Florent CHERVET
\documentclass[11pt,french,a4paper,oneside]{scrartcl}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{geometry,doc,ltxdockit,txfonts,fancyhdr}
\usepackage{etextools}
\hypersetup{colorlinks,pdfstartview={FitH}}
\geometry{top=2cm,bottom=2cm,left=2.5cm,right=1cm}
\fancyhf{}
\fancyhead[L]{Examples for the \sty{etextools} package}
\pagestyle{fancy}
\MakeShortVerb{\|}

\makeatletter
\def\smex{\leavevmode\hb@xt@2em{\hfil$\longrightarrow$\hfil}}
\def\strip@meaning{\expandafter\strip@prefix\meaning}
\def\strip@macro{\expandafter\strip@macroprefix\meaning}
\def\get@params#1{\expandafter\@get@params\meaning#1\@nil}
\edef\@get@params{%
   \def\noexpand\@get@params\detokenize{macro:}##1\detokenize{->}##2\noexpand\@nil{##1}%
}\@get@params
\def\make@macro#1{\string\def\string#1\get@params#1\string{\strip@meaning#1\string}}
\newcommand\preline{\@ifstar{\@preline}{\hrulefill\par\@preline}}
\def\@preline#1{\noindent\hskip6pt\texttt{\make@macro#1}\par\vskip1.5ex}

\def\meaningcs#1{\expandafter\meaning\csname#1\endcsname}
\def\Meaningcs#1{\expandafter\strip@meaning\csname #1\endcsname}

\newcommand\test[1]{%
   \csname test#1\endcsname
   \edef\usercmd{\Meaningcs{test#1}}\edef\result{\meaningcs{#1Test}}\noindent
   \begin{tabular}{lp{15cm}}
   \multicolumn{2}{l}{\textcolor{blue}{\llap\smex\tt \usercmd}} \\[1.5ex]
   \cmd{#1Test}= & \tt\bfseries\result
   \end{tabular}\par\nobreak\hrulefill\null\goodbreak}

\begin{document}
\title{etextools examples}
\subtitle{Examples for some macros provided by the \sty{etextools} package}
\author{Florent Chervet}
\date{July 22, 2009}
\maketitle

\tableofcontents

\section{\cmd{expandnext} examples}

\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}

\clearpage
\subsection{Detokenize the replacement text of a named-sequence}
\def\detokenizecs#1{\expandnext\expandnext\detokenize{\csname #1\endcsname}}
\def\testexpandnext{%
   \edef\expandnextTest{\detokenizecs{document}}}
\preline\detokenizecs
\test{expandnext}

\section{Testing characters}
\subsection{\cmd{ifsinglechar} versus \cmd{iffirstchar}}
\def\testifsinglechar{%
   \edef\ifsinglecharTest{\ifsinglechar *{*hello*}{ single star }{ something else }}
}\hrulefill\par
\test{ifsinglechar}

\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}

\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{testbf}}
\def\testcsvloop{%
   \protected@edef\csvloopTest{\csvloop*[\textbf]{hello ,my ,friends}}
}\hrulefill\par
\test{csvloop}

\subsection{\cmd{getlistitem}}
\csvtolist*\mylist{one,two,three,four,five,alpha,beta,gamma}
\def\testgetlistitem{%
   \edef\getlistitemTest{\getlistitem\mylist{4}}
}\hrulefill\par
\noindent\hskip6pt|\csvtolist*\mylist{one,two,three,four,five,alpha,beta,gamma}|\par\vskip1.5ex
\test{getlistitem}

\subsection{\cmd{getlistindex} {\mdseries(not expandable)}}
\getlistindex{four}\mylist
\hrulefill\par
\noindent\hskip6pt|\csvtolist*\mylist{one,two,three,four,five,alpha,beta,gamma}|\par\vskip1.5ex
\noindent\hskip6pt\textcolor{blue}{\llap\smex\cmd{getlistindex}{four}\cmd{mylist}}\par\vskip1.5ex
\noindent\hskip6pt\cmd{indexinlist}=\quad{\bfseries\meaning\indexinlist}\par\hrulefill\par

\end{document}

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