[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Strip trailing newline from macro expansion in @example
From: |
Gavin Smith |
Subject: |
Strip trailing newline from macro expansion in @example |
Date: |
Sat, 15 Aug 2015 18:43:44 +0100 |
Below is the change I plan on making to fix a bug. It manages to strip
the final newline from the macro's body when expanded, regardless if
it's being expanded in a context where CR has the usual meaning (a
space, and multiple blank lines break a paragraph), and a context
where it always ends the line, as in an @example environment. It does
this by testing the catcode of CR with an \ifnum conditional. It
appears to produce good results with the test file I've attached.
Index: texinfo.tex
===================================================================
--- texinfo.tex (revision 6518)
+++ texinfo.tex (working copy)
@@ -7343,6 +7343,11 @@
}
\fi
+% Used to remove a category 13 newline, added to the end of the last
+% line read in by \scantokens.
+{\catcode`\^^M=13 \gdef\gobblecr^^M{}}
+
+% Argument is macro body with arguments substituted
\def\scanmacro#1{\begingroup
\newlinechar`\^^M
\let\xeatspaces\eatspaces
@@ -7357,15 +7362,14 @@
% ... and for \example:
\spaceisspace
%
- % The \empty here causes a following catcode 5 newline to be eaten as
- % part of reading whitespace after a control sequence. It does not
- % eat a catcode 13 newline. There's no good way to handle the two
- % cases (untried: maybe e-TeX's \everyeof could help, though plain TeX
- % would then have different behavior). See the Macro Details node in
- % the manual for the workaround we recommend for macros and
- % line-oriented commands.
- %
- \scantokens{#1\empty}%
+ \ifnum\catcode`\^^M=5
+ % The \empty here causes a following catcode 5 newline to be eaten as
+ % part of reading whitespace after a control sequence.
+ \scantokens{#1\empty}%
+ \else
+ \catcode`\^^M=13
+ \scantokens{#1\gobblecr}%
+ \fi
\endgroup}
stripmacrocr.texi
Description: TeXInfo document
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Strip trailing newline from macro expansion in @example,
Gavin Smith <=