add the --dvipdf flag to scribble
This adds a new back-end pipeline for generating pdf to scribble, with the hope that included picts (e.g., those generated by Redex) will look better when viewed with on-screen pdf viewers Current problem: the descent adjustment is messed up, as can be seen by this example program's output: #lang scribble/base @(require redex/pict pict redex/reduction-semantics) @title{} @(define-language L (e ::= (e e) x (λ (x) e))) @(render-language L) ff@(text "f" '(italic . roman) 20)ff x@(text "x")y@(text "y") original commit: 5280395f8802d21764ef074540421441cb8ac999
This commit is contained in:
parent
adc82b0c67
commit
1afd6c802a
|
@ -35,6 +35,9 @@ its file suffix:
|
|||
@item{@DFlag{pdf} --- PDF @filepath{@|fn|.pdf} that is generated
|
||||
via @exec{pdflatex}}
|
||||
|
||||
@item{@DFlag{dvipdf} --- PDF @filepath{@|fn|.pdf} that is generated
|
||||
via @exec{latex} and @exec{dvipdf}}
|
||||
|
||||
@item{@DFlag{latex-section} @nonterm{n} --- LaTeX source
|
||||
@filepath{@|fn|.tex} plus additional @filepath{.tex} files to
|
||||
be included in the enclosing document's preamble, where the
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
(define-runtime-path skull-tex "scribble-skull.tex")
|
||||
(define skull-style (make-style #f (list (tex-addition skull-tex))))
|
||||
|
||||
(define (render-mixin %)
|
||||
(define (render-mixin % #:convert-as-ps-not-pdf? [convert-as-ps-not-pdf? #t])
|
||||
(class %
|
||||
(inherit-field prefix-file style-file style-extra-files)
|
||||
|
||||
|
@ -355,10 +355,14 @@
|
|||
(not (disable-images))
|
||||
(let ([ftag (lambda (v suffix) (and v (list v suffix)))]
|
||||
[xlist (lambda (v) (and v (list v #f #f #f #f)))])
|
||||
(or (ftag (convert e 'pdf-bytes+bounds) ".pdf")
|
||||
(ftag (xlist (convert e 'pdf-bytes)) ".pdf")
|
||||
(ftag (xlist (convert e 'eps-bytes)) ".ps")
|
||||
(ftag (xlist (convert e 'png-bytes)) ".png"))))
|
||||
(if convert-as-ps-not-pdf?
|
||||
(or (ftag (convert e 'eps-bytes+bounds) ".ps")
|
||||
(ftag (xlist (convert e 'eps-bytes)) ".ps")
|
||||
(ftag (xlist (convert e 'png-bytes)) ".png"))
|
||||
(or (ftag (convert e 'pdf-bytes+bounds) ".pdf")
|
||||
(ftag (xlist (convert e 'pdf-bytes)) ".pdf")
|
||||
(ftag (xlist (convert e 'eps-bytes)) ".ps")
|
||||
(ftag (xlist (convert e 'png-bytes)) ".png")))))
|
||||
=> (lambda (bstr+info+suffix)
|
||||
(check-render)
|
||||
(let* ([bstr (list-ref (list-ref bstr+info+suffix 0) 0)]
|
||||
|
|
|
@ -3,8 +3,15 @@
|
|||
(require "private/indirect-renderer.rkt" "private/run-pdflatex.rkt"
|
||||
(prefix-in latex: "latex-render.rkt"))
|
||||
|
||||
(provide render-mixin)
|
||||
(provide render-mixin
|
||||
dvi-render-mixin)
|
||||
|
||||
(define render-mixin
|
||||
(make-indirect-renderer-mixin
|
||||
latex:render-mixin #".tex" #".pdf" run-pdflatex))
|
||||
latex:render-mixin #".tex" #".pdf"
|
||||
run-pdflatex))
|
||||
|
||||
(define dvi-render-mixin
|
||||
(make-indirect-renderer-mixin
|
||||
(λ (%) (latex:render-mixin % #:convert-as-ps-not-pdf? #t)) #".tex" #".pdf"
|
||||
run-dvipdf-latex))
|
||||
|
|
|
@ -2,11 +2,18 @@
|
|||
|
||||
(require scheme/system scheme/port)
|
||||
|
||||
(provide run-pdflatex)
|
||||
(provide run-pdflatex run-dvipdf-latex)
|
||||
|
||||
(define (run-pdflatex file [notify void])
|
||||
(define (run-pdflatex file [notify void]) (run file notify #f))
|
||||
(define (run-dvipdf-latex file [notify void])
|
||||
(parameterize ([function-name 'run-dvipdf-latex])
|
||||
(run file notify #t)))
|
||||
|
||||
(define max-runs 5)
|
||||
(define (run file notify via-dvipdf?)
|
||||
(define latex-cmd-name (if via-dvipdf? "latex" "pdflatex"))
|
||||
(define cmd
|
||||
(list (get-pdflatex-binary)
|
||||
(list (get-latex-binary latex-cmd-name)
|
||||
"-interaction=batchmode"
|
||||
(format "~a" file)))
|
||||
(define logfile (path-replace-suffix file #".log"))
|
||||
|
@ -19,13 +26,13 @@
|
|||
(lambda (log) (copy-port log (current-error-port))))
|
||||
(err "got error exit code")))
|
||||
(let loop ([n 0])
|
||||
(when (= n 5)
|
||||
(when (= n max-runs)
|
||||
(err "didn't get a stable result after ~a runs" n))
|
||||
(if (zero? n)
|
||||
(notify "running pdflatex on ~a" file)
|
||||
(notify "running ~a on ~a" latex-cmd-name file)
|
||||
(notify " running ~a~a time"
|
||||
(add1 n)
|
||||
(case (add1 n) [(2) 'nd] [(3) 'rd] [else 'th])))
|
||||
(case (normalize-for-suffix (add1 n)) [(2) 'nd] [(3) 'rd] [else 'th])))
|
||||
(run)
|
||||
;; see if we get a "Rerun" note, these seem to come in two flavors
|
||||
;; * Label(s) may have changed. Rerun to get cross-references right.
|
||||
|
@ -36,27 +43,43 @@
|
|||
[(zero? n)
|
||||
(notify "WARNING: no \"Rerun\" found in first run of pdflatex for ~a"
|
||||
file)]))
|
||||
(when via-dvipdf?
|
||||
(define dvi-file (path-replace-suffix file #".dvi"))
|
||||
(unless (file-exists? dvi-file) (err "didn't find .dvi file"))
|
||||
(define dvipdf (get-latex-binary "dvipdf"))
|
||||
(notify "running dvipdf on ~a" dvi-file)
|
||||
(unless (parameterize ([current-output-port (open-output-nowhere)])
|
||||
(system* dvipdf dvi-file))
|
||||
(err "got error exit code")))
|
||||
(path-replace-suffix file #".pdf"))
|
||||
|
||||
(define (get-pdflatex-binary)
|
||||
(define (normalize-for-suffix n)
|
||||
(cond
|
||||
[(<= 10 n 20) 0]
|
||||
[else (modulo n 10)]))
|
||||
|
||||
(define (get-latex-binary name)
|
||||
(define ans
|
||||
(case (system-type)
|
||||
[(macosx) (or (find-executable-path "pdflatex")
|
||||
(for/or ([macosx-candidate (in-list macosx-candidates)])
|
||||
[(macosx) (or (find-executable-path name)
|
||||
(for/or ([macosx-candidate-dir (in-list macosx-candidate-dirs)])
|
||||
(define macosx-candidate (build-path macosx-candidate-dir name))
|
||||
(and (file-exists? macosx-candidate)
|
||||
macosx-candidate)))]
|
||||
[(windows) (or (find-executable-path "pdflatex")
|
||||
(find-executable-path "pdflatex.exe"))]
|
||||
[(unix) (find-executable-path "pdflatex")]))
|
||||
[(windows) (or (find-executable-path name)
|
||||
(find-executable-path (format "~a.exe" name)))]
|
||||
[(unix) (find-executable-path name)]))
|
||||
(unless ans
|
||||
(err "could not find a `pdflatex' executable"))
|
||||
(err (format "could not find a `~a' executable" name)))
|
||||
ans)
|
||||
|
||||
(define (err fmt . args) (apply error 'run-pdflatex fmt args))
|
||||
(define function-name (make-parameter 'run-pdflatex))
|
||||
(define (err fmt . args) (apply error (function-name) fmt args))
|
||||
|
||||
;; under mac os x, gui apps do not get started with
|
||||
;; a good path environment, so put likely candidates
|
||||
;; for a latex installation here so that the "scribble
|
||||
;; pdf" button is more likely to work in drracket
|
||||
(define macosx-candidates
|
||||
'("/usr/texbin/pdflatex"))
|
||||
;; for directories holding latex/pdflatex binaries
|
||||
;; here so that the "scribble pdf" button is more
|
||||
;; likely to work in drracket
|
||||
(define macosx-candidate-dirs
|
||||
'("/usr/texbin"))
|
||||
|
|
|
@ -62,9 +62,12 @@
|
|||
[("--latex") "generate LaTeX-format output"
|
||||
(current-html #f)
|
||||
(current-render-mixin latex:render-mixin)]
|
||||
[("--pdf") "generate PDF-format output (with PDFLaTeX)"
|
||||
[("--pdf") "generate PDF-format output (via PDFLaTeX)"
|
||||
(current-html #f)
|
||||
(current-render-mixin pdf:render-mixin)]
|
||||
[("--dvipdf") "generate PDF-format output (via LaTeX and DVIPDF)"
|
||||
(current-html #f)
|
||||
(current-render-mixin pdf:dvi-render-mixin)]
|
||||
[("--latex-section") n "generate LaTeX-format output for section depth <n>"
|
||||
(current-html #f)
|
||||
(let ([v (string->number n)])
|
||||
|
|
Loading…
Reference in New Issue
Block a user