--- mathml.spad.pamphlet 2007-12-11 07:00:45.000000000 -0800 +++ mathml.spad.pamphlet.new 2007-12-16 08:16:28.000000000 -0800 @@ -25,14 +25,14 @@ At this time (2007-02-11) the package only has a presentation package. A content package is in the works however it is more difficult. Unfortunately Axiom does -not make its semantics easliy available. The \spadtype{OutputForm} +not make its semantics easily available. The \spadtype{OutputForm} domain mediates between the individual Axiom domains and the user visible output but \spadtype{OutputForm} does not provide full semantic information. From my currently incomplete understanding of Axiom it appears that remedying this would entail going back to the individual domains and rewriting a lot of code. However some semantics are conveyed directly by \spadtype{OutputForm} and other -things can be deduced from \spadtype{OutputForm} or form the original +things can be deduced from \spadtype{OutputForm} or from the original user command. \section{Displaying MathML} @@ -107,7 +107,7 @@ I don't know of any Axiom command that produces such an object. In fact at present I see the case of "SUPERSUB" being used for putting primes in the superscript position to denote ordinary differentiation. -I also only see the "SUB" case being only used to denote partial +I also only see the "SUB" case being used to denote partial derivatives. \section{)set output mathml on} @@ -116,7 +116,7 @@ Making mathml appear as output during a normal Axiom session by invoking ")set output mathml on" proved to be a bit tedious and seems to be undocumented. I document my experience here -in case in proves useful to somebody else trying to get a new +in case it proves useful to somebody else trying to get a new output format from Axiom. In \spadtype{MathMLFormat} the functions @@ -231,7 +231,7 @@ I don't see that this file is used anywhere but I made the appropriate changes anyway by searching for "TEX" and -mimicing everthing for MMLFORM. +mimicing everything for MMLFORM. \subsection{File src/doc/axiom.bib.pamphlet} @@ -285,14 +285,14 @@ The publicly exposed functions are: \spadfun{coerce: E -$>$ S} This function is the main one for converting -and expression in domain OutputForm into a MathML string. +an expression in domain OutputForm into a MathML string. \spadfun{coerceS: E -$>$ S} This function is for use from the command line. It converts an OutputForm expression into a MathML string and does some formatting so that the output is not one long line. If you take the output from this function, stick it in an emacs buffer in nxml-mode and then indent according to mode, you'll get something that's -nicer to look at than comes from coerce. Note that coerceS returns +nicer to look at than what comes from coerce. Note that coerceS returns the same value as coerce but invokes a display function as well so that the result will be printed twice in different formats. The need for this is that the output from coerce is automatically formatted with line breaks @@ -377,7 +377,7 @@ import List OutputForm import List String - -- local variables declarations and definitions + -- local variable declarations and definitions expr: E prec,opPrec: I @@ -884,6 +884,8 @@ formatSub(expr : E, args : L E, opPrec : I) : S == -- This one produces differential notation partial derivatives. + -- It doesn't work in all cases and may not be workable, use + -- formatSub1 below for now. -- At this time this is only to handle partial derivatives. -- If the SUB case handles anything else I'm not aware of it. -- This an example of the 4th partial of y(x,z) w.r.t. x,x,z,x @@ -1002,26 +1004,32 @@ s := s"(" i := 1 while i < #posLS+1 repeat - tmpS := stringify args.i +-- tmpS := stringify args.i + tmpS := formatMml(first args,minPrec) + args := rest args s := s""tmpS"" if i < #posLS then s := s"," i := i+1 s := s")" - formatSuperSub1(expr : E, args : L E, opPrec : I) : S == - -- this produces differential notation ordinary derivatives. + formatSuperSub(expr : E, args : L E, opPrec : I) : S == + -- this produces prime notation ordinary derivatives. -- first have to divine the semantics, add cases as needed + WriteLine$Lisp "SuperSub1 begin" atomE : L E := atomize(expr) op : S := stringify first atomE - op ^= "SUPERSUB" => "Mistake in formatSuperSub: no SUPERSUB" - #args ^= 1 => "Mistake in SuperSub: #args <> 1" + WriteLine$Lisp "op: "op + op ^= "SUPERSUB" => "Mistake in formatSuperSub: no SUPERSUB1" + #args ^= 1 => "Mistake in SuperSub1: #args <> 1" var : E := first args -- should be looking at something like {{SUPERSUB}{var}{ }{,,...,}} for -- example here's the second derivative of y w.r.t. x -- {{{SUPERSUB}{y}{ }{,,}}{x}}, expr is the first {} and args is the -- {x} funcS : S := stringify first rest atomE + WriteLine$Lisp "funcS: "funcS bvarS : S := stringify first args + WriteLine$Lisp "bvarS: "bvarS -- count the number of commas commaS : S := stringify first rest rest rest atomE commaTest : S := "," @@ -1030,15 +1038,18 @@ i := i+1 commaTest := commaTest"," s : S := ""funcS"" + WriteLine$Lisp "s: "s j : I := 0 while j < i repeat s := s"" j := j + 1 - s := s"("bvarS")" + s := s"("formatMml(first args,minPrec)")" - formatSuperSub(expr : E, args : L E, opPrec : I) : S == - -- This one produces ordinary derivatives with prime notation. + formatSuperSub1(expr : E, args : L E, opPrec : I) : S == + -- This one produces ordinary derivatives with differential notation, + -- it needs a little more work yet. -- first have to divine the semantics, add cases as needed + WriteLine$Lisp "SuperSub begin" atomE : L E := atomize(expr) op : S := stringify first atomE op ^= "SUPERSUB" => "Mistake in formatSuperSub: no SUPERSUB" @@ -1057,7 +1068,7 @@ while position(commaTest,commaS,1) > 0 repeat ndiffs := ndiffs+1 commaTest := commaTest"," - s : S := ""string(ndiffs)""funcS""bvarS""string(ndiffs)"("bvarS")" + s : S := ""string(ndiffs)""funcS""formatMml(first args,minPrec)""string(ndiffs)"("formatMml(first args,minPrec)")" formatPlex(op : S, args : L E, prec : I) : S == hold : S @@ -1191,15 +1202,31 @@ null args => "" p : I := position(op,naryOps) p < 1 => error "unknown nary op" - -- need to test for "ZAG" case and divert it here, here's an - -- example including "op", the args list would be the rest of this + -- need to test for "ZAG" case and divert it here + -- ex 1. continuedFraction(314159/100000) -- {{+}{3}{{ZAG}{1}{7}}{{ZAG}{1}{15}}{{ZAG}{1}{1}}{{ZAG}{1}{25}} -- {{ZAG}{1}{1}}{{ZAG}{1}{7}}{{ZAG}{1}{4}}} - -- The first arg, the "3" in this case, could be a "ZAG" or something + -- this is the preconditioned output form + -- including "op", the args list would be the rest of this + -- i.e op = '+' and args = {{3}{{ZAG}{1}{7}}{{ZAG}{1}{15}} + -- {{ZAG}{1}{1}}{{ZAG}{1}{25}}{{ZAG}{1}{1}}{{ZAG}{1}{7}}{{ZAG}{1}{4}}} + -- ex 2. continuedFraction(14159/100000) + -- this one doesn't have the leading integer + -- {{+}{{ZAG}{1}{7}}{{ZAG}{1}{15}}{{ZAG}{1}{1}}{{ZAG}{1}{25}} + -- {{ZAG}{1}{1}}{{ZAG}{1}{7}}{{ZAG}{1}{4}}} + -- + -- ex 3. continuedFraction(3,repeating [1], repeating [3,6]) + -- {{+}{3}{{ZAG}{1}{3}}{{ZAG}{1}{6}}{{ZAG}{1}{3}}{{ZAG}{1}{6}} + -- {{ZAG}{1}{3}}{{ZAG}{1}{6}}{{ZAG}{1}{3}}{{ZAG}{1}{6}} + -- {{ZAG}{1}{3}}{{ZAG}{1}{6}}{...}} + -- In each of these examples the args list consists of the terms + -- following the '+' op + -- so the first arg could be a "ZAG" or something -- else, but the second arg looks like it has to be "ZAG", so maybe - -- test for #args > 1 and args.2 is "ZAG". - -- This test should work so long as axiom doesn't try to evaluate - -- the second half of the "and" when the first half is false. + -- test for #args > 1 and args.2 contains "ZAG". + -- Note that since the resulting MathML s are nested we need + -- to handle the whole continued fraction at once, i.e. we can't + -- just look for, e.g., {{ZAG}{1}{6}} (#args > 1) and (position("ZAG",stringify first rest args,1) > 0) => tmpS : S := stringify first args position("ZAG",tmpS,1) > 0 => formatZag(args) @@ -1224,11 +1251,17 @@ s formatZag(args : L E) : S == - -- {{ZAG}{1}{7}} + -- args will be a list of things like this {{ZAG}{1}{7}}, the ZAG + -- must be there, the '1' and '7' could conceivably be more complex + -- expressions tmpZag : L E := first args pretend L E + -- may want to test that tmpZag contains 'ZAG' #args > 1 => ""formatMml(first rest tmpZag,minPrec)""formatMml(first rest rest tmpZag,minPrec)"+"formatZag(rest args)"" - ""formatMml(first rest tmpZag,minPrec)formatMml(first rest rest tmpZag,minPrec)"" - + (first args = "..."::E)@Boolean => "" + position("ZAG",stringify first args,1) > 0 => + ""formatMml(first rest tmpZag,minPrec)formatMml(first rest rest tmpZag,minPrec)"" + "formatZag: Unexpected kind of ZAG" + formatZag1(args : L E) : S == -- make alternative ZAG format without diminishing fonts, maybe -- use a table @@ -1285,12 +1318,23 @@ -- where it arises. Removed 2007-02-14 concat(concat("",str),"") -- if we get to here does that mean it's a variable? + -- test for something like #\A and strip off #\ + str.1 = char "#" and str.2 = char "\" => + u : US := segment(3,len)$US + concat ["",str.u,""] concat ["",str,""] l : L E := (expr pretend L E) null l => blank op : S := stringify first l args : L E := rest l nargs : I := #args + -- need to test here in case first l is SUPERSUB case and then + -- pass first l and args to formatSuperSub. + position("SUPERSUB",op,1) > 0 => + formatSuperSub(first l,args,minPrec) + -- now test for SUB + position("SUB",op,1) > 0 => + formatSub1(first l,args,minPrec) -- special cases member?(op, specialOps) => formatSpecial(op,args,prec) @@ -1310,13 +1354,6 @@ -- nary case member?(op,naryNGOps) => formatNaryNoGroup(op,args, prec) member?(op,naryOps) => formatNary(op,args, prec) - -- need to test here in case first l is SUPERSUB case and then - -- pass first l and args to formatSuperSub. - position("SUPERSUB",op,1) > 0 => - formatSuperSub(first l,args,minPrec) - -- now test for SUB - position("SUB",op,1) > 0 => - formatSub(first l,args,minPrec) op := formatMml(first l,minPrec) formatFunction(op,args,prec)