我使用 Emacs 和 AucTeX 作为我的写作环境。我很高兴能选择一个引擎(PDFTeX、LuaTeX、XeTeX)并将其作为我所有编译的默认引擎。
但是,我有一个项目需要使用与默认引擎不同的引擎。我尝试使用 Emacs 方式设置它,使用局部变量
%%% TeX-engine: "default"
行以及指定项目主文件的行,但这似乎没有设置适当的变量,并且如果我尝试在未为 设定合适值的情况下进行编译,Emacs 将完全锁定TeX-engine
。
有没有办法向 XeTeX 发出信号,告知传入文件应使用 PDFTeX 进行编译?或者有没有好办法向 Emacs 发出信号,告知此特定文件应使用其他程序进行编译?
答案1
正如 Philipp 在评论中指出的那样,但从未发布为答案,我的问题是TeX-engine
期望 a 而symbol
不是 a string
。因此,我需要写而不是我写的
%%% TeX-engine: default
让一切正常运作。
答案2
我怀疑这是否会让我在 Emacs 社区或 TeX 社区赢得任何朋友,但我有一个实现此目的的技巧。唯一的警告(对于您的情况)是我不使用 AucTeX,所以不知道它如何与它一起工作。当我编辑时.tex
,我会加载下面的文件。这允许我根据我想要使用的输出/引擎设置一些选项。
其中也有一些垃圾内容,但大部分内容都集中在这个问题上。它的工作原理是重写命令tex-file
和,tex-view-file
以便可以根据为output type
文件选择(实际上比输出类型更精确)设置的选项来修改它们。
所以我只需这样做M-x set-tex-output-type xe
,然后使用就可以编译我的文件xelatex
。
;(server-start)
;(load "xdvi-search.el")
(setq latex-block-names '("theorem" "corollary" "proof" "lemma" "defn" "thm"))
;(setq tex-dvi-view-command
; (if (eq window-system 'x) "xdvi" nil))
;(setq tex-dvi-print-command "dvips -Pmirkti *")
(setq tex-alt-dvi-print-command "dvips * -ta4 -o")
(defcustom tex-output-type "pdf"
"*Default output type for TeX jobs."
:type '(radio (const :tag "Postscript" "ps")
(const :tag "Postscript (rv)" "psrv")
(const :tag "PDF" "pdf")
(const :tag "PDF (rv)" "pdfrv")
(const :tag "Dvi" "dvi")
(const :tag "Dvi (draft)" "dvid")
(const :tag "XeLaTeX" "xe")
(const :tab "LuaLaTeX" "lua")
(const :tag "HTML" "html")
(const :tag "XHTML" "xhtml")
(const :tag "MathML" "xml")
(const :tag "OpenOffice" "sxw")
(const :tag "maruku" "maruku"))
:group 'tex-run)
(defcustom tex-ext-alist
'(("ps" . "ps")
("psrv" . "ps")
("pdf" . "pdf")
("pdfrv" . "pdf")
("dvi" . "dvi")
("dvid" . "dvi")
("xe" . "pdf")
("lua" . "pdf")
("html" . "html")
("xhtml" . "xhtml")
("xml" . "xml")
("sxw" . "sxw")
("maruku" . "xhtml"))
"*alist of eventual file extensions")
(defcustom tex-command-alist
'(("pdf" . "pdflatex")
("pdfrv" . "pdflatex")
("ps" . "latex")
("psrv" . "latex")
("dvi" . "latex")
("dvid" . "latex")
("xe" . "xelatex")
("lua" . "lualatex")
("html" . "mk4ht")
("xhtml" . "mk4ht")
("xml" . "mk4ht")
("sxw" . "mk4ht")
("maruku" . "maruku")
)
"*alist for processing file into various types of output")
(defcustom tex-start-options-alist
'(("pdf" . "\\\\nonstopmode\\\\input")
("pdfrv" . "\\\\nonstopmode\\\\input")
("ps" . "\\\\nonstopmode\\\\input")
("psrv" . "\\\\nonstopmode\\\\input")
("dvi" . "\\\\nonstopmode\\\\input")
("dvid" . "-src-specials \\\\nonstopmode\\\\input")
("xe" . "\\\\nonstopmode\\\\input")
("lua" . "\\\\nonstopmode\\\\input")
("html" . "htlatex")
("xhtml" . "xhlatex")
("xml" . "mzlatex")
("sxw" . "oolatex")
("maruku" . "-m itex2mml")
)
"*alist for options that preceed the filename")
(defcustom tex-end-options-alist
'(("pdf" . "")
("pdfrv" . "")
("ps" . "")
("psrv" . "")
("dvi" . "")
("dvid" . "")
("xe" . "")
("lua" . "")
("html" . "\"html,3,frames\"")
("xhtml" . "\"html,3,frames\"")
("xml" . "\"html,3,frames\"")
("sxw" . "\"html,3,frames\"")
("maruku" . "")
)
"*alist for options that postceed the filename")
(defcustom tex-post-command-alist
'(("pdf" . "")
("pdfrv" . "")
("ps" . "dvips * -ta4 -o 2> /dev/null")
("psrv" . "dvips * -ta4 -o 2> /dev/null")
("dvi" . "")
("dvid" . "")
("xe" . "")
("lua" . "")
("html" . "")
("xhtml" . "")
("xml" . "")
("sxw" . "")
("maruku" . "")
)
"*alist for post-processing commands")
(defcustom tex-mid-ext-alist
'(("ps" . "dvi")
("psrv" . "dvi")
("pdf" . "")
("pdfrv" . "")
("dvi" . "")
("dvid" . "")
("xe" . "")
("lua" . "")
("html" . "")
("xhtml" . "")
("xml" . "")
("sxw" . "")
("maruku" . "")
)
"*alist of mid-point file extensions if we do a two-stage process")
(defcustom tex-view-commands-alist
; (cond
; ((eq window-system 'x)
'(("pdf" . "xpdf")
("pdfrv" . "xpdf")
("ps" . "gv -ad=~/.gv_spartan_right.dat")
("psrv" . "gv -ad=~/.gv_spartan_right_rv.dat")
("dvi" . "xdvi")
("dvid" . "xdvi")
("xe" . "xpdf")
("lua" . "xpdf")
("html" . "firefox")
("xhtml". "firefox")
("xml". "firefox")
("sxw". "ooffice2")
("maruku" . "firefox")
)
; (t
; '(("pdf" . "pdftotext * | cat -s")
; ("ps" . "ps2ascii * | cat -s")
; ("dvi" . "dvips * | ps2ascii | cat -s")
; ("html". "lynx")
; ("xhtml". "lynx")
; ("xml". "lynx")
; ("sxw". "false"))
; )))
"*alist for viewing the various types of output")
;(defcustom tex-dvi-to-ps-command
; "dvips * -ta4 -o 2> /dev/null"
; "*Command for conversion from dvi to ps."
; :type 'string
; :group 'tex-run)
(defun tex-font-lock-type-alist
'(("pdf" . "")
("pdfrv" . "")
("ps" . "")
("psrv" . "")
("dvi" . "")
("dvid" . "")
("xe" . "")
("lua" . "")
("html" . "")
("xhtml" . "")
("xml" . "")
("sxw" . "")
("maruku" . "markdown-mode-font-lock-keywords")
)
"*alist for modifying font-lock defaults")
(modify-syntax-entry ?\\ "." tex-mode-syntax-table)
(defun set-tex-main-file ()
"Set 'tex-main-file' to something appropriate from the current buffer."
(interactive)
(make-variable-buffer-local 'tex-main-file)
(setq tex-main-file (expand-file-name (car (find-file-read-args
"(La)TeX main file name for buffer: " nil))))
)
(defun set-tex-output-type ()
"Set the 'tex-output-type'."
(interactive)
(setq newtype
(completing-read "TeX Output Type: " tex-ext-alist nil t)
)
(if (not (equal newtype ""))
(setq tex-output-type newtype)
)
)
(defun template ()
"Insert template.tex at the appropriate place."
(interactive)
(insert-file-contents "~/tex/papers/useful/template.tex")
)
(defun end-document ()
"Insert end-of-document commands at the point."
(interactive)
(insert "\\bibliography{arxiv,articles,books,misc}\n\n\\end{document}\n\n")
)
(defun find-end-document ()
"Skips to the end of the current document."
(interactive)
; (goto-char (point-min))
(search-forward "\\end{document}")
)
(defun my-tex-file ()
"Modify \\[tex-file] to take into account the desired output type."
(interactive)
(let ((tex-command (concat
(cdr (assoc tex-output-type tex-command-alist))
" "
(cdr (assoc tex-output-type tex-start-options-alist))
" \* "
(cdr (assoc tex-output-type tex-end-options-alist)))))
(tex-file)
)
(if (< 0 (length (cdr (assoc tex-output-type tex-post-command-alist))))
(let ((tex-mid-file (tex-append tex-print-file (concat "." (cdr (assoc tex-output-type tex-mid-ext-alist))))))
(if (not (file-exists-p tex-mid-file))
(error "No appropriate file could be found")
(tex-send-command (cdr (assoc tex-output-type tex-post-command-alist)) tex-mid-file)
)
)
)
)
(defun my-tex-view ()
"Modify \\[tex-view] to take into account the desired output type."
(interactive)
(let* ((tex-suffix (concat "." (cdr (assoc tex-output-type tex-ext-alist))))
(tex-view-command (cdr (assoc tex-output-type tex-view-commands-alist)))
(view-file-name (tex-append tex-print-file tex-suffix))
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) (concat "." (cdr (assoc tex-output-type tex-ext-alist)))))
(buffer-file-name)))
(setq view-file-name test-name))
(if (not (file-exists-p view-file-name))
(error "No appropriate file could be found to view.")
(if (tex-shell-running)
(tex-kill-job)
(tex-start-shell))
(tex-send-command
tex-view-command view-file-name
t))))
(define-key tex-mode-map "\C-c\C-n" 'find-end-document)
(define-key tex-mode-map "\C-c\C-d" 'end-document)
(define-key tex-mode-map [remap tex-file] 'my-tex-file)
(define-key tex-mode-map [remap tex-view] 'my-tex-view)
(define-key tex-shell-map [remap tex-file] 'my-tex-file)
(define-key tex-shell-map [remap tex-view] 'my-tex-view)
(defadvice server-visit-files (around save-buffers last activate)
"Try to emulate gnuclient behaviour with emacsclient.
Works only for visiting one buffer at a time."
(let* ((filen (car (car (ad-get-arg 0))))
(buf (get-file-buffer filen))
(this-buf-modified-p nil))
;;; the following is copied from server-visit-files, with
;;; a modification for the `verify-visited-file-modtime' test
(if (and buf (set-buffer buf))
(if (file-exists-p filen)
;;; if the file has changed on disk, reload it
;;; using `find-file-noselect'
(if (not (verify-visited-file-modtime buf))
(progn
(find-file-noselect filen)
;;; if user answered `no', reset modtime anyway
;;; so that server-visit-files doesn't realize
;;; the difference:
(set-visited-file-modtime)))
;;; if file exists no longer, we let server-visit-files
;;; deal with that
t)
(setq buf (find-file-noselect filen)))
(setq this-buf-modified-p (buffer-modified-p buf))
(set-buffer buf)
(set-buffer-modified-p nil)
ad-do-it
(set-buffer-modified-p this-buf-modified-p)))
(require 'markdown-mode)
(defun markdown-font-locks ()
"Set the font lock to that of markdown mode."
(interactive)
(set (make-local-variable 'font-lock-defaults)
'(markdown-mode-font-lock-keywords))
(set (make-local-variable 'font-lock-multiline) t)
(setq font-lock-mode-major-mode nil)
(font-lock-fontify-buffer)
)