User’s Guide to the Overword package^{∗}

Frank G. Bennett, Jr.

February 6, 1997

Abstract

This package provides two low-level macros for the parsing of text using L^{A}TEX 2ε.

1 Using the macros

This package provides two macros which can be used as building blocks for the parsing of text. For an example of their use, see the Calendar package

(calendar.dtx).

The \@ifoverword macro takes four arguments. These are, in order, a token to match, a text to expand when a match is found, a text to expand if the match is not found, and a text to expand if the macro encounters \end. This last is required to allow macros to be built which will react gracefully when the end of an environment or a document is encountered.

This macro hops over word units (delimited by a space or spaces), and expands text according to what it finds on the other side. Within the text arguments, the \@overword can be used to insert the word that has been gobbled. The expanded text can contain the name of the macro that invokes \@ifoverword; which makes it easy to build text-parsing loops. Note that \@overword is relaxed at each invocation of the macro. This can be used to detect whether the macro has encountered an \end immediately after itself or beyond a word, and thereby exit cleanly in either case.

The file demo.tex contains a sample of the use of this macro. This can be used as a model for building text-parsing loops.

\@overword

1 ⟨∗style⟩

 2 \long\def\@ifoverword#1#2#3#4{%
 3 \let\reserved@a=#1%
 4 \def\reserved@d{#4}\def\reserved@b{#2}\def\reserved@c{#3}%
 5 \gdef\@preoverwordspace{}%
 6 \let\@overword\relax%
 7 \futurelet\@let@token\@ifowd}
 8 \long\def\@ifowd{%
 9 \ifx\@let@token\@sptoken%
10  \gdef\@preoverwordspace{ }%
11  \let\reserved@e\@xifowd%

∗This file is version number v1.2. It was last revised on 1997/01/09.

12 \else%
13  \ifx\@let@token\end%
14  \let\reserved@e\reserved@d%
15  \else%
16  \ifx\@let@token\par%
17  \let\reserved@e\@xifpargobble%
18  \else%
19  \long\def\reserved@e##1 {\long\gdef\@overword{##1}\@@ifowd}%
20  \fi%
21  \fi%
22 \fi%
23 \reserved@e}
24 \long\def\@xifpargobble#1{\futurelet\@let@token\@ifowd}
25 \def\:{\@xifowd} \expandafter\def\: {\futurelet\@let@token\@ifowd}
26 \def\@@ifowd{\futurelet\@let@token\@ifnparnch}

We hack the internals of \@ifnextchar so that it will also ignore \par.

27 \long\def\@xifpargobblench#1{\futurelet\@let@token\@ifparnch}
\@ifoverword
28 \long\def\@ifnextnparchar#1#2#3#4{%
29 \let\reserved@a=#1%
30 \def\reserved@b{#2}\def\reserved@c{#3}\def\reserved@d{#4}%
31 \futurelet\@let@token\@ifnparnch}
32 \long\def\@ifnparnch{%
33 \ifx\@let@token\@sptoken%
34  \let\reserved@e\@xifnparnch%
35 \else%
36  \ifx\@let@token\end%
37  \let\reserved@e\reserved@d%
38  \else%
39  \ifx\@let@token\par%
40  \let\reserved@e\@xifpargobblench%
41  \else%
42  \ifx\@let@token\reserved@a%
43  \let\reserved@e\reserved@b%
44  \else%
45  \let\reserved@e\reserved@c%
46  \fi%
47  \fi%
48  \fi%
49 \fi%
50 \reserved@e}
51 \long\def\@xifpargobblench#1{\futurelet\@let@token\@ifnparnch}
52 \def\:{\@xifnparnch}
53 \expandafter\def\: {\futurelet\@let@token\@ifnparnch}

54 ⟨/style⟩

2 Demo file

55 ⟨∗demo⟩

56 \documentclass{minimal}
57 \usepackage{overword}

58

59 \begin{document}

60

61 \makeatletter

62

63 \newtoks\registerone
64 \newtoks\registertwo
65 \def\list{}

66

67 \def\stashonright{%
68 \registerone=\expandafter{\@overword}
69 \registertwo=\expandafter{\list}
70 \edef\list{%
71  \noexpand\\{\the\registerone}\the\registertwo}}

72

73 \def\showlist{%
74 \def\\##1{\message{##1}}
75 \message{\space\space -> }
76 \list
77 \message{^^J}}

78

79 \def\readlistagain{%
80 \def\\##1{ ##1 }
81 \edef\listtext{\list}
82 \message{\listtext}
83 \expandafter\store\listtext\enditall}

84

85 \def\storeandshow{%
86 \@ifoverword\enditall
87 {\message{^^J^^JRan into enditall!^^J}
88  \stashonright
89  \expandafter\showlist\@gobble}
90 {\stashonright
91  \storeandshow}
92 {\message{^^J^^JRan into end!^^J}
93  \stashonright
94  \showlist}}

95

96 \storeandshow This is a demonstration of the overword package \enditall

97

98 \let\listclone\list
99 \def\list{}
100 \def\\#1{ #1 }
101 \edef\listtext{\listclone}
102 \expandafter\storeandshow\listtext

103

104 \end{document}

105 ⟨/demo⟩

3 The Installation File

106 ⟨∗installer⟩

107 \def\batchfile{overword.ins}
108 \input docstrip.tex

109

110 \keepsilent

111

112 \preamble

113

114 This file is part of the Overword package.
115 Copyright (C) 1996 Frank Bennett, Jr.
116 All rights reserved.
117 ------------------------------------------
118 This is a generated file.

119

120 IMPORTANT NOTICE:

121

122 You are not allowed to change this file.  You may however copy
123 this file to a file with a different name and then change the
124 copy if (a) you do not charge for the modified code, (b) you
125 acknowledge the author(s) in the new file, if it
126 is distributed to others, and (c) you attach these same
127 conditions to the new file.

128

129 You are not allowed to distribute this file alone.  You are not
130 allowed to take money for the distribution or use of this file
131 (or a changed version) except for a nominal charge for copying
132 etc.

133

134 You are allowed to distribute this file under the condition that
135 it is distributed with all of its contents, intact.

136

137 For error reports, or offers to help make this a more powerful,
138 friendlier, and better package, please contact me on
139 `fb' at soas.ac.uk

140

141 \endpreamble

142

143 \generate{\file{overword.sty}{\from{overword.dtx}{style}}

144 }

145

146 \preamble

147

148 This file is part of the Overword package,
149 Copyright (C) 1996 Frank Bennett, Jr.
150 All rights reserved.
151 ------------------------------------------
152 This file is provided for demonstration purposes; feel free
153 to edit it in any way whatsoever.
154 ------------------------------------------

155 156 157

158 \endpreamble

159

160 \postamble
161 \endpostamble

162

163 \generate{\file{demo.tex}{\from{overword.dtx}{demo}}

165

166 \Msg{***********************************************************}
167 \Msg{*}
168 \Msg{* To finish the installation, you have to move the following}
169 \Msg{* file into a directory searched by TeX:}
170 \Msg{*}
171 \Msg{* \space\space overword.sty}
172 \Msg{*}
173 \Msg{***********************************************************}

174 } 175 ⟨/installer⟩