You are not logged in.

#1 2014-10-28 16:43:00

emacsomancer
Member
Registered: 2014-09-20
Posts: 211

[Solved] Setting up AUCTeX in Emacs to work with Zathura (synctex etc)

I would like to set up AUCTeX to call upon Zathura as the output viewer - and enable synctex.  I see the description of how to do this with the built-in TeX package in Emacs on the Arch wiki ( https://wiki.archlinux.org/index.php/em … eX_support ), but I wondered if anyone has it set-up to work with AUCTeX?

Last edited by emacsomancer (2014-11-05 20:15:14)

Offline

#2 2014-10-30 14:13:56

fedxa
Member
Registered: 2014-10-30
Posts: 2

Re: [Solved] Setting up AUCTeX in Emacs to work with Zathura (synctex etc)

Not the nicest solution, but it should work,

1. Create file zathura-sync.sh somewhere in you path with the following contents:

#!/bin/sh
pos="$1"
pdffile="$2"
zathura --synctex-forward "$pos" "$pdffile" || \
    (
    zathura -s -x "emacsclient --eval '(progn (switch-to-buffer (file-name-nondirectory \"%{input}\")) (goto-line %{line}))'" "$pdffile" &
    sleep 1; zathura --synctex-forward "$pos" "$pdffile" )

exit

2. Add to .emacs or customize the emacs variable TeX-view-program-list

(setq TeX-view-program-list
      '(("zathura" 
	 ("zathura" (mode-io-correlate "-sync.sh")
	  " "
	  (mode-io-correlate "%n:1:%t ")
	  "%o"))))

3. Restart emacs

4. Customize TeX-view-program-selection to use "zathura" for output-pdf

Last edited by fedxa (2014-10-31 02:11:21)

Offline

#3 2014-10-31 00:00:18

emacsomancer
Member
Registered: 2014-09-20
Posts: 211

Re: [Solved] Setting up AUCTeX in Emacs to work with Zathura (synctex etc)

Thanks fedxa! I'll try that.

Offline

#4 2014-11-01 23:30:36

emacsomancer
Member
Registered: 2014-09-20
Posts: 211

Re: [Solved] Setting up AUCTeX in Emacs to work with Zathura (synctex etc)

fedxa wrote:

Not the nicest solution, but it should work,

1. Create file zathura-sync.sh somewhere in you path with the following contents:

#!/bin/sh
pos="$1"
pdffile="$2"
zathura --synctex-forward "$pos" "$pdffile" || \
    (
    zathura -s -x "emacsclient --eval '(progn (switch-to-buffer (file-name-nondirectory \"%{input}\")) (goto-line %{line}))'" "$pdffile" &
    sleep 1; zathura --synctex-forward "$pos" "$pdffile" )

exit

2. Add to .emacs or customize the emacs variable TeX-view-program-list

(setq TeX-view-program-list
      '(("zathura" 
	 ("zathura" (mode-io-correlate "-sync.sh")
	  " "
	  (mode-io-correlate "%n:1:%t ")
	  "%o"))))

3. Restart emacs

4. Customize TeX-view-program-selection to use "zathura" for output-pdf

I can't seem to get this to work.  When I run it from emacs, nothing happens. 

If I try running the script "by hand" from the terminal (after having compiled a LaTeX file, like file.tex, in AUCTeX),
e.g. if I run something like

zathura-sync.sh 976:1:/path/to/file.tex /path/to/file.pdf

, I get errors:

error: Could not find open instance for '/path/to/file.pdf' or got no usable data from synctex.
error: Error parsing command line arguments: Unknown option -s

error: Could not find open instance for /path/to/file.pdf' or got no usable data from synctex.

What am I doing wrong?

Last edited by emacsomancer (2014-11-01 23:46:05)

Offline

#5 2014-11-02 15:32:31

fedxa
Member
Registered: 2014-10-30
Posts: 2

