Function: tex-region
tex-region is an interactive and byte-compiled function defined in
tex-mode.el.gz.
Signature
(tex-region BEG END)
Documentation
Run TeX on the current region, via a temporary file.
The file's name comes from the variable tex-zap-file and the
variable tex-directory says where to put it.
If the buffer has a header, the header is given to TeX before the
region itself. The buffer's header is all lines between the strings
defined by tex-start-of-header and tex-end-of-header inclusive.
The header must start in the first 100 lines of the buffer.
The value of tex-trailer is given to TeX as input after the region.
The value of tex-command specifies the command to use to run TeX.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/tex-mode.el.gz
;;; The commands:
(defun tex-region (beg end)
"Run TeX on the current region, via a temporary file.
The file's name comes from the variable `tex-zap-file' and the
variable `tex-directory' says where to put it.
If the buffer has a header, the header is given to TeX before the
region itself. The buffer's header is all lines between the strings
defined by `tex-start-of-header' and `tex-end-of-header' inclusive.
The header must start in the first 100 lines of the buffer.
The value of `tex-trailer' is given to TeX as input after the region.
The value of `tex-command' specifies the command to use to run TeX."
(interactive "r")
(if (tex-shell-running)
(tex-kill-job)
(tex-start-shell))
(or tex-zap-file
(setq tex-zap-file (tex-generate-zap-file-name)))
;; Temp file will be written and TeX will be run in zap-directory.
;; If the TEXINPUTS file has relative directories or if the region has
;; \input of files, this must be the same directory as the file for
;; TeX to access the correct inputs. That's why it's safest if
;; tex-directory is ".".
(let* ((zap-directory
(file-name-as-directory (expand-file-name tex-directory)))
(tex-out-file (expand-file-name (concat tex-zap-file ".tex")
zap-directory))
;; We may be running from an unsaved buffer, in which case
;; there's no point in guessing for a main file name.
(main-file (and buffer-file-name
(expand-file-name (tex-main-file))))
(ismain (string-equal main-file (buffer-file-name)))
already-output)
;; Don't delete temp files if we do the same buffer twice in a row.
(or (eq (current-buffer) tex-last-buffer-texed)
(tex-delete-last-temp-files t))
(let ((default-directory zap-directory)) ; why?
;; We assume the header is fully contained in tex-main-file.
;; We use f-f-ns so we get prompted about any changes on disk.
(if (not main-file)
(setq already-output 0)
(with-current-buffer (find-file-noselect main-file)
(setq already-output (tex-region-header tex-out-file
(and ismain beg)))))
;; Write out the specified region (but don't repeat anything
;; already written in the header).
(write-region (if ismain
(max beg already-output)
beg)
end tex-out-file (not (zerop already-output)))
;; Write the trailer, if any.
;; Precede it with a newline to make sure it
;; is not hidden in a comment.
(if tex-trailer
(write-region (concat "\n" tex-trailer) nil
tex-out-file t)))
;; Record the file name to be deleted afterward.
(setq tex-last-temp-file tex-out-file)
;; Use a relative file name here because (1) the proper dir
;; is already current, and (2) the abs file name is sometimes
;; too long and can make tex crash.
(tex-start-tex tex-command (concat tex-zap-file ".tex") zap-directory)
(setq tex-print-file tex-out-file)))