简体   繁体   English

emacs auctex命令编译和查看

[英]emacs auctex commandto compile and view

I use EMACS/AucTeX. 我使用EMACS / AucTeX。 In order to compile I do Cc Cc, then it asks 为了编译我做Cc Cc,然后它问

"Command: (default LaTeX)" “命令:(默认LaTeX)”

I press RET and it is compiled. 我按下RET然后编译。 To view the compiled document I do Cc Cv. 要查看已编译的文档,我会执行Cc Cv。

I would like to have a simple shortcut, like pressing F1 or some other key combination to compile and then view the document. 我想有一个简单的快捷方式,比如按F1或其他一些组合键来编译然后查看文档。 There is any simple command/function that can be inserted in .emacs to do that? 有没有简单的命令/功能可以插入.emacs来做到这一点?

Thanks Pietro 谢谢Pietro

Cc Ca(TeX-command-run-all)将在AUCTeX 11.89中完成工作。

I don't think there's anything that will work out of the box, and the naive approach of just calling the two commands in sequence won't work because you need the compilation process to finish before you can view the output. 我认为没有任何东西可以开箱即用,并且只是按顺序调用这两个命令的天真方法将无法工作,因为您需要在查看输出之前完成编译过程。

Here's a quick and dirty solution that might work for you: 这是一个可能适合您的快速而肮脏的解决方案:

(defun my/TeX-view-once (doc)
  "View TeX output and clean up after `my/TeX-compile-and-view'.

Call `TeX-view' to display TeX output, and remove this function
from `TeX-after-TeX-LaTeX-command-finished-hook', where it may
have been placed by `my/TeX-compile-and-view'."
  (TeX-view)
  (remove-hook 'TeX-after-TeX-LaTeX-command-finished-hook #'my/TeX-view-once))


(defun my/TeX-compile-and-view ()
  "Compile current master file using LaTeX then view output.

Run the \"LaTeX\" command on the master file for active buffer.
When compilation is complete, view output with default
viewer (using `TeX-view').
  (interactive)
  (TeX-command "LaTeX" 'TeX-master-file)
  (add-hook 'TeX-after-TeX-LaTeX-command-finished-hook #'my/TeX-view-once))

You may want to tinker with the TeX-command line in my/TeX-compile-and-view , since it hard-codes a lot of things that Cc Cc ( TeX-command-master ) does not. 你可能想修改my/TeX-compile-and-viewTeX-command行,因为它硬编码很多Cc CcTeX-command-master )没有的东西。 In particular, I'm not sure what it will do if there is no master file set, and it will recompile even if it doesn't need to. 特别是,如果没有主文件集,我不确定它会做什么,即使它不需要也会重新编译。

EDIT: After some tinkering, it looks like everything runs fine without a master file, so long as you have this line in your .emacs: 编辑:经过一些修补,看起来没有主文件的一切运行正常,只要你的.emacs中有这一行:

(setq-default TeX-master nil)

I'm not sure why this is the case, since this says AUCTeX should query you for a master file if it's not already set, and this command does no querying even in that case. 我不确定为什么会出现这种情况,因为这说AUCTeX应该查询一个主文件(如果它尚未设置),即使在这种情况下该命令也不会查询。 If you don't want to use this line, it shouldn't be too hard to make the above function work on the buffer instead. 如果您不想使用此行,则不应该太难以使上述函数在缓冲区上起作用。

You could bind F1 to one function, TeX-master-command, since Cc Cc will set the viewer if you use it just after compiling with Cc Cc. 您可以将F1绑定到一个函数TeX-master-command,因为如果您在使用Cc Cc编译后使用它,Cc Cc将设置查看器。 Here is a quote from auctex manual 以下是auctex手册的引用

Once you started the command selection with Cc Cc, Cc Cs or Cc Cb you will be prompted for the type of command. 使用Cc Cc,Cc Cs或Cc Cb启动命令选择后,系统将提示您输入命令类型。 AUCTeX will try to guess which command is appropriate in the given situation and propose it as default. AUCTeX将尝试猜测在给定情况下哪个命令是合适的并将其建议为默认值。 Usually this is a processor like 'TeX' or 'LaTeX' if the document was changed or a viewer if the document was just typeset. 通常,如果文档被更改,这是像'TeX'或'LaTeX'的处理器,如果文档只是排版,则是查看器。

To set this function to F1, you should try something like: 要将此功能设置为F1,您应该尝试以下方法:

(add-hook 'LaTeX-mode-hook
     '(lambda()
     (local-set-key (kbd "<F1>") 'TeX-master-command)
     ))

You still will be prompted and have to press RET after F1. 您仍会收到提示,必须在F1后按RET。 Binding F1 to Aaron Haaris TeX-compile-and-view might spare this RET. 将F1绑定到Aaron Haaris TeX-compile-and-view可以省去这个RET。

Since you are tired of those Cc Cc, you should try latexmk. 既然你厌倦了那些Cc Cc,你应该尝试latexmk。 All you have is to launch it once, and then it will compile your .tex after every new save. 你只需要启动它一次,然后它会在每次新的保存后编译你的.tex。 You can set the viewer, how often latexmk checks if your .tex file as changed and, many, many other things. 您可以设置查看器,latexmk检查您的.tex文件是否已更改的频率以及许多其他内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM