我需要帮助使用View
在 Emacs 中运行的 AUCTeX 中的命令。这对于查看 PDF 至关重要,没有它我就无法制作 TeX 文档。在我的.emacs
文件中,我有以下内容(由 创建M-x customize-variable
):
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(TeX-view-program-list (quote (("Preview" "\"open -a Preview.app %o\""))))
现在我打开一个.tex
文档并输入C-c C-c
(我已经编译好了):
Emacs 提供:Command: (default View)
我按下回车键
Emacs 给出了这个默认命令:View command: dvi2tty -q -w 132
我按下回车键,Emacs 说:View: done.
但 PDF 阅读器中没有显示任何内容!
dvi2tty
适用于纯文本设备,该命令实际上在 Emacs 中创建一个新的缓冲区,尝试显示 PDF 文件(非常混乱)。无论如何,如果我dvi2tty -q -w 132
用“open -a Preview.app %o”替换(我正在运行 Mac os X 10.8.4,Preview 是默认 PDF 阅读器的名称),那么 Preview 就会打开 PDF!
- 如何将默认值
View command
从dvi2tty -q -w 132
更改为open -a Preview.app %o
?
非常感谢所有帮助!
答案1
我很幸运,找到了解决方案!
按着这些次序
M-x customize-variable
- Emacs 给出:
Customize variable:
输入:TeX-command-list
- 搜索
View
(输入C-s
然后键入“查看” - Emacs 将带您进入查看命令,您可以在其中输入文本。
它看起来会像这样(命令之后会有一个用于文本输入的地方):
[INS] [DEL] Name: View
Command: open -a Preview.app %s.pdf
How: [Value Menu] TeX-run-command
Create a process for NAME using COMMAND to process FILE. More
Prompt: [Toggle] on (non-nil)
Modes: [Value Menu] All
Menu elements:
[INS] [DEL] Lisp expression: :help
[INS] [DEL] Lisp expression: "Run Text viewer"
将后面的文本更改Command:
为您需要的任何内容。这将自动更改您的~/.emacs
文件。
答案2
以下示例包括*.pdf
在 Windows 和 OSX 上生成文档并*.pdf
在用户定义的查看器中显示文件的 AUCTeX 和非 AUCTeX 方法。
;;;;;;;;;;;;;;;;;;;;;;;;;;;; LATEXMK and AUCTEX ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://tex.stackexchange.com/a/156617/26911
;; Sample `latexmkrc` for OSX that copies the *.pdf file from the `/tmp` directory
;; to the working directory:
;; $pdflatex = 'pdflatex -file-line-error -synctex=1 %O %S && (cp "%D" "%R.pdf")';
;; $pdf_mode = 1;
;; $out_dir = '/tmp';"
;; Skim's displayline is used for forward search (from .tex to .pdf)
;; option -b highlights the current line
;; option -g opens Skim in the background
;; option -o open Skim in the foreground with full application focus.
;; Skim -- turn on auto-refresh by typing the following into the terminal:
;; defaults write -app Skim SKAutoReloadFileUpdate -boolean true
;; TexLive on OSX:
;; (setenv "PATH" (concat (getenv "PATH") ":/usr/texbin"))
(eval-after-load "tex" '(progn
(setenv "PATH" (concat (getenv "PATH") ":/Users/HOME/.0.data/.0.emacs/.0.texlive/texlive/2012/bin/x86_64-darwin"))
(add-to-list 'TeX-view-predicate-list-builtin '(output-pdf t))
(add-to-list 'TeX-expand-list '("%(tex-file-name)" (lambda ()
(concat "\"" (with-current-buffer TeX-command-buffer buffer-file-name) "\""))))
(add-to-list 'TeX-expand-list '("%(pdf-file-name)" (lambda ()
(concat
"\"" (car (split-string (with-current-buffer TeX-command-buffer buffer-file-name) "\\.tex"))
".pdf" "\""))))
(add-to-list 'TeX-expand-list '("%(line-number)" (lambda ()
(format "%d" (line-number-at-pos)))))
(cond
((eq system-type 'darwin)
(add-to-list 'TeX-expand-list '("%(latexmkrc-osx)" (lambda () "/Users/HOME/.0.data/.0.emacs/.latexmkrc")))
(add-to-list 'TeX-command-list '("latexmk-osx" "latexmk -r %(latexmkrc-osx) %s" TeX-run-TeX nil t))
(add-to-list 'TeX-expand-list '("%(skim)" (lambda () "/Users/HOME/.0.data/.0.applications/Skim.app/Contents/SharedSupport/displayline")))
(add-to-list 'TeX-command-list '("Skim" "%(skim) -g %(line-number) %(pdf-file-name) %(tex-file-name)" TeX-run-TeX nil t))
(add-to-list 'TeX-view-program-list '("skim-viewer" "%(skim) -g %(line-number) %(pdf-file-name) %(tex-file-name)"))
(setq TeX-view-program-selection '((output-pdf "skim-viewer"))))
((eq system-type 'windows-nt)
(add-to-list 'TeX-expand-list '("%(latexmkrc-nt)" (lambda () "y:/.0.data/.0.emacs/.latexmkrc-nt")))
(add-to-list 'TeX-command-list '("latexmk-nt" "latexmk -r %(latexmkrc-nt) %s" TeX-run-TeX nil t))
(add-to-list 'TeX-expand-list '("%(sumatra)" (lambda () "\"c:/Program Files/SumatraPDF/SumatraPDF.exe\"")))
(add-to-list 'TeX-command-list '("SumatraPDF" "%(sumatra) -reuse-instance -forward-search %(tex-file-name) %(line-number) %(pdf-file-name)" TeX-run-TeX nil t))
(add-to-list 'TeX-view-program-list '("sumatra-viewer" "%(sumatra) -reuse-instance -forward-search %(tex-file-name) %(line-number) %(pdf-file-name)"))
(setq TeX-view-program-selection '((output-pdf "sumatra-viewer"))))) ))
(defun auctex-latexmk ()
"Compile, view *.pdf, and clean (maybe)."
(interactive)
(require 'tex)
(require 'latex)
(let ((TeX-PDF-mode t)
(TeX-source-correlate-mode t)
(TeX-source-correlate-method 'synctex)
(TeX-source-correlate-start-server nil)
(TeX-clean-confirm t))
(when (buffer-modified-p)
(save-buffer))
(set-process-sentinel
(TeX-command "LaTeX" 'TeX-master-file)
(lambda (p e)
(when (not (= 0 (process-exit-status p)))
(TeX-next-error t) )
(when (= 0 (process-exit-status p))
(delete-other-windows)
(TeX-command "View" 'TeX-active-master 0)
;; `set-process-sentinel` cannot be used on Windows XP for post-view cleanup,
;; because Emacs treats SumatraPDF as an active process until SumatraPDF exits.
(let ((major-mode 'latex-mode))
(with-current-buffer TeX-command-buffer
(TeX-command "Clean" 'TeX-master-file))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LATEXMK START-PROCESS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun combined-latexmk-function ()
(interactive)
(cond
((eq system-type 'darwin)
(latexmk))
((eq system-type 'windows-nt)
(xp-latexmk) )))
(defun xp-latexmk ()
".latexmkrc contains the following entries:
$pdflatex = 'pdflatex -file-line-error -synctex=1 %O %S';
$pdf_mode = 1;
$recorder = 0;
$clean_ext = 'synctex.gz synctex.gz(busy) aux fdb_latexmk log';"
(interactive)
(lexical-let* (
(latexmk-tex-file buffer-file-name)
(latexmk-base-file (car (split-string buffer-file-name "\\.tex")))
(latexmk-w32-tex-file (concat "\"" buffer-file-name "\""))
(latexmk-w32-pdf-file (concat "\"" latexmk-base-file ".pdf" "\""))
(latexmk-line (format "%d" (line-number-at-pos)))
(latexmk-sumatra "c:/Program Files/SumatraPDF/SumatraPDF.exe")
(latexmk-w32-document (concat
"-reuse-instance"
" "
"-forward-search"
" "
latexmk-w32-tex-file
" "
latexmk-line
" "
latexmk-w32-pdf-file))
(latexmk-tex-output (concat "*" (file-name-nondirectory buffer-file-name) "*") )
(latexmk-pl "c:/texlive/2013/bin/win32/latexmk.exe")
(latexmk-latexmkrc "y:/.0.data/.0.emacs/.latexmkrc-nt") )
(if (buffer-modified-p)
(save-buffer))
(delete-other-windows)
(set-window-buffer (split-window-horizontally) (get-buffer-create latexmk-tex-output))
(with-current-buffer latexmk-tex-output (erase-buffer))
;; `-reuse-instance` seems to be working very nicely, so no need to kill prior instance.
;; (start-process "tskill" nil "c:/WINDOWS/system32/tskill.exe" "SumatraPDF")
(set-process-sentinel
(start-process "deep-clean" nil latexmk-pl "-C" "-r" latexmk-latexmkrc latexmk-tex-file)
(lambda (p e) (when (= 0 (process-exit-status p))
(set-process-sentinel
(start-process "compile" latexmk-tex-output latexmk-pl "-r" latexmk-latexmkrc latexmk-tex-file)
(lambda (p e) (when (= 0 (process-exit-status p))
(when (get-buffer-process (get-buffer latexmk-tex-output))
(process-kill-without-query (get-buffer-process
(get-buffer latexmk-tex-output))))
(kill-buffer latexmk-tex-output)
(delete-other-windows)
(switch-to-buffer (get-file-buffer latexmk-tex-file))
(w32-shell-execute "open" latexmk-sumatra latexmk-w32-document)
(sit-for 1)
(start-process "clean" nil latexmk-pl "-c" "-r" latexmk-latexmkrc latexmk-tex-file)))))))))
(defun latexmk-process-filter (proc string)
(let ((inhibit-read-only t))
(with-current-buffer (messages-buffer)
(goto-char (point-max))
(when (not (bolp))
(insert "\n"))
(insert string)
(when (not (bolp))
(insert "\n")))
(when (string-match "?" string)
(display-buffer (messages-buffer))
(with-current-buffer (messages-buffer)
(goto-char (point-max))
(walk-windows
(lambda (window)
(when (string-equal (buffer-name (window-buffer window)) "*Messages*")
(set-window-point window (point-max))))
nil t)))))
(defun latexmk ()
".latexmkrc contains the following entries (WITHOUT the four backslashes):
$pdflatex = 'pdflatex -file-line-error -synctex=1 %O %S && (cp \"%D\" \"%R.pdf\")';
$pdf_mode = 1;
$out_dir = '/tmp';"
(interactive)
(lexical-let* (
(latexmk-tex-file buffer-file-name)
(latexmk-pdf-file (concat "/tmp/"
(car (split-string (file-name-nondirectory buffer-file-name) "\\.tex")) ".pdf"))
(latexmk-line (format "%d" (line-number-at-pos)))
(latexmk-skim "/Users/HOME/.0.data/.0.applications/Skim.app/Contents/SharedSupport/displayline")
(latexmk-pl "/usr/local/texlive/2012/texmf-dist/scripts/latexmk/latexmk.pl")
(latexmk-latexmkrc "/Users/HOME/.0.data/.0.emacs/.latexmkrc")
(latexmk-close-skim-window (concat
"set myWindowTitle to \"" (file-name-nondirectory latexmk-pdf-file) "\"\n"
"tell application \"System Events\"\n"
"tell application \"Skim\" to close (every window whose name contains myWindowTitle)\n"
"end tell")) )
(when (buffer-modified-p)
(save-buffer))
(when (not (one-window-p t))
(delete-other-windows))
(set-process-sentinel
(start-process "close-window" nil "osascript" "-e" latexmk-close-skim-window)
(lambda (p e) (when (= 0 (process-exit-status p))
(set-process-sentinel
(start-process "deep-clean" nil latexmk-pl "-C" "-r" latexmk-latexmkrc latexmk-tex-file)
(lambda (p e) (when (= 0 (process-exit-status p))
(when (get-process "compile")
(delete-process (get-process "compile")))
(start-process "compile" nil latexmk-pl "-r" latexmk-latexmkrc latexmk-tex-file)
(set-process-filter (get-process "compile") 'latexmk-process-filter)
(set-process-sentinel
(get-process "compile")
(lambda (p e) (when (= 0 (process-exit-status p))
(set-process-sentinel
(start-process "displayline" nil latexmk-skim latexmk-line latexmk-pdf-file latexmk-tex-file)
(lambda (p e) (when (= 0 (process-exit-status p))
(when (not (one-window-p t))
(delete-other-windows))))))))))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
答案3
我不记得在哪里找到了以下代码,但是:为了使 auctex 默认调用 pdflatex 并使用 okular 预览 pdf 文件,我将以下内容放在文件末尾~/.xemacs/init.el
:
(setq TeX-PDF-mode t)
(defun pdfevince ()
(add-to-list 'TeX-output-view-style
'("^pdf$" "." "evince %o %(outpage)")))
(defun pdfokular ()
(add-to-list 'TeX-output-view-style
'("^pdf$" "." "okular %o %(outpage)")))
;(add-hook 'LaTeX-mode-hook 'pdfevince t) ; AUCTeX LaTeX mode
(add-hook 'LaTeX-mode-hook 'pdfokular t) ; AUCTeX LaTeX mode
如果您更喜欢 evince 而不是 okular,请取消注释倒数第二行并注释掉最后一行。这是针对 xemacs 的;对于 emacs,我想您应该将其放入 .emacs 文件中。