开发者

Emacs/AUCTeX: Rewriting the Okular-make-url function to work with new synctex (full path + "./") syntax [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about programming within the scope defined in the help center.

Closed 9 years ago.

Improve this question

The basic problem:

Need to write an Emacs lisp function that handles forward search from a TeX file in Emacs to a line in the PDF output corresponding to the current position within the TeX file. Synctex allows for this sort of operation. However, synctex files are referenced differently as of the new version of TeXlive 2011, requiring writing of the Emacs function.

Background:

Synctex in TeXlive 2011 uses a different syntax for referring the TeX sources (technically, I suppose it has to do with the way pdflatex in TeXlive 2011 creates synctex files). In TeXlive 2010 TeX sources are just referenced using a relative path; in TeXlive 2011 TeX sources are referenced using /full/path/to/tex/source/./tex-source-file.tex.

In any case, this makes the forward search from TeX source in Emacs to pdf output in Okular break. One way of doing forward search开发者_StackOverflow社区 in Emacs to Okular involved a function like:

(defun okular-make-url () (concat
    "file://"
    (expand-file-name (funcall file (TeX-output-extension) t)
        (file-name-directory (TeX-master-file)))
    "#src:"
    (TeX-current-line)
    (TeX-current-file-name-master-relative)))

(and

 (add-to-list 'TeX-expand-list
       '("%u" okular-make-url))

 (setq TeX-view-program-list '(("Okular" "okular --unique %u")))

)

This generates a command like:

okular --unique my-file.pdf#src:88my-file.tex

Which, as of TeXlive 2010, correctly jumps to the line in the pdf output corresponding to line 88 of the TeX input. But, as discussed above, it doesn't work with TeXlive 2011, due to the new way of handling synctex paths to TeX sources.

What is needed:

What is needed is a rewriting of okular-make-url which generates something like:

okular --unique my-file.pdf#src:88/full/path/to/my/tex/source/./my-file.tex

I.e., with (1)the full path of the file + (2)"./" + (3)the file-name.

I'm not adept enough with Emacs lisp commands (and AUCTeX elisp code in particular) to be sure of how to do this. Obviously, it has to do with changing the last part of the okular-make-url function.

Suggestions?


The following seems to work:

  1. Update to latest version of Okular (v0.13) - this may or may not be necessary.
  2. Define new expander to get current directory of TeX source:
    1. Go to "Customize AUCTeX" choose "TeXCommand" then go to "TeX Expand List" and add one:
    2. Add:
      • Key: %(dir)
      • Expander: (lambda nil default-directory)
  3. In your .emacs, instead of

    (setq TeX-view-program-list '(("Okular" "okular --unique %o#src:%n%b")))
    

    use:

    (setq TeX-view-program-list '(("Okular" "okular --unique %o#src:%n%(dir)./%b")))
    

from: https://bugs.kde.org/show_bug.cgi?id=274294#c18


The answer by BeSlayed does not work for me when the .tex file being edited is in a different directory than TeX-master. The following does work:

  1. Define new expander to get current directory of TeX source:
    1. M-x customize-variable <RET> TeX-expand-list <RET>
    2. Add a new entry to the list:
      • Key: %(masterdir)
      • Expander: (lambda nil (expand-file-name (TeX-master-directory)))
      • Arguments: none
  2. Define a new view program for Okular:
    1. M-x customize-variable <RET> TeX-view-program-list <RET>
    2. Add a new entry to the list:
      • Name: Okular
      • Choice: Command
      • Command: okular --unique %o#src:%n%(masterdir)./%b
  3. Configure Okular as the PDF viewer:
    1. M-x customize-variable <RET> TeX-view-program-selection <RET>
    2. For output-pdf change the viewer to Okular

Or you can put the following in your .emacs:

;; use Okular to view AUCTeX-generated PDFs
(push '("%(masterdir)" (lambda nil (expand-file-name (TeX-master-directory))))
      TeX-expand-list)
(push '("Okular" "okular --unique %o#src:%n%(masterdir)./%b")
      TeX-view-program-list)
(push '(output-pdf "Okular") TeX-view-program-selection)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