# alternative macro language for TeX?

5 views

### Andrei Alexandrescu (See Website for Email)

Jun 29, 2004, 8:35:51 PM6/29/04
to
Following Robin Fairbanks' excellent advice, I looked at the perltex package
and it seems to be a promising approach for the intricate text manipulation
that I need to do in a paper; yet for whatever reasons perltex doesn't seem
to cut it, plus I am not a perl pro.

I vaguely recall I've seen some TeX alternative or preprocessor that used ML
as a macro language... does anyone know about it? Or, in general, are there
smarter preprocessors that allow a decent language to be used on top of TeX?

Thanks,

Andrei

### Ari Johnson

Jun 29, 2004, 8:59:07 PM6/29/04
to
Andrei Alexandrescu (See Website for Email) wrote:
> I vaguely recall I've seen some TeX alternative or preprocessor that used ML
> as a macro language... does anyone know about it? Or, in general, are there
> smarter preprocessors that allow a decent language to be used on top of TeX?

You could use XSLT with plain-text output to process XML input into TeX
code. But whether or not the preprocessor is smart doesn't mean the
idea of using it for this necessarily is. You really want to use ML
over Perl? I'm no fan of Perl, but give me Lisp or Ruby - not ML. :)

### Brian Blackmore

Jun 30, 2004, 1:54:13 AM6/30/04
to

If you need that much preprocessing, you need to simply generate the
TeX document from your language of choice. And since you're
probably in a hurry, as many people seem to be, why bother wasting
any time? Just write your code in whatever language suits you, dump
the TeX to standard out or a file, and compile away.

Incidentally, what exactly are you doing that's so complicated?

--
Brian Blackmore
blb8 at po dot cwru dot edu

### Achim Blumensath

Jun 30, 2004, 3:23:22 AM6/30/04
to
Andrei Alexandrescu wrote:
> I vaguely recall I've seen some TeX alternative or preprocessor that
> used ML as a macro language... does anyone know about it?

That would be ant which can be found on my homepage:

Achim
--
________________________________________________________________________
| \_____/ |
Achim Blumensath \O/ \___/\ |
LaBRI / Bordeaux =o= \ /\ \|
www-mgi.informatik.rwth-aachen.de/~blume /"\ o----|
____________________________________________________________________\___|

### Andrei Alexandrescu (See Website for Email)

Jun 30, 2004, 3:46:11 AM6/30/04
to
"Brian Blackmore" <bl...@po.cwru.edu> wrote in message
news:cbtki5$o81$1...@gnus01.u.washington.edu...

I am doing research in programming languages, which routinely uses long
inference rules, judgments, and so on. The package mathpartir (which I am
happily using) is only a pale start in the direction of helping with type
inference rules. Formatting is not the major problem; being able to
establish proper abstractions so as to raise the level of one's discourse is
essential. It is also crucial to be able to write things once and only once,
and that means all kinds of weird stuff such as macros that generate other
macros that in turn use string manipulation etc. My first version of a paper
was "brute force" TeX (5 lemmas, 3 theorems, 5 figures...) and had about 20
typos due to redundancy.

Working comfortably with abstractions via macros and string manipulation
would be great, and so far I have had only limited success. Macros are just
a very primitive abstraction mechanism, hard to scale and frail, and it
seems like I ran into very subtle TeX issues and limitations in a very short
time, sigh. On the other hand, as others pointed out... for other kinds of
documents TeX does everything no sweat.

Andrei

### Andrei Alexandrescu (See Website for Email)

Jun 30, 2004, 3:47:32 AM6/30/04
to
"Achim Blumensath" <bl...@labri.fr> wrote in message
news:cbtppa$psk$1...@news.u-bordeaux.fr...

> Andrei Alexandrescu wrote:
> > I vaguely recall I've seen some TeX alternative or preprocessor that
> > used ML as a macro language... does anyone know about it?
>
> That would be ant which can be found on my homepage:
>
> www-mgi.informatik.rwth-aachen.de/~blume/pub/ant-current.tar.bz2

Thanks very much, that was it! You may want to figure out ways of making ant
appearing upped in google when one searches for "latex ml" or "latex
advanced macros" or "latex preprocessor" or "latex macro alternative" etc.
:o)

Andrei

### Brian Blackmore

Jun 30, 2004, 12:53:49 PM6/30/04
to
"Andrei Alexandrescu" <SeeWebsit...@moderncppdesign.com> wrote:
> "Brian Blackmore" <bl...@po.cwru.edu> wrote in message
> >
> > Incidentally, what exactly are you doing that's so complicated?

