Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: HOWTO: Evince + SyncTeX + vim/emacs/scite/lyx/kile/$EDITOR + forward/backward search

  1. #1
    Join Date
    Nov 2008
    Beans
    5

    HOWTO: Evince + SyncTeX + vim/emacs/scite/lyx/kile/$EDITOR + forward/backward search

    Hi!

    For all of you who didn't get forward/backward search to work. Here is my solution. Thanks to José Aliste who wrote gedit-synctex-plugin:

    Preamble

    1. Download these files
    2. deflate them to ~/bin (or something within $PATH)


    Backward Search (Evince → Editor)

    1. Adopt the first line of »~/bin/evince« (EDITORCMD) to your needs. (run »evince_backward_search« to get help for possible entries)
    2. Compile your .tex File with synctex (»pdflatex -synctex=1 myfile.tex«)
    3. Run »evince myfile.pdf« (The script should run evince_backward_search and evince)
    4. click on some text in evince with »Ctrl+leftclick«
    5. the editor should jump to the corresponding line


    Forward Search (Editor → Evince)

    1. you have to tell your editor, to run »evince_forward_search $PDFFILE $LINE $TEXFILE« when pressing some key.
    2. go to some line in your editor and press the key
    3. evince should mark the corresponding line



    in my case (using vim-latexsuite), I wrote in ~/.vim/after/ftplugin/tex.vim:

    Code:
    function! Tex_ForwardSearchLaTeX()
      let cmd = 'evince_forward_search ' . fnamemodify(Tex_GetMainFileName(), ":p:r") .  '.pdf ' . line(".") . ' ' . expand("%:p")
      let output = system(cmd)
    endfunction
    Afterwards you can do forward search in vim with \ls

    Ben

    edit: thanks to hugmenot, I changed the code according to your comment
    edit: changed .vim/ftplugin to .vim/after/ftplugin (thanks to jorges00)
    Last edited by Ben___; July 21st, 2011 at 12:44 AM. Reason: adopted to jorges00 advice

  2. #2
    Join Date
    Mar 2006
    Beans
    Hidden!

    Re: HOWTO: Evince + SyncTeX + vim/emacs/scite/lyx/kile/$EDITOR + forward/backward sea

    I have the following improvements:


    Code:
    EDITORCMD="vim --servername 'VIM' --remote-silent '+%l<Enter>:match Search /\%%ll/' %f"
    Make it remote-silent and highlight the line it jumped to. (in bin/evince, ignore vim --servername 'VIM')


    And

    Code:
    function! Tex_ForwardSearchLaTeX()
    	let commandline = 'evince_forward_search '. fnamemodify(Tex_GetMainFileName(), ":p:r") .'.pdf '. line(".") .' '. expand("%:p")
    	let output = system(commandline)
    endfunction
    Use system() to make it silent and not prompt the user.

  3. #3
    Join Date
    Mar 2006
    Beans
    Hidden!

    Re: HOWTO: Evince + SyncTeX + vim/emacs/scite/lyx/kile/$EDITOR + forward/backward sea

    Once we have sorted this out properly we should post it here

  4. #4
    Join Date
    Jun 2007
    Beans
    10

    Re: HOWTO: Evince + SyncTeX + vim/emacs/scite/lyx/kile/$EDITOR + forward/backward sea

    Was this solution tested on gnome-2.32 or in gnome-3. I've read here that the dbus interface has changed in gnome-3, and I get some messages about function on_sync_source() taking exactly 3 arguments, but being given 4. Could this be the source of the error?

    The solution in the link above works for me under gnome-3, but the one given here seems much cleaner, i.e. don't have to manually launch a process, etc.

    Thanks in advance,

    jorges

  5. #5
    Join Date
    Jun 2007
    Beans
    10

    Re: HOWTO: Evince + SyncTeX + vim/emacs/scite/lyx/kile/$EDITOR + forward/backward sea

    Quote Originally Posted by jorges00 View Post
    Was this solution tested on gnome-2.32 or in gnome-3. I've read here that the dbus interface has changed in gnome-3, and I get some messages about function on_sync_source() taking exactly 3 arguments, but being given 4. Could this be the source of the error?

    The solution in the link above works for me under gnome-3, but the one given here seems much cleaner, i.e. don't have to manually launch a process, etc.

    Thanks in advance,

    jorges
    I found the answer myself: The solution posted above needs some changes in order to work with gnome-3, as it seems the dbus interface changed.

    Below there's a diff of the required changes:

    Code:
    diff -urN evince_synctex/evince_backward_search evince_synctex.mod/evince_backward_search
    --- evince_synctex/evince_backward_search       2011-04-26 03:20:28.000000000 -0300
    +++ evince_synctex.mod/evince_backward_search   2011-05-05 00:57:11.848306440 -0300
    @@ -104,14 +104,14 @@
                 if self._log:
                     self._log.debug("GetWindowList returned empty list")
    
    -    def on_sync_source(self, input_file, source_link):
    +    def on_sync_source(self, input_file, source_link, time):
             print input_file + ":" + str(source_link[0])
             cmd = re.sub("%f",input_file,self.editor)
             cmd = re.sub("%l",str(source_link[0]), cmd)
             print cmd
             subprocess.call(cmd, shell=True)
             if self.source_handler is not None:
    -            self.source_handler(input_file, source_link)
    +            self.source_handler(input_file, source_link, time)
    
    
     ## This file offers backward search in any editor.
    diff -urN evince_synctex/evince_forward_search evince_synctex.mod/evince_forward_search
    --- evince_synctex/evince_forward_search        2011-03-23 18:53:05.000000000 -0300
    +++ evince_synctex.mod/evince_forward_search    2011-05-05 00:57:21.511639938 -0300
    @@ -44,4 +44,4 @@
     except dbus.DBusException:
         print_exc()
    
    -window.SyncView(tex_file, (line_number,1), dbus_interface="org.gnome.evince.Window")
    +window.SyncView(tex_file, (line_number,1), 0, dbus_interface="org.gnome.evince.Window")
    jorges

  6. #6
    Join Date
    Jun 2007
    Beans
    10

    Re: HOWTO: Evince + SyncTeX + vim/emacs/scite/lyx/kile/$EDITOR + forward/backward sea

    Quote Originally Posted by hugmenot View Post
    I have the following improvements:


    Code:
    EDITORCMD="vim --servername 'VIM' --remote-silent '+%l<Enter>:match Search /\%%ll/' %f"
    Would someone explain the pattern used to highlight the line in vim? I mean the "\%%ll" pattern. I can't find the information within vim's docs, and google searches are useless as it ignores special characters.

    Thanks

    jorges

  7. #7
    Join Date
    Mar 2006
    Beans
    Hidden!

    Re: HOWTO: Evince + SyncTeX + vim/emacs/scite/lyx/kile/$EDITOR + forward/backward sea

    Quote Originally Posted by jorges00 View Post
    Code:
    EDITORCMD="vim --servername 'VIM' --remote-silent '+%l<Enter>:match Search /\%%ll/' %f"
    Would someone explain the pattern used to highlight the line in vim? I mean the "\%%ll" pattern. I can't find the information within vim's docs, and google searches are useless as it ignores special characters.
    Yes. The regex pattern /\%50l/ would match the whole line 50, check :help /ordinary-atom. The awkward part come in where %l is also the replacement variable that Evince needs to substitute the line number.

    • +%l → go to line %l (and Enter to do it)
    • :match Search /\%%ll/' → highlight line %l
    • %f → load file %f

  8. #8
    Join Date
    Jun 2007
    Beans
    10

    Re: HOWTO: Evince + SyncTeX + vim/emacs/scite/lyx/kile/$EDITOR + forward/backward sea

    Quote Originally Posted by hugmenot View Post
    Yes. The regex pattern /\%50l/ would match the whole line 50, check :help /ordinary-atom. The awkward part come in where %l is also the replacement variable that Evince needs to substitute the line number.

    • +%l → go to line %l (and Enter to do it)
    • :match Search /\%%ll/' → highlight line %l
    • %f → load file %f
    Ahh! that's why I couldn't find the pattern in the vim docs. Thanks for clarifying it!

    jorges

  9. #9
    Join Date
    Sep 2009
    Beans
    1

    Re: HOWTO: Evince + SyncTeX + vim/emacs/scite/lyx/kile/$EDITOR + forward/backward sea

    Hi Ben!
    I also use the vim-latexsuite package (just installed today) and i can't do forward search (nor backward). I added the lines you mentioned to the tex.vim file but i get the same result as if i'd use my old tex.vim file. I'm kind of newbie at all this, so if you need more information please ask. I don't know if it is relevant information, but i use debian squeeze.
    Thanks!

  10. #10
    Join Date
    Jun 2007
    Beans
    10

    Re: HOWTO: Evince + SyncTeX + vim/emacs/scite/lyx/kile/$EDITOR + forward/backward sea

    Quote Originally Posted by ezitoc View Post
    Hi Ben!
    I also use the vim-latexsuite package (just installed today) and i can't do forward search (nor backward). I added the lines you mentioned to the tex.vim file but i get the same result as if i'd use my old tex.vim file. I'm kind of newbie at all this, so if you need more information please ask. I don't know if it is relevant information, but i use debian squeeze.
    Thanks!
    The same happened to me. What I did to solve it was to define the function suggested by Ben in the ~/.vim/after/ftplugin/tex.vim, and then it did take precedence over the function defined by latex-suite.

    jorges

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •