bug-texinfo
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Texinfo macros and m4


From: Patrice Dumas
Subject: Re: Texinfo macros and m4
Date: Sun, 4 Sep 2011 21:08:40 +0200
User-agent: Mutt/1.4.2.2i

On Sun, Aug 28, 2011 at 09:29:50AM -0400, Eli Zaretskii wrote:
> 
> There's a possibility to run the Texinfo input through "makeinfo -E"
> first, which expands the macros and is supposed to leave everything
> else intact, and texi2dvi even uses it (I think), but somehow this
> isn't enough.  Perhaps nested macros are not expanded? or maybe the
> problem was with conditional macros surrounded by @ifset/@ifclear,
> which "makeinfo -E" didn't process? I don't remember anymore.

In the upcoming implementation, makeinfo -E should do right, as long
as the correct command-line options are given, since it is now
pretty output neutral.

The only places where macros are not expanded by makeinfo -E,
unless I am wrong, is in @everyheading and similar commands.

> As for the makeinfo side, here are the issues I remember:
> 
>  . The quoting issue
> 
>    @macro arguments are separated by commas, but sometimes you need to
>    pass an argument that includes a literal comma.  You are supposed
>    to be able to do that by escaping the comma with a backslash, but
>    this raises problems when a macro calls another macro.  Similar
>    problems happen with using literal backslashes -- the Groff manual
>    suffers from this problem.
> 
>    A related problem is caused by the fact that macro arguments are
>    used by enclosing them between 2 backslashes, as in \arg\.

Nowadays, this issue may be woked around in some cases by using 
@comma{}.  But not when an actual comma is needed.

>  . The whitespace issue
> 
>    there's the issue with the newlines before and after the body.  A
>    typical nuisance is that you cannot easily write a single macro
>    that will work both in @example and in the normal environment,
>    because there are contradicting requirements wrt keeping or
>    removing the newlines.

Currently, the last newline is always removed, if I remember well.

>  . It is impossible to have a macro that defines another macro.
>    Also, you cannot have "@macro" without the matching "@end macro",
>    or vice versa, inside a macro.  This precludes writing dynamic

Well, currently it is possible to have something like

 @macro truc {}
 truc.
 @macro bidule {}
 bidule.
 @end macro
 @end macro

that is, nested macros.  It is expanded as:

 @macro truc {}
 truc.
 @macro bidule {}
 bidule.
 @end macro
 @end macro

 truc.
 @macro bidule {}
 bidule.
 @end macro

 bidule.

Yet, even if that works, if I recall well, it cannot be used 
to really define dynamically macros because arguments are 
expanded after macro body expansion.  So for example (something 
that breaks texi2dvi):

 @macro othermacro
 initial
 @end macro

 @macro redefineothermacro {arg}
 @unmacro othermacro
 @macro othermacro
 different
 @end macro
 \arg\
 @end macro

 @address@hidden

leads to the following, without 'initial' being expanded in
the new macro definition:

 @macro othermacro
 initial
 @end macro

 @macro redefineothermacro {arg}
 @unmacro othermacro
 @macro othermacro
 different
 @end macro
 \arg\
 @end macro

 @unmacro othermacro
 @macro othermacro
 different
 @end macro
 different


Now, it could be possible to have the arguments expanded before
the body, it was that way in texi2html @macro handling.  But for
now in the parser I sticked to what makeinfo did.


Yet, even if the arguments were expanded before the body which
would allow, for example, to have a macro body grows, it is still
very cumbersome to redefine macros.  Here is an example which worked 
with texi2html (and, also if I recall well could be made to 
work with the Parser with a recursive call to the parser and 
the backend that converts a tree to Texinfo):

@macro glossarytext
@table @asis
@end macro

@macro glossary
@glossarytext{}
@end table

@end macro

@macro gentry {id, name, text}
@ifhtml
@ref{\id\,\name\}
@end ifhtml
@ifnothtml
\name\ (@pxref{\id\})
@end ifnothtml
@unmacro expandglossary
@macro expandglossary{glossary}
@unmacro glossarytext
@macro glossarytext
\\glossary\\
@item \name\ @anchor{\id\}
\text\
@end macro
@end macro
@expandglossary address@hidden

@end macro

The @gentry{id1, name1, text1\, arg1 } is used in many cases while
@gentry{id2, name2, text2} is quite specific

@glossary{}


-- 
Pat



reply via email to

[Prev in Thread] Current Thread [Next in Thread]