I'm trying to write an expanded macro to a file without the expansion eating the space after it.
I could replace the {}
empty group with an explicit \space
, but I want this to be fairly robust. Is this possible to do?
I'm guessing since TeX never gets to the layout portion of the process, it doesn't know what to do with the unexpandable {}
tokens, which is why they show up during the \write
?
Example
% tex test.tex
\def \test {Hello}
\openout 0 hello.txt
\write 0 {\test{} World}
\end
Contents of hello.txt
Hello{} World
Expected
Hello World
Background
In broad strokes, this project is trying to retrofit a sort of note/cross-reference system to a large document with many macros and edited by many people.
...
\def\proj{Foobar}
\def\rev{1.0}
\def\revstr{\proj{} v\rev}
\def\complicated{...} % essentially a bunch of ifs and concats
... % A bunch of macros scattered throughout
Body of document contains macros like \proj{} and \revstr.
The definitions of these macros are tweaked and modified.
... % A bunch of text with \notes scattered throughout,
% also tweaked/modified, added/removed
\note{Used for callouts to \proj{} and whatever else}
...
The notes are currently typeset with the document, and the task is to also put them into a file for processing by an external program. For the vast majority of cases, callouts just have text and macros: no formatting or anything that couldn't be represented in ASCII.
Manually going through all the macros to replace {}
with \space
is somewhat out of the question, due to the volume and going against the established workflow.
The fallback is just post-process the file once TeX is done with it. Seems like the ham-fisted approach though, since TeX has all the information necessary to boil down the text.
Maybe there is a way to pretend layout a page, but then strip the content out of the boxes and put it into a file?
\space
?\space
, but then\test
changed to include a macro expansion itself, like\greeting{} friend
. The same problem would come up again and that would need to be replaced with\space
too. TeX seems happy with the\test{}
convention in other places, would be nice if it could work in this scenario as well. I'm looking to use some macros like this in multiple places in the document (in addition to writing to file).\space
is the choice for the business. However, it's hard to tell what your real aim is. Can you please be a bit more explicit about your project? Small “Hello world” examples are good, but not for describing complex tasks.