> I am doing research in programming languages, which routinely uses long
> inference rules, judgments, and so on. The package mathpartir (which I am
> happily using) is only a pale start in the direction of helping with type
> inference rules. Formatting is not the major problem; being able to
> establish proper abstractions so as to raise the level of one's discourse is
> essential. It is also crucial to be able to write things once and only once,
> and that means all kinds of weird stuff such as macros that generate other
> macros that in turn use string manipulation etc. My first version of a paper
> was "brute force" TeX (5 lemmas, 3 theorems, 5 figures...) and had about 20
> typos due to redundancy.

> Working comfortably with abstractions via macros and string manipulation
> would be great, and so far I have had only limited success. Macros are just
> a very primitive abstraction mechanism, hard to scale and frail, and it
> seems like I ran into very subtle TeX issues and limitations in a very short
> time, sigh. On the other hand, as others pointed out... for other kinds of
> documents TeX does everything no sweat.

Unfortunately, this evokes many images and possibilities, so it's the
type of thing that I could imagine being rather easy or rather hard,
depending on whether or not one is doing things in the right way, and
depending on the specifics of the situation. This goes back to the
ideas that were discussed in our recent thread (recursive macros),
namely that the approach is wrong so the task seems impossible. It's
like climbing a mountain: If you go the wrong way, you're going to run
into the overhang.

For instance, are things being complicated by looking at this problem as
string replacement? For example:
"I want to type Hello world' and then take that string,
replace Hello' with Goodbye', and type that."
"Yes, so you \def\toworld#1{#1 world}\toworld{Hello}
\toworld{Goodbye}.
"That is, don't think of replacing strings, think of making
them parameters or variables in the first place."

As to redundancy issues, I absolutely agree. You have one copy and the
hope is that there won't be any typos later in the document. But there
are many different things that can be done in terms of keeping the same
entity around long enough to influence the document as much as is
required.

Moreover, there are even more complicated constructions. For instance,
you have notation that generates graphs, and you have metapost coded for
that notion; so you code TeX macros that pass that notation on directly,
perhaps changing the entered appearance once or twice for in-document
display purposes, labeling, etc., but are still able to get the exact
same object in notation to metapost. Thus, you autogenerate everything
based on a single command in your TeX document, there is no redundancy,
and you don't get a picture of an apple when you expected an orange.

And there's more, but let's suppose that there's a simple answer and go
from there. No need to complicate matters unnecessarily.

### Andrei Alexandrescu (See Website for Email)

Jul 1, 2004, 7:56:22 PM7/1/04
to
"Brian Blackmore" <bl...@po.cwru.edu> wrote in message
news:cbur6t$a2n$1...@gnus01.u.washington.edu...

I took a couple of days to answer to this insightful post.

First off, thank you Brian for a very deep and delicate answer. I can tell
not only that you know what you're talking about, but also you took the time
to talk nicely to an obvious (and obviously annoyed) beginner. :o)

On to the actual content; I totally agree with what you say above, with the
amendment that there are two sides of the coins. The other side is "...it's
like climbing a particular mountain. The only path that could take you up is
a trail that has a huge pile of dung all over it". :oD

> For instance, are things being complicated by looking at this problem as
> string replacement? For example:
> "I want to type Hello world' and then take that string,
> replace Hello' with Goodbye', and type that."
> "Yes, so you \def\toworld#1{#1 world}\toworld{Hello}
> \toworld{Goodbye}.
> "That is, don't think of replacing strings, think of making
> them parameters or variables in the first place."

Yes, that's what I am doing now. The problem, however, is that there is no
solid notion of variable arguments. Say I need to define some rules that
have a variable number of antecedents, one consequent, and a lot of other
stuff. The way I do now is to define \MakeTypingRule, \MakeTypingRuleII,
\MakeTypingRuleIII and so on, which use each other. They also define the
antecedents \AnteI, \AnteII, all those good things. (Did I mention I find it
stupid that one can't have but alphabetical chars in a macro name? Thank God
for the Roman numerals!)

I don't know about you, but I found no obviously better way to do that, I
saw nothing better in equivalent TeX code written by connoisseurs, and I
find that awkward. I get excited whenever I learn a new language (I even had
fun learning Javascript!) but with TeX it is a continuous disappointment. At
first, I thought, wow, a full-blown Turing complete language for
typesetting! And now I'm like, every piece of code that does something
interesting looks like transmission line noise...

