Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Functional TeX implementations

11 views
Skip to first unread message

Matt Timmermans

unread,
Feb 10, 2002, 2:36:47 AM2/10/02
to
Has anyone re-implemented TeX in a functional language? Preferably SML?


Graham Douglas

unread,
Feb 10, 2002, 6:17:09 AM2/10/02
to

Matt Timmermans <ma...@timmermans.nospam-remove.org> wrote in message
news:oop98.39582$l37.4...@news20.bellglobal.com...

> Has anyone re-implemented TeX in a functional language? Preferably
SML?
>
>
I once saw this link posted on another newsgroup.

It's a paper entitled

"A Functional Description of TeX's Formula Layout"

Uses SML.

http://rw4.cs.uni-sb.de/~heckmann/abstracts/neuform-review.html

Regards

Graham


Sebastian Rahtz

unread,
Feb 10, 2002, 11:23:12 AM2/10/02
to
"Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:

> Has anyone re-implemented TeX in a functional language? Preferably SML?

In a word, "no". The only working reimplementation I have ever heard
of is in Java (NTS).

Apart from buzzword points, what would be the point of TeX in SML?

--
Sebastian Rahtz OUCS Information Manager
13 Banbury Road, Oxford OX2 6NN. Phone +44 1865 283431

Robin Fairbairns

unread,
Feb 10, 2002, 12:38:54 PM2/10/02
to
Sebastian Rahtz <sebasti...@computing-services.oxford.ac.uk> wrote:
>"Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:
>
>> Has anyone re-implemented TeX in a functional language? Preferably SML?
>
>In a word, "no". The only working reimplementation I have ever heard
>of is in Java (NTS).

i suspect he means "version" (as in web2c) rather than what you or i
might think of as reimplemententation.

something like reimplementing tth in objective caml (was it?).

>Apart from buzzword points, what would be the point of TeX in SML?

if i'm right, it might make a reasonable undergraduate project: i've
never suggested such a thing myself for any of our kiddies, but i can
imagine the sort of mind that would think it an appropriate torture.
--
Robin Fairbairns, Cambridge -- rf10 at cam dot ac dot uk

Matt Timmermans

unread,
Feb 10, 2002, 1:08:57 PM2/10/02
to

"Graham Douglas" <g.do...@readytext.co.uk> wrote in message
news:5Ks98.5631$HC4.55465@NewsReader...

> I once saw this link posted on another newsgroup.
>
> It's a paper entitled
>
> "A Functional Description of TeX's Formula Layout"
>
> Uses SML.
>
> http://rw4.cs.uni-sb.de/~heckmann/abstracts/neuform-review.html


Thanks, Graham. I've seen that, but it still leaves a lot of work to do! I
was hoping that, since the papers is a bit old, someone might have finished
the job in the meantime.


Matt Timmermans

unread,
Feb 10, 2002, 1:32:22 PM2/10/02
to

"Sebastian Rahtz" <sebasti...@computing-services.oxford.ac.uk> wrote in
message news:87r8nt2...@spqr.oucs.ox.ac.uk...

> "Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:
>
> > Has anyone re-implemented TeX in a functional language? Preferably SML?
>
> In a word, "no". The only working reimplementation I have ever heard
> of is in Java (NTS).

Thanks. I'll have a look at that. If I have to do it myself, it'll
probably be easier to work from than the original TeX sources.

> Apart from buzzword points, what would be the point of TeX in SML?

That's a bit complicated -- I'm thinking of writing a real-time WSIWYG TeX
editor that could be extended to other layout systems as well, and I don't
want to spend years on it. I'm intending to do a magic implementation that
works mostly like this:

1) get the typesetter written as a function in SML -- this is a
straitforward batch-mode program just like TeX that reads the input and
produces DVI.

2) From the typesetting function, _automatically_ generate a function that
can efficiently calculate the _difference_ in the typesetting output, given
some state saved from a previous run and a record of changes to the input.

3) Use the delta function from (2) to dynamically update the display as the
input is edited.

Obviously, step (2) can be hard -- it requires an implementation of the
typesetter's programming language itself that can keep track of dependencies
between the input and intermediate results. It will be *much* easier to do
if that if the programming language is simple and functional. SML is a real
language with a nice, small core, and several implementations exist that
translate SML into even simpler functional intermediate languages that fit
the bill nicely.

I figure that this is not only is the fastest way to write such an editor,
but also the most reliable -- the typesetting function is quite complex, and
trying to make it dynamic by hand would be quite a daunting task.

Matt Timmermans

unread,
Feb 10, 2002, 3:02:17 PM2/10/02
to

"Robin Fairbairns" <r...@pallas.cl.cam.ac.uk> wrote in message
news:a46b7e$7c2$1...@pegasus.csx.cam.ac.uk...

> i suspect he means "version" (as in web2c) rather than what you or i
> might think of as reimplemententation.

"version" might suffice, but I can't help but think that an automated
translation from WEB to a functional language wouldbe exceedingly ugly.
Reimplementation would be better, since (see previous response) I _am_ going
to need to modify the typesetting function to some extent, because I want it
to be able to render the caret/cursor and selection highlighting as well
inserting navigational aids into the typeset output.

> if i'm right, it might make a reasonable undergraduate project: i've
> never suggested such a thing myself for any of our kiddies, but i can
> imagine the sort of mind that would think it an appropriate torture.

That would be cruel. This is entirely self-inflicted, I'm afraid -- which
is why I'm looking for ways to minimize the tortuous part.

William F. Hammond

unread,
Feb 10, 2002, 3:10:42 PM2/10/02
to
"Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:

> "Sebastian Rahtz" <sebasti...@computing-services.oxford.ac.uk> wrote in
> message news:87r8nt2...@spqr.oucs.ox.ac.uk...
> > "Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:
> >
> > > Has anyone re-implemented TeX in a functional language? Preferably SML?
> >
> > In a word, "no". The only working reimplementation I have ever heard
> > of is in Java (NTS).

Perhaps, re-phrasing, one could say "yes" for functional language
because of NTS, and "no" for SML.

What characteristics of SML would make it better in your view than
other functional languages, especially (1) java, (2) object-oriented
Perl, or (3) Python? What does the "small core" of SML have to do
with it: are you envisioning some type of code translation?

> That's a bit complicated -- I'm thinking of writing a real-time WSIWYG TeX
> editor that could be extended to other layout systems as well, and I don't
> want to spend years on it. I'm intending to do a magic implementation that
> works mostly like this:

Isn't WYSIWYG a mirage except for very easy layout tasks?

-- Bill

Matt Timmermans

unread,
Feb 10, 2002, 4:19:22 PM2/10/02
to

"William F. Hammond" <ham...@pluto.math.albany.edu> wrote in message
news:i7pu3dk...@pluto.math.albany.edu...

> Perhaps, re-phrasing, one could say "yes" for functional language
> because of NTS, and "no" for SML.

"functional" in this context (I gather you're from comp.text.tex, because
comp.lang.functional is all about this) means "side-effect-free", not
"robust".

> What characteristics of SML would make it better in your view than
> other functional languages, especially (1) java, (2) object-oriented
> Perl, or (3) Python? What does the "small core" of SML have to do
> with it: are you envisioning some type of code translation?

Not translation, but I'll be automatically deriving new code with enhanced
functionality from old code, i.e., creating differential-TeX from batch-TeX.

> Isn't WYSIWYG a mirage except for very easy layout tasks?

The point of this exercise is that it doesn't have to be.

Bill enry Gates

unread,
Feb 10, 2002, 5:35:29 PM2/10/02
to
are you aware that atleast two free wysiwyg editors for latex which do
realtime compilation in the background?

--
-kbg

logfilter v0.43 at
http://fermi.ruc.dk/~kbilsted/lf/

Matt Timmermans

unread,
Feb 10, 2002, 10:17:04 PM2/10/02
to

"Bill enry Gates" <bill...@microsorft.com> wrote in message
news:Xns91B1F03D8137Bbi...@193.88.15.201...

> are you aware that atleast two free wysiwyg editors for latex which do
> realtime compilation in the background?

I know about LyX. What's the other one?

Jesper Harder

unread,
Feb 10, 2002, 11:34:01 PM2/10/02
to
"Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:

> That's a bit complicated -- I'm thinking of writing a real-time WSIWYG
> TeX editor that could be extended to other layout systems as well, and
> I don't want to spend years on it. I'm intending to do a magic
> implementation that works mostly like this:
>
> 1) get the typesetter written as a function in SML -- this is a
> straitforward batch-mode program just like TeX that reads the input
> and produces DVI.
>
> 2) From the typesetting function, _automatically_ generate a function
> that can efficiently calculate the _difference_ in the typesetting
> output, given some state saved from a previous run and a record of
> changes to the input.
>
> 3) Use the delta function from (2) to dynamically update the display
> as the input is edited.

You might want to look at a paper by Jonathan Fine in the EuroTeX 2001
proceedings about using a "TeX daemon" for instant preview:
<http://www.ntg.nl/eurotex/proceedings.html>


Jesper Harder

unread,
Feb 11, 2002, 12:23:11 AM2/11/02
to
"Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:

> "Bill enry Gates" <bill...@microsorft.com> wrote:
>
>> are you aware that atleast two free wysiwyg editors for latex which
>> do realtime compilation in the background?
>
> I know about LyX. What's the other one?

TeXmacs, <http://www.texmacs.org/>.

Peter G. Hancock

unread,
Feb 11, 2002, 3:41:07 AM2/11/02
to

<URL http://www.texmacs.org>, perhaps?

Peter Hancock

Sven Utcke

unread,
Feb 11, 2002, 10:11:38 AM2/11/02
to
"Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:

> That's a bit complicated -- I'm thinking of writing a real-time WSIWYG TeX
> editor that could be extended to other layout systems as well, and I don't
> want to spend years on it. I'm intending to do a magic implementation that
> works mostly like this:
>
> 1) get the typesetter written as a function in SML -- this is a
> straitforward batch-mode program just like TeX that reads the input and
> produces DVI.
>
> 2) From the typesetting function, _automatically_ generate a function that
> can efficiently calculate the _difference_ in the typesetting output, given
> some state saved from a previous run and a record of changes to the input.
>
> 3) Use the delta function from (2) to dynamically update the display as the
> input is edited.

This sounds somewhat similar to preview-latex, available for Emacs
21.x. Maybe you should look there?

Sven
--
_ __ The Cognitive Systems Group
| |/ /___ __ _ ___ University of Hamburg
| ' </ _ \/ _` (_-< phone: +49 (0)40 42883-2576 Vogt-Koelln-Strasse 30
|_|\_\___/\__, /__/ fax : +49 (0)40 42883-2572 D-22527 Hamburg
|___/ http://kogs-www.informatik.uni-hamburg.de/~utcke/home.html

Sven Utcke

unread,
Feb 11, 2002, 10:13:18 AM2/11/02
to
Jesper Harder <har...@myrealbox.com> writes:

Nothing to do with TeX (nor Emacs), I'm afraid. It's simply a
singularly badly choosen name...

David Kastrup

unread,
Feb 11, 2002, 10:50:02 AM2/11/02
to
Sven Utcke <utcke...@informatik.uni-hamburg.de> writes:

> "Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:
>
> > That's a bit complicated -- I'm thinking of writing a real-time WSIWYG TeX
> > editor that could be extended to other layout systems as well, and I don't
> > want to spend years on it. I'm intending to do a magic implementation that
> > works mostly like this:
> >
> > 1) get the typesetter written as a function in SML -- this is a
> > straitforward batch-mode program just like TeX that reads the input and
> > produces DVI.
> >
> > 2) From the typesetting function, _automatically_ generate a function that
> > can efficiently calculate the _difference_ in the typesetting output, given
> > some state saved from a previous run and a record of changes to the input.
> >
> > 3) Use the delta function from (2) to dynamically update the display as the
> > input is edited.
>
> This sounds somewhat similar to preview-latex, available for Emacs
> 21.x. Maybe you should look there?

As the preview-latex project leader, I tend to disagree. The update
of preview-latex occurs on request, not automatically. Also, you
cannot edit around in the previewed entities while they are "closed";
you have to switch them into "open" form.

OTOH, it works, provides good WYSIWYG for the purpose of authoring
papers (I find it a big relief to have most formulas in the buffer in
WYSIWYG form, as it makes it easier to concentrate on developing the
math) and can be combined with x-symbol that offers a different angle
on WYSIWYG principles, making formulas more readable in their input
form.

One "instant redisplay" project is Jonathan Fine's ActiveTeX, which
however requires the use of a separate preview window and a version of
TeX compiled with IPC enabled.

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
Email: David....@t-online.de

Matej Cepl

unread,
Feb 11, 2002, 10:26:08 AM2/11/02
to

LyX DOES NOT make realtime compilation in the background and I
believe, that it is The Right Thing(TM), that it doesn't. LyX is
honest WYSIWYM editor for the structured authoring which uses
LaTeX as its backend. I do not see any reason, why I need
realtime compilation.

Matej

--
Matej Cepl, cepl...@yahoo.com
138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488

Sometimes it is said that man cannot be trusted with the
government of himself. Can he, then, be trusted with the
government of others?
-- Thomas Jefferson, in his 1801 inaugural address

Giuseppe Bilotta

unread,
Feb 11, 2002, 11:16:20 AM2/11/02
to
Jesper Harder wrote:
>
> You might want to look at a paper by Jonathan Fine in the EuroTeX 2001
> proceedings about using a "TeX daemon" for instant preview:
> <http://www.ntg.nl/eurotex/proceedings.html>

Another good starting point is TeXlite from Igor Strokov (sorry, can't
remember URLs. Google should give hits, IIRC)

--
Giuseppe "Oblomov" Bilotta

Axiom I of the Giuseppe Bilotta
theory of IT:
Anything is better than MS

Giuseppe Bilotta

unread,
Feb 11, 2002, 11:16:16 AM2/11/02
to
Matt Timmermans wrote:
> "version" might suffice, but I can't help but think that an automated
> translation from WEB to a functional language wouldbe exceedingly ugly.
> Reimplementation would be better, since (see previous response) I _am_ going
> to need to modify the typesetting function to some extent, because I want it
> to be able to render the caret/cursor and selection highlighting as well
> inserting navigational aids into the typeset output.

Oh my, another one. Working on WYSIWYG TeX? How many of us are?

William F. Hammond

unread,
Feb 11, 2002, 3:59:44 PM2/11/02
to
Giuseppe Bilotta <obl...@freemail.it> writes:

> Oh my, another one. Working on WYSIWYG TeX? How many of us are?

Is that really what it's about? (I'm confused.)

However, _if_ WYSIWYG TeX is a good idea, WYSIWYG xml under the
_right_ document type _could_ _be_ an even better idea.

(But someone with modest keyboard skills will be slowed.)

The point is that the right xml document type gives one a firm
footing for structured processing to many output formats such
as LaTeX and HTML.

-- Bill

Giuseppe Bilotta

unread,
Feb 11, 2002, 4:55:17 PM2/11/02
to
William F. Hammond wrote:
> Giuseppe Bilotta <obl...@freemail.it> writes:
>
> > Oh my, another one. Working on WYSIWYG TeX? How many of us are?
>
> Is that really what it's about? (I'm confused.)
>
> However, _if_ WYSIWYG TeX is a good idea, WYSIWYG xml under the
> _right_ document type _could_ _be_ an even better idea.

My plan is to separate the TeX typesetting engine from the TeX parser
and the DVI producer. Once this is done, you can plug whatever input
in and get whatever output out. See the TeXlib project on SourceForge.

Graham Douglas

unread,
Feb 11, 2002, 5:45:36 PM2/11/02
to

Giuseppe Bilotta <obl...@freemail.it> wrote in message
news:MPG.16d25ca1b...@powernews.libero.it...

Hi Giuseppe

As an aside, I don't know if you've been
keeping an eye on Waldek Hebisch's
site but he's just released a newer version
of "TeX in C":

http://www.math.uni.wroc.pl/~hebisch/tex/texinc-0.1.tar.gz

I've compiled it under <close your eyes Giuseppe>
Win32 (Visual C++) and am having "fun" stepping
through the C code. Full respect to Waldek in
creating pretty readable C from the WEB/Pascal morass.

Has anyone ever written a paper/article explaining,
in step-by-step *detail*, how to do the
WEB --> C conversion. It seems to be a pretty
complex/messy process. Interesting reading
though.


Regards

Graham

Matt Timmermans

unread,
Feb 12, 2002, 12:02:57 AM2/12/02
to
I must say that, even though there don't appear to be any implementations of
TeX in side-effect-free languages floating around, that you comp.text.tex
guys appear to be the most generally helpful bunch of netizens I've seen in
usenet.

Thanks much.

Achim Blumensath

unread,
Feb 12, 2002, 3:29:08 AM2/12/02
to
Matt Timmermans wrote:
>Has anyone re-implemented TeX in a functional language? Preferably SML?

I'n not quite finished yet (but mostly) with translating ant to OCaml.
It's not 100% TeX compatible but if you are interested I could send you
the sources.

Achim
--
________________________________________________________________________
| \_____/ |
Achim Blumensath \O/ \___/\ |
Mathematische Grundlagen der Informatik =o= \ /\ \|
www-mgi.informatik.rwth-aachen.de/~blume /"\ o----|
____________________________________________________________________\___|

Giuseppe Bilotta

unread,
Feb 12, 2002, 8:27:02 AM2/12/02
to
Graham Douglas wrote:
>
> Hi Giuseppe
>
> As an aside, I don't know if you've been
> keeping an eye on Waldek Hebisch's
> site but he's just released a newer version
> of "TeX in C":
>
> http://www.math.uni.wroc.pl/~hebisch/tex/texinc-0.1.tar.gz

Hey, I didn't know about this! Thank you for the reference!

Graham Douglas

unread,
Feb 12, 2002, 8:59:08 AM2/12/02
to

Giuseppe Bilotta <obl...@freemail.it> wrote in message
news:MPG.16d327f39...@powernews.libero.it...

[snip]

>
> > http://www.math.uni.wroc.pl/~hebisch/tex/texinc-0.1.tar.gz
>
> Hey, I didn't know about this! Thank you for the reference!
>

[snip]

Hi Giuseppe

You're welcome -- Waldek Hebisch
is doing some very interesting work and
should be supported/encouraged
in his task -- I don't know if he's part
of a team or doing this on his own?

No doubt there is some
overlap and/or scope for collaboration
with your libTeX project?
(or is it TeXlib, sorry).

Three cheers for Waldek! :-) --
and all those intrepid souls able
to coax readable C from WEB/Pascal
-- total admiration!

Regards

Graham

André Pönitz

unread,
Feb 12, 2002, 11:16:09 AM2/12/02
to
In comp.text.tex Giuseppe Bilotta <obl...@freemail.it> wrote:
>> http://www.math.uni.wroc.pl/~hebisch/tex/texinc-0.1.tar.gz
>
> Hey, I didn't know about this! Thank you for the reference!

Since we are at it: has anybody seen some kind of TeX parser, preferably
written in C/C++ where one could hook in after the 'generation' of a token
and/or when a macro is about to be expanded?

Sort of a --very-verbose option to TeX?
Can I abuse TeX itself for that purpose?

Andre'

--
André Pönitz .............................................. poe...@gmx.de

Jules Bean

unread,
Feb 12, 2002, 11:29:15 AM2/12/02
to
Bill enry Gates wrote:
> are you aware that atleast two free wysiwyg editors for latex which do
> realtime compilation in the background?

As far as I am aware, there are exactly none.

Care to enlighten me?

Jules


Oliver Bandel

unread,
Feb 12, 2002, 12:08:23 PM2/12/02
to

In comp.text.tex Matt Timmermans <ma...@timmermans.nospam-remove.org> wrote:

> "Sebastian Rahtz" <sebasti...@computing-services.oxford.ac.uk> wrote in
> message news:87r8nt2...@spqr.oucs.ox.ac.uk...
>> "Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:
>>
>> > Has anyone re-implemented TeX in a functional language? Preferably SML?
>>
>> In a word, "no". The only working reimplementation I have ever heard
>> of is in Java (NTS).

> Thanks. I'll have a look at that. If I have to do it myself, it'll
> probably be easier to work from than the original TeX sources.

>> Apart from buzzword points, what would be the point of TeX in SML?

> That's a bit complicated -- I'm thinking of writing a real-time WSIWYG TeX
> editor that could be extended to other layout systems as well, and I don't
> want to spend years on it. I'm intending to do a magic implementation that
> works mostly like this:


There was such an attempt to write a interactive
TeX in LISP many years ago.

If you are interested of that project, mail me.
I have to search, where I have the URL of that project.

Ciao,
Oliver
--
I'm looking for musicians in Berlin, which want to make groovy music
and are open-minded enough to add tapdance to the band
Look here for an improvisation-example:
http://www.belug.org/~ob/tap-impro-1.mpg

Oliver Bandel

unread,
Feb 12, 2002, 11:59:37 AM2/12/02
to

In comp.text.tex Oliver Bandel <oli...@first.in-berlin.de> wrote:

> In comp.text.tex Sebastian Rahtz <sebasti...@computing-services.oxford.ac.uk> wrote:
>> "Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:

>>> Has anyone re-implemented TeX in a functional language? Preferably SML?

>> In a word, "no". The only working reimplementation I have ever heard
>> of is in Java (NTS).

