* latex can take in tex commands (including '\nonstopmode', which is

useful), so do some... very bare-bones parsing of such so that
   we don't error if \nonstopmode + \input{foo} is used.
 * Have pdf-latex return a non-zero code to the shell if it fails
   instead of always returning 0.

svn: r10559
This commit is contained in:
Stevie Strickland 2008-07-02 16:57:43 +00:00
parent f3559964fb
commit 17cd54a1ad
3 changed files with 40 additions and 17 deletions

View File

@ -10,9 +10,17 @@
;; set up drag and drop ;; set up drag and drop
(error 'slatex "pdf-slatex not supported under Mac OS Classic")] (error 'slatex "pdf-slatex not supported under Mac OS Classic")]
[(windows unix macosx) [(windows unix macosx)
(when (eq? (vector) argv) (when (equal? (vector) argv)
(error 'slatex "expected a file on the command line~n")) (fprintf (current-error-port) "pdf-slatex: expected a file on the command line\n")
(parameterize ([error-escape-handler exit]) (exit 1))
(pdf-slatex (vector-ref argv 0))) (let-values ([(nonstop? file) (if (string=? "\\nonstopmode" (vector-ref argv 0))
(exit)])) (values #t (vector-ref argv 1))
(values #f (vector-ref argv 0)))])
(let ([result
(parameterize ([error-escape-handler exit]
[nonstop-mode? nonstop?])
(pdf-slatex file))])
(if result
(exit)
(exit 1))))]))

View File

@ -12,12 +12,16 @@
(for-each slatex (vector->list argv))] (for-each slatex (vector->list argv))]
[(windows unix macosx) [(windows unix macosx)
(when (eq? (vector) argv) (when (equal? (vector) argv)
(fprintf (current-error-port) "slatex: expected a file on the command line\n") (fprintf (current-error-port) "slatex: expected a file on the command line\n")
(exit 1)) (exit 1))
(let-values ([(nonstop? file) (if (string=? "\\nonstopmode" (vector-ref argv 0))
(values #t (vector-ref argv 1))
(values #f (vector-ref argv 0)))])
(let ([result (let ([result
(parameterize ([error-escape-handler exit]) (parameterize ([error-escape-handler exit]
(slatex (vector-ref argv 0)))]) [nonstop-mode? nonstop?])
(slatex file))])
(if result (if result
(exit) (exit)
(exit 1)))])) (exit 1))))]))

View File

@ -1,12 +1,12 @@
(module slatex-wrapper mzscheme (module slatex-wrapper scheme/base
(require mzlib/file (require mzlib/file
mzlib/process mzlib/process
mzlib/sendevent mzlib/sendevent
"slatex.ss") "slatex.ss")
(provide slatex latex pdf-slatex pdf-latex slatex/no-latex (provide slatex latex pdf-slatex pdf-latex slatex/no-latex
filename->latex-filename) filename->latex-filename nonstop-mode?)
(define (add-suffix p s) (define (add-suffix p s)
(path->string (path->string
@ -14,20 +14,31 @@
(bytes-append (bytes-append
(path->bytes (if (string? p) (string->path p) p)) s)))) (path->bytes (if (string? p) (string->path p) p)) s))))
(define (filename->latex-filename input-file) (define (strip-input input-file)
(let ([norm (normalize-path input-file)])
(cond (cond
[(file-exists? norm) input-file] [(regexp-match #rx"^\\\\input{(.*)}$" input-file) => cadr]
[else input-file]))
(define (filename->latex-filename input-file)
(let* ([filename (strip-input input-file)]
[norm (normalize-path filename)])
(cond
[(file-exists? norm) filename]
[(file-exists? (add-suffix norm #".tex")) [(file-exists? (add-suffix norm #".tex"))
(add-suffix input-file #".tex")] (add-suffix filename #".tex")]
[else [else
(error 'filename->latex-filename "~e does not exist" input-file)]))) (error 'filename->latex-filename "~e does not exist" filename)])))
(define nonstop-mode?
(make-parameter #f))
(define (exec-latex exe file) (define (exec-latex exe file)
(let ([latex-path (find-executable-path exe #f)]) (let ([latex-path (find-executable-path exe #f)])
(unless latex-path (unless latex-path
(error 'latex "could not find latex binary: ~e" exe)) (error 'latex "could not find latex binary: ~e" exe))
(system* latex-path file))) (if (nonstop-mode?)
(system* latex-path "\\nonstopmode" (string-append "\\input{" file "}"))
(system* latex-path file))))
;; latex, pdf-latex : string -> boolean ;; latex, pdf-latex : string -> boolean
;; boolean result indicates success ;; boolean result indicates success