On Wed, Feb 05, 2025 at 02:56:29PM +0000, Werner LEMBERG wrote: > > > The reason, AFAICS, is that user-defined macros are not immediately > > expanded while writing an entry to the `.toc` file. Is there a > > reason for it? > > Note that it works just fine if I use `@set` and `@value` for the > purpose shown in the file, and this is probably even a better solution > for the example at hand. > > If you think that the behaviour of `@macro` with respect to ToC > entries is a feature, please document it (and also say that `@set` is > not affected)
It's not a feature so much as a limitation, one which can't be removed. @macro expansion in the @node argument can't work the same in texinfo.tex as it does in texi2any. In texi2any @macro commands are expanded pretty much everywhere, as soon as they are read. This leads to differences for multiline macro expansions, where only the first line from the expansion is used for the argument. In texinfo.tex, the argument to @node (and other line commands) is found from the end of the line without any expansion of any macros contained within. Another reason why using @macro macros in node names is likely not reliable is that node names are written to and read from auxiliary files. This does not work because in technical TeX terms, the implementation of @macro expansion is not "expansion safe". We should document that node names should not contain @macro-defined macros, and texi2any could give a warning if a document does this. @value is implemented in such a way in texinfo.tex to be "expansion safe" in contexts when writing to auxiliary files, so works in this case. @value is much more simple than @macro expansions as these flags do not take arguments. One possibility is to expand to the entire @node line instead, as in: @macro Node {name} @node \name\ @end macro Then invoking this as @Node name should expand safely to: @node name I don't know if that is useful, though as I don't know what you are doing with this.