Debian Codegraph @

texmf-dist/source/latex/trimspaces/trimspaces.tex

raw
1 \RequirePackage{filecontents}
2 \begin{filecontents*}{README.txt}
3 ______________________
4 The TRIMSPACES package
5 v1.1
6
7 This package provides commands that allow you to expandably
8 remove spaces around a token list or remove surrounding
9 spaces within a macro definition.
10
11 Will Robertson
12 Copyright 2009
13 Released under the LaTeX Project Public License
14
15 \end{filecontents*}
16
17 \begin{filecontents}{trimspaces.sty}
18 \ProvidesPackage{trimspaces}[2009/09/17 v1.1
19 Trim spaces around a token list]
20
21 % Trimming surrounding spaces:
22 \catcode`\Q=3
23 \newcommand\trim@spaces[1]{%
24 \romannumeral-`\q\trim@trim@\noexpand#1Q Q%
25 }
26 \long\def\trim@trim@#1 Q{\trim@trim@@#1Q}
27 \long\def\trim@trim@@#1Q#2{#1}
28 \catcode`\Q=11
29
30 \newcommand\trim@spaces@noexp[1]{%
31 \unexpanded\expandafter\expandafter\expandafter
32 {\trim@spaces{#1}}%
33 }
34
35 \newcommand\trim@spaces@in[1]{%
36 \edef#1{\expandafter\trim@spaces@noexp\expandafter{#1}}%
37 }
38
39 % Trimming preceding spaces:
40 \newcommand\trim@pre@space[1]{%
41 \romannumeral-`\.\expandafter\noexpand#1%
42 }
43
44 \newcommand\trim@pre@space@noexp[1]{%
45 \unexpanded\expandafter{%
46 \romannumeral-`\.\expandafter\noexpand#1%
47 }%
48 }
49
50 \newcommand\trim@pre@space@in[1]{%
51 \expandafter\def\expandafter#1\expandafter{%
52 \romannumeral-`\.\expandafter\noexpand#1%
53 }%
54 }
55
56 % Trimming trailing space:
57 \catcode`\Q=3
58 \newcommand\trim@post@space[1]{\trim@trim@#1Q Q}
59 \catcode`\Q=11
60
61 \newcommand\trim@post@space@noexp[1]{%
62 \unexpanded\expandafter\expandafter\expandafter
63 \expandafter\expandafter\expandafter\expandafter
64 {\trim@post@space{#1}}%
65 }
66
67 \newcommand\trim@post@space@in[1]{%
68 \edef#1{\expandafter\trim@post@space@noexp\expandafter{#1}}%
69 }
70
71 % That's it.
72 \end{filecontents}
73 %%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5
74
75
76 % Conditionally compile the documentation & generate the .ins file:
77 \providecommand\pstoolCompile{Y}
78 \if\pstoolCompile N
79 \expandafter\endinput
80 \fi
81
82
83 \begin{filecontents*}{trimspaces.ins}
84 %&latex
85 \def\pstoolCompile{N}
86 \input pstool.tex
87 \csname @@end\endcsname
88 \end{filecontents*}
89
90
91
92
93 \makeatletter
94 \documentclass{article}
95 \usepackage[rm,medium]{titlesec}
96 \usepackage{xcolor}
97 \usepackage[colorlinks,linktocpage]{hyperref}
98 \usepackage{gmdoc}
99 \usepackage{gmverb}
100 \dekclubs
101 \stanzaskip=\bigskipamount
102 \CodeSpacesGrey
103
104 \let\pkg\textsf
105
106 \usepackage{trimspaces}
107 \usepackage[T1]{fontenc}
108 \usepackage{microtype}
109 \usepackage{lmodern}
110 \usepackage[sc,osf]{mathpazo}
111 \linespread{1.1}
112 \frenchspacing
113
114 \GetFileInfo{trimspaces.sty}
115 \begin{document}
116
117 \title{The \pkg{trimspaces} package}
118 \author{Package author: Will Robertson\\Code thanks to Morten H\o gholm}
119 \date{\fileversion\qquad\filedate}
120
121 \maketitle
122 \tableofcontents
123
124 \section{Use of the package}
125 This package provides a collection of space trimming macros for the \LaTeX\ programmer. Tools are provided to remove either preceding space, trailing space, or both from a token list or the contents of a macro.
126
127 For an extensive discussion on this topic, see chapter fifteen of Peter Wilson's compendium of Michael Downes' `Around the Bend' exercises:
128 \par\centerline{\url{http://tug.ctan.org/pkg/around-the-bend}}
129
130 The code that this package is based on, however, originates with Morten H\o gholm. Thanks!
131
132 \subsection{Trimming spaces}
133 \begin{itemize}
134 \item \cs{trim@spaces} \marg{text}\\
135 \cs{trim@pre@space} \marg{text}\\
136 \cs{trim@post@space} \marg{text}\par
137 Fully expandable, removes spaces at the beginning and/or end of \meta{text}.
138
139 \item \cs{trim@spaces@noexp} \marg{text}\\
140 \cs{trim@pre@space@noexp} \marg{text}\\
141 \cs{trim@post@space@noexp} \marg{text}\par
142 Variants of the above that after full expansion result in the original unexpanded text stripped of surrounding spaces.
143 (\textit{Requires $\varepsilon$-\TeX}.)
144
145 \item \cs{trim@spaces@in} \meta{macro}\\
146 \cs{trim@pre@space@in} \meta{macro}\\
147 \cs{trim@post@space@in} \meta{macro}\par
148 Re-defines \meta{macro} as itself stripped of its surrounding spaces
149 (these commands are obviously not expandable).
150 \end{itemize}
151
152 \subsection{Examples}
153
154 Trimming surrounding spaces:
155 \begin{verbatim}
156 \def\foo{bar}
157 \edef\a{\trim@spaces{ a \foo ! }}
158 \edef\aa{\trim@spaces@noexp{ aa \foo ! }}
159 \def\b{ b \foo ! }
160 \trim@spaces@in\b
161 a: [\detokenize\expandafter{\a}] \\
162 aa: [\detokenize\expandafter{\aa}] \\
163 b: [\detokenize\expandafter{\b}]
164 \end{verbatim}
165 which produces:
166 \begin{quote}
167 \makeatletter
168 \def\foo{bar}
169 \edef\a{\trim@spaces{ a \foo ! }}
170 \edef\aa{\trim@spaces@noexp{ aa \foo ! }}
171 \def\b{ b \foo ! }
172 \trim@spaces@in\b
173 a: [\detokenize\expandafter{\a}] \\
174 aa: [\detokenize\expandafter{\aa}] \\
175 b: [\detokenize\expandafter{\b}]
176 \end{quote}
177 Only removing preceding spaces:
178 \begin{verbatim}
179 \def\foo{bar}
180 \edef\a{\trim@pre@space{ a \foo ! }}
181 \edef\aa{\trim@pre@space@noexp{ aa \foo ! }}
182 \def\b{ b \foo ! }
183 \trim@pre@space@in\b
184 a: [\detokenize\expandafter{\a}] \\
185 aa: [\detokenize\expandafter{\aa}] \\
186 b: [\detokenize\expandafter{\b}]
187 \end{verbatim}
188 which produces:
189 \begin{quote}
190 \makeatletter
191 \def\foo{bar}
192 \edef\a{\trim@pre@space{ a \foo ! }}
193 \edef\aa{\trim@pre@space@noexp{ aa \foo ! }}
194 \def\b{ b \foo ! }
195 \trim@pre@space@in\b
196 a: [\detokenize\expandafter{\a}] \\
197 aa: [\detokenize\expandafter{\aa}] \\
198 b: [\detokenize\expandafter{\b}]
199 \end{quote}
200 Only removing trailing spaces:
201 \begin{verbatim}
202 \def\foo{bar}
203 \edef\a{\trim@post@space{ a \foo ! }}
204 \edef\aa{\trim@post@space@noexp{ aa \foo ! }}
205 \def\b{ b \foo ! }
206 \trim@post@space@in\b
207 a: [\detokenize\expandafter{\a}] \\
208 aa: [\detokenize\expandafter{\aa}] \\
209 b: [\detokenize\expandafter{\b}]
210 \end{verbatim}
211 which produces:
212 \begin{quote}
213 \makeatletter
214 \def\foo{bar}
215 \edef\a{\trim@post@space{ a \foo ! }}
216 \edef\aa{\trim@post@space@noexp{ aa \foo ! }}
217 \def\b{ b \foo ! }
218 \trim@post@space@in\b
219 a: [\detokenize\expandafter{\a}] \\
220 aa: [\detokenize\expandafter{\aa}] \\
221 b: [\detokenize\expandafter{\b}]
222 \end{quote}
223
224
225 \section{Package information}
226 The most recent publicly released version of \pkg{trimspaces} is available at \textsc{ctan}: \url{http://tug.ctan.org/pkg/trimspaces/}. Historical and developmental versions are available at GitHub: \url{http://github.com/wspr/trimspaces/}.
227
228 While general feedback via email is welcomed, specific bugs or feature requests should be reported through the issue tracker: \url{http://github.com/wspr/trimspaces/issues}.
229
230 \subsection{Licence}
231
232 This package is freely modifiable and distributable under the terms and conditions of the \LaTeX\ Project Public License,\footnote{Available at the \LaTeX\ Project website: \url{http://www.latex-project.org/lppl/}} version 1.3c or greater (your choice). This work consists of the source file \texttt{\jobname.tex} and the derived files \texttt{\jobname.sty}, \texttt{\jobname.ins}, and the documentation \texttt{\jobname.pdf}.
233
234 This work is author-maintained by \textsc{Will Robertson}.
235
236 \section{Implementation}
237 \parindent=0pt
238 \DocInput{trimspaces.sty}
239
240 \end{document}