Skip to content

Instantly share code, notes, and snippets.

@hlian
Created November 18, 2010 04:09
Show Gist options
  • Save hlian/704615 to your computer and use it in GitHub Desktop.
Save hlian/704615 to your computer and use it in GitHub Desktop.
(defun tex-view ()
"Preview the last `.dvi' file made by running TeX under Emacs.
This means, made using \\[tex-region], \\[tex-buffer] or \\[tex-file].
The variable `tex-dvi-view-command' specifies the shell command for preview.
You must set that variable yourself before using this command,
because there is no standard value that would generally work."
(interactive)
(or tex-dvi-view-command
(error "You must set `tex-dvi-view-command'"))
;; Restart the TeX shell if necessary.
(or (tex-shell-running)
(tex-start-shell))
(let ((tex-dvi-print-command (eval tex-dvi-view-command)))
(tex-file)
(tex-print)))
(defun tex-print (&optional alt)
"Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file].
Runs the shell command defined by `tex-dvi-print-command'. If prefix argument
is provided, use the alternative command, `tex-alt-dvi-print-command'."
(interactive "P")
(let ((print-file-name-dvi (tex-append tex-print-file ".pdf"))
test-name)
(if (and (not (equal (current-buffer) tex-last-buffer-texed))
(buffer-file-name)
;; Check that this buffer's printed file is up to date.
(file-newer-than-file-p
(setq test-name (tex-append (buffer-file-name) ".pdf"))
(buffer-file-name)))
(setq print-file-name-dvi test-name))
(if (not (file-exists-p print-file-name-dvi))
(error "No appropriate `.pdf' file could be found")
(if (tex-shell-running)
(tex-kill-job)
(tex-start-shell))
(tex-send-command
(if alt tex-alt-dvi-print-command tex-dvi-print-command)
print-file-name-dvi
t))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment