提问:Emacs+Auctex无法编译成功

我的Emacs已经安装了Prucell配置和所有与之相关的拓展 系统也已经正确安装texlive 但是无法正确编译tex文件(除非使用pdftex + 文件名 但是这样无法排版任何格式)

image 这是我 Tex的内容

如果强行使用pdftex导出 会出现这样无法正确排版格式的情况

这是强行编译pdftex时给出的信息

希望各位道友能给出贴切的解决方案,在此先表示感谢!

  1. 将以下init-tex.el文档copy至.emacs.d/lisp中
;;; emacs + auctex

(require-package 'auctex)
(require-package 'ivy-bibtex)

;; auctex configuration
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)

(add-hook 'LaTeX-mode-hook
      (lambda()
        (add-to-list 'TeX-command-list '("PDFLaTeX" "%`pdflatex --synctex=1%(mode)%' %t" TeX-run-TeX nil t))
        (add-to-list 'TeX-command-list '("XeTeX" "%`xelatex --synctex=1%(mode)%' %t" TeX-run-TeX nil t))
        (setq TeX-command-default "PDFLaTeX")))

(mapc (lambda (mode)
    (add-hook 'LaTeX-mode-hook mode))
  (list 'auto-fill-mode
        'LaTeX-math-mode
        'turn-on-reftex
        'linum-mode))
(add-hook 'LaTeX-mode-hook
      (lambda ()
        (setq TeX-auto-untabify t ;; remove all tabs before saving
              TeX-engine 'xetex   ;; ('xetex) | ('default)
              TeX-show-compilation t) ;; display compilation windows
        (TeX-global-PDF-mode t) ;; PDF mode enable, not plain
        (setq TeX-save-query nil)
        (imenu-add-menubar-index)
        ;; (define-key LaTeX-mode-map (kbd "TAB") 'TeX-complete-symbol)
        ))

(setq TeX-insert-quote t)
;; (ispell-change-dictionary "american" t)
;; (setq-default ispell-program-name "aspell")
(add-hook 'doc-view-mode-hook 'auto-revert-mode)

;; ivy-bibtex configuration
(autoload 'ivy-bibtex "ivy-bibtex" "" t)
(setq ivy-re-builders-alist
  '((ivy-bibtex . ivy--regex-ignore-order)
    (t . ivy--regex-plus)))
(setq bib-custom-file (expand-file-name "bib-custom.el" user-emacs-directory))
(when (file-exists-p bib-custom-file)
  (load bib-custom-file))

;; (after-load 'ivy
;;   (ivy-add-actions
;;    'ivy-bibtex
;;    '(("i" ivy-bibtex-insert-bibtex "Insert citation"))))

;; The following was commented by Ming Zhang
;; (when *is-a-mac*
;;   (setq TeX-source-correlate-mode t)
;;   (setq TeX-source-correlate-method 'synctex)
;;   (setq TeX-view-program-list
;;         '(("Skim" "/Applications/Skim.app/Contents/SharedSupport/displayline %n %o %b")("Preview" "open -a Preview.app %o")))
;;   (setq TeX-view-program-selection
;;         '((output-pdf "Skim")
;;           (output-dvi "xdvi")))

;;   ;; use default app to open pdf if available
;;   (setq bibtex-completion-pdf-open-function
;; 		(lambda (fpath)
;; 		  (call-process "open" nil 0 nil fpath)))
;;   )

;; (when *is-a-linux*
;;   ;; Synctex with Okular
;;   (setq TeX-source-correlate-mode t
;;         TeX-source-correlate-start-server t)
;;   (eval-after-load "tex"
;;     '(setcar (cdr (assoc 'output-pdf TeX-view-program-selection)) "Okular"))
;;   (setq TeX-source-correlate-method 'synctex)

;;   ;; use default app to open pdf if available
;;   (setq bibtex-completion-pdf-open-function
;; 		(lambda (fpath)
;; 		  (call-process "evince" nil 0 nil fpath)))
;;   )

;;(when *is-a-windows*
;;   (setq TeX-source-correlate-mode t)
;;   (setq TeX-source-correlate-method 'synctex)
;;   (setq TeX-view-program-list
;;         '(("Sumatra PDF" ("\"C:/Program Files/SumatraPDF/SumatraPDF.exe\" -reuse;; -instance" (mode-io-correlate " -forward-search %b %n ") " %o"))))
;;   (setq TeX-view-program-selection
;;         '((output-pdf "Sumatra PDF")
;;           (output-dvi "xdvi")))
;;   )

;;;end emacs + auctex


(provide 'init-tex)
  1. 在init.el中的众多(require …)语句中间加一句

(require 'init-tex)

  1. 选择XeTeX编译
1 个赞

我觉得你应该是需要用 pdflatex,可以试试把你在命令行中的pdftex换成pdflatex

TeXLaTeX是不一样的。像 \documentclass 是在 LaTeX中定义的,而在TeX中是无法识别的,所以使用pdftex的话会报错。我们现在一般都使用LaTeX,因为更加方便。

1 个赞

我觉得楼主的问题不是这么简单,很可能出在配置方面。此外,其选择了更麻烦的实现方法,选择山人倡导的spacemacs要方便许多。在dotspacemacs-configuration-layers中添加以下layer就OK了。

 (latex :variables
        latex-backend 'lsp
        latex-build-command "LaTeX"
        latex-build-engine 'xetex
        latex-enable-auto-fill nil
        latex-enable-folding t
        latex-refresh-preview t)
1 个赞

把documentclass中的article改成ctexart,然后用xelatex编译。

1 个赞

xelatex、lualatex中英文都方便。我也用过好长一段时间lualatex,没问题

谢谢 顺利解决了! :smile: :+1: :+1: :+1: