diff --git a/tex-buf.el b/tex-buf.el index 58e1602..66daad0 100644 --- a/tex-buf.el +++ b/tex-buf.el @@ -797,10 +797,9 @@ omitted) and `TeX-region-file'." (TeX-process-get-variable name 'TeX-command-next - (if (and TeX-PDF-via-dvips-ps2pdf TeX-PDF-mode) - "Dvips" - TeX-command-Show))) - (list "Dvips" TeX-command-Show)) + (or (and TeX-PDF-mode (TeX-PDF-from-DVI)) + TeX-command-Show))) + (list "Dvips" "Dvipdfmx" TeX-command-Show)) (cdr (assoc (expand-file-name (concat name ".idx")) LaTeX-idx-changed-alist))) "Index") @@ -1009,7 +1008,7 @@ Return the new process." "Remember TeX command to use to NAME and set corresponding output extension." (setq TeX-command-default name TeX-output-extension - (if (and (null TeX-PDF-via-dvips-ps2pdf) TeX-PDF-mode) "pdf" "dvi")) + (if (and (null (TeX-PDF-from-DVI)) TeX-PDF-mode) "pdf" "dvi")) (let ((case-fold-search t) (lst TeX-command-output-list)) (while lst @@ -1121,6 +1120,14 @@ run of `TeX-run-TeX', use process (TeX-synchronous-sentinel name file process)))) +(defun TeX-run-dvipdfmx (name command file) + "Create a process for NAME using COMMAND to convert FILE with dvipdfmx." + (let ((process (TeX-run-command name command file))) + (setq TeX-sentinel-function #'TeX-dvipdfmx-sentinel) + (if TeX-process-asynchronous + process + (TeX-synchronous-sentinel name file process)))) + (defun TeX-run-ps2pdf (name command file) "Create a process for NAME using COMMAND to convert FILE with ps2pdf." (let ((process (TeX-run-command name command file))) @@ -1361,10 +1368,11 @@ errors or warnings to show." (if (and TeX-error-overview-open-after-TeX-run TeX-error-list) (TeX-error-overview))) (message (concat name ": formatted " (TeX-current-pages))) - (if (with-current-buffer TeX-command-buffer - (and TeX-PDF-via-dvips-ps2pdf TeX-PDF-mode)) - (setq TeX-command-next "Dvips") - (setq TeX-command-next TeX-command-Show)))) + (let (dvi2pdf) + (if (with-current-buffer TeX-command-buffer + (and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI)))) + (setq TeX-command-next dvi2pdf) + (setq TeX-command-next TeX-command-Show))))) (defun TeX-current-pages () "Return string indicating the number of pages formatted." @@ -1421,10 +1429,11 @@ Return nil ifs no errors were found." 'TeX-current-master)) t)) t) - (if (with-current-buffer TeX-command-buffer - (and TeX-PDF-via-dvips-ps2pdf TeX-PDF-mode)) - (setq TeX-command-next "Dvips") - (setq TeX-command-next TeX-command-Show)) + (let (dvi2pdf) + (if (with-current-buffer TeX-command-buffer + (and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI)))) + (setq TeX-command-next dvi2pdf) + (setq TeX-command-next TeX-command-Show))) nil)) ;; This regexp should catch warnings of the type @@ -1514,18 +1523,20 @@ Rerun to get outlines right" nil t) ((re-search-forward "^LaTeX Warning: Reference" nil t) (message "%s%s%s" name ": there were unresolved references, " (TeX-current-pages)) - (if (with-current-buffer TeX-command-buffer - (and TeX-PDF-via-dvips-ps2pdf TeX-PDF-mode)) - (setq TeX-command-next "Dvips") - (setq TeX-command-next TeX-command-Show))) + (let (dvi2pdf) + (if (with-current-buffer TeX-command-buffer + (and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI)))) + (setq TeX-command-next dvi2pdf) + (setq TeX-command-next TeX-command-Show)))) ((re-search-forward "^\\(?:LaTeX Warning: Citation\\|\ Package natbib Warning:.*undefined citations\\)" nil t) (message "%s%s%s" name ": there were unresolved citations, " (TeX-current-pages)) - (if (with-current-buffer TeX-command-buffer - (and TeX-PDF-via-dvips-ps2pdf TeX-PDF-mode)) - (setq TeX-command-next "Dvips") - (setq TeX-command-next TeX-command-Show))) + (let (dvi2pdf) + (if (with-current-buffer TeX-command-buffer + (and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI)))) + (setq TeX-command-next dvi2pdf) + (setq TeX-command-next TeX-command-Show)))) ((re-search-forward "Package longtable Warning: Table widths have \ changed\\. Rerun LaTeX\\." nil t) (message @@ -1551,10 +1562,11 @@ Rerun to get mark in right position\\." nil t) ")")))) (message "%s" (concat name ": successfully formatted " (TeX-current-pages) add-info))) - (if (with-current-buffer TeX-command-buffer - (and TeX-PDF-via-dvips-ps2pdf TeX-PDF-mode)) - (setq TeX-command-next "Dvips") - (setq TeX-command-next TeX-command-Show))) + (let (dvi2pdf) + (if (with-current-buffer TeX-command-buffer + (and TeX-PDF-mode (setq dvi2pdf (TeX-PDF-from-DVI)))) + (setq TeX-command-next dvi2pdf) + (setq TeX-command-next TeX-command-Show)))) (t (message "%s%s%s" name ": problems after " (TeX-current-pages)) (setq TeX-command-next TeX-command-default))) @@ -1639,11 +1651,26 @@ Rerun to get mark in right position\\." nil t) "\\\\[TeX-recenter-output-buffer]"))) (t (if (with-current-buffer TeX-command-buffer - (and TeX-PDF-via-dvips-ps2pdf TeX-PDF-mode)) + (and (equal (TeX-PDF-from-DVI) "Dvips") TeX-PDF-mode)) (setq TeX-output-extension "ps" TeX-command-next "Ps2pdf")) (message "Dvips finished successfully. ")))) +(defun TeX-dvipdfmx-sentinel (_process _name) + "Cleanup TeX output buffer after running dvipdfmx." + (goto-char (point-max)) + (cond + ((search-backward "TeX Output exited abnormally" nil t) + (message "Dvipdfmx failed. Type `%s' to display output." + (substitute-command-keys + "\\\\[TeX-recenter-output-buffer]"))) + (t + (if (with-current-buffer TeX-command-buffer + (and (equal (TeX-PDF-from-DVI) "Dvipdfmx") TeX-PDF-mode)) + (setq TeX-output-extension "pdf" + TeX-command-next TeX-command-Show)) + (message "Dvipdfmx finished successfully. ")))) + (defun TeX-ps2pdf-sentinel (_process _name) "Cleanup TeX output buffer after running ps2pdf." (goto-char (point-max)) @@ -1654,7 +1681,7 @@ Rerun to get mark in right position\\." nil t) "\\\\[TeX-recenter-output-buffer]"))) (t (if (with-current-buffer TeX-command-buffer - (and TeX-PDF-via-dvips-ps2pdf TeX-PDF-mode)) + (and (equal (TeX-PDF-from-DVI) "Dvips") TeX-PDF-mode)) (setq TeX-command-next TeX-command-Show TeX-output-extension "pdf")) (message "ps2pdf finished successfully. ")))) diff --git a/tex.el b/tex.el index 026824d..0493eac 100644 --- a/tex.el +++ b/tex.el @@ -151,6 +151,8 @@ If nil, none is specified." :help "Generate PostScript file") ("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil t :help "Convert DVI file to PostScript") + ("Dvipdfmx" "dvipdfmx %d" TeX-run-dvipdfmx nil t + :help "Convert DVI file to PDF with dvipdfmx") ("Ps2pdf" "ps2pdf %f" TeX-run-ps2pdf nil t :help "Convert PostScript file to PDF") ("Index" "makeindex %s" TeX-run-index nil t @@ -447,7 +449,7 @@ string." ("%(PDF)" (lambda () (if (and (eq TeX-engine 'default) (if TeX-PDF-mode - (not TeX-PDF-via-dvips-ps2pdf) + (not (TeX-PDF-from-DVI)) TeX-DVI-via-PDFTeX)) "pdf" ""))) @@ -2123,19 +2125,50 @@ already established, don't do anything." :group 'TeX-command :type 'boolean) +(defcustom TeX-PDF-from-DVI nil + "Specify if and how to produce PDF output from a DVI file. + +If non-nil, the default compiler produces DVI output. The value +should be the name of the command to be used to convert the DVI +file to PDF or to an intermediate type. + +Possible values are + +* \"Dvips\": the DVI file is converted to PS with dvips. After + successfully running it, ps2pdf will be the default command to + convert the PS file to PDF +* \"Dvipdfmx\": the PDF is produced with dvipdfmx + +Programs should not use this variable directly but the function +`TeX-PDF-from-DVI' which handles now obsolete variable +`TeX-PDF-via-dvips-ps2pdf'." + :group 'TeX-command + :type '(choice + (const :tag "No DVI to PDF conversion" nil) + (const :tag "dvips - ps2pdf sequence" "Dvips") + (const :tag "dvipdfmx" "Dvipdfmx"))) +(make-variable-buffer-local 'TeX-PDF-from-DVI) +(put 'TeX-PDF-from-DVI 'safe-local-variable + (lambda (x) (or (stringp x) (null x)))) + (defcustom TeX-PDF-via-dvips-ps2pdf nil "Whether to produce PDF output through the (La)TeX - dvips - ps2pdf sequence." :group 'TeX-command :type 'boolean) (make-variable-buffer-local 'TeX-PDF-via-dvips-ps2pdf) -(put 'TeX-PDF-via-dvips-ps2pdf 'safe-local-variable 'booleanp) +(put 'TeX-PDF-via-dvips-ps2pdf 'safe-local-variable 'TeX-booleanp) +(make-obsolete-variable 'TeX-PDF-via-dvips-ps2pdf 'TeX-PDF-from-DVI "11.90") -(defun TeX-toggle-PDF-via-dvips-ps2pdf () - "Toggle `TeX-PDF-via-dvips-ps2pdf'." - (interactive) - (setq TeX-PDF-via-dvips-ps2pdf (not TeX-PDF-via-dvips-ps2pdf)) - (message (concat "TeX-PDF-via-dvips-ps2pdf: " - (if TeX-PDF-via-dvips-ps2pdf "on" "off")))) +(defun TeX-PDF-from-DVI () + "Return the value of variable `TeX-PDF-from-DVI'. + +If `TeX-PDF-from-DVI' is not set and obsolete option +`TeX-PDF-via-dvips-ps2pdf' is non-nil, return \"dvips-ps2pdf\" +for backward compatibility." + (cond + (TeX-PDF-from-DVI) + (TeX-PDF-via-dvips-ps2pdf + "Dvips"))) (define-minor-mode TeX-interactive-mode "Minor mode for interactive runs of TeX." @@ -4960,10 +4993,21 @@ Brace insertion is only done if point is in a math construct and :style toggle :selected TeX-PDF-mode :active (not (eq TeX-engine 'omega)) :help "Use PDFTeX to generate PDF instead of DVI"] - [ "PDF via dvips + ps2pdf" TeX-toggle-PDF-via-dvips-ps2pdf - :style toggle :selected TeX-PDF-via-dvips-ps2pdf + ( "PDF from DVI" :visible TeX-PDF-mode - :help "Compile with (La)TeX and convert to PDF with dvips + ps2pdf"] + :help "Compile to DVI with (La)TeX and convert to PDF" + [ "Compile directly to PDF" + (lambda () (interactive) (setq TeX-PDF-from-DVI nil)) + :style radio :selected (null (TeX-PDF-from-DVI)) + :help "Compile directly to PDF without intermediate conversions"] + [ "dvips + ps2pdf" + (lambda () (interactive) (setq TeX-PDF-from-DVI "Dvips")) + :style radio :selected (equal (TeX-PDF-from-DVI) "Dvips") + :help "Convert DVI to PDF with dvips + ps2pdf sequence"] + [ "dvipdfmx" + (lambda () (interactive) (setq TeX-PDF-from-DVI "Dvipdfmx")) + :style radio :selected (equal (TeX-PDF-from-DVI) "Dvipdfmx") + :help "Convert DVI to PDF with dvipdfmx"]) [ "Run Interactively" TeX-interactive-mode :style toggle :selected TeX-interactive-mode :keys "C-c C-t C-i" :help "Stop on errors in a TeX run"]