Emacs + Synctex + Skim:如何正确设置同步? [现有方法均无法正常工作]
我正在 Mac OS X 10.7.2 上使用 GNU Emacs 23.3 (9.0)。我想使用synctex 在 .tex 和 .pdf 文件之间跳转。尽管网络上有很多不同的方法,但没有一个能正常工作(我尝试了 8 种不同的方法......)。我最终采用了此处描述的相当简单的方法: http:// /sourceforge.net/apps/mediawiki/skim-app/index.php?title=TeX_and_PDF_Synchronization
所以我的 .emacs 包含:
'(LaTeX-command "latex -synctex=1")
(require 'tex-site)
(add-hook 'TeX-mode-hook
(lambda ()
(add-to-list 'TeX-output-view-style
'("^pdf$" "."
"/Applications/Skim.app/Contents/SharedSupport/displayline -b %n %o %b")))
)
(server-start)
当然,我还设置了浏览(首选项 -> 同步 -> 检查“检查文件更改”并选择预设:带有命令 emacsclient 和参数的 Emacs --no-wait +%line "%file")
如您所见,我包含了 -b
显示行选项。我可以从终端调用 displayline,它会打开 .pdf 并显示带有黄色/突出显示栏的相应行。尽管如此,如果我从 Emacs.app 中的 shell 使用 latexmk -pvc -pdf
编译文档,当前行上不会显示任何内容。
问题 1:我怎样才能让它工作/如何显示当前行?
问题 2:是否可以通过单击 .tex 并跳转到 .pdf 文档中的相应行来进行“正确”的正向搜索?如何在 emacs 中“单击”?标准的 CMD + Shift + 单击在 emacs 中不起作用。
我也尝试过使用......的方法
(setq TeX-source-correlate-method 'synctex)
(add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)
,但没有任何改变。
我可以 CMD + shift + 单击 .pdf 并跳转到 .tex,这样就可以了。
我唯一没有研究过的方向是:
这是一个 Latexmk 问题吗?很可能不会,因为 Latexmk 显式显示
pdflatex -interaction=nonstopmode -synctex=1
所以synctex 被识别这是一个错误的浏览首选项设置吗?也许我必须在那里调整 emacsclient 的参数(?)
解决方案
确实 Latexmk 是问题所在。我终于弄清楚了以下设置:
~/.emacs
;; make latexmk available via C-c C-c
;; Note: SyncTeX is setup via ~/.latexmkrc (see below)
(add-hook 'LaTeX-mode-hook (lambda ()
(push
'("latexmk" "latexmk -pdf %s" TeX-run-TeX nil t
:help "Run latexmk on file")
TeX-command-list)))
(add-hook 'TeX-mode-hook '(lambda () (setq TeX-command-default "latexmk")))
;; use Skim as default pdf viewer
;; 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
(setq TeX-view-program-selection '((output-pdf "PDF Viewer")))
(setq TeX-view-program-list
'(("PDF Viewer" "/Applications/Skim.app/Contents/SharedSupport/displayline -b -g %n %o %b")))
(server-start); start emacs in server mode so that skim can talk to it
~/.latexmkrc
$pdflatex = 'pdflatex -interaction=nonstopmode -synctex=1 %O %S';
$pdf_previewer = 'open -a skim';
$clean_ext = 'bbl rel %R-blx.bib %R.synctex.gz';
这完美地允许在 Cc Cc 和 Cc Cv 上默认使用 Latexmk 进行编译,并在当前位置打开 Skim很好地突出显示的线。通过 CMD + shift + 单击 .pdf,可以跳回 .tex 文件中的相应段落(感谢 server-start
)。
I'm working with GNU Emacs 23.3 (9.0) on Mac OS X 10.7.2. I would like to use synctex to jump between .tex and .pdf files. Although there are many different approaches on the web, none worked properly (I tried 8 different approaches...). I finally ended up with the rather simple approach described here: http://sourceforge.net/apps/mediawiki/skim-app/index.php?title=TeX_and_PDF_Synchronization
So my .emacs contains:
'(LaTeX-command "latex -synctex=1")
(require 'tex-site)
(add-hook 'TeX-mode-hook
(lambda ()
(add-to-list 'TeX-output-view-style
'("^pdf$" "."
"/Applications/Skim.app/Contents/SharedSupport/displayline -b %n %o %b")))
)
(server-start)
Of course, I also set up Skim (Preferences -> Sync -> checked "Check for file changes" and chose Preset: Emacs with command emacsclient and arguments --no-wait +%line "%file")
As you can see, I included the -b
option to displayline. I can call displayline from the terminal and it opens the .pdf and displays the corresponding line with a yellow/highlighted bar. Still, nothing is displayed on the current line if I compile the document with latexmk -pvc -pdf
from a shell within Emacs.app.
Question 1: How can I get this to work/How can I display the current line?
Question 2: Is it possible to have a "proper" forward search by clicking the .tex and jumping to the corresponding line in the .pdf document? How can I "click" in emacs? The standard CMD + shift + click does not work in emacs.
I also tried approaches using...
(setq TeX-source-correlate-method 'synctex)
(add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)
... but nothing changes.
I can CMD + shift + click in the .pdf and jump to the .tex, so that works.
The only directions which I haven't looked into are:
is this a latexmk problem? Most likely not, since latexmk explicitly displays
pdflatex -interaction=nonstopmode -synctex=1
so synctex is recognizedis it a wrong skim preference setting? Maybe I have to adjust the arguments to emacsclient there (?)
Solution
Indeed latexmk is the problem. I finally figured out the following settings:
~/.emacs
;; make latexmk available via C-c C-c
;; Note: SyncTeX is setup via ~/.latexmkrc (see below)
(add-hook 'LaTeX-mode-hook (lambda ()
(push
'("latexmk" "latexmk -pdf %s" TeX-run-TeX nil t
:help "Run latexmk on file")
TeX-command-list)))
(add-hook 'TeX-mode-hook '(lambda () (setq TeX-command-default "latexmk")))
;; use Skim as default pdf viewer
;; 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
(setq TeX-view-program-selection '((output-pdf "PDF Viewer")))
(setq TeX-view-program-list
'(("PDF Viewer" "/Applications/Skim.app/Contents/SharedSupport/displayline -b -g %n %o %b")))
(server-start); start emacs in server mode so that skim can talk to it
~/.latexmkrc
$pdflatex = 'pdflatex -interaction=nonstopmode -synctex=1 %O %S';
$pdf_previewer = 'open -a skim';
$clean_ext = 'bbl rel %R-blx.bib %R.synctex.gz';
This perfectly allows to compile with latexmk as default on C-c C-c and C-c C-v opens Skim at the current line which is nicely highlighted. With CMD + shift + click in the .pdf, one can then jump back to the corresponding paragraph in the .tex file (thanks to server-start
).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了启用同步的单击功能,我将: 添加
到我的
.emacs
文件中。注意:确保您处于
PDF
模式(使用(setq TeX-PDF-mode t)
)。To enable the clicking feature of the sync, I added:
to my
.emacs
file.NOTE: make sure that you are in
PDF
mode (use(setq TeX-PDF-mode t)
).当您按
Cc Cv
(运行TeX-view
)时,它应该打开Skim,并且栏位于当前行。这就是您使用TeX-output-view-style
设置的内容。您无法从latexmk -pvc
获得该行为,因为它不知道您在哪一行。 Latexmk 只知道文件已更改。为了进行正向搜索,您需要运行TeX-view
。来绑定 CMD + shift + 单击来运行
TeX-view
您可以通过添加或可能
添加到
TeX-mode-hook
。这取决于您需要的设置,但可以通过按Ch Ck
然后 CMD+shift+click 找到。当然,添加两者应该不会造成问题。When you press
C-c C-v
(which runsTeX-view
) it should open Skim with the bar on the current line. This is what you set up with theTeX-output-view-style
. You can't get that behaviour fromlatexmk -pvc
since it doesn't know which line you are on. All latexmk knows is that the file changed. In order to do a forward search you need to runTeX-view
.You can bind CMD + shift + click to run
TeX-view
by addingor possibly
to your
TeX-mode-hook
. It depends on your settings which you need, but can find out by pressingC-h C-k
and then CMD+shift+click. Of course adding both shouldn't cause a problem.