axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Axiom-developer] steps towards better TeXmacs interface


From: root
Subject: Re: [Axiom-developer] steps towards better TeXmacs interface
Date: Fri, 26 Aug 2005 15:39:47 -0400

> 1. What is the correct file to put the definition and initialisation of 
>    $InterfaceStrings ?

choose a new file.

> 2. Is there some way in which this initialisation could be made dependent 
>  on external conditions? For example, can I pass a command-line argument to 
>  AXIOMsys, and check it in boot code? Or check an environment variable in 
>  the boot code?
>  At the moment, I know only one way to pass some information to axiom: 
>  .axiom.input. But it would not be a good idea for TeXmacs, for example, to 
>  overwrite the user's .axiom.input (if the user has one).

Generally when you want a certain special output mode in Axiom the technique
is to use
  )set output texmacs on
which sets a flag enabling the output.

> Making text exchanges between axiom and an external program to follow some 
> structured, predictable protocol (without playing guessing games) is the 
> first and the most important goal. But there are further necessary steps. 
> The current TeX generation (algebra/tex.spad.pamphlet) was written 15 
> years ago. Naturally, it does not produce modern standard LaTeX. I've made 
> a number of changes in tex.spad.pamphlet, to produce more 
> standards-complying LaTeX code instead of some historic relicts ( \over , 
> \sub , \root ... \of ... , etc.). But this is not exactly what's needed. 

It's "old-style" tex but still seems to work. The book uses it everywhere.
Why is it necessary to change it? Given the hundreds of things that need
work this is pretty low on my list but you're welcome to investigate what
might be needed. I believe that the line-break algorithm might be sensitive
to these tex symbols but memory fails me in the details.

> TeXmacs has some strange requirements of its own (e.g., using \* for 
> multiplication). Therefore, I want to leave the old TeX generation alone, 
> and to introduce the new kind of output: texmacs. So that it will be 
> possible to say
> )set output texmacs on

This would be the correct path. Then texmacs can adapt axiom to its needs.
Writing output delimiters could be transparent since they would not
normally be seen by users and can be removed by Texmacs

> OK, I can easily duplicate tex.spad.pamphlet (should this be a new file, 
> texmacs.spad.pamphlet, or I just double the contents of tex.spad.pamphlet 
> ?) I'll rename the domain TexFormat to TexmacsFormat, and make the 
> improvements I want. But what to do next? My (very incomplete...) 
> understanding is that I should insert the necessary pieces into 
> setvars.boot.pamphlet and setvart.boot.pamphlet (based on the TeX pieces, 
> with renamings and some small changes). But setvars.boot.pamphlet says 
> that if I change the boot code (and I'm going to do this), I have to 
> translate it to lisp and insert it into the same file. How do I do this, 
> exactly?

I wish I knew what needed to be done exactly but I haven't modified that
code in 15 years so your guess is nearly as good as mine. All I can suggest
is to experiment and document. Please document as you go so we don't have
to reverse engineer it a second time.

> The new domain TexmacsFormat is the natural place to put the line-breaking 
> functionality. Some ideas can be taken from the C code which does such 
> line-breaking, and which is available. Of course, it is much more natural 
> to do this in the spad domain, where all the information about the 
> expression structure is available. Also, this C code generates LaTeX which 
> gives a reasonably-looking output, but is mathematically meaningless (it 
> uses \array's all over the place for things which are not arrays). This 
> leads to the fact that, if this C code is used, it is absolutely 
> impossible (and never will be possible) to copy a (part of) output by the 
> mouse and insert in into an input field (because it is not possible to 
> reconstruct the mathematical meaning of an expression from this obfuscated 
> LaTeX). And this goal is highly desirable. Therefore, the aim of 
> TexmacsForm will be to generate a meaningful LaTeX, with line breaking, 
> which can be used as a source of drag-and-drop in TeXmacs.

I'm not sure what it means to "drag and drop" a 2D expression into a 1D
input line. Who flattens the line? I've never seen a specification of a
mapping from 1D <-> 2D. We do it all the time by hand, of course, but 
that's not good enough for a machine. Furthermore each Axiom domain
determines its own OutputForm representation (internal structure -> 2D).
The surface structure (print representation) might not carry all of
the needed information, most of which is hidden in the internal type.

> There is another possibility, which requires some thought. What if we send 
> expression tree from axiom to TeXmacs as an S-expression, instead of 
> serializing it via LaTeX? TeXmacs understands not only latex: fields, but 
> also scheme: fields. Generating scheme syntax from an axiom expression may 
> well be easier than generating LaTeX. Line breaking can be done on the 
> TeXmacs side, where the necessary information is available (it is in 
> principle impossible to tell, what is the width of a sub-expression after 
> typesetting, without actually typesetting it). But this is, probably, a 
> more long-term project. For now, I'd better keep as much as possible from 
> the current interface, but make it more robust and less ugly.

The notion of an S-expression form of an expression comes up a few times
a year. Axiom does not have such a notion. The closest you can come to
it (as far as I'm aware) is to:

===================================================================
FAQ 19: How can I get equations written on one line?
===================================================================

> Dear Axiom supporters,
> 2. I would also like to have the output of kind
> 
>  "  - (s-1) * (s+1) * (p^4 +(2*e^3 + (24*s^2 - 4)*e)*p^3 * ...) * ... 
>  "
> 
> For example, my DoCon program can read this format ...
> 
> 2.1 It prints these polynomials like for  (Z[e])[p]:  
>                                               " (e^2 + 2e)*p "
>     How to print it like for  Z[p,e]: 
>                                               " 2*p*e + e^2 "

You may wish to use the InputForm domain, where you can find some
bizarre functions. In your case, "unparse" may help you, as follows.

(1) -> p:=(a+b+y)^2*y+1-(x+y+z)^4

   (1)
        4               3        2             2  2
     - z  + (- 4y - 4x)z  + (- 6y  - 12x y - 6x )z
   + 
          3        2      2      3      4              3        2            2
     (- 4y  - 12x y  - 12x y - 4x )z - y  + (- 4x + 1)y  + (- 6x  + 2b + 2a)y
   + 
          3    2           2      4
     (- 4x  + b  + 2a b + a )y - x  + 1
                                                     Type: Polynomial Integer
(2) -> pi:=p::InputForm

  (2)
  (+
     (+
       (+  (+ (* - 1 (** z 4)) (* (+ (* - 4 y) (* - 4 x)) (** z 3)))
       (* (+ (+ (* - 6 (** y 2)) (* (* - 12 x) y)) (* - 6 (** x 2))) (** z 2)))

      (*
         (+
           (+  (+ (* - 4 (** y 3)) (* (* - 12 x) (** y 2)))
           (* (* - 12 (** x 2)) y))
          (* - 4 (** x 3)))
        z)
      )

    (+
       (+
         (+  (+ (* - 1 (** y 4)) (* (+ (* - 4 x) 1) (** y 3)))
         (* (+ (* - 6 (** x 2)) (+ (* 2 b) (* 2 a))) (** y 2)))
        (* (+ (* - 4 (** x 3)) (+ (+ (** b 2) (* (* 2 a) b)) (** a 2))) y))
      (+ (* - 1 (** x 4)) 1))
    )
                                                              Type: InputForm
(3) -> unparse(pi)

   (3)
  "(-z**4)+((-4*y)+(-4*x))*z**3+((-6*y*y)+(-12*x*y)+(-6*x*x))*z*z+((-4*y**3)+(-
  12*x*y*y)+(-12*x*x*y)+(-4*x**3))*z+(-y**4)+((-4*x)+1)*y**3+((-6*x*x)+2*b+2*a)
  *y*y+((-4*x**3)+b*b+2*a*b+a*a)*y+(-x**4)+1"
                                                                 Type: String


Aternatively you can get the LaTex output string:

(4) -> )lisp (|parseAndInterpret| "integrate(sin(x),x)::TexFormat::OutputForm")


   (4)  ["$$","-{\cos ","\left(","{x} ","\right)}","$$"]
                                                             Type: OutputForm
Value = ((|OutputForm|) WRAPPED BRACKET (AGGLST "\"$$\"" "\"-{\\cos \""
"\"\\left(\"" "\"{x} \"" "\"\\right)}\"" "\"$$\""))

or the text form:

(5) -> )lisp (|parseAndInterpret| "integrate(sin(x),x)::OutputForm")

   (5)  - cos(x)
                                                             Type: OutputForm
Value = ((|OutputForm|) WRAPPED "-" (|cos| |x|))

or the actual string output:

Axiom's algebra gets output to a stream called |$algebraOutputStream|
Thus you can get the output you want by:

)set message autoload off
)lisp (progn
          ; we need a new output stream that is backed by a string
        (setq tmpout (make-string-output-stream))
          ; we hold on to the regular algebra output stream
        (setq save |$algebraOutputStream|)
          ; we capture the algebra output into the string stream
        (setq |$algebraOutputStream| tmpout)
          ; we generate output from string input
        (|parseAndInterpret| "(x+1)^9")
          ; we save the output into the result variable
        (setq result (get-output-stream-string |$algebraOutputStream|))
          ; we restore the regular algebra output stream
        (setq |$algebraOutputStream| save)
          ; and we return the string as our value
        result)

)lisp result

result contains the output from axiom that you want.

===================================================================
FAQ 32: How can I input an equation as a string?
===================================================================

There is an embedded command server within AXIOMsys.
Look at:
http://daly.axiom-developer.org/TimothyDaly_files/lisptalk/pages/lisp35.html

In particular, see the function

  parseAndInterpret stringBuf

(which is boot language code. So in lisp I have
to tack on the | | onto the function name and then I can
call it like this:

  (1) -> )lisp (|parseAndInterpret| "integrate(sin x,x)")

   (1)  - cos(x)
                          Type: Union(Expression Integer,...)

  Value = ((|Union| (|Expression| (|Integer|)) (|List| (|Expression|
(|Integer|)))
  ) WRAPPED 0 (1 #<vector 10ccde54> (1 0 . -1)) 0 . 1)

  (2) ->

and sure enough! Axiom parses and interprets the string.

The result appears as stdout and the value returned
seems to contain the type information. The "WRAPPED"
information is the lisp data structure.

> The string output function mentioned in FAQ 19 is a linear
> form of the output. However Axiom's native output machinery
> is called CHARYBDIS which was a research project from the
> 60s with the goal of printing mathematics on typewriters.
> Axiom still uses that code.










reply via email to

[Prev in Thread] Current Thread [Next in Thread]