[plt-scheme] Using texpict or mrpict

From: Paulo J. Matos (pocm at soton.ac.uk)
Date: Fri Nov 3 12:24:34 EST 2006

Sorry all for the delay on this but I had in the meantime a trip to
Portugal where I'll spend my weekend.

Here's the current code (I'll be updating this to send to Planet):

(module lt mzscheme

  (require (lib "utils.ss" "texpict")
           (lib "file.ss"))

  (define tex2im-path (make-parameter "/usr/bin/tex2im"))

  (define (latex-formula text size)
    ;; Returns path to the temporary latex image
    (let* ([tmp-file-path-tex (path->string (make-temporary-file))]
           [tmp-file-path-png (string-append tmp-file-path-tex ".png")]
           [fp (open-output-file tmp-file-path-tex 'text 'replace)])
      (fprintf fp text) ; writing tex file
      (close-output-port fp)
      (let-values
          ([(tex2im-proc stdout stdin stderr) (subprocess #f #f #f
(tex2im-path) "-z" "-a" "-r" size "-o" tmp-file-path-png
tmp-file-path-tex)])
        (subprocess-wait tex2im-proc))
      (if (not (file-exists? tmp-file-path-png))
          (raise '(displayer-image-not-found))
          tmp-file-path-png)))

  (define xxs "75x75")
  (define xs "100x100")
  (define s "150x150")
  (define m "300x300")
  (define l "350x350")
  (define xl "400x400")
  (define xxl "415x415")

  (define (lt text size)
    (bitmap (latex-formula text size)))

  (define (lt-xxs text) (lt text xxs))
  (define (lt-xs text) (lt text xs))
  (define (lt-s text) (lt text s))
  (define (lt-m text) (lt text m))
  (define (lt-l text) (lt text l))
  (define (lt-xl text) (lt text xl))
  (define (lt-xxl text) (lt text xxl))

  (provide lt lt-xxs lt-xs lt-s lt-m lt-l lt-xl lt-xxl)
  )

One thing I currently don't like is how it is handling resolution and
the lack of docs, but I'll handle that in the next few days. Well,
briefly lt* functions will return a bitmap with the text given as
argument (the text as argument should be latex code usable inside the
displaymath env). The different suffixes have to do with the different
resolutions.

Soon you'll hear more on this.

Regards,
-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK


Posted on the users mailing list.