#lang scheme/base (require "mfile.ss" scheme/system) (provide dvi->png ;; indexer dvi->pngs ;; all as list dvi->pdf tex->dvi texinputs) ;; Example of how to use mfile to call external programs in a temp ;; directory and collect the results. ;; (define texinputs (make-parameter ".:~/papers:")) (define texinputs (make-parameter ".:")) ;; External command wrappers. (define (fsystem . args) (let ((cmd (apply format args))) (printf "> ~a\n" cmd) (system cmd))) (define (latex tex [latex-path (texinputs)]) (define (cmd) (fsystem "TEXINPUTS=~s latex -interaction=batchmode ~s" latex-path tex)) (cmd) (cmd)) ;; run twice to resolve forward refs. (define dpi 120) (define (dvipng dvi png n) (fsystem "dvipng ~s -o ~s -T tight -D ~s -l ~a -p ~a" dvi png dpi n n)) (define (dvipngs dvi [fmt "%04d.png"]) (fsystem "dvipng ~s -o ~s -T tight -D ~s" dvi fmt dpi)) ;; TODO: This still uses implicit output names. If all filenames are ;; made explicit, they can be abstracted away. ;; Filesystem wrapping (define (tex->dvi mfile) (mdir-refs (with-mdir `(("doc.tex" . ,mfile)) (lambda () (latex "doc.tex"))) "doc.dvi")) (define (dvi->pdf mfile) (mdir-refs (with-mdir `(("doc.dvi" . ,mfile)) (lambda () (system "dvipdf doc.dvi"))) "doc.pdf")) (define (dvi->png mfile n) (mdir-refs (with-mdir `(("doc.dvi" . ,mfile)) (lambda () (dvipng "doc.dvi" "page.png" n))) "page.png")) (define (dvi->pngs mfile) (mdir-sorted (with-mdir `(("doc.dvi" . ,mfile)) (lambda () (dvipngs "doc.dvi"))))) ;; Example ; (define paper (make-mfile "/tmp/test.tex")) ; (define dvi (parameterize ((texinputs ".:~/papers:")) (tex->dvi paper))) ;; (define (page n) (dvi->png dvi n))