> As to redundancy issues, I absolutely agree. You have one copy and the
> hope is that there won't be any typos later in the document. But there
> are many different things that can be done in terms of keeping the same
> entity around long enough to influence the document as much as is
> required.
>
> Moreover, there are even more complicated constructions. For instance,
> you have notation that generates graphs, and you have metapost coded for
> that notion; so you code TeX macros that pass that notation on directly,
> perhaps changing the entered appearance once or twice for in-document
> display purposes, labeling, etc., but are still able to get the exact
> same object in notation to metapost. Thus, you autogenerate everything
> based on a single command in your TeX document, there is no redundancy,
> and you don't get a picture of an apple when you expected an orange.
>
> And there's more, but let's suppose that there's a simple answer and go
> from there. No need to complicate matters unnecessarily.

Thanks a lot for the tips.

Andrei

### Oleg Paraschenko

Jul 2, 2004, 6:36:52 AM7/2/04
to
Hello Andrei,

"Andrei Alexandrescu $$See Website for Email$$"
<SeeWebsit...@moderncppdesign.com> wrote in message
news:<2keg78F...@uni-berlin.de>...

I see next approaches to have a decent language for TeX:

* some TeX wrapper or extension;
* an external language, and
* a language on top of TeX macros.

You mentioned perltex, there is also pytex and maybe some other
extensions. Although they can help a lot, I am prejudiced against
this approach.

External languages are good; personally I prefer XSLT with
TeXML. Unfortunately, I think that they are good only for data
transformation but not for writing LaTeX class/style files.
In the latter case actual definitions may depend on a document
preamble, so you anyway have to write TeX macros.

Now I'm thinking about the third approach, a language on top
of TeX macros. Having "car", "cdr", "cons" and "apply", it is not
a problem to do token list processing as in traditional languages.
The only obstacle is that I'm not sure that "apply" (execute
a macro and get resulted tokens) is possible. I'm asking about it

Regards, Oleg

### Brian Blackmore

Jul 4, 2004, 3:58:11 AM7/4/04
to
"Andrei Alexandrescu" <SeeWebsit...@moderncppdesign.com> wrote:
> "Brian Blackmore" <bl...@po.cwru.edu> wrote in message
> news:cbur6t$a2n$1...@gnus01.u.washington.edu...
> > "Andrei Alexandrescu" <SeeWebsit...@moderncppdesign.com> wrote:
> > > "Brian Blackmore" <bl...@po.cwru.edu> wrote in message
> > > >
> > > > Incidentally, what exactly are you doing that's so complicated?
> >
> > > I am doing research in programming languages, which routinely uses long
> > > inference rules, judgments, and so on.

> > For instance, are things being complicated by looking at this problem as

> > string replacement? For example:
> > "I want to type Hello world' and then take that string,
> > replace Hello' with `Goodbye', and type that."
> > "Yes, so you \def\toworld#1{#1 world}\toworld{Hello}
> > \toworld{Goodbye}.
> > "That is, don't think of replacing strings, think of making
> > them parameters or variables in the first place."

> Yes, that's what I am doing now. The problem, however, is that there is no
> solid notion of variable arguments.

That's something you, the author, need to define. It's hard to
design the code without the underlying syntax that is required, and
the appropriate algorithm for turning that syntax into actual
output.

> Say I need to define some rules that
> have a variable number of antecedents, one consequent,

Sounds like the macros I wrote years ago for someone who was doing

> and a lot of other stuff.

Such as?

> (Did I mention I find it
> stupid that one can't have but alphabetical chars in a macro name? Thank God
> for the Roman numerals!)

Well, that's not entirely true, but yeah.

> I don't know about you, but I found no obviously better way to do that, I
> saw nothing better in equivalent TeX code written by connoisseurs, and I
> find that awkward. I get excited whenever I learn a new language (I even had
> fun learning Javascript!) but with TeX it is a continuous disappointment. At
> first, I thought, wow, a full-blown Turing complete language for
> typesetting! And now I'm like, every piece of code that does something
> interesting looks like transmission line noise...

Yeah, this is common. I still think most of it is that the TeX
world is all about LaTeX, LaTeX, LaTeX these days, so if there's no
package for it, you're screwed. As there are no catalogues of
examples of these types of things, the programmer is a bit lost. In
general, you need enough knowledge of the system to go through
various chunks of code, such as latex, plain tex, eplain, and
various other packages, to see how things were done.

