On 2016-12-10, Qian Hong <fract...@gmail.com> wrote: > No, this is not automatically enough, I'm looking for an automatic way > rather than manually rewriting every expressions. In other words, I'm > looking for something like 100k lines of sage expression samples, and > then automatically generate 100k latex expressions and 100k images. > Thank you for point out the relevant code, I'll start from there!
For what it's worth, if it's OK to use Maxima instead of Sage, you can create a function which prevents evaluation and simplification of expressions and then get TeX output for them. If you need only to parse the input and generate the output (no mathematical operations) maybe that's enough. I've appended superq.lisp which implements "super" quoting. Here's an example of how it could be used. foo.input contains expressions terminated by semicolons. s : openr ("/tmp/foo.input"); l : []; while (e : read_superq (s)) # false do push (e, l); map (tex, reverse (l)); Um, I guess another line of Lisp code is needed before you do that. :lisp (defun $read_superq (s) (let ((e (mread s))) (if e (list '($superq) (third e))))) Maxima has a simple-minded representation of expressions which is just ((FOO) X Y Z) to represent foo(x, y, z) or x foo y foo z. Maybe this is something that could be exploited to see if expressions generated from images are the same as expected. As to getting 100k examples, maybe you can generate expressions by choosing an operator and arguments at random. I can help with that if you want. Hope this helps in some way. If you want to go down this road I'll be happy to answer any questions. Robert Dodier PS. ;; superq.lisp -- "super" quoting for Maxima ;; Copyright 2008 by Robert Dodier ;; I release this work under the terms of the GNU General Public License ;; Examples: ;; load (superq); ;; '(1 + 1); ;; => 2 ;; superq (1 + 1); ;; => superq(1 + 1) ;; '(5!); ;; => 120 ;; superq (5!); ;; => superq(5!) ;; '(sin (0)); ;; => 0 ;; superq (sin (0)); ;; => superq(sin(0)) ;; '('diff (x, x, 1)); ;; => 1 ;; superq('diff (x, x, 1)); ;; => superq('diff(x,x,1)) ;; tex ('(1 + 1)); ;; => $$2$$ ;; tex (superq (1 + 1)); ;; => $$1+1$$ ;; tex ('(5!)); ;; => $$120$$ ;; tex (superq (5!)); ;; => $$5!$$ ;; tex ('(sin (0))); ;; => $$0$$ ;; tex (superq (sin (0))); ;; => $$\sin 0$$ ;; tex ('('diff (x, x, 1))); ;; => $$1$$ ;; tex (superq('diff (x, x, 1))); ;; => $${{d}\over{d\,x}}\,x$$ (defmspec $superq (e) e) (defun simp-$superq (x y z) (declare (ignore y z)) x) (setf (get '$superq 'operators) 'simp-$superq) (defun tex-$superq (x l r) (tex (second x) l r 'mparen 'mparen)) (setf (get '$superq 'tex) 'tex-$superq) -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.