1This directory contains the version of the SML implementation of 2TeX Maths Layout algorithms. It has been updated to allow for changes 3to the specification of SML from '90 to '97. 4 5Further to the minimal changes needed to work with SML-97 there are 6two sorts of change here. One is a collection of upgrades worked on 7by Zach Hauser that implement support for accents, delimiters and 8radicals. The second are some basically grotty cganges made by ACN that 9re-work this code to use less of the "clever" features of SML. Specifically 10the plan is to avoid use of ML modules (ie signatures and structures). To 11avoid higher order functions as much as reasonably possible, and to use 12function definitions with a definite number of arguments in place of 13curried ones. The motivation for these changes is to make mapping the 14SML code onto other languages easier. 15(1) The signature/structure scheme protects name-spaces and helps keep the 16 code modular. But the code here is only around 2500 lines long anyway 17 and that is not large enough to run terrible risks of name clashes. 18 Getting rid of the modules avoids the need to support the module-style 19 namespace protection in any re-write. I observe that there are only 20 a very few clashes anyway. Ha ha - when one removes the module stuff 21 you end up with only 1500 lines of code! 22(2) There seem to be remarkably few uses of higher order functions in the 23 original code. The only uses of FOLD are in a prologue. There are only 24 half a dozen uses of map. Cleaning them away does not do much damage 25 to the code structure and avoids need for full support for static 26 scoping of synamic variables and worries about closures in a translation. 27(3) Most of the functions in the original are defined as Curried but are 28 never partially applied. There are a number of cases where this is not 29 so, but merely making the extra arguments explicit sorts that out 30 rather easily. As with the other changes this will ease translation. 31 Making the change is a mess, but the SML type-checker can ensure that 32 I do not end up messing things up! Hmmm - on further thought this is not 33 necessary - in any translation I can treat "f x y" as if it has been 34 "f(x,y)" and so provided no partial application is used all will be well. 35 And any partial application would show up as functions being called with 36 the wrong number of args - an easy case to spot. 37 The original code contains a number of cases of 38 fun F x y = ...; 39 val G = F X; 40 that I can turn into 41 fun G y = F X y; 42 without significant loss of clarity, and I should make that conversion. 43(4) There was one instance of a use of an "infix" directive, which is used 44 with purely local scope and was easy to remove. 45(5) I would probably like to end up with symbol names all distinct even if 46 handled in a case-insensitive manner. 47 48 49Thanks are due to Heckmann and Wilhelm for this code. 50 51 ACN February 2015 52 June 2016 53 54 55 56 57 58===================================================================== 59The following exchanges of emails confirm permission to make use of the 60files here. 61 62 63 64From heckmann@absint.com Thu Apr 15 17:25:43 2010 65Date: Thu, 15 Apr 2010 18:25:14 +0200 66From: Reinhold Heckmann <heckmann@absint.com> 67To: Arthur Norman <acn1@cam.ac.uk> 68Cc: wilhelm@cs.uni-sb.de 69Subject: Re: TeX in SML from around 1997 70 71Arthur Norman wrote: 72> Hi! I have just come across that paper and so let me start by saying 73> what fun it is. 74That's nice to hear. 75 76> I had been considering what would be involved with 77> re-creating exactly the formula layout that TeX uses for display of 78> formulae for the Reduce algebra system (check reduce-algebra at 79> Sourceforge). At present the way I display formula there is to use code 80> that maps Reduce onto TeX-format textual stuff like $\int \sqrt ...$, I 81> pass that to some C++ code that I wrote that instantly turns it back 82> from textual form into an internal representation, then box structures. 83> I then have code that paints direct from the boxes on the screen. I use 84> cmr10, cmmi10, cmsy10 and cmex10 when painting. But I do not use any 85> code from TeX itself and the exact layout and spacing I have is my own 86> thoughtless code - it is a maths display but purists fuss that it is not 87> as good as it should be... specifically that TeX gets the spacing a lot 88> better! 89 90Parts of this can be usefully combined with our layouter, I think. 91We never created a parser from $\int \sqrt ...$ to SML terms. 92On the other side, I programmed a translator from box terms to dvi, 93but painting the box terms directly may also be useful. 94 95> I might also add that a few years ago I taight the SML course at 96> Cambridge - Larry Paulson has been doing that for a while, but I gave it 97> before im and stood in for him a few years back when he went on leave. 98> 99> There are three ways your work really encourages me - one is that SML 100> code is so much nicer than the Web/Pascal TeX original. The second is 101> that you concentrate on just the maths mode layout, and for my purposes 102> at present I do not care about the rest! And finally your code 103> demonstrates that the guts of the TeX maths layout stuff can fit in 104> under 2500 lines of code (albeit SML - a *NOTABLY* concise language) and 105> that is a nice size body of code to work on individually or with one or 106> two friends... it is feasible to look at. 107 108> OK, so after the above introduction, a couple of questions: 109> 110> (1) I have fetched your code from the ftp server as mentioned in your 111> paper. It does not have any explicit license terms attached. In a spirit 112> of caution before I look much further I should ask your permission to 113> use the code you have, hack at it, use it as a basis for other 114> experiments etc etc... if anything derived from it weher to end up in 115> Reduce I note that we have the rest of Reduce under the 2-clause BSD 116> license (which in effect says "do what you like with this, but you may 117> not blame me if it bits you"), so I should explicitly check your 118> reaction to using it in that context. 119 120For my part, I think you can use it since I stopped working with it long ago. 121 122> (2) The things you list as incomplete in the version in the FTP server 123> are (a) radicals such as \sqrt (b) huge delimiters built up out of 124> towers and (c) accented symbols. I guess also a box that embeds 125> text-mode TeX inside a formula could also go beyond your scope! I 126> presume that you stopped work on the project soon after the paper and 127> that you do not have a version that is more complete, but I ought to ask! 128 129Yes, that's true. 130 131> And do you believe that the things that need finishing off 132> introduce real new serious issues or do you view them as just "more of 133> the same"? Any hints or advice there would be interesting. 134 135I think (b) and (c) are more of the same. 136\sqrt might be a bit more tricky since the V-like part of it varies in size 137according to the size of the argument, 138and has to fit exactly to the overline-like part. 139 140What we did to derive our SML code was to study Knuth's TeX book 141and to translate the Pascal code to SML, applying the simplifications 142offered by this more powerful language. 143So you should look at Knuth's implementation of \sqrt and translate it, too. 144 145> I do not know if I will find the energy or time to make serious use of 146> your work to replace or improve the layout of my display, but you can 147> probably see why it interests me! 148 149> I am sending this email in the immediate run up to Easter (so Happy 150> Easter!), and I will then be away from Cambridge and email for around a 151> fortnight, so do not need an instant response... And at this stage I 152> have downloaded your code and read the paper and a few lines of the code 153> itself, but e.g. not tried it... this message is so I know where I am 154> before I invest real time... 155 156I was also away a few days ... 157 158Best wishes for your work 159Reinhold Heckmann 160 161From wilhelm@gigasun.cs.uni-sb.de Thu Apr 15 17:38:26 2010 162Date: Thu, 15 Apr 2010 18:38:21 +0200 (CEST) 163From: wilhelm@gigasun.cs.uni-sb.de 164To: Reinhold Heckmann <heckmann@absint.com> 165Cc: Arthur Norman <acn1@cam.ac.uk>, wilhelm@cs.uni-sb.de 166Subject: Re: TeX in SML from around 1997 167 168Hi, 169I also agree to you using the code without formal license agreement. 170It would be nice, though, if you would acknowledge the paper and the 171origin of the SML code if you extend it and integrate it somewhere. 172 173Cheers, Reinhard Wilhelm 174 175 176 177===================================================================== 178 179 180This directory contains a re-implementation of TeX's formula layout 181written in Standard ML of New Jersey, version 109.2 182by Reinhold Heckmann, Universitaet des Saarlandes, 183following suggestions by Reinhard Wilhelm, Universitaet des Saarlandes. 184 185WARNING: The system is still in the status of development. 186------- This distribution may contain errors of any kind. 187 188The present system can typeset nearly all formulae 189by translating them from formula terms (see MathTypes.sml) 190into box terms (see BoxTypes.sml). 191The only exceptions are accents, roots, and big delimiters. 192The resulting box terms can be translated into dvi output. 193At present, there is no good way to enter formulae; 194a parser is needed which can read TeX input and build formula terms from it. 195Also, the testing possibilities and user friendliness 196are not yet well developed. 197 198To install: 199 get formulae.tar.gz 200 zcat formulae.tar.gz | tar -xf - 201This gives a directory called `formulae'. 202Go into this directory. 203Start sml (best: Standard ML of New Jersey, version 109.2). 204 use "edit.m"; 205 U "all"; 206... and everything is read in and translated (hopefully). 207 208At the moment, the system provides two test functions (see test.sml) 209 test1, test2: unit -> unit 210which, when executed, typeset certain fixed formulae, 211translate them to dvi and write them into file "das.dvi". 212(Sorry, this file name is built in.) 213As an example, the distributed system contains 214the file "das.dvi" resulting from running test1. 215It also contains a TeX file "dastex.tex" which contains the formulae 216of test2 to allow comparing TeX layout with our system's layout. 217More tests can be programmed by editing or augmenting file "test.sml". 218 219The typesetting system itself is contained in files "----.sml". 220For a rough description of their organization, see file "OVERVIEW". 221In addition, there are files RM05 ... RM10 MI05 ... MI10 SY05 ... SY10 EX09 EX10 222which contain condensed font information (height, depth, and width of characters). 223These files have been derived from TeX's TFM files. 224 225File "edit.m" contains functions which provide access to the Unix editor "vi" 226from within sml. 227 E "xxx"; 228runs the editor on file "xxx.sml" (note the addition of the suffix). 229After leaving the editor, the file is reloaded 230if there have been any changes to it. 231A call 232 U "xxx"; 233loads file "xxx.sml" without editing. 234Both functions store the file name internally; 235if the same file is to be edited / loaded again, 236it suffices to call 237 E ""; 238and likewise with U. 239 240File "all.sml" contains a sequence of U's 241which load the files containing the system in their proper order. 242(Sorry, there is no "make" or any other kind of source code management.) 243 244Documentation: 245The core system is described in the paper 246"A Functional Description of TeX's Formula Layout" 247submitted to Journal of Functional Programming. 248Unfortunately, there is no documentation of the usage of the system 249other than the remarks in this file 250(mainly because we have not yet implemented a nice user interface). 251