[plt-scheme] In-line LaTeX in REPL

From: Greg Woodhouse (gregory.woodhouse at gmail.com)
Date: Tue Dec 2 18:43:32 EST 2008

I like it. To be honest, I use TeXShop and don't generally deal with
command-line utilities, but that's okay. There is a manual. :)

Right now, I'm working on a matrix algebra module, and I'd like to be able
to work with rings of polynomials, exponential polynomials and so forth, but
it would be nice to display the output to the the user in some
comprehensible format. For now, I'm thinking about just displaying
unprocessed LaTeX and worrying about typesetting later.

On Tue, Dec 2, 2008 at 3:21 PM, Anthony Cowley <acowley at seas.upenn.edu>wrote:

> Here's a version of Mark's code that does the processing locally. It
> needs some attention regarding the system calls depending on your
> setup, as it calls pdflatex and convert (ImageMagick) as well as
> creates a couple temporary files.
>
> ;;; Create an image snip object from a latex equation.
> ;;; Technique from
> http://dererumnatura.us/archives/2008/02/rendering-equat-1.html
> #lang scheme
> (require scheme/system)
> (require scheme/gui/base)
> (define latex
>  (let ((template-head (string-join  '("\\documentclass{article}"
>                                       "\\usepackage{amsmath}"
>                                       "\\pagestyle{empty}"
>                                       "\\begin{document}"
>                                       "\\Huge"
>                                       "\\[")
>                                     "~n"))
>        (template-foot (string-join '("\\]"
>                                      "\\end{document}")
>                                    "~n")))
>    (lambda (str)
>      (call-with-output-file "/tmp/latex.tex"
>        (lambda (f) (fprintf f (string-join (list template-head str
> template-foot) "~n")))
>        #:mode 'text
>        #:exists 'replace)
>      (system "PATH=/sw/bin:$PATH pdflatex -output-directory /tmp
> latex.tex > /dev/null")
>      (system "PATH=/sw/bin:$PATH convert /tmp/latex.pdf -trim +repage
> /tmp/latex.png")
>      (make-object image-snip% "/tmp/latex.png"))))
>
> ;; Example
> ; (latex "\\sum_{i=0}^{\\infty}\\lambda_i")
>
> Anthony
>
> On Tue, Dec 2, 2008 at 4:32 PM, Mark Engelberg <mark.engelberg at gmail.com>
> wrote:
> > BTW, my code looks like this:
> > #lang scheme
> > (require scheme/system)
> > (require scheme/gui/base)
> > (define (latex str)
> >  (let ([escaped-str (regexp-replace* #rx" " str "%20")])
> >    (system (format "C:\\temp\\curl
> > \"http://www.codecogs.com/eq.latex?~a\" -o C:\\temp\\latex.gif"
> > escaped-str))
> >    (make-object image-snip% "c:\\temp\\latex.gif")))
> >
> > I keep the curl executable in my temp directory.
> >
> > So you can do something like (latex "3 \\geq 2") and it will produce
> > the latex output for that.
> >
> > While it's downloading the latex gif, the repl displays a read input
> > box.  I'm not sure how to suppress that.
>  > _________________________________________________
> >  For list-related administrative tasks:
> >  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20081202/9c6f1686/attachment.html>

Posted on the users mailing list.