summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/trimspaces
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/trimspaces
Initial commit
Diffstat (limited to 'macros/latex/contrib/trimspaces')
-rw-r--r--macros/latex/contrib/trimspaces/README12
-rw-r--r--macros/latex/contrib/trimspaces/trimspaces.ins4
-rw-r--r--macros/latex/contrib/trimspaces/trimspaces.pdfbin0 -> 174846 bytes
-rw-r--r--macros/latex/contrib/trimspaces/trimspaces.tex240
4 files changed, 256 insertions, 0 deletions
diff --git a/macros/latex/contrib/trimspaces/README b/macros/latex/contrib/trimspaces/README
new file mode 100644
index 0000000000..0e4e8ac9f6
--- /dev/null
+++ b/macros/latex/contrib/trimspaces/README
@@ -0,0 +1,12 @@
+______________________
+The TRIMSPACES package
+v1.1
+
+This package provides commands that allow you to expandably
+remove spaces around a token list or remove surrounding
+spaces within a macro definition.
+
+Will Robertson
+Copyright 2009
+Released under the LaTeX Project Public License
+
diff --git a/macros/latex/contrib/trimspaces/trimspaces.ins b/macros/latex/contrib/trimspaces/trimspaces.ins
new file mode 100644
index 0000000000..7177afc608
--- /dev/null
+++ b/macros/latex/contrib/trimspaces/trimspaces.ins
@@ -0,0 +1,4 @@
+%&latex
+\def\pstoolCompile{N}
+\input pstool.tex
+\csname @@end\endcsname
diff --git a/macros/latex/contrib/trimspaces/trimspaces.pdf b/macros/latex/contrib/trimspaces/trimspaces.pdf
new file mode 100644
index 0000000000..50a6a8ef9b
--- /dev/null
+++ b/macros/latex/contrib/trimspaces/trimspaces.pdf
Binary files differ
diff --git a/macros/latex/contrib/trimspaces/trimspaces.tex b/macros/latex/contrib/trimspaces/trimspaces.tex
new file mode 100644
index 0000000000..d8041d36c7
--- /dev/null
+++ b/macros/latex/contrib/trimspaces/trimspaces.tex
@@ -0,0 +1,240 @@
+\RequirePackage{filecontents}
+\begin{filecontents*}{README.txt}
+______________________
+The TRIMSPACES package
+v1.1
+
+This package provides commands that allow you to expandably
+remove spaces around a token list or remove surrounding
+spaces within a macro definition.
+
+Will Robertson
+Copyright 2009
+Released under the LaTeX Project Public License
+
+\end{filecontents*}
+
+\begin{filecontents}{trimspaces.sty}
+\ProvidesPackage{trimspaces}[2009/09/17 v1.1
+ Trim spaces around a token list]
+
+% Trimming surrounding spaces:
+\catcode`\Q=3
+\newcommand\trim@spaces[1]{%
+ \romannumeral-`\q\trim@trim@\noexpand#1Q Q%
+}
+\long\def\trim@trim@#1 Q{\trim@trim@@#1Q}
+\long\def\trim@trim@@#1Q#2{#1}
+\catcode`\Q=11
+
+\newcommand\trim@spaces@noexp[1]{%
+ \unexpanded\expandafter\expandafter\expandafter
+ {\trim@spaces{#1}}%
+}
+
+\newcommand\trim@spaces@in[1]{%
+ \edef#1{\expandafter\trim@spaces@noexp\expandafter{#1}}%
+}
+
+% Trimming preceding spaces:
+\newcommand\trim@pre@space[1]{%
+ \romannumeral-`\.\expandafter\noexpand#1%
+}
+
+\newcommand\trim@pre@space@noexp[1]{%
+ \unexpanded\expandafter{%
+ \romannumeral-`\.\expandafter\noexpand#1%
+ }%
+}
+
+\newcommand\trim@pre@space@in[1]{%
+ \expandafter\def\expandafter#1\expandafter{%
+ \romannumeral-`\.\expandafter\noexpand#1%
+ }%
+}
+
+% Trimming trailing space:
+\catcode`\Q=3
+\newcommand\trim@post@space[1]{\trim@trim@#1Q Q}
+\catcode`\Q=11
+
+\newcommand\trim@post@space@noexp[1]{%
+ \unexpanded\expandafter\expandafter\expandafter
+ \expandafter\expandafter\expandafter\expandafter
+ {\trim@post@space{#1}}%
+}
+
+\newcommand\trim@post@space@in[1]{%
+ \edef#1{\expandafter\trim@post@space@noexp\expandafter{#1}}%
+}
+
+% That's it.
+\end{filecontents}
+%%%%%%%%%1%%%%%%%%%2%%%%%%%%%3%%%%%%%%%4%%%%%%%%%5
+
+
+% Conditionally compile the documentation & generate the .ins file:
+\providecommand\pstoolCompile{Y}
+\if\pstoolCompile N
+ \expandafter\endinput
+\fi
+
+
+\begin{filecontents*}{trimspaces.ins}
+%&latex
+\def\pstoolCompile{N}
+\input pstool.tex
+\csname @@end\endcsname
+\end{filecontents*}
+
+
+
+
+\makeatletter
+\documentclass{article}
+\usepackage[rm,medium]{titlesec}
+\usepackage{xcolor}
+\usepackage[colorlinks,linktocpage]{hyperref}
+\usepackage{gmdoc}
+\usepackage{gmverb}
+\dekclubs
+\stanzaskip=\bigskipamount
+\CodeSpacesGrey
+
+\let\pkg\textsf
+
+\usepackage{trimspaces}
+\usepackage[T1]{fontenc}
+\usepackage{microtype}
+\usepackage{lmodern}
+\usepackage[sc,osf]{mathpazo}
+\linespread{1.1}
+\frenchspacing
+
+\GetFileInfo{trimspaces.sty}
+\begin{document}
+
+\title{The \pkg{trimspaces} package}
+\author{Package author: Will Robertson\\Code thanks to Morten H\o gholm}
+\date{\fileversion\qquad\filedate}
+
+\maketitle
+\tableofcontents
+
+\section{Use of the package}
+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.
+
+For an extensive discussion on this topic, see chapter fifteen of Peter Wilson's compendium of Michael Downes' `Around the Bend' exercises:
+\par\centerline{\url{http://tug.ctan.org/pkg/around-the-bend}}
+
+The code that this package is based on, however, originates with Morten H\o gholm. Thanks!
+
+\subsection{Trimming spaces}
+\begin{itemize}
+\item \cs{trim@spaces} \marg{text}\\
+\cs{trim@pre@space} \marg{text}\\
+\cs{trim@post@space} \marg{text}\par
+Fully expandable, removes spaces at the beginning and/or end of \meta{text}.
+
+\item \cs{trim@spaces@noexp} \marg{text}\\
+\cs{trim@pre@space@noexp} \marg{text}\\
+\cs{trim@post@space@noexp} \marg{text}\par
+Variants of the above that after full expansion result in the original unexpanded text stripped of surrounding spaces.
+(\textit{Requires $\varepsilon$-\TeX}.)
+
+\item \cs{trim@spaces@in} \meta{macro}\\
+\cs{trim@pre@space@in} \meta{macro}\\
+\cs{trim@post@space@in} \meta{macro}\par
+Re-defines \meta{macro} as itself stripped of its surrounding spaces
+(these commands are obviously not expandable).
+\end{itemize}
+
+\subsection{Examples}
+
+Trimming surrounding spaces:
+\begin{verbatim}
+\def\foo{bar}
+\edef\a{\trim@spaces{ a \foo ! }}
+\edef\aa{\trim@spaces@noexp{ aa \foo ! }}
+\def\b{ b \foo ! }
+\trim@spaces@in\b
+a: [\detokenize\expandafter{\a}] \\
+aa: [\detokenize\expandafter{\aa}] \\
+b: [\detokenize\expandafter{\b}]
+\end{verbatim}
+which produces:
+\begin{quote}
+\makeatletter
+\def\foo{bar}
+\edef\a{\trim@spaces{ a \foo ! }}
+\edef\aa{\trim@spaces@noexp{ aa \foo ! }}
+\def\b{ b \foo ! }
+\trim@spaces@in\b
+a: [\detokenize\expandafter{\a}] \\
+aa: [\detokenize\expandafter{\aa}] \\
+b: [\detokenize\expandafter{\b}]
+\end{quote}
+Only removing preceding spaces:
+\begin{verbatim}
+\def\foo{bar}
+\edef\a{\trim@pre@space{ a \foo ! }}
+\edef\aa{\trim@pre@space@noexp{ aa \foo ! }}
+\def\b{ b \foo ! }
+\trim@pre@space@in\b
+a: [\detokenize\expandafter{\a}] \\
+aa: [\detokenize\expandafter{\aa}] \\
+b: [\detokenize\expandafter{\b}]
+\end{verbatim}
+which produces:
+\begin{quote}
+\makeatletter
+\def\foo{bar}
+\edef\a{\trim@pre@space{ a \foo ! }}
+\edef\aa{\trim@pre@space@noexp{ aa \foo ! }}
+\def\b{ b \foo ! }
+\trim@pre@space@in\b
+a: [\detokenize\expandafter{\a}] \\
+aa: [\detokenize\expandafter{\aa}] \\
+b: [\detokenize\expandafter{\b}]
+\end{quote}
+Only removing trailing spaces:
+\begin{verbatim}
+\def\foo{bar}
+\edef\a{\trim@post@space{ a \foo ! }}
+\edef\aa{\trim@post@space@noexp{ aa \foo ! }}
+\def\b{ b \foo ! }
+\trim@post@space@in\b
+a: [\detokenize\expandafter{\a}] \\
+aa: [\detokenize\expandafter{\aa}] \\
+b: [\detokenize\expandafter{\b}]
+\end{verbatim}
+which produces:
+\begin{quote}
+\makeatletter
+\def\foo{bar}
+\edef\a{\trim@post@space{ a \foo ! }}
+\edef\aa{\trim@post@space@noexp{ aa \foo ! }}
+\def\b{ b \foo ! }
+\trim@post@space@in\b
+a: [\detokenize\expandafter{\a}] \\
+aa: [\detokenize\expandafter{\aa}] \\
+b: [\detokenize\expandafter{\b}]
+\end{quote}
+
+
+\section{Package information}
+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/}.
+
+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}.
+
+\subsection{Licence}
+
+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}.
+
+This work is author-maintained by \textsc{Will Robertson}.
+
+\section{Implementation}
+\parindent=0pt
+\DocInput{trimspaces.sty}
+
+\end{document}