[texhax] intermediate output

Graham Toal gtoal at gtoal.com
Sun Nov 4 07:25:57 CET 2007

On 11/3/07, Graham Toal <gtoal at gtoal.com> wrote:
> Personally I'ld hack up a quick macro processor in C and do it
> myself[*]
> [*: easy as long as you're not mucking around with catcodes - you only
> need to worry about the characters: '\', '{', '}']

I have to confess it wasn't as easy as I'd imagined, or as quick.

This took about 3 hours of programming :-/ ...

( http://www.gtoal.com/src/newcommand/newcommand.c )

I'm a little out of touch with TeX and especially LaTeX so I may have
made some assumptions that don't hold.  The main assumption I've
made is that \newcommand is always of the forms:



\newcommand{\ve}[1]{\ensuremath{#1_1 ... #1_n}}

but *NOT* of the form:


If that assumption breaks your document, let me know and I'll fix it.
In fact, if this doesn't preprocess your document properly (and there's nothing
sensitive in the document), mail me a copy and I'll tweak the program
until it handles your doc properly.

I've also assumed that that the input is well formed, and if I do detect a
mistake, the program exits with an error code rather than trying to recover.

The code uses static arrays a lot to avoid heap fragmentation/lossage, and
seldom checks the bounds of arrays.  That would be for a v0.2 version if
the program is considered useful.  Otherwise it's just disposable code.

I do hope it's useful to somebody :-)

Why did I do this?  Well, I've never written a macro processor before
and I thought it would be good practice.  It was interesting to see
the pitfalls of expanding macros
which invoke other macros in the expansion.


More information about the texhax mailing list