Function: tex-main-file

tex-main-file is a byte-compiled function defined in tex-mode.el.gz.

Signature

(tex-main-file)

Documentation

Return the relative name of the main file.

View in manual

Probably introduced at or before Emacs version 20.1.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/tex-mode.el.gz
(defun tex-main-file ()
  "Return the relative name of the main file."
  (let* ((file (or tex-main-file
		   ;; Compatibility with AUCTeX.
		   (with-no-warnings
		    (when (boundp 'TeX-master)
		      (cond ((stringp TeX-master)
			     (setq-local tex-main-file TeX-master))
			    ((and (eq TeX-master t) buffer-file-name)
			     (file-relative-name buffer-file-name)))))
		   ;; Try to guess the main file.
		   (if (not buffer-file-name)
		       (error "Buffer is not associated with any file")
		     (file-relative-name
		      (if (save-excursion
			    (goto-char (point-min))
			    (re-search-forward tex-start-of-header
					       (+ (point) 10000) t))
			  ;; This is the main file.
			  buffer-file-name
			;; This isn't the main file, let's try to find better,
			(or (tex-guess-main-file)
			    (tex-guess-main-file 'sub)
			    ;; (tex-guess-main-file t)
			    buffer-file-name)))))))
    (if (or (file-exists-p file) (string-match "\\.tex\\'" file))
	file (concat file ".tex"))))