> NTS is not functional.... it's OO-like TeX.
> (And it's slow...)


> There is a functional TeX reeimplementation.

> I don't know if it's written in SML, Haskell or Scheme,
> but some months ago I've read about it.

OK, there was a second TeX-reeimplementation:
it was an interactive TeX, written in Lisp, but the
project was not finished.

Oliver Bandel

unread,
Feb 12, 2002, 11:55:38 AM2/12/02
to

In comp.text.tex Sebastian Rahtz <sebasti...@computing-services.oxford.ac.uk> wrote:
> "Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:

>> Has anyone re-implemented TeX in a functional language? Preferably SML?

> In a word, "no". The only working reimplementation I have ever heard
> of is in Java (NTS).

NTS is not functional.... it's OO-like TeX.
(And it's slow...)


There is a functional TeX reeimplementation.

I don't know if it's written in SML, Haskell or Scheme,
but some months ago I've read about it.

Ciao,

Oliver Bandel

unread,
Feb 12, 2002, 12:11:19 PM2/12/02
to

In comp.text.tex Matt Timmermans <ma...@timmermans.nospam-remove.org> wrote:


TeXtures.... a commercial software for Mac.

Oliver Bandel

unread,
Feb 12, 2002, 12:03:53 PM2/12/02
to

> Hi Giuseppe

> http://www.math.uni.wroc.pl/~hebisch/tex/texinc-0.1.tar.gz


Normally the websc-program is part of TeX-distributions...

Oliver Bandel

unread,
Feb 12, 2002, 12:10:06 PM2/12/02
to

In comp.text.tex William F. Hammond <ham...@pluto.math.albany.edu> wrote:
> "Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:

>> "Sebastian Rahtz" <sebasti...@computing-services.oxford.ac.uk> wrote in
>> message news:87r8nt2...@spqr.oucs.ox.ac.uk...

>> > "Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:
>> >
>> > > Has anyone re-implemented TeX in a functional language? Preferably SML?
>> >
>> > In a word, "no". The only working reimplementation I have ever heard
>> > of is in Java (NTS).

> Perhaps, re-phrasing, one could say "yes" for functional language
> because of NTS, and "no" for SML.

Java is an OO-language, not a functional language.

Graham Douglas

unread,
Feb 12, 2002, 2:07:50 PM2/12/02
to

André Pönitz <poe...@gmx.de> wrote in message
news:a4bf49$jg2$3...@narses.hrz.tu-chemnitz.de...

> In comp.text.tex Giuseppe Bilotta <obl...@freemail.it> wrote:
> >> http://www.math.uni.wroc.pl/~hebisch/tex/texinc-0.1.tar.gz
> >
> > Hey, I didn't know about this! Thank you for the reference!
>
> Since we are at it: has anybody seen some kind of TeX parser,
preferably
> written in C/C++ where one could hook in after the 'generation' of a
token
> and/or when a macro is about to be expanded?
>
> Sort of a --very-verbose option to TeX?
> Can I abuse TeX itself for that purpose?
>


Hi

Don't know if this helps but...

Line 5394 (onwards) of TeX.c
(from TeX in C) is the function:

Static void expand(void)
{

...

}

which implements expansion per
Section 366 (and many others)
of the TeX'ed output from WEAVEing
TeX.web. Perhaps you can hook into that?

The comments in TeX.c provide
cross-references back to the sections
from TeX.web which gave birth to the
C source.

Regards

Graham

Jean-Marie Kubek

unread,
Feb 12, 2002, 4:34:56 PM2/12/02
to
Sebastian Rahtz <sebasti...@computing-services.oxford.ac.uk> writes:

> "Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:
>
> > Has anyone re-implemented TeX in a functional language? Preferably SML?
>
> In a word, "no". The only working reimplementation I have ever heard
> of is in Java (NTS).
>

> Apart from buzzword points, what would be the point of TeX in SML?
>

Maybe a functional, side effect free, backend for jadetex :)

Jean-Marie Kubek
INSA Toulouse

Matt Timmermans

unread,
Feb 12, 2002, 11:00:06 PM2/12/02
to
"Achim Blumensath" <bl...@diabolo.informatik.rwth-aachen.de> wrote in
message

> I'n not quite finished yet (but mostly) with translating ant to OCaml.
> It's not 100% TeX compatible but if you are interested I could send you
> the sources.

I spent a while wondering what that Apache build tool had to do with TeX,
before going to your page. Now that I know what you mean... yes, I would
love to see your sources. Could you outline what parts aren't TeX
compatible?

Jacques Garrigue

unread,
Feb 13, 2002, 2:54:41 AM2/13/02
to
"Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:

> Reimplementation would be better, since (see previous response) I _am_ going
> to need to modify the typesetting function to some extent, because I want it
> to be able to render the caret/cursor and selection highlighting as well
> inserting navigational aids into the typeset output.

A combination of WhizzyTeX and ActiveDVI (a reimplementation of xdvi
in Caml) can do part of what you are asking for: real time editing of
LaTeX in emacs. That's almost wysiwyg, and this is not a structured
editor.

http://cristal.inria.fr/~remy/whizzytex/

---------------------------------------------------------------------------
Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp
<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>

Achim Blumensath

unread,
Feb 13, 2002, 4:52:42 AM2/13/02
to

The syntax currently is slightly different but the output is the same as
TeX's except for some rounding differences. Furthermore, some things
aren't implemented yet. I don't think it would be difficult to make ant
99% TeX compatible, but it is low on my TODO list.

I'm nearly finished with the translation to OCaml. I can send you the
current sources or you could wait until the next release which hopefully
will be in one or two weeks.

André Pönitz

unread,
Feb 13, 2002, 4:55:42 AM2/13/02
to
Graham Douglas <g.do...@readytext.co.uk> wrote:
> Don't know if this helps but...
>
> Line 5394 (onwards) of TeX.c
> (from TeX in C) is the function:

I'll have a look, thnaks for the pointer.

> The comments in TeX.c provide
> cross-references back to the sections
> from TeX.web which gave birth to the
> C source.

I am not familiar with the web sources...

Jules Bean

unread,
Feb 13, 2002, 6:32:42 AM2/13/02
to
André Pönitz wrote:
> In comp.text.tex Giuseppe Bilotta <obl...@freemail.it> wrote:
>
>>>http://www.math.uni.wroc.pl/~hebisch/tex/texinc-0.1.tar.gz
>>>
>>Hey, I didn't know about this! Thank you for the reference!
>>
>
> Since we are at it: has anybody seen some kind of TeX parser, preferably
> written in C/C++ where one could hook in after the 'generation' of a token
> and/or when a macro is about to be expanded?
>
> Sort of a --very-verbose option to TeX?
> Can I abuse TeX itself for that purpose?

Bad news, Andre' :-(

TeX isn't parsed. At least, not in the sense you hope. TeX's parser is
stateful, and its state is influenced by the stream. There is no
conventional static way to parse a TeX document and then execute it,
rather parsing and executing are pipelined together more-or-less
inseparably.

This is one of the things which is confusing about TeX, until you get
around it.

For example, a simple TeX parser might well attempt to balance {}s.
Unfortunately, as far as TeX is concerned, {}s are no more than any old
characters of category codes 1 and 2. So in the following:

{\catcode`>=2>

the second '>' is the closing brace for the {. Worse still, in:

{\expandafter\catcode\expandafter`\foobar=2 ...

You can't even tell what character has been assigned catcode 2 unless
you know what \foobar is defined to at that scope.

Not that anyone would write TeX like that, but for reasons like that,
you can't really parse TeX without actually interpreting TeX.

Jules

André Pönitz

unread,
Feb 13, 2002, 7:06:22 AM2/13/02
to
Jules Bean <ju...@dcs.qmul.ac.uk> wrote:
> Bad news, Andre' :-(
>
> TeX isn't parsed. At least, not in the sense you hope. TeX's parser is
> stateful, and its state is influenced by the stream. There is no
> conventional static way to parse a TeX document and then execute it,
> rather parsing and executing are pipelined together more-or-less
> inseparably.

I think I understand that tokens are only generated from the input stream
as far as they are needed. Nevertheless, in the end, macros get expanded
and primitives executed in some linear order uniquely determined by the
input. Getting that order would be nice. I guess one can get something like
that with postprocessing the output when using some of the \tracing...
stuff, but this is not really easily parsed, either (but of course much
easier then re-doing the macro expansions 'by hand'). The tricky part here
is to get 'everything' output somehow. How do I get e.g. all letters of
a word in the .log? With \tracingcommands=1 I see the first letter of each
word. How can I get the others?

> the second '>' is the closing brace for the {. Worse still, in:
>
> {\expandafter\catcode\expandafter`\foobar=2 ...
>
> You can't even tell what character has been assigned catcode 2 unless
> you know what \foobar is defined to at that scope.

I know...

> Not that anyone would write TeX like that, but for reasons like that,
> you can't really parse TeX without actually interpreting TeX.

That's why I'd like to do TeX the hard part itself and just get called back
when something happens that I consider 'interesting'

Jules Bean

unread,
Feb 13, 2002, 7:03:11 AM2/13/02
to
Achim Blumensath wrote:
> I'm nearly finished with the translation to OCaml. I can send you the
> current sources or you could wait until the next release which hopefully
> will be in one or two weeks.

I think that many people would be interested in comp.text.tex. Would
you announce it (at least) there, please?

Jules

David Kastrup

unread,
Feb 13, 2002, 7:26:48 AM2/13/02
to
Jules Bean <ju...@dcs.qmul.ac.uk> writes:

> TeX isn't parsed. At least, not in the sense you hope. TeX's parser
> is stateful, and its state is influenced by the stream. There is no
> conventional static way to parse a TeX document and then execute it,
> rather parsing and executing are pipelined together more-or-less
> inseparably.
>
> This is one of the things which is confusing about TeX, until you get
> around it.
>
> For example, a simple TeX parser might well attempt to balance
> {}s. Unfortunately, as far as TeX is concerned, {}s are no more than
> any old characters of category codes 1 and 2. So in the following:
>
> {\catcode`>=2>
>
> the second '>' is the closing brace for the {.

This is actually a very nice example for surprises in TeX: the second
`>' here is *not* the closing brace for the { but just an ordinary
character that gets typeset as such (actually, as an inverted question
mark, but that's a different thing). However, in the following, `>'
indeed is the closing brace:
{\catcode`>=2 >
See the difference?

> Worse still, in:
>
> {\expandafter\catcode\expandafter`\foobar=2 ...

The first \expandafter is redundant. BTW, if \foobar is \let to
\empty, it will be the `=' character that will get reassigned.

> You can't even tell what character has been assigned catcode 2 unless
> you know what \foobar is defined to at that scope.

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
Email: David....@t-online.de

Lucian Wischik

unread,
Feb 13, 2002, 7:55:20 AM2/13/02
to
Jules Bean <ju...@dcs.qmul.ac.uk> wrote:

>Andre Pnitz wrote:
>>Since we are at it: has anybody seen some kind of TeX parser
>>where one could hook in after the 'generation' of a token
>>and/or when a macro is about to be expanded?
>TeX isn't parsed. At least, not in the sense you hope. TeX's parser is
>stateful, and its state is influenced by the stream. There is n
>conventional static way to parse a TeX document and then execute it,
>rather parsing and executing are pipelined together more-or-less
>inseparably.

Presumably the parser knows when a macro starts to get expanded. Is it also
able to tell when a macro has finished being expanded? Then could it hook in
*after* the generation of tokens and macros?

--
Lucian Wischik, Queens' College, Cambridge CB3 9ET. www.wischik.com/lu

Jules Bean

unread,
Feb 13, 2002, 7:57:11 AM2/13/02
to
André Pönitz wrote:
> That's why I'd like to do TeX the hard part itself and just get called back
> when something happens that I consider 'interesting'

Tricky.

If by 'interesting' you mean the execution of a primitive command, then
in principle you can redefine the primitive commands to do what you want
(log something, presumably).

Unfortunately, by `interesting', you also probably mean the typesetting
of individual characters which, AFAIK, you can't hook into.

One thing you can do, give a small TeX fragment you want to understand,
is put it in a box and \showbox it. (With appropriate debug flags set to
high enough values that you see all the interesting stuff).

Jules

Jules Bean

unread,
Feb 13, 2002, 8:00:11 AM2/13/02
to

The problem is the circularity of the process: tokens are tokenised only
when needed. So the typical process is : tokenise enough to get one
token. Expand it. That expansion may, due to expansion rules, call for
more tokens to be tokenises. Now expand whatever is currently the
'front' token. Repeat. If you run out of tokens, tokenise the next
thing on the current input stream.

Which is not to say that you couldn't put in some hooks around those
times, because clearly you could..

Jules

David Kastrup

unread,
Feb 13, 2002, 9:16:12 AM2/13/02
to
ljw...@cus.cam.ac.uk (Lucian Wischik) writes:

> Jules Bean <ju...@dcs.qmul.ac.uk> wrote:
> >Andre Pnitz wrote:
> >>Since we are at it: has anybody seen some kind of TeX parser
> >>where one could hook in after the 'generation' of a token
> >>and/or when a macro is about to be expanded?
> >TeX isn't parsed. At least, not in the sense you hope. TeX's parser is
> >stateful, and its state is influenced by the stream. There is n
> >conventional static way to parse a TeX document and then execute it,
> >rather parsing and executing are pipelined together more-or-less
> >inseparably.
>
> Presumably the parser knows when a macro starts to get expanded.

Macros don't "start" to get expanded. Once they are expanded, they
are completely replaced by a token list. You can redefine the macro
in that token list without affecting the execution of the existing
token list.

Loops are usually implemented in that manner, by seemingly infinite
tail recursion that stops by redefining the recursively executed
macro.

> Is it also able to tell when a macro has finished being expanded?
> Then could it hook in *after* the generation of tokens and macros?

Just when is "after"?

Bill enry Gates

unread,
Feb 13, 2002, 9:53:36 AM2/13/02
to
Jules Bean <ju...@dcs.qmul.ac.uk> wrote in news:3C6942DB.3030307
@dcs.qmul.ac.uk:

the names have already been mentioned in this thread...but maybe the
programs are not included in the set of programs you name wysiwyg? :)

--
-kbg

logfilter v0.43 (for tex and latex) at
http://fermi.ruc.dk/~kbilsted/lf/

Jules Bean

unread,
Feb 13, 2002, 10:05:49 AM2/13/02
to
Bill enry Gates wrote:
> Jules Bean <ju...@dcs.qmul.ac.uk> wrote in news:3C6942DB.3030307
> @dcs.qmul.ac.uk:
>
>
>>Bill enry Gates wrote:
>>
>>>are you aware that atleast two free wysiwyg editors for latex which do
>>>realtime compilation in the background?
>>>
>>As far as I am aware, there are exactly none.
>>
>>Care to enlighten me?
>>
>>
>
> the names have already been mentioned in this thread...but maybe the
> programs are not included in the set of programs you name wysiwyg? :)

Well, as has been pointed out, LyX is neither WYSIWYG nor does it edit
LaTeX; rather it is somewhat visual, and exports LaTeX.

TeXmacs is certainly WYSIWYG, but again it isn't LaTeX. (It can, I
believe, export LaTeX)

Jules


Lucian Wischik

unread,
Feb 13, 2002, 10:26:25 AM2/13/02
to
David Kastrup <David....@t-online.de> wrote:

>ljw...@cus.cam.ac.uk (Lucian Wischik) writes:
>> Presumably the parser knows when a macro starts to get expanded.
>Macros don't "start" to get expanded. Once they are expanded, they
>are completely replaced by a token list.

By "start" I meant the start of this token list.

>> Is it also able to tell when a macro has finished being expanded?
>> Then could it hook in *after* the generation of tokens and macros?
>Just when is "after"?

The end of the token list

Giuseppe Bilotta

unread,
Feb 13, 2002, 1:47:41 PM2/13/02
to
David Kastrup wrote:
> > For example, a simple TeX parser might well attempt to balance
> > {}s. Unfortunately, as far as TeX is concerned, {}s are no more than
> > any old characters of category codes 1 and 2. So in the following:
> >
> > {\catcode`>=2>
> >
> > the second '>' is the closing brace for the {.
>
> This is actually a very nice example for surprises in TeX: the second
> `>' here is *not* the closing brace for the { but just an ordinary
> character that gets typeset as such (actually, as an inverted question
> mark, but that's a different thing). However, in the following, `>'
> indeed is the closing brace:
> {\catcode`>=2 >
> See the difference?

Yup. Since in the original example the > is scanned when looking for
the end of the number, it preserves the original catcode. In the
second example, the number ends with the space, so the catcode
assignment takes place before the scanning of the >, which therefore
gets the endgroup catcode.

Giuseppe Bilotta

unread,
Feb 13, 2002, 1:47:53 PM2/13/02
to
Jules Bean wrote:
>
> The problem is the circularity of the process: tokens are tokenised only
> when needed. So the typical process is : tokenise enough to get one
> token. Expand it. That expansion may, due to expansion rules, call for
> more tokens to be tokenises. Now expand whatever is currently the
> 'front' token. Repeat. If you run out of tokens, tokenise the next
> thing on the current input stream.
>

This is the reason why the procedure(s) to get the next token are
driving me crazy. I'm trying to implement a draft TeX input parser to
test the pre-draft TeXlib code, but I'm getting tired of trying to get
it even slightly close to TeX's.

Anybody volunteer? ;-)

André Pönitz

unread,
Feb 14, 2002, 5:29:21 AM2/14/02
to
Giuseppe Bilotta <obl...@freemail.it> wrote:
> This is the reason why the procedure(s) to get the next token are
> driving me crazy.

Welcome in the club...

> I'm trying to implement a draft TeX input parser to test the pre-draft
> TeXlib code, but I'm getting tired of trying to get it even slightly
> close to TeX's.
>
> Anybody volunteer? ;-)

Not really. But remember to drop me a note when you are done ;-)

Jules Bean

unread,
Feb 14, 2002, 6:15:52 AM2/14/02
to
Giuseppe Bilotta wrote:
> Jules Bean wrote:
>
>>The problem is the circularity of the process: tokens are tokenised only
>>when needed. So the typical process is : tokenise enough to get one
>>token. Expand it. That expansion may, due to expansion rules, call for
>>more tokens to be tokenises. Now expand whatever is currently the
>>'front' token. Repeat. If you run out of tokens, tokenise the next
>>thing on the current input stream.
>>
>>
>
> This is the reason why the procedure(s) to get the next token are
> driving me crazy. I'm trying to implement a draft TeX input parser to
> test the pre-draft TeXlib code, but I'm getting tired of trying to get
> it even slightly close to TeX's.

I'm not quite sure I understand why you're trying to do that.

I'm also not sure it is possible without substantially re-implementing
TeX. I think you would at least need to implement enough of TeX to
store the catcode tables and the control-sequence dictionary.

Jules

Giuseppe Bilotta

unread,
Feb 14, 2002, 8:06:05 AM2/14/02
to
=?iso-8859-1?Q?Andr=E9_P=F6nitz?= wrote:
> Giuseppe Bilotta <obl...@freemail.it> wrote:
> > This is the reason why the procedure(s) to get the next token are
> > driving me crazy.
>
> Welcome in the club...

I was thinking about setting up a SourceForge foundry on TeX. This
could be discussed there.

André Pönitz

unread,
Feb 14, 2002, 9:03:36 AM2/14/02
to
Giuseppe Bilotta <obl...@freemail.it> wrote:
>> Welcome in the club...
>
> I was thinking about setting up a SourceForge foundry on TeX. This
> could be discussed there.

I would subscribe to a mailing list but I am really annoyed of web
interfaces in general...

William F. Hammond

unread,
Feb 14, 2002, 9:31:42 AM2/14/02
to
Jules Bean <ju...@dcs.qmul.ac.uk> writes:

> TeX isn't parsed. At least, not in the sense you hope. TeX's parser
> is stateful, and its state is influenced by the stream. There is no
> conventional static way to parse a TeX document and then execute it,
> rather parsing and executing are pipelined together more-or-less
> inseparably.

This is a valid criticism of an author-level markup engine, but not so
clearly a bad thing -- maybe even a good thing -- for a typesetting
engine.

It's the reason I began work on GELLMU.

-- Bill

William F. Hammond

unread,
Feb 14, 2002, 9:47:10 AM2/14/02
to
Jean-Marie Kubek <ku...@irving.insa-tlse.fr> writes:

Now that we're just here in comp.text.tex (no longer cross-posted), I
suspect I am not alone in having choked on the jargon meaning of
"functional" and, while we're at it, "side-effect-free".

Could somebody explain. The interface between jade and tex has a
following here.

-- Bill

Giuseppe Bilotta

unread,
Feb 14, 2002, 11:21:00 AM2/14/02
to
Jules Bean wrote:

> Giuseppe Bilotta wrote:
> >
> > This is the reason why the procedure(s) to get the next token are
> > driving me crazy. I'm trying to implement a draft TeX input parser to
> > test the pre-draft TeXlib code, but I'm getting tired of trying to get
> > it even slightly close to TeX's.
>
> I'm not quite sure I understand why you're trying to do that.

Because I need it to start testing the library. I could do some other
way, but if I went this way I would also have half of the work done
for the TeX input plug-in to TeXlib.

> I'm also not sure it is possible without substantially re-implementing
> TeX.

But this is whay I'm (we at TeXlib are ...) doing ...

> I think you would at least need to implement enough of TeX to
> store the catcode tables and the control-sequence dictionary.

That's not difficul. The hard part is the 'getting the next token'
process.

Jonathan Fine

unread,
Feb 14, 2002, 3:11:12 PM2/14/02
to te...@tug.org
posted to comp.text.tex, comp.lang.functional and te...@tug.org

Recently Matt Timmermans started a thread
> Functional TeX implementations
in these newsgroups.

He concluded by writing
>
> I must say that, even though there don't appear to be any implementations of
> TeX in side-effect-free languages floating around, that you comp.text.tex
> guys appear to be the most generally helpful bunch of netizens I've seen in
> usenet.
>
> Thanks much.

His motive was to have the typesetting engine for a wysiwyg editor. But
if he asked a different question, he might have gotten a different
answer.

On 25 Feb 2000 David Carlisle, LaTeX3 project member, wrote on the
XSLT-list

[\ldots] functional programming style generally is a
GoodThing. I think the reasoning behind using this
style for styling langauges is that if there is no
global state then if you jump to page 1001 you can
start to render that page immediately without having
to process the entire document in order to find the
values of all global variables.

XSLT is, of course, a functional programming language. For that matter,
so is TeX's macro expansion language (except for a side effect from
\csname xxxx\endcsname when \xxxx is undefined).

So the question I would like to ask is this: Are there any functional
(in the technical sense) TeX macro packages (which allow you to do
'random-access typesetting'), and if not why not?

When TeX is run in daemon mode (the output dvi goes to a pipe, and
is then sent on to the calling application) the substantial start up
cost is avoided, and a twenty-fold speed increase is obtained for
small files.

Pages written for a functional macro packages could then be sent through
the TeX daemon, and the state after the production of dvi would be
unchanged.

For information about the TeX daemon visit
http://www.activetex.org
But unless you're mad keen, put it off for a week. A new release is
in the works.
(Don't be put off if you get an ISP screen. They host me for free,
and the ISP screen is a temporary result of administrative changes.)

Jonathan Fine, Cambridge, UK

Giuseppe Bilotta

unread,
Feb 14, 2002, 4:33:49 PM2/14/02
to
=?iso-8859-1?Q?Andr=E9_P=F6nitz?= wrote:
> Giuseppe Bilotta <obl...@freemail.it> wrote:
> >> Welcome in the club...
> >
> > I was thinking about setting up a SourceForge foundry on TeX. This
> > could be discussed there.
>
> I would subscribe to a mailing list but I am really annoyed of web
> interfaces in general...

I don't yet know enough about SourceForge foundries internals to know
if it's possible to get a mail copy of forum messages ... anybody?

Vidhyanath Rao

unread,
Feb 14, 2002, 5:17:05 PM2/14/02
to

"Jonathan Fine" <jf...@active-tex.demon.co.uk> wrote in message
news:3C6C19E0...@active-tex.demon.co.uk...

> When TeX is run in daemon mode (the output dvi goes to a pipe, and
> is then sent on to the calling application) the substantial start up
> cost is avoided, and a twenty-fold speed increase is obtained for
> small files.
>
> Pages written for a functional macro packages could then be sent
through
> the TeX daemon, and the state after the production of dvi would be
> unchanged.

AmigaTeX (by Tomas Rockiki) had something called the loop mode. It was
meant for the same kind of the thing as above. I am not sure of the
internals (it was a commercial package), but it went something like
this: A copy of the initial state was saved and at the end of each dvi
generation, the initial state was restored. So any macro package could
be used without worrying about final side-effects. [However, the fmt
used had to stay fixed.] I ran AmigaTeX on 8MHz 68K with 3M ram and 2
floppies for a total of 6 years and it worked quite well. It took 3-4
seconds between documents (that is not much when you consider that a 8
page paper could take a couple of minutes on my Amiga).

Matt Timmermans

unread,
Feb 15, 2002, 12:29:19 AM2/15/02
to

"William F. Hammond" <ham...@pluto.math.albany.edu> wrote in message
news:i78z9wp...@pluto.math.albany.edu...

> Now that we're just here in comp.text.tex (no longer cross-posted), I
> suspect I am not alone in having choked on the jargon meaning of
> "functional" and, while we're at it, "side-effect-free".
>
> Could somebody explain. The interface between jade and tex has a
> following here.

Sure. In programming languages, programs are composed of smaller units, and
these units are typically named in order to facilitate reuse.

In a functional programming language, these named units are functions, in
the strict mathematical sense -- the output of a function is a returned
value that is computed from its declared inputs, and _nothing_ else.
"nothing else" means no "side-effects". The primary advantage of functional
programming is the way it lets you analyze and reason about programs. For
instance, if you see something like this (I'll use a C-ish syntax)

If (a(x)||b(x)) ...

and you determine that a(x) always returns false, then you can remove that
code, because you _know_ that a(x) does'nt _do_ anything except return its
return value -- it can't be writing to some variable you don't know about
that may affect the execution of the program later on.

Similarly, you _know_ that changing (a(x)||b(x)) to (b(x)||a(x)) will not
affect the ouput of your program, and you can also remove the code if you
can determine that b(x) always returns false.

There are an astounding variety of transformations that can be automatically
and efficiently performed on functional programs.

What C calls a "function" is actually a procedure. If you see If
(a(x)||b(x))... in a C program, before you can remove it, you need to
inspect the code for a(x) to determine what else that procedure might be
doing in addition to returning its return value -- you need to know what the
side effects are. If you can determine that a(x) doesn't do anything that
might mess you up later on, _then_ you can remove the code. C is a
procedural language. It makes automated transformations difficult, because
multiple procedures accessing the same state interfere in very complicated
ways.

Procedural languages are also called "imperative", because a procedural
program is a set of instructions that tell the computer what to do.
Functional programs are also called "declarative", because a functional
program is a set of declarations that _define_ the output in terms of the
input, and let the compiler or interpreter determine the sequence of
operations to be executed. This lets the compiler or interpter do lots of
cool things -- like automatically generate efficient parallel
implementations, for example. In C, a(x)*b(x) means "execute a(x), execute
b(x), and multiply the results". In a functional language a(x)*b(x) means
"the product of a(x) and b(x)", which can be calculated however you like.
Guaranteed non-interference means that a(x) and b(x) can be blithely
calculated on separate machines, if the compiler decides that it's a good
idea.

TeX is a strange macro language. In TeX, if you see something like
If(a(x)||b(x)) in a definition, you don't know a thing about it. You need
to know all about _all_ the contexts in which it might be called in order to
know anything about it at all, because that macro could be expanded in a
context that completely redefines the meaning of if, a, b, and x in ways
that are completely unanticipated by the original designer of that
definition! Effectively, no two definitions are the same unless they match
character-for-character, and no automated program transformations are
possible without making unfounded assumptions about context.


Rowland McDonnell

unread,
Feb 15, 2002, 12:34:47 AM2/15/02
to
Giuseppe Bilotta <obl...@freemail.it> wrote:

> =?iso-8859-1?Q?Andr=E9_P=F6nitz?= wrote:
[snip]

> > I would subscribe to a mailing list but I am really annoyed of web
> > interfaces in general...
>
> I don't yet know enough about SourceForge foundries internals to know
> if it's possible to get a mail copy of forum messages ... anybody?

I don't know at all, but I do know that SourceForge runs mailing lists -
I'm subscribed to a couple related to a text editor I use (tcl based and
under development) - why not do it that way directly?

Rowland.


--
Remove the animal for email address: rowland....@dog.physics.org
PGP pub key 0x62DCCA78 Sorry - the spam got to me
http://www.mag-uk.org
UK biker? Join MAG and help keep bureaucracy at bay

Matt Timmermans

unread,
Feb 15, 2002, 1:30:52 AM2/15/02
to

"Achim Blumensath" <bl...@diabolo.informatik.rwth-aachen.de> wrote in
message

> I'm nearly finished with the translation to OCaml. I can send you the
> current sources or you could wait until the next release which hopefully
> will be in one or two weeks.

Thanks, Achim. I can wait a few weeks.


Jules Bean

unread,
Feb 15, 2002, 3:46:59 AM2/15/02
to
Jonathan Fine wrote:
> On 25 Feb 2000 David Carlisle, LaTeX3 project member, wrote on the
> XSLT-list

> XSLT is, of course, a functional programming language. For that matter,
> so is TeX's macro expansion language (except for a side effect from
> \csname xxxx\endcsname when \xxxx is undefined).


David's credentials are indisputable, but I question that statement. In
what sense can TeX be considered a functional language? Surely TeX
macros are executed imperatively, and alter a rather large set of state
(the dictionary of control-sequences and cat-codes).

Jules


Jules Bean

unread,
Feb 15, 2002, 3:42:27 AM2/15/02
to

Ack.

It is both LaTeX's strength and LaTeX's weakness that it combines
author-level markup with typesetting.

Jules

André Pönitz

unread,
Feb 15, 2002, 4:11:12 AM2/15/02
to
In comp.text.tex Jules Bean <ju...@dcs.qmul.ac.uk> wrote:
> David's credentials are indisputable, but I question that statement. In
> what sense can TeX be considered a functional language? Surely TeX
> macros are executed imperatively, and alter a rather large set of state
> (the dictionary of control-sequences and cat-codes).

If you consider that state as function argument and (part of) the return
value it might work out formally...

David Kastrup

unread,
Feb 15, 2002, 4:18:07 AM2/15/02
to
Jules Bean <ju...@dcs.qmul.ac.uk> writes:

> Jonathan Fine wrote:
> > On 25 Feb 2000 David Carlisle, LaTeX3 project member, wrote on the
> > XSLT-list
>
>
> > XSLT is, of course, a functional programming language. For that matter,
> > so is TeX's macro expansion language (except for a side effect from
> > \csname xxxx\endcsname when \xxxx is undefined).
>
>
> David's credentials are indisputable, but I question that statement.

If his credentials are indisputable, you should perhaps reread his
statement before questioning it.

> In what sense can TeX be considered a functional language?

He is not talking about TeX in general, but its macro expansion
language (or system). Expansion is *not* definition.

> Surely TeX macros are executed imperatively,

No, this is entirely false. TeX *macros* are *never* executed at all,
they are expanded. The results of that expansion may be primitive TeX
sequences or characters which may in an imperative context lead to
imperative execution. Apart from macros themselves, there are also
TeX primitives that are part of the expansion system (like
conditionals, \number, \csname).

> and alter a rather large set of state (the dictionary of
> control-sequences and cat-codes).

No, not at all. Please note that \def, \let, and the like are *not*
TeX macros. They are TeX primitives.

Donald Arseneau

unread,
Feb 15, 2002, 4:25:08 AM2/15/02
to
Jules Bean <ju...@dcs.qmul.ac.uk> writes:

> Jonathan Fine wrote:
> > On 25 Feb 2000 David Carlisle,
>

> > XSLT is, of course, a functional programming language. For that matter,
> > so is TeX's macro expansion language (except for a side effect from
> > \csname xxxx\endcsname when \xxxx is undefined).
>
> David's credentials are indisputable, but I question that statement.
> In what sense can TeX be considered a functional language? Surely TeX
> macros are executed imperatively, and alter a rather large set of
> state (the dictionary of control-sequences and cat-codes).

No, that statement is entirely correct, including the exception
of \csname converting undefined -> \relax (a "feature" that caused
many TeX bugs, if I recall). Maybe you are confusing TeX's assignments
with its macro expansion. Or maybe you are claiming that recursion,
by filling up a stack, is "stateful".

as...@triumf.ca


David Kastrup

unread,
Feb 15, 2002, 4:33:01 AM2/15/02
to
David Kastrup <David....@t-online.de> writes:

> Jules Bean <ju...@dcs.qmul.ac.uk> writes:
>
> > Jonathan Fine wrote:
> > > On 25 Feb 2000 David Carlisle, LaTeX3 project member, wrote on the
> > > XSLT-list
> >
> >
> > > XSLT is, of course, a functional programming language. For that matter,
> > > so is TeX's macro expansion language (except for a side effect from
> > > \csname xxxx\endcsname when \xxxx is undefined).
> >
> >
> > David's credentials are indisputable, but I question that statement.
>

> He is not talking about TeX in general, but its macro expansion
> language (or system). Expansion is *not* definition.
>
> > Surely TeX macros are executed imperatively,
>
> No, this is entirely false. TeX *macros* are *never* executed at all,
> they are expanded. The results of that expansion may be primitive TeX
> sequences or characters which may in an imperative context lead to
> imperative execution.

For an example of a more complicated package that defines macros
working entirely by macro expansion (not changing TeX's inner state),
see CTAN:macros/generic/kastrup/binhex.dtx. This does number
conversion to binary and hexadecimal (among others).

Jules Bean

unread,
Feb 15, 2002, 4:42:38 AM2/15/02
to
David Kastrup wrote:
> Jules Bean <ju...@dcs.qmul.ac.uk> writes:
>
>
>>Jonathan Fine wrote:
>>
>>>On 25 Feb 2000 David Carlisle, LaTeX3 project member, wrote on the
>>>XSLT-list
>>>
>>
>>>XSLT is, of course, a functional programming language. For that matter,
>>>so is TeX's macro expansion language (except for a side effect from
>>>\csname xxxx\endcsname when \xxxx is undefined).
>>>
>>
>>David's credentials are indisputable, but I question that statement.
>>
>
> If his credentials are indisputable, you should perhaps reread his
> statement before questioning it.

And I did. But I still didn't get it.

>>In what sense can TeX be considered a functional language?
>
> He is not talking about TeX in general, but its macro expansion
> language (or system). Expansion is *not* definition.


...and that's the ball I dropped.

Yes, I can see that the expansion rules, with the given exception, are
functional. I didn't realise that David meant "TeX's macro expansion
language" as distinct from the whole language. Thank you for the
clarification.

Jules

William F. Hammond

unread,
Feb 15, 2002, 7:41:44 AM2/15/02
to
"Matt Timmermans" <ma...@timmermans.nospam-remove.org> writes:

> Sure. In programming languages, programs are composed of smaller units, and
> these units are typically named in order to facilitate reuse.
>
> In a functional programming language, these named units are functions, in
> the strict mathematical sense -- the output of a function is a returned
> value that is computed from its declared inputs, and _nothing_ else.

> "nothing else" means no "side-effects". . . .

Many thanks for the explanation.

So shared structures are ruled out. What about _static_ shared
structures?

-- Bill

Dan Luecking

unread,
Feb 15, 2002, 5:34:52 PM2/15/02
to
Jules Bean <ju...@dcs.qmul.ac.uk> wrote in message news:<3C6CCB03...@dcs.qmul.ac.uk>...

> Jonathan Fine wrote:
> > On 25 Feb 2000 David Carlisle, LaTeX3 project member, wrote on the
> > XSLT-list
>

You snipped Jonathan's quote of David Carlisle:

[\ldots] functional programming style generally is a
GoodThing. I think the reasoning behind using this
style for styling langauges is that if there is no
global state then if you jump to page 1001 you can
start to render that page immediately without having
to process the entire document in order to find the
values of all global variables.

And then quote part of Jonathan's comments on David's words:

>
> > XSLT is, of course, a functional programming language. For that matter,
> > so is TeX's macro expansion language (except for a side effect from
> > \csname xxxx\endcsname when \xxxx is undefined).
>

It may well be that David has made this assertion, but you cannot
conclude that from Jonathan's posting.

>
> David's credentials are indisputable, but I question that statement. In
> what sense can TeX be considered a functional language? Surely TeX
> macros are executed imperatively, and alter a rather large set of state
> (the dictionary of control-sequences and cat-codes).

Whether the words are Jonathan's or David's, they are nevertheless
true. I wish, in fact, that the \csname exception had never
been committed to the language, despite its occasional usefulness.

Dan Luecking

Matt Timmermans

unread,
Feb 15, 2002, 8:44:13 PM2/15/02
to

"William F. Hammond" <ham...@pluto.math.albany.edu> wrote in message
> Many thanks for the explanation.
>
> So shared structures are ruled out. What about _static_ shared
> structures?

You can have shared structures as long as they're guaranteed not to change.
Static or global makes no difference -- anything you can reference is
constant.

For instance, in an OO language, you can send messages to objects:

obj->mutate(args)

In a functional language, you can't change anything, but you can write:

obj=mutate(obj,args)

The difference is that the functional version returns a new object.
Anything referencing the previous binding of 'obj' is unaffected, and the
old 'version' of obj remains accessible:

obj2=mutate(obj,args)

works too. And because objects you reference are guaranteed not to change,
the new object can actually share a lot of memory with the old object.


Robin Fairbairns

unread,
Feb 16, 2002, 4:29:56 AM2/16/02
to
Dan Luecking <luec...@uark.edu> wrote:
>Whether the words are Jonathan's or David's, they are nevertheless
>true. I wish, in fact, that the \csname exception had never
>been committed to the language, despite its occasional usefulness.

with a programmer as committed as knuth was in the 80s to a *non*-
"functional" style of programming, adding \csname to the expansion
language would have seemed natural.

personally, i wouldn't like to be left without latex, and i think that
tex as a text-processing language is too weak for latex to exist as a
practical tool of the 1980s without \csname. perhaps the language
ought to have been extended in a different direction, but speculating
as to _what_ that might be is surely a pointless exercise unless
someone has the energy to both write the replacement for tex and that
for latex.

[comp.lang.functional removed from this: i doubt those guys are
interested in navel-gazing by one who knows almost nothing of
functional programming.]
--
Robin Fairbairns, Cambridge -- rf10 at cam dot ac dot uk

Jonathan Fine

unread,
Feb 15, 2002, 7:59:31 AM2/15/02
to
Apologies. Due to an ambiguity in my quoting, readers have
attributed to David Carlisle a statement which is in fact
mine, namely the one quoted further on.

The side-effect of \csname has interesting consequences.

This code blows TeX up: due to lack of save stack.
===
\def\doit{%
\advance\count0 1
\message{\number\count 0}
\csname \number \count0 \endcsname
\doit
}

\begingroup
\doit

However, use
\begingroup\expandafter\endgroup\csname ...
and the side effect disappears.

You get lot's of undefined control sequences, and then
TeX blows up: due to lack of hash table entries.

This is not an academic point. As I recall, reading in .aux
files needlessly places \xxxx=\relax on the save stack.
As a result, when a student combines all the chapters into
a thesis, TeX's capacity is exceeded. (So I guess it is
an academic point.)


Jonathan Fine, Cambridge, UK

Dan Luecking

unread,
Feb 16, 2002, 3:54:06 PM2/16/02
to
r...@pallas.cl.cam.ac.uk (Robin Fairbairns) wrote in message news:<a4l8qk$gvj$1...@pegasus.csx.cam.ac.uk>...

> Dan Luecking <luec...@uark.edu> wrote:
> >Whether the words are Jonathan's or David's, they are nevertheless
> >true. I wish, in fact, that the \csname exception had never
> >been committed to the language, despite its occasional usefulness.
>
> with a programmer as committed as knuth was in the 80s to a *non*-
> "functional" style of programming, adding \csname to the expansion
> language would have seemed natural.
>
> personally, i wouldn't like to be left without latex, and i think that
> tex as a text-processing language is too weak for latex to exist as a
> practical tool of the 1980s without \csname.

I wasn't wishing for \csname to be left out (that would indeed seem
to make LaTeX impossible). I was wishing for the _exception_ to be
left out, namely that \csname x\endcsname has the side effect of
making \x temporarily equal to \relax when \x is undefined. Without
that exception, the expansion engine would be completely free of
side effects.

Dan Luecking

Donald Arseneau

unread,
Feb 17, 2002, 4:42:32 AM2/17/02
to
luec...@uark.edu (Dan Luecking) writes:

> r...@pallas.cl.cam.ac.uk (Robin Fairbairns) wrote in message news:<a4l8qk$gvj$1...@pegasus.csx.cam.ac.uk>...
> > Dan Luecking <luec...@uark.edu> wrote:
> > >true. I wish, in fact, that the \csname exception had never
> > >been committed to the language, despite its occasional usefulness.
> >
> > with a programmer as committed as knuth was in the 80s to a *non*-
> > "functional" style of programming, adding \csname to the expansion
> > language would have seemed natural.
>

> I wasn't wishing for \csname to be left out

I understood what you wrote. The word "exception" is unclear when the
quote is isolated, but it made sense in the original.

> making \x temporarily equal to \relax when \x is undefined. Without

Correction: permanently. Several parts of TeX temporarily cause
(certain) tokens to be treated as \relax:
o \noexpand before any token
o \else,\fi tokens when TeX is expanding the argument of an \if* test
o Font selection commands when TeX is expanding the font name, to
assign that font command (as \xxx in \font\xxx=foobar\xxx)
(these are just what I remember of the top of my head) and they
don't mes up the "state". The problem with the \csname exception
is that the token is permanently assigned the meaning of \relax.

(Dan knows all this, and "temporarily" was probably a little slip,
but for the viewers at home...)

Donald Arseneau as...@triumf.ca

Sven Utcke

unread,
Feb 18, 2002, 6:58:53 AM2/18/02
to
ham...@pluto.math.albany.edu (William F. Hammond) writes:

> So shared structures are ruled out. What about _static_ shared
> structures?

Something like:

int max(int i)
{
static int m=0;
if (i>m) {
m=i;
}
return m
}

such that max(1)*max(10) = 10
but max(10)*max(1) = 100

Hmm. Not an option either, I dare say...

Sven

PS: of course the above assumes that the compiler always evaluates in
the same order...
--
_ __ The Cognitive Systems Group
| |/ /___ __ _ ___ University of Hamburg
| ' </ _ \/ _` (_-< phone: +49 (0)40 42883-2576 Vogt-Koelln-Strasse 30
|_|\_\___/\__, /__/ fax : +49 (0)40 42883-2572 D-22527 Hamburg
|___/ http://kogs-www.informatik.uni-hamburg.de/~utcke/home.html

Dan Luecking

unread,
Feb 18, 2002, 11:48:46 AM2/18/02
to
Donald Arseneau <as...@triumf.ca> wrote in message news:<yfir8nk...@triumf.ca>...

So kind of you to say that, but... I didn't know _any_ of this!
And "temporarily" was intended. These are some of the bits of TeX
I've never personally encountered, and so never got reinforced and
were forgotten (if they were ever known). I have been assuming,
for example, that \noexpand\x (outside \edef) was just relaced by
\x and would be detected as undefined when read again. I guess even
I can learn something new every once in a while if you speak slowly
and clearly.

Dan Luecking

David Kastrup

unread,
Feb 18, 2002, 11:54:52 AM2/18/02
to
luec...@uark.edu (Dan Luecking) writes:

> So kind of you to say that, but... I didn't know _any_ of this! And
> "temporarily" was intended. These are some of the bits of TeX I've
> never personally encountered, and so never got reinforced and were
> forgotten (if they were ever known). I have been assuming, for
> example, that \noexpand\x (outside \edef) was just relaced by \x and
> would be detected as undefined when read again.

Which is just what it does. On the other hand
\csname x\endcsname causes \x to be permanently defined as \relax.

Donald Arseneau

unread,
Feb 18, 2002, 10:16:24 PM2/18/02
to
luec...@uark.edu (Dan Luecking) writes:

> Donald Arseneau <as...@triumf.ca> wrote in message news:<yfir8nk...@triumf.ca>...

> > > making \x temporarily equal to \relax when \x is undefined. Without
> >
> > Correction: permanently. Several parts of TeX temporarily cause

^^^^^^^^^^^ ^^^^^^^^^^^


> > (certain) tokens to be treated as \relax:
> > o \noexpand before any token
> > o \else,\fi tokens when TeX is expanding the argument of an \if* test
> > o Font selection commands when TeX is expanding the font name, to
> > assign that font command (as \xxx in \font\xxx=foobar\xxx)

I should have been more consistent, instead of jumping from topic-to-
topic. Those three are items are indeed temporary, as you always
thought (and I said). \csname is the stark exception in that it
performs a (permanent) assignment.

Donald Arseneau as...@triumf.ca


Dan Luecking

unread,
Feb 19, 2002, 11:58:27 AM2/19/02
to
David Kastrup <David....@t-online.de> wrote in message news:<x5pu32o...@tupik.goethe.zz>...

> luec...@uark.edu (Dan Luecking) writes:
>
> > So kind of you to say that, but... I didn't know _any_ of this! And
> > "temporarily" was intended. These are some of the bits of TeX I've
> > never personally encountered, and so never got reinforced and were
> > forgotten (if they were ever known). I have been assuming, for
> > example, that \noexpand\x (outside \edef) was just relaced by \x and
> > would be detected as undefined when read again.
>
> Which is just what it does.

No it doesn't. At least it doesn't do what I tried to say, but it
may do what you thought I said. (I guess I have to brush up on my
communication skills.) I thought that \noexpand\x would just expand
to \x and raise an error.

The document:
\noexpand\xxx
\end
Produces no error message. But before Don's posting, I thought the
following would happen in a typesetting context: TeX's expansion
routines encounter \noexpand, they then read the next token \xxx,
and place it in the input stream without expanding it, but then
*read it again*, this time doing whatever action it requires. This,
in fact doesn't happen if \xxx is expandable or undefined: nothing
happens. If \xxx is not expandable, it seems to be executed.

I would never have guessed or expected this. I also find the
following very strange (I understand it, but still find it
strange):

\expandafter\ifx\noexpand\the\the
\message{"Equal."}\else\message{"Not equal."}\fi

produces "Not equal." This happens for any undefined or expandable
token (even primative ones like \the). However

\expandafter\ifx\noexpand\advance\advance
\message{"Equal."}\else\message{"Not equal."}\fi

says "Equal."

This seems a feasible test for expandability of a token.

Dan Luecking

Donald Arseneau

unread,
Feb 19, 2002, 10:02:39 PM2/19/02
to
luec...@uark.edu (Dan Luecking) writes:

> David Kastrup <David....@t-online.de> wrote in message news:<x5pu32o...@tupik.goethe.zz>...
> > luec...@uark.edu (Dan Luecking) writes:
> >
> > > example, that \noexpand\x (outside \edef) was just relaced by \x and
> > > would be detected as undefined when read again.
> >
> > Which is just what it does.
>
> No it doesn't. At least it doesn't do what I tried to say,
>

> The document:
> \noexpand\xxx
> \end
> Produces no error message.

Indeed, and now I see what you were saying. This is still a
"temporary" "assignment". The expansion of \noexpand\xxx is
\xxx with the *temporary* meaning of \relax. This \relax
meaning is passed on to TeX's assignment-and-typesetting levels,
as shown by

\noexpand\xxx
\xxx
\end

which raises an error on the second \xxx, but not the first.

Contrast the equivalent example

\csname xxx\endcsname
\xxx
\end

which raises no errors, even on the second \xxx.

> \expandafter\ifx\noexpand\advance\advance
> \message{"Equal."}\else\message{"Not equal."}\fi
>
> says "Equal."
>
> This seems a feasible test for expandability of a token.

Excellent! I got a surprise myself. I had expected that:

\expandafter\ifx\noexpand\the\relax

\message{"Equal."}\else\message{"Not equal."}\fi

would report "Equal", but it says "Not Equal". However

\expandafter\let\expandafter\fff\noexpand\the \show\fff

reports \fff=\relax! And finally:

*\expandafter\show\noexpand\the
> \the=\relax.
<recently read> \notexpanded: \the

So I wonder what token a \noexpanded-token really equals.

According to tex.web, \noexpand does not actually work directly,
but inserts an internal "dont_expand" token (which may be shown as
\notexpanded). Then the "inner loop" of token processing detects
this prefix and takes the next token without expansion.


Donald Arseneau as...@triumf.ca

Norman Gray

unread,
Feb 20, 2002, 5:59:49 AM2/20/02
to
Greetings,

Donald Arseneau <as...@triumf.ca> writes:

>luec...@uark.edu (Dan Luecking) writes:
>> \expandafter\ifx\noexpand\advance\advance
>> \message{"Equal."}\else\message{"Not equal."}\fi
>>
>> says "Equal."
>>
>> This seems a feasible test for expandability of a token.

`Surprising', `instructive', `dismaying'. Words can't get there!

>Excellent! I got a surprise myself. I had expected that:
>
>\expandafter\ifx\noexpand\the\relax
> \message{"Equal."}\else\message{"Not equal."}\fi
>
>would report "Equal", but it says "Not Equal". However

...but now I _am_ confused.

\the is indeed `a control sequence that would ordinarily be expanded
by TeX's expansion rules', so it should be `interpreted as if its
meaning were \relax' (or am I looking at the wrong page?). Thus this
should be equivalent to
\ifx<something interpreted as \relax>\relax

\message{"Equal."}\else\message{"Not equal."}\fi

\ifx does not expand control sequences: these two tokens are not
macros, they do not represent the same (character code, category code)
pair, but they _do_ represent the same TeX primitive (which seems to be
the most reasonable interpretation of `as if its meaning were
\relax'). So I seem to have persuaded myself that this should report
"Equal.". Where have I gone wrong?

Donald reports that tex.web appears to special-case this particular
construction. I appreciate how that could make a difference, but I
couldn't deduce that from the book.

Is the problem caused by the difference between

`interpreted as if it were \relax'
and
`interpreted as if its meaning were \relax'

I can see the difference between a thing and the meaning of a thing,
but this distinction doesn't seem to be made elsewhere. Could `as if
its meaning were \relax' be taken to mean `has the same result as
\relax', in the sense that `TeX does nothing', but specifically not be
equal to \relax? Again, that doesn't seem the most natural deduction from
the explanation.

I wonder if there's a link with `meaning' as in `the expansion of
\meaning', but I think I'm starting to become silly (in a variety of
senses).

Norman

--
---------------------------------------------------------------------------
Norman Gray http://www.astro.gla.ac.uk/users/norman/

Dan Luecking

unread,
Feb 20, 2002, 3:01:04 PM2/20/02
to
Donald Arseneau <as...@triumf.ca> wrote in message news:<yfig03w...@triumf.ca>...

> luec...@uark.edu (Dan Luecking) writes:
> > \expandafter\ifx\noexpand\the\the
> > \message{"Equal."}\else\message{"Not equal."}\fi
> >
> > says "Not equal."
[snip]

> >
> > This seems a feasible test for expandability of a token.
>
> Excellent! I got a surprise myself. I had expected that:
>
> \expandafter\ifx\noexpand\the\relax
> \message{"Equal."}\else\message{"Not equal."}\fi
>
> would report "Equal", but it says "Not Equal".

That's what I expected, too. (I never tested it.) I have to retract
my statement (not quoted) that I understand what happens.

Quick quiz: what does
\count0=11
\count2=2\noexpand\the\count0
\end
assign to \count2, and what, if anything, does it put in the .dvi
file and the .log file?

Part 2: answer the same questions for this
\count0=11
\count2=2 \noexpand\the\count0
\end

(These I did test.)

I think it's clear that \noexpand is rather special and not
entirely explained in the TeXbook.

Dan Luecking

Robin Fairbairns

unread,
Feb 20, 2002, 6:06:05 PM2/20/02
to
Dan Luecking <luec...@uark.edu> wrote:
>Quick quiz: what does
> \count0=11
> \count2=2\noexpand\the\count0
> \end
>assign to \count2, and what, if anything, does it put in the .dvi
>file and the .log file?

i got the first answer right: the rest is quite mad

>Part 2: answer the same questions for this
> \count0=11
> \count2=2 \noexpand\the\count0
> \end
>
>(These I did test.)

so why is the answer different?

>I think it's clear that \noexpand is rather special and not
>entirely explained in the TeXbook.

this is plainly silly. eny fule kno that everything is completely
explained in the texbook and you don't need anything else.

we plainly haven't either of us read the beastly thing often enough.

or maybe you've found a bug in tex (part 1, i think).

Giuseppe Bilotta

unread,
Feb 20, 2002, 6:46:42 PM2/20/02
to
Robin Fairbairns wrote:
> Dan Luecking <luec...@uark.edu> wrote:
> >Quick quiz: what does
> > \count0=11
> > \count2=2\noexpand\the\count0
> > \end
> >assign to \count2, and what, if anything, does it put in the .dvi
> >file and the .log file?
>
> i got the first answer right: the rest is quite mad
>
> >Part 2: answer the same questions for this
> > \count0=11
> > \count2=2 \noexpand\the\count0
> > \end
> >
> >(These I did test.)
>
> so why is the answer different?

In the first example, \noexpand is scanned while looking for numbers,
it finds \the, temporarily binds it to \relax, and terminates the
number. The \the is then scanned again. (This is the important part.)

Another example: try:

\def\my#1{#1}
\count0=11
\count2=2\my\the\count0

--
Giuseppe "Oblomov" Bilotta

Axiom I of the Giuseppe Bilotta
theory of IT:
Anything is better than MS

Donald Arseneau

unread,
Feb 20, 2002, 7:48:54 PM2/20/02
to
luec...@uark.edu (Dan Luecking) writes:

> Quick quiz:

I did get these.

> \count0=11
> \count2=2\noexpand\the\count0

This gets to the heart of of how \noexpand works, and it does
match the very loose description in the TeXbook, and fits with
this thread of a "temporary assignment".

When assigning \count2, the \noexpand\the is bound to \relax
*for one expansion operation*. This apparent \relax terminates
the number but is not consumed (a terminating space is consumed
by the number). After the assignment \count2=2 is complete,
TeX then sees \the\count0, with \the having its ordinary meaning.
This it prints 11 on the page.

Internally, what happens (I think) is that \noexpand inserts the
internal \notexpanded token, which is consumed by the attempted
expansion. That's how TeX performs the "nonce" assignment.

It is interesting to contrast numeric arrignments, where \relax
is not consumed, to the consumption of <filler>, including \relax,
in other parts of Tex's syntax.

\toks0={{grouped}}
\toks1=\noexpand\the\toks0
\toks2=\the\toks0
\toks3=\relax\toks0

All the assignments work without error, and the \toks1 assignment
preserves the braces, indicating that \the was consumed as \relax
would be (demonstrated by \toks3).

> \count0=11
> \count2=2 \noexpand\the\count0

This is pretty ordinary, since the parts are completely uncoupled.
TeX performs \count2=2 (consuming the space) and then sees
\noexpand\the which it treats as \relax, and sees no need to rescan,
and then hits \count0 which it readss as an incomplete assignment.

> I think it's clear that \noexpand is rather special and not
> entirely explained in the TeXbook.

Yes, there are several nitty-gritty details that are not explained
fully. Knuth says the TeXbook is full of lies, and the statement
near the end that all of TeX has been explaind is one of them.


Donald Arseneau as...@triumf.ca

Robin Fairbairns

unread,
Feb 21, 2002, 4:26:41 AM2/21/02
to
Giuseppe Bilotta <obl...@freemail.it> wrote:
>Robin Fairbairns wrote:
>> Dan Luecking <luec...@uark.edu> wrote:
>> >Quick quiz: what does
>> > \count0=11
>> > \count2=2\noexpand\the\count0
>> > \end
>> >assign to \count2, and what, if anything, does it put in the .dvi
>> >file and the .log file?
>>
>> i got the first answer right: the rest is quite mad
>>
>> >Part 2: answer the same questions for this
>> > \count0=11
>> > \count2=2 \noexpand\the\count0
>> > \end
>> >
>> >(These I did test.)
>>
>> so why is the answer different?
>
>In the first example, \noexpand is scanned while looking for numbers,
>it finds \the, temporarily binds it to \relax, and terminates the
>number. The \the is then scanned again. (This is the important part.)

so the explanation in the texbook is at least deeply misleading.

"the expansion is the token itself; but that token is interpreted as
if its meaning were `\relax' if it is a control sequence that would
ordinarily be expanded by tex's expansion rules."

\the is a control sequence that ..., so any rational consideration of
the first example would expect the \noexpanded \the to terminate the
expression and to do nothing else. but no: the temporariness of the
non-expansion is even more cursory than rational analysis would
imagine.

>Another example: try:
>
>\def\my#1{#1}
>\count0=11
>\count2=2\my\the\count0

entirely unsurprising, i would say.

Donald Arseneau

unread,
Feb 21, 2002, 4:55:58 AM2/21/02
to
r...@pallas.cl.cam.ac.uk (Robin Fairbairns) writes:

> "the expansion is the token itself; but that token is interpreted as
> if its meaning were `\relax'

> \the is a control sequence that ..., so any rational consideration of


> the first example would expect the \noexpanded \the to terminate the
> expression and to do nothing else. but no: the temporariness of the
> non-expansion is even more cursory than rational analysis would
> imagine.

Well that part works as I imagined; which doesn't necessarily
contradict you.

The point is that even a real \relax gets looked at by the expander
when trying to parse the number, and then re-scanned after the assignment
has been performed.

Donald Arseneau as...@triumf.ca


Jules Bean

unread,
Feb 21, 2002, 6:06:26 AM2/21/02
to
Donald Arseneau wrote:
>>I think it's clear that \noexpand is rather special and not
>>entirely explained in the TeXbook.
>>

What an instructive (sub)thread.

> Yes, there are several nitty-gritty details that are not explained
> fully. Knuth says the TeXbook is full of lies, and the statement
> near the end that all of TeX has been explaind is one of them.

It is dangerous to second-guess anyone, especially DEK, but I presume he
would have said that the real documentation for TeX is tex.web, suitably
woven.

Jules


Giuseppe Bilotta

unread,
Feb 21, 2002, 8:14:46 AM2/21/02
to
Robin Fairbairns wrote:
> >
> >In the first example, \noexpand is scanned while looking for numbers,
> >it finds \the, temporarily binds it to \relax, and terminates the
> >number. The \the is then scanned again. (This is the important part.)
>
> so the explanation in the texbook is at least deeply misleading.
>
> "the expansion is the token itself; but that token is interpreted as
> if its meaning were `\relax' if it is a control sequence that would
> ordinarily be expanded by tex's expansion rules."
>
> \the is a control sequence that ..., so any rational consideration of
> the first example would expect the \noexpanded \the to terminate the
> expression and to do nothing else. but no: the temporariness of the
> non-expansion is even more cursory than rational analysis would
> imagine.

It lasts only for the "first scanning" and not for subsequent rescans.
Of course, since rescanning doesn't happen very often, this usually
goes unnoticed. Yet there are a few things I don't understand.

\let\EA\expandafter

\EA\EA\EA\show\EA\relax\noexpand\the

give (expectedly): \relax=\relax and \notexpanded:the as "to be read
again", which THIS TIME gets interpreted as \relax. (\the=\relax also
with

\EA\show\noexpand\the

) If you go with:

\EA\EA\EA\show\EA\EA\noexpand\the\message{Checkpoint.}

\message does NOT get expanded. Why? Yet the second and fifth \EA get
"executed". Yet this gives \the=the, showing that (and how) the
\the=\relax position was temporary.

Dan Luecking

unread,
Feb 21, 2002, 2:26:27 PM2/21/02
to
Giuseppe Bilotta <obl...@freemail.it> wrote in message news:<MPG.16df0ec6d...@powernews.libero.it>...

> Robin Fairbairns wrote:
> > >
> > >In the first example, \noexpand is scanned while looking for numbers,
> > >it finds \the, temporarily binds it to \relax, and terminates the
> > >number. The \the is then scanned again. (This is the important part.)
> >
> > so the explanation in the texbook is at least deeply misleading.
> >
> > "the expansion is the token itself; but that token is interpreted as
> > if its meaning were `\relax' if it is a control sequence that would
> > ordinarily be expanded by tex's expansion rules."
> >
> > \the is a control sequence that ..., so any rational consideration of
> > the first example would expect the \noexpanded \the to terminate the
> > expression and to do nothing else. but no: the temporariness of the
> > non-expansion is even more cursory than rational analysis would
> > imagine.
>
> It lasts only for the "first scanning" and not for subsequent rescans.

The point of my example was to compare it with the other one. Compare
\expandafter\ifx\noexpand\the\the ...\else ...\fi
with
\count0=2\noexpand\the\count2
in both cases \noexpand\the is scanned twice. In the first case
\expandafter forces the expansion of \noexpand\the and then \ifx
examines the result. In the second case, TeX expands \noexpand\the
to determine the end of the assignment, then examines it again
when done with the assignment. I thought the difference lay in this
part of robin's quote from the TeXbook:
as if its meaning were \relax *if it is a control sequence that
would ordinarily be expanded by tex's expansion rules.*
In both cases \noexpand\the is first encountered in a context where it
is expanded, so by the above it becomes \relax, on the second encounter
the resultant token is *not* being expanded in the \ifx case and *is*
being expanded in the assignment case. What should be the meaning of
this token on the second pass?

I'm beginning to think the problem is with \ifx, since
we have demonstrated that \expandafter\ifx\noexpand\the <cs>
produces false for both <cs>=\the and <cs>=\relax.



>
> \let\EA\expandafter
>
> \EA\EA\EA\show\EA\relax\noexpand\the
>
> give (expectedly): \relax=\relax and \notexpanded:the as "to be read
> again", which THIS TIME gets interpreted as \relax. (\the=\relax also
> with
>
> \EA\show\noexpand\the
>
> ) If you go with:
>
> \EA\EA\EA\show\EA\EA\noexpand\the\message{Checkpoint.}
>
> \message does NOT get expanded. Why?

Because \message is not an expandable token.

By now I think we will all be relieved to know that
\EA\EA\EA\ifx\EA\noexpand\EA\the\noexpand\the
\message{***Equal***}\else\message{***Not equal***}\fi
produces "Equal". I.e., \noexpand\the equals \noexpand\the
in an \ifx test. If we could only figure out what it equals

> Yet the second and fifth \EA get
> "executed". Yet this gives \the=the, showing that (and how) the
> \the=\relax position was temporary.

Well there is no argument that it is temporary, (\noexpand\x\x
proves that) the question is only "How long is temporary?"
Also (as the \ifx test shows) it seems \noepand\the can have 3
meanings: \the, \relax, and some meaning not either of those.

This is beginning to feel like one of those C examples where
x++ or ++x occur in the middle of an assignment and everone
argues where the checkpoints are and when the increment happens.

I always hated those.

Dan Luecking

Dan Luecking

unread,
Feb 21, 2002, 2:45:08 PM2/21/02
to
Donald Arseneau <as...@triumf.ca> wrote in message news:<yfi7kp7...@triumf.ca>...

> luec...@uark.edu (Dan Luecking) writes:
>
> > Quick quiz:
>
> I did get these.
>
> > \count0=11
> > \count2=2\noexpand\the\count0
>
> This gets to the heart of of how \noexpand works, and it does
> match the very loose description in the TeXbook, and fits with
> this thread of a "temporary assignment".
>
> When assigning \count2, the \noexpand\the is bound to \relax
> *for one expansion operation*. This apparent \relax terminates
> the number but is not consumed (a terminating space is consumed
> by the number). After the assignment \count2=2 is complete,
> TeX then sees \the\count0, with \the having its ordinary meaning.
> This it prints 11 on the page.
>
> Internally, what happens (I think) is that \noexpand inserts the
> internal \notexpanded token, which is consumed by the attempted
> expansion. That's how TeX performs the "nonce" assignment.

And in \expandafter\ifx\noexpand\the\the there is no expansion
and "\notexpanded: \the" is compared to "\the"? Somehow the
internal \notexpanded token doesn't quite explain things. I think
the best we can say is, "in and \ifx test this happens, in this other
case that happens, and in another case this other thing happens, etc."
(perhaps there are only these three cases, but I wouldn't bet too much
on it).

> > \count0=11
> > \count2=2 \noexpand\the\count0
>
> This is pretty ordinary, since the parts are completely uncoupled.
> TeX performs \count2=2 (consuming the space) and then sees
> \noexpand\the which it treats as \relax, and sees no need to rescan,

> and then hits \count0 which it reads as an incomplete assignment.
>

I know, it was just to lift the student's spirits after missing
the first part of the quiz :-)

I was really trying to contrast the behavior in \ifx with other
contexts.

Dan Luecking

Giuseppe Bilotta

unread,
Feb 21, 2002, 5:34:45 PM2/21/02
to
Dan Luecking wrote:
>
> I'm beginning to think the problem is with \ifx, since
> we have demonstrated that \expandafter\ifx\noexpand\the <cs>
> produces false for both <cs>=\the and <cs>=\relax.

Uhm. Probably because it's a \notexpanded token you are comparing with
something, and \notexpanded is "not really the original token" but
also "not really relax". Wow.

Now what happens if I do

\expandafter\let\expandafter\mycs\noexpand\the

?

> By now I think we will all be relieved to know that
> \EA\EA\EA\ifx\EA\noexpand\EA\the\noexpand\the
> \message{***Equal***}\else\message{***Not equal***}\fi
> produces "Equal". I.e., \noexpand\the equals \noexpand\the
> in an \ifx test. If we could only figure out what it equals

\notexpanded:the

as shown if you let TeX tell you what's to be read again.

Donald Arseneau

unread,
Feb 22, 2002, 4:31:59 AM2/22/02
to
Giuseppe Bilotta <obl...@freemail.it> writes:

> \EA\EA\EA\show\EA\relax\noexpand\the

This shouldn't be any different from

\EA\show\EA\relax\noexpand\the

because pre-expanding \relax just gives \relax. The "to be read again"
is there because \the has been looked at and put back in the input
stream.

> again", which THIS TIME gets interpreted as \relax. (\the=\relax also

I wonder what you are getting at though. You are not \show-ing the
meaning of (unexpanded)\the, but just the ordinary \relax! Since
the \show\relax amd \the are unrelated, this is the same as

\show\relax \noexpand\the

except that the non-expansion of \the has been pre-arranged before
\show\relax, so it is visible in the "context" of TeX's message.

Donald Arseneau as...@triumf.ca

It is loading more messages.
0 new messages