From 927de03cd3ccba6cefd19f89e233666a8e98b3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mos=C3=A8=20Giordano?=
Date: Mon, 17 Aug 2015 00:33:01 +0200 Subject: [PATCH 2/2] Generate PDF via dvips + ps2pdf. --- tex-buf.el | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------- tex.el | 27 +++++++++++++++++-- 2 files changed, 101 insertions(+), 14 deletions(-) diff --git a/tex-buf.el b/tex-buf.el index 668a5b5..8164831 100644 --- a/tex-buf.el +++ b/tex-buf.el @@ -322,7 +322,7 @@ This works only with TeX commands and if the (TeX-parse-TeX (- arg) nil) ;; XXX: moving backward in the errors hasn't yet been implemented for ;; other parsing functions. - (error "Jumping to previous error not supported."))))) + (error "Jumping to previous error not supported"))))) ;;; Command Query @@ -427,8 +427,8 @@ without further expansion." (defun TeX-check-files (derived originals extensions) "Check if DERIVED is newer than any of the ORIGINALS. Try each original with each member of EXTENSIONS, in all directories -in `TeX-check-path'. Returns true if any of the ORIGINALS with any of the -EXTENSIONS are newer than DERIVED. Will prompt to save the buffer of any +in `TeX-check-path'. Returns true if any of the ORIGINALS with any of the +EXTENSIONS are newer than DERIVED. Will prompt to save the buffer of any ORIGINALS which are modified but not saved yet." (let (existingoriginals found @@ -595,7 +595,9 @@ first run of the function and some variables need to be reset." (if LaTeX-using-Biber TeX-command-Biber TeX-command-BibTeX)) ((TeX-process-get-variable name 'TeX-command-next - TeX-command-Show)) + (if (and TeX-PDF-via-dvips-ps2pdf TeX-PDF-mode) + "Dvips" + TeX-command-Show))) (TeX-command-Show))) (defun TeX-command-query (name) @@ -778,7 +780,8 @@ Return the new process." (defun TeX-run-set-command (name command) "Remember TeX command to use to NAME and set corresponding output extension." (setq TeX-command-default name - TeX-output-extension (if TeX-PDF-mode "pdf" "dvi")) + TeX-output-extension + (if (and (null TeX-PDF-via-dvips-ps2pdf) TeX-PDF-mode) "pdf" "dvi")) (let ((case-fold-search t) (lst TeX-command-output-list)) (while lst @@ -862,6 +865,22 @@ run of `TeX-run-TeX', use process (TeX-synchronous-sentinel name file process)))) +(defun TeX-run-Dvips (name command file) + "Create a process for NAME using COMMAND to convert FILE with Dvips." + (let ((process (TeX-run-command name command file))) + (setq TeX-sentinel-function 'TeX-Dvips-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))) + (setq TeX-sentinel-function 'TeX-ps2pdf-sentinel) + (if TeX-process-asynchronous + process + (TeX-synchronous-sentinel name file process)))) + (defun TeX-run-compile (name command file) "Ignore first and third argument, start compile with second argument." (let ((default-directory (TeX-master-directory))) @@ -1075,7 +1094,10 @@ errors or warnings to show." (TeX-parse-all-errors)) (if (and TeX-error-overview-open-after-TeX-run TeX-error-list) (TeX-error-overview)) - (setq TeX-command-next TeX-command-Show))) + (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)))) (defun TeX-current-pages () "Return string indicating the number of pages formatted." @@ -1116,7 +1138,10 @@ Return nil ifs no errors were found." 'TeX-current-master)) t)) t) - (setq TeX-command-next TeX-command-Show) + (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)) nil)) (defun TeX-LaTeX-sentinel-has-warnings () @@ -1198,12 +1223,18 @@ 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)) - (setq TeX-command-next TeX-command-Show)) + (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))) ((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)) - (setq TeX-command-next TeX-command-Show)) + (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))) ((re-search-forward "Package longtable Warning: Table widths have \ changed\\. Rerun LaTeX\\." nil t) (message @@ -1229,7 +1260,10 @@ Rerun to get mark in right position\\." nil t) ")")))) (message "%s" (concat name ": successfully formatted " (TeX-current-pages) add-info))) - (setq TeX-command-next TeX-command-Show)) + (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))) (t (message "%s%s%s" name ": problems after " (TeX-current-pages)) (setq TeX-command-next TeX-command-default))) @@ -1284,6 +1318,36 @@ Rerun to get mark in right position\\." nil t) "Run LaTeX again to get citations right.")) (setq TeX-command-next TeX-command-default)))) +(defun TeX-Dvips-sentinel (_process _name) + "Cleanup TeX output buffer after running Dvips." + (goto-char (point-max)) + (cond + ((search-backward "TeX Output exited abnormally" nil t) + (message "Dvips failed. Type `%s' to display output." + (substitute-command-keys + "\\