简体   繁体   English

将Emacs AUCTeX与Sumatra PDF同步

[英]Sync Emacs AUCTeX with Sumatra PDF

With these lines in my init.el I am able to sync the Emacs LaTeX buffer with Sumatra: 在我的init.el使用这些行,我可以将Emacs LaTeX缓冲区与Sumatra同步:

(setq TeX-source-correlate-mode t)
(setq TeX-source-correlate-method 'synctex)
(setq TeX-view-program-list 
  '(("Sumatra PDF" ("\"C:/bin86/SumatraPDF/SumatraPDF.exe\" -reuse-instance" 
                      (mode-io-correlate " -forward-search %b %n ") " %o"))))
(setq TeX-view-program-selection  
      '(((output-dvi style-pstricks) "dvips and start") (output-dvi "Yap") 
       (output-pdf "Sumatra PDF") (output-html "start")))

To set a double click on the PDF to get me to the related LaTeX code, I also set in Sumatra options Set inverse search command line to: 要设置双击PDF以使我获得相关的LaTeX代码,我还在Sumatra选项中Set inverse search command line为:

"c:\bin86\GNU Emacs 24.2\bin\emacsclient.exe" --no-wait +%l "%f" 

Despite the sync works, I'd like to code it differently. 尽管同步工作,我想以不同的方式编码。

If I didn't set the last expression, (setq TeX-view-program-selection... , I would get the default values, which are the same as above, apart from the value for the PDF output that would be: (output-pdf "start") . I'd like to change this one to "Sumatra PDF" and leave the other values to their default, that is, I'd like to ask Emacs the default values for the viewers and change only the PDF value. 如果我没有设置最后一个表达式, (setq TeX-view-program-selection... ,除了PDF输出的值之外,我会得到与上面相同的默认值(output-pdf "start") 。我想把这个更改为“Sumatra PDF”并将其他值保留为默认值,也就是说,我想向Emacs询问查看器的默认值并仅更改PDF值。

It is mostly an ELisp question concerning the manipulation of the variable TeX-view-program-selection . 它主要是关于操作变量TeX-view-program-selection的ELisp问题。 Thanks for helping. 谢谢你的帮助。

PS Please tell me if this question is best fit on tex.stackexchange PS请告诉我这个问题是否最适合tex.stackexchange

Update based on lunaryorn comments/answer 根据lunaryorn评论/答案更新

To update TeX-view-program-selection I could use: 要更新TeX-view-program-selection我可以使用:

(assq-delete-all 'output-pdf  TeX-view-program-selection)
(add-to-list 'TeX-view-program-selection   '(output-pdf "Sumatra PDF"))

The first line is optional, but it makes the list look "cleaner". 第一行是可选的,但它使列表看起来“更干净”。

In both cases (with or without assq-delete-all ) I now need to insert the code in the proper hook, since TeX-view-program-selection is void in init.el . 在这两种情况下(有或没有assq-delete-all )我现在需要在适当的钩子中插入代码,因为在init.el TeX-view-program-selection是无效的。

My credits to lunaryorn for suggestions! 我对lunaryorn的建议! I am repackaging the steps involved to the benefits of the others. 我正在重新包装涉及其他人利益的步骤。

Emacs side Emacs方面

Add to your init.el : 添加到您的init.el

(setq TeX-PDF-mode t)
(setq TeX-source-correlate-mode t)
(setq TeX-source-correlate-method 'synctex)
(setq TeX-view-program-list
   '(("Sumatra PDF" ("\"path/to/SumatraPDF/SumatraPDF.exe\" -reuse-instance"
                      (mode-io-correlate " -forward-search %b %n ") " %o"))))

(eval-after-load 'tex
  '(progn
     (assq-delete-all 'output-pdf TeX-view-program-selection)
     (add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF"))))

Sumatra side 苏门答腊方面

In Settings->Options dialog set Set inverse search command line to: 在设置 - >选项对话框中将Set inverse search command line为:

"path\to\GNU Emacs ver\bin\emacsclient.exe" --no-wait +%l "%f" 

How to use 如何使用

In your LaTeX document in Emacs type Cc Cv or double click the related PDF in Sumatra and ... enjoy)) 在Emacs中的LaTeX文档中键入Cc Cv或双击Sumatra中的相关PDF并...享受))