Re: [Solved] Setting up AUCTeX in Emacs to work with Zathura (synctex etc)

Ok, seems zathura's interface is quite in a development stage.  My script stoped working for me after I updated zathura to a later version smile
Try the following:

#!/bin/sh
pos="$1"
pdffile="$2"
zathura --synctex-forward "$pos" "$pdffile" || \
    (
    zathura -x "emacsclient --eval '(progn (switch-to-buffer (file-name-nondirectory \"%{input}\")) (goto-line %{line}))'" "$pdffile" &
    sleep 1; zathura --synctex-forward "$pos" "$pdffile" )

Offline

#6 2014-11-02 17:55:40

emacsomancer
Member
Registered: 2014-09-20
Posts: 211

Re: [Solved] Setting up AUCTeX in Emacs to work with Zathura (synctex etc)

Many thanks - it now works perfectly!  (Zathura is really great too - nice, quick, etc. - much better than Okular for editing TeX files.)

Offline

#7 2014-11-14 15:04:07

Javafant
Member
Registered: 2012-04-02
Posts: 19

Re: [Solved] Setting up AUCTeX in Emacs to work with Zathura (synctex etc)

Just a quick remark: if you use a different master file synctex will not properly like this. This can be easily fixed by replacing

(mode-io-correlate "%n:1:%t ")

with

(mode-io-correlate "%n:1:%b ")

Offline

#8 2014-11-14 15:25:25

Javafant
Member
Registered: 2012-04-02
Posts: 19

Re: [Solved] Setting up AUCTeX in Emacs to work with Zathura (synctex etc)

And another tip: replacing

(switch-to-buffer (file-name-nondirectory \"%{input}\"))

with

(find-file \"%{input}\")

automatically opens the correct files if they are not already open instead of just creating a buffer with that name.

Offline

#9 2014-11-14 17:10:03

emacsomancer
Member
Registered: 2014-09-20
Posts: 211

Re: [Solved] Setting up AUCTeX in Emacs to work with Zathura (synctex etc)

Thanks Javafant - I'll try those.

Offline

#10 2020-11-07 02:18:59

bvraghav
Member
Registered: 2020-11-07
Posts: 1

Re: [Solved] Setting up AUCTeX in Emacs to work with Zathura (synctex etc)

A simpler solution to the same problem can be inferred from this page...

Combining it with the solutions illustrated here: Add the following to $HOME/.config/zathura/zathurarc

# $HOME/.config/zathura/zathurarc
# Adding reverse search between emacs and zathura
set synctex true
set synctex-editor-command "emacsclient +%{line} %{input}"

For a quick and dirty check, try:

$ zathura --synctex-forward 1440:0:foo.tex foo.pdf

Tested. It works with

GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.22) of 2020-08-13

Try opening a pdf in zathura, and ctrl+click. It should work. Assuming, of course, that an emacs instance is running in daemon mode.

The forward search is relatively easy, and is also clearly listed on emacswiki and emacs stackexchange:

;; Add this to .emacs.d/init.el:
(with-eval-after-load "tex"
  ;; enable synctex support for latex-mode
  (add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)
  ;; add a new view program
  (add-to-list 'TeX-view-program-list
        '(;; arbitrary name for this view program
          "Zathura"
          (;; zathura command (may need an absolute path)
           "zathura"
           ;; %o expands to the name of the output file
           " %o"
           ;; insert page number if TeX-source-correlate-mode
           ;; is enabled
           (mode-io-correlate " --synctex-forward %n:0:%b"))))
  ;; use the view command named "Zathura" for pdf output
  (setcdr (assq 'output-pdf TeX-view-program-selection) '("Zathura")))

The only advantage to using '-x' switch on 'zathura' commandline, is that FWIW, the synctex works even without explicitly having spawned the viewer with emacs.

Last edited by bvraghav (2020-11-07 02:58:06)

Offline

Board footer

Powered by FluxBB