I think in this case you're not getting examples because we don't
know what you want. We need:

1. What is the input syntax that is desired?
2. What is the output associated with that input?

In other words, describe, fully, what you want to type and what you
should be seeing. We will then suggest hopefully appropriate
alternatives based on syntax difficulties (not because it's
impossible, but to make things easy on the coding side), and go from
there.

Perhaps the sample ADTs above provide an idea that it Can be done.

### Andrei Alexandrescu (See Website for Email)

Jul 6, 2004, 6:47:24 PM7/6/04
to
(Continuing a long discussion... I allowed myself to quote it in full.

"Brian Blackmore" <bl...@po.cwru.edu> wrote in message

news:cc8dai$j89$1...@gnus01.u.washington.edu...

Yes, that looks very very close to what I need.

Yes, I became convinced that it can be done. Also, the keyval package gives
a lot of hope. So let me spell what I believe I need. I need a solid
variable arguments package with the following features:

* One should be able to define macros with an unbounded number of arguments.
Inside the macro, argument count can be referred to as \argcount and each
argument can be referred to as \argvalue{n}, where n is a number.

* The format of the parens () vs. {} vs. [] doesn't matter. One should,
however, be able to invoke the macro without any paren (see below). Also,
parens must be matched properly, e.g. "\somemacro(a + (b + c), d)" is an
invocation with two arguments, not one.

* Arguments should be separated by, say commas, but the caller should be
able to pass commas in by bracing them, e.g. \somemacro(a, b, c {,} d) and
\somemacro(a, b, {c , d}) would invoke \somemacro with three arguments.

* Default arguments should be supported for any position. The default
argument kicks in in one of two cases: (1) it is an unspecified trailing
argument, like \somemacro(a, b) assuming \somemacro has a default argument
in position 3, or (2) when the invoker passes in a special symbol, say,
\somemacro(a, !, b) would pass the default argument in position 2. Invoking
\somemacro(a, {!}, b) would pass the actual exclamation mark. If the macro
is invoked without any arguments, all arguments have their default values.
The default values should just fill the \argvalue{n} numbers.

* The framework should make writing such macros is as easy as it gets.
Ideally it would encapsulate a lot of complexity and provide a simple recipe
for writing such macros.

Well, if anyone is up for the challenge, or knows of a package that does
that, let me know!

Andrei

### Jonathan Fine

Jul 8, 2004, 12:31:56 PM7/8/04
to
"Andrei Alexandrescu (See Website for Email)"
<SeeWebsit...@moderncppdesign.com> wrote in message >
<snip>

Well, I suggest using a modern object-oriented language as a front end.

And TeX (plain TeX or even plainer) as the back end.

My preference is to use Python as the front end.

Some years ago I developed Active TeX, which has a novel macro
programming environment.

This was intended to provide an easier framework for writing macros.

I discontinued work on it after a while, in favour of Pytex.

I've posted this to comp.lang.python as well as the original
comp.text.tex.

Jonathan

### Grant Edwards

Jul 8, 2004, 3:57:12 PM7/8/04
to
On 2004-07-08, Jonathan Fine <J.F...@open.ac.uk> wrote:

> My preference is to use Python as the front end.
>
> See http://www.pytex.org

It sounds very interesting, and I just read what I could find
on that site. But, I still don't have any real idea what PyTeX
is for. Is it for documenting source code? Writing novels?
Typesetting a resume? I was also unable to find any examples
of either input or output.

Are there any concrete examples of how to use PyTeX?

--
Grant Edwards grante Yow! Civilization is
at fun! Anyway, it keeps
visi.com me busy!!

### Peter Wyzlic

Jul 8, 2004, 7:03:03 PM7/8/04
to
Grant Edwards wrote:
> On 2004-07-08, Jonathan Fine <J.F...@open.ac.uk> wrote:
>
>>My preference is to use Python as the front end.
>>
>>See http://www.pytex.org

>
> It sounds very interesting, and I just read what I could find
> on that site. But, I still don't have any real idea what PyTeX
> is for. Is it for documenting source code? Writing novels?
> Typesetting a resume? I was also unable to find any examples
> of either input or output.
>
> Are there any concrete examples of how to use PyTeX?

The sourceforge project page says "status: planning" and a bit below
"This Project Has Not Released Any Files". So it seems to be more an
idea than a stable project for production.

Peter