Maybe some work to make Maxima display much better



Andrey G. Grozin wrote:

> Hello *,
> 
> On Thu, 13 Dec 2001, Richard Fateman wrote:
> 
>>Right now there is a program in maxima called displa   which takes any
>>maxima expression and produces a 2-dimensional fixed-width character
>>display on a page of width  $linel  or less.  This defines the typesetting
>>"semantics" in a completely deterministic way.  The program can be
>>changed to put in variable-width fonts and special characters like
>>alpha, with very little work.
>>
> There is a *huge* distance from such a simple program to real typesetting.


I think that quality typesetting from TeX requires some hand corrections
in some cases, so even TeX is not a perfect solution.  On the other 
hand, for visual display on a screen, TeX is probably too good (it has a 
higher resolution than necessary) and also not good enough, because of 
line breaks and feedback.


> Have you read The TeXBook carefully? I have. It would take a lot of effort
> to implement these algorithms.


I have not read the TeXBook recently, but the algorithms are available 
in Pascal, C, and in Lisp:  there are two implementations, neither of
  which I can find right now.  Someone in France wrote a TeX in Lisp, 
and Bill Schelter wrote a TeX mode in the Texas Instruments Lisp Machine 
system (an extension to the emacs-like editor).  Schelter's program was, 
I think, something like TeXmacs, but only for the Lisp Machine.  I do 
not know where the code for this might be, or how close it is to the 
Common Lisp of today.

> TeX solves a very complicated nonlinear
> optimization problem. Development and fine-tuning of these algorithms took
> many "Knuth-years". I doubt if we have another Knuth on this mailing list.


1. I don't think it has to be fine-tuned as much. At least if we are 
doing this automatically.  If we want to allow human hand-tuning of the 
result of computing, then I propose that we don't have to do anything.
We already have maxima --> LaTex.  A perfectionist can modify the LaTex 
code, and redisplay it.
2. The dynamic programming algorithm used by Knuth is available in 
carefully documented source code, if it makes sense to use it.  I don't 
know that it affects mathematical displays very much.  It matters more 
when you are typesetting a paragraph with relatively few places for glue 
(in-between words).  In math you have glue very often, like almost every 
symbol, and I think humans are less sensitive to minor differences in math.


> 
> 
>>1. LaTex cannot do line-breaks as well as the computer program
>>that understands math.
>>
> I still have to see at least one program which can do line-breaking in
> typesetted maths. 

There are several: Mathematica, Maple, (commercial) Macsyma, and even 
the free Maxima, if you allow fixed-width display in 2D to count as 
typesetting.

> This is just too complicated problem. TeX cannot say in
> advance how much space will be occupied by some formula. Therefore, it has
> no possibility to decide if it has to break it or not. Trial-and-error
> approach (typeset on one line; if it's too long, break it) is unacceptable
> for efficiency reasons.


It is actually not so  difficulty to get a very good approximation to an 
optimal solution.  The same exact problem occurs and has been solved by 
Lisp pretty-printing programs. (Printing an indented version of a lisp 
program given a particular line-width). A naive solution takes time 
exponential in the size of the program to be displayed.  A cleverer 
solution takes (usually) linear time, and sometimes n^2.


> 
>>3. Installing LaTex can be tricky.   I find it very irritating to
>>here from someone "try my free software X" and discover that to
>>use it I must first find and download and install Tcl/TK, GCL,MikTeX,
>>python, Perl, emacs21, new fonts, etc.
>>
> This is because you use Windows. If you just install any recent Linux
> distribution, you will have all this stuff, and a lot more. (Well, Emacs
> 21 is too new to be in a distribution. Just
> ./configure
> make
> make install
> By the way, I installed GCL 2.4.0 on RedHat 7.0 in exactly this way.
> 



We could require that Maxima users must have RedHat 7.0, or some
  other standard Linux, but to tell people "you use Windows, you lose"
is probably a bad idea :)

There is another way of typesetting which can be set up, and works like 
this:  you come up with an expression you wish to display.  You open up 
a connection to a typesetting program on the internet.  Send the 
expression.  The typesetting program sends back a GIF.  This may seem 
crazy, but actually it exists, and I have been using it for experiments.
Look up MINSE and glyphd
http://web.lfw.org/math/

Perhaps it is significant that I have been connecting to MINSE from a 
lisp program..

It doesn't solve the problem of line-breaking, nor does it, at the 
moment, give feedback/ subexpression selection.  The author of MINSE is 
a grad student at Berkeley, and some other students have looked at it. 
Advantage:  you don't need TeX etc AT ALL on your computer.
Disadvantage: you need to be connected to the internet!

I am not particularly advocating this solution.  I imagine the best 
solution to be finding Schelter's old Texmacs equivalent, all in lisp, 
and see if that works and can do line-breaking etc. and use emacs21, 
when it works for display in windows as well as linux. But this is 
speculative.

I would expect that generating postscript directly from the Maxima
displa program would be easy, but I agree that doing "batch" ghostscript
is not ideal. And what could be done is take the back end of the 
ghostscript interpreter, the part that looks up font shapes and sprays 
bits on a screen, is the significant part:  if that exists in a machine 
independent form it represents a useful piece of the solution...

Regards,

RJF