1
0
Fork 0

Initial commit of this pain-in-the-ass

The goal of epmanners is to provide a means of coping with the \everypar
issues caused by LaTeX' rude implementation; that is---to teach LaTeX (and
hopefully other packages that use \everypar) some manners.

As mentioned in Knuth's TeXbook, \everypar is a token register that is
processed after entering horizontal mode to begin a new paragraph. This
register is very useful for a number of circumstances, including paragraph
numbering and itemized lists. LaTeX uses \everypar internally for things
such as itemized lists and section headings; unfortunately, since it does
not care much about what others are using \everypar for, it ends up
clobbering the register after it is done, leading to frustration after
section/chapter headings, \end, and others.

In developing sPxTeX, which performs paragraph numbering and marginal notes
for each paragraph, this became painfully apparent.

Rather than simply patching the appropriate commands at runtime or handling
specific cases, which wouldn't be a general solution for other packages, the
approach was to instead redefine \everypar to be a command rather than a
token register. This will allow fine control over what ends up in the
register, but creates a number of headaches (e.g. \the\everypar). This
initial implementation retains the LaTeX kernel's original functionality and
will allow \the\everypar from within \everpar itself; this means that the
register can be manipulated as usual without any problems. However, there is
still work to be done to ensure that \the\everypar works in all contexts,
not just within \everypar itself.

Once the initial redefinition is complete, this package will provide a means
to control tokens that should always appear in the \everypar token register,
or should be automatically re-added when the register is reset
(\everypar{}); additional features will be considered if needed.

This package is written primarily in plain TeX, and so would be easily
ported outside of LaTeX where useful. Note that this package is not likely
to be useful in plain TeX environments since \everypar isn't systematically
abused by TeX itself (though you may include macros that do).
master
Mike Gerwitz 2013-09-04 23:07:10 -04:00
commit 4fbc7b8ebb
No known key found for this signature in database
GPG Key ID: F22BB8158EE30EAB
2 changed files with 131 additions and 0 deletions

3
.gitignore vendored 100644
View File

@ -0,0 +1,3 @@
*.aux
*.log
*.pdf

128
epmanners.sty 100644
View File

@ -0,0 +1,128 @@
% epmanners---Teach LaTeX some manners to respect \everypar
%
% Copyright (C) 2013 Mike Gerwitz
%
% This file is part of epmanners.
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%
% do not be alarmed.
\let\@@epm@the\the
\let\@@epm@ep\everypar
\newtoks\@@epm@tokempty
% first, insert an identifier into the \everypar token list, allowing us to
% recognize when tokens passed to the redefined \everypar below contain
% \the\everypar
% redefine \everypar as a command instead of a token register, allowing us
% to dictate its behavior more precisely; note that, in order for \the to
% work properly as if \everypar were still a token register, we must always
% have it produce the original \everypar
\def\everypar{%
\@@epm@tokempty{}%
\futurelet\@@epn\@epm@epf
}
\def\@epm@epf{%
\begingroup
\ifvmode
% the \expandafter here ensures that the common notation of
% \everypar\expandafter[...] will be executed as expected by assigning
% the value of \everypar to the value of the \expandafter expression,
% while still retaining proper evaluation of all other cases
\aftergroup\expandafter
\aftergroup\@epm@epf@set
\else
\aftergroup\the
\aftergroup\@@epm@ep
\fi
\endgroup
}
\newtoks\@@epm@epclean
\def\@epm@epf@set#1{%
\@epm@cleantok\@@epm@epclean{#1}%
\@@epm@ep\expandafter{\the\@@epm@epclean}%
}
\def\@epm@epf@the{%
\the\@@epm@ep
}
%%
% utilities
%
% consume next token
\def\@epm@omnom#1{}
% ``cleans'' tokens by stripping the result of \the\everypar and storing it
% in a destination token register
\def\@epm@cleantok#1#2{%
\let\@@epm@tokdest#1%
\global\@@epm@tokdest{}%
\futurelet\@@epn\@epm@docleantok#2\@@epm@end
}
\def\@epm@docleantok{%
\begingroup
% stop once we reach the end
\ifx\@@epn\@@epm@end
\aftergroup\@epm@omnom
\else
\ifx\@@epn\@epm@epf
% since this token is only used in the \everypar definition, we know
% that \the has been used; insert a \relax to cancel the \futurelet
% in its definition before continuing
\aftergroup\relax
\aftergroup\@epm@cleantok@strip
\else
% token is good; retain it and recurse, noting that we must handle
% space tokens separately to ensure that they are not gobbled up by
% the parser and lost forever
\ifcat\space\@@epn
\aftergroup\@epm@docleantok@recursesp
\else
\aftergroup\@epm@docleantok@recurse
\fi
\fi
\fi
\endgroup
}
% consumes the next token and then continues
\def\@epm@docleantok@recurse#1{%
\@@epm@tokdest\expandafter{\the\@@epm@tokdest#1}%
\futurelet\@@epn\@epm@docleantok
}
% similar to the above, but is intended to consume a blank token (charcode
% 10) and recurse, re-adding the token that follows it
\def\@epm@docleantok@recursesp#1{%
\@@epm@tokdest\expandafter{\the\@@epm@tokdest\ }%
\futurelet\@@epn\@epm@docleantok#1
}
\def\@epm@cleantok@strip#1{%
% this macro has stripped the entirety of the \everypar definition, so we
% are now free to replace it with whatever tokens we wish (that is, they
% typed \the\everypar, so we should produce \the\@@epm@ep)
\@@epm@tokdest\expandafter{%
\the\expandafter\@@epm@tokdest
\the\@@epm@ep%
}%
\futurelet\@@epn\@epm@docleantok
}