On 22 June 2015 at 00:37, Gavin Smith <[email protected]> wrote: > However, you would still want to interpret backslashes, so that "\\", > "\{" and "\}" (and maybe "\,") would be interpreted as "\", "{", "}" > and "," respectively, while leaving "\a" as "\a" for any other > character "a". You'd want to do this for compatibility with existing > documents and makeinfo implementations. I've been experimenting with > making "\" an active character to try to get this to work, however > it's not there yet. (I'm still struggling to "grok" TeX; I've been > working with "TeX by Topic" which has gotten me a lot further than any > of my previous attempts.)
Hello David and Karl,
Allow me to post my work so far. I seem to have something working for
backslashes. I haven't got { and } to work yet.
My test file is "macro-backslash.texi", attached. I've tested macro
invocations both with and without braces, to check that I am not
messing anything up for the case with braces. To test this, try
replacing one of the instances of "\\yesbrace" with "\yesbrace", in
order to get an error message about an undefined control sequence. As
you can see from the output dvi file, both "\\" and "\" effect a "\"
in the output for a line argument.
The diff is attached for texinfo.tex. I've added a second macro
\oneargbraceorline, based on the existing \braceorline. This sets the
catcodes for reading the macro argument depending on whether a {
followed the use of the macro name. If it's a line argument, we simply
call \scanctxt, which doesn't set catcode for \ to 0, instead of
calling \macroargctxt. We also \let \ to a new \sometimesescape macro,
which is intended to escape backslashes only (and { and } as well, if
I ever get that to work).
To be honest I don't know why it is working: I don't understand is why
\ is active when reading the argument. Hopefully it is not a fluke.
Index: texinfo.tex
===================================================================
--- texinfo.tex (revision 6352)
+++ texinfo.tex (working copy)
@@ -7429,6 +7429,17 @@
\usembodybackslash
}
+% \sometimesescape - backslash behaviour - expand \\ as \, otherwise
+% keep \ as it is
+{
+\catcode`\@=0 @catcode`@\=@other
+@catcode`@[=1 @catcode`@]=2
+@gdef@sometimesescape#1[%
+% we need noexpand because \ is active
+@if @noexpand \@noexpand #1 @normalbackslash%
+@else @normalbackslash#1%
+@fi]]
+
\def\macroargctxt{% used when scanning invocations
\scanctxt
\catcode`\\=0
@@ -7828,8 +7839,8 @@
\noexpand\scanmacro{\temp}\egroup}%
\or % 1
\expandafter\xdef\csname\the\macname\endcsname{%
- \bgroup\noexpand\macroargctxt
- \noexpand\braceorline
+ \bgroup\noexpand\scanctxt
+ \noexpand\oneargbraceorline
\expandafter\noexpand\csname\the\macname xxx\endcsname}%
\expandafter\xdef\csname\the\macname xxx\endcsname##1{%
\egroup
@@ -7875,7 +7886,24 @@
\expandafter\parsearg
\fi \macnamexxx}
+\def\oneargbraceorline#1{%
+ \let\macnamexxx=#1\futurelet\nchar\oneargbraceorlinexxx}
+% \oneargbraceorlinexxx
+% We need to set \ as active so the @let works
+{\catcode`\@=0 @catcode`@\=\active
+@gdef@oneargbraceorlinexxx{%
+ @ifx@nchar@bgroup
+ @macroargctxt
+ @message{argument in braces,}
+ @else
+ @message{argument on line,}
+ @scanctxt
+ @global@let\=@sometimesescape
+ @expandafter@parsearg
+ @fi @macnamexxx}}
+
+
% @alias.
% We need some trickery to remove the optional spaces around the equal
% sign. Make them active and then expand them all to nothing.
macro-backslash.texi
Description: TeXInfo document
macro-backslash.dvi
Description: TeX dvi file
