3 # Copyright (C) 2010 Jose Aliste <jose.aliste@gmail.com>
4 # 2011 Benjamin Kellermann <Benjamin.Kellermann@tu-dresden.de>
6 # Translated from Bash to Python by Juergen Spitzmueller <spitz@lyx.org> 2017.
8 # This program is free software; you can redistribute it and/or modify it under
9 # the terms of the GNU General Public Licence as published by the Free Software
10 # Foundation; either version 2 of the Licence, or (at your option) any later
13 # This program is distributed in the hope that it will be useful, but WITHOUT
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 # FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for more
18 # You should have received a copy of the GNU General Public Licence along with
19 # this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
20 # Street, Fifth Floor, Boston, MA 02110-1301, USA
23 from subprocess import Popen
25 # The lyxclient command for backward search
26 editor_cmd = "lyxclient -g %f %l"
28 # Check we have (only) one argument
29 if len(sys.argv) != 2:
30 print("Usage: evince_sync_lyx pdf_file")
33 # Arg 1 is supposed to be the PDF file
34 pdf_file = os.path.abspath(sys.argv[1])
36 # Check whether the file exists & is readable
37 if not os.path.isfile(pdf_file):
38 print("%s is not valid/readable PDF file." % pdf_file)
41 # The accompanying synctex file has the same name than the PDF
42 # but with .synctex.gz extension
43 synctex_file, ext = os.path.splitext(pdf_file)
44 synctex_file += ".synctex.gz"
46 # If we have a synctex file, start the evince_backward_search script
48 if os.path.isfile(synctex_file):
49 bsproc = Popen(["evince_backward_search", pdf_file, editor_cmd])
52 # Notwithstanding the previous, start evince and open the PDF
53 vproc = Popen(['evince', pdf_file])
56 # If evince has been closed (hence vproc.wait()), we terminate
57 # the evince_backward_search script (if we have started it)