mathlete
mathlete

Reputation: 6692

Elisp/texi2dvi: How to call texi2dvi from Emacs?

I try to write a function based on the code from: Latex, Emacs: automatically open *TeX Help* buffer on error and close it after correction of the error?

I would like to replace latexmk by texi2dvi, but TeX-master-file does not contain the file ending .tex (which seems to be required for texi2dvi). I found out that one can add .tex by using TeX-master-file t. However, I can't make it work (I'm not an elisp programmer). Here is what I tried:

;; texi2dvi 
(defun run-texi2dvi ()
  (interactive)
  (let ((TeX-save-query nil)
        (TeX-process-asynchronous nil)
        (master-file (expand-file-name (TeX-master-file t)))); append `.tex`
    (TeX-save-document "")
    (TeX-run-TeX "texi2dvi"
         (TeX-command-expand "PDFLATEX='pdflatex -synctex=1' texi2dvi -p %s" 'TeX-master-file)
                 master-file)
    (if (plist-get TeX-error-report-switches (intern master-file))
        (TeX-next-error t)
      (progn
    (demolish-tex-help)
    (minibuffer-message "texi2dvi: done.")))))

Upvotes: 0

Views: 137

Answers (2)

mathlete
mathlete

Reputation: 6692

See here for a more detailed description of the issue and a simple workaround: https://tex.stackexchange.com/questions/67244/how-to-set-up-texi2dvi-with-synctex-and-error-handling/67384#67384

Upvotes: 0

Tassilo Horn
Tassilo Horn

Reputation: 821

No clue if there's a better way to do it, but this version should work. Basically, TeX-command-expand was given the function TeX-master-file as a symbol which was called internally, and there it was called without the I-want-the-extension argument. The replacing lambda forces that.

(defun run-texi2dvi ()
  (interactive)
  (let ((TeX-save-query nil)
        (TeX-process-asynchronous nil)
        (master-file (expand-file-name (TeX-master-file t)))); append `.tex`
    (TeX-save-document "")
    (TeX-run-TeX "texi2dvi"
         (TeX-command-expand
          "PDFLATEX='pdflatex -synctex=1' texi2dvi -p %s"
          (lambda (ext-ignored nondir)
            (TeX-master-file t nondir)))
                 master-file)
    (if (plist-get TeX-error-report-switches (intern master-file))
        (TeX-next-error t)
      (progn
    (demolish-tex-help)
    (minibuffer-message "texi2dvi: done.")))))

Upvotes: 1

Related Questions