Use add-to-list instead of setq . 使用add-to-list而不是setq See Ch f add-to-list for more information. 有关详细信息,请参阅Ch f add-to-list

TeX-view-program-selection is defined in tex.el , so you'll need to execute this code after this library is loaded: TeX-view-program-selectiontex.el定义,因此您需要在加载此库后执行此代码:

(eval-after-load 'tex
  '(progn
     (assq-delete-all 'output-pdf TeX-view-program-selection)
     (add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF"))))

I was driven nearly mad by the quoting conventions for windows ->emacs If you install SumatraPDF in the default place, then this works on windows 8.1 我被Windows的引用约定吓到了 - > emacs如果你在默认位置安装SumatraPDF,那么这适用于Windows 8.1

(setq TeX-view-program-list
   '(("Sumatra PDF" ("\"C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe\" -reuse-instance"
          (mode-io-correlate " -forward-search %b %n ") " %o")))))

That's an hour or so I'll never get back :) 那是一个小时左右我永远不会回来:)

I have prepared a batch file, Emacs_SumatraPDF.bat . 我准备了一个批处理文件Emacs_SumatraPDF.bat

It works perfect with sumatra-forward.el to realize forward and backward search. 它与sumatra-forward.el完美配合,实现向前和向后搜索。

For example: 例如:

Download 下载

http://www.ai.soc.i.kyoto-u.ac.jp/~shi/files/Emacs_SumatraPDF.bat http://www.ai.soc.i.kyoto-u.ac.jp/~shi/files/Emacs_SumatraPDF.bat

http:/william.famille-blum.org/software/sumatra/sumatra-forward.el HTTP:/william.famille-blum.org/software/sumatra/sumatra-forward.el


Prepare 准备

put Emacs_SumatraPDF.bat and SumatraPDF.exe --> %Emacs_Home%/bin . Emacs_SumatraPDF.batSumatraPDF.exe - > %Emacs_Home%/bin

put sumatra-forward.el --> %Emacs_Home%/site-lisp sumatra-forward.el - > %Emacs_Home%/site-lisp


Usage 用法

;Emacs_Home=C:/Program Files (x86)/GNU Emacs 23.4
;~\.emacs add following information


;;; Emacs_SumatraPDF.bat
;;  @info: pdf viewer 
;   @refer: 
(setq TeX-view-program-list '(
      ("Sumatra" "C:/Program Files (x86)/GNU Emacs 23.4/bin/Emacs_SumatraPDF.bat 
                   %o %t %n") ))         

(setq TeX-view-program-selection '(
     (output-pdf "Sumatra") 
     (output-dvi "Yap") 
     ((output-dvi style-pstricks) "dvips and start") 
     (output-html "start"))) 

 ;;; sumatra-forward.el
 ;;  @info: forward search. 
 ;   @refer: http:/william.famille-blum.org/blog/static.php?page=static081010-000413
 (require 'sumatra-forward)

That is all. 就这些。


Besides 除了

Emacs 4 Latex Support under Windows 7 for newcomer for Emacs. Windows 7下的Emacs 4 Latex支持适用于Emacs的新手。

http://chunqishi.github.io/emacs4ls/ http://chunqishi.github.io/emacs4ls/


It's worth mentioning that Set inverse search command line is invisible in the Settings->Options dialog by default. 值得一提的是,默认情况下, Set inverse search command lineSettings->Options对话框中不可见。 To show this option field, go to Settings->Advanced options or open SumatraPDF-settings.txt and turn on EnableTeXEnhancements = true . 要显示此选项字段,请转到Settings->Advanced options或打开SumatraPDF-settings.txt并启用EnableTeXEnhancements = true

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

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