2 # Compile latex document and open viewer at specified location via synctex
3 # latexmk (included in texlive-bin) and wmctrl are used by the script. wmctrl
4 # is used to give evince focus after updating the document, you don't have to
5 # install it, if you don't want this functionality.
7 # latexmk is used to compile document - it should automatically
8 # compile your document multiple times and run bibtex as required.
9 # You have to tell latexmk to use the --synctex=1 option when running
10 # pdflatex, to do so, create a file ~/.latexmkrc containing:
11 # $pdflatex = 'pdflatex --interaction nonstopmode --synctex=1 %O %S';
12 # There must be a newline after this line. I havent found any way to
13 # give this info to latexmk directly from the commandline, but that
14 # would be alot easier.
16 # To get AUCTEX to use this scipt, add the following lines to your .emacs file:
17 # You can then use C-c C-c Synctex RET to compile and view in evince
18 # (eval-after-load "tex"
19 # '(add-to-list 'TeX-command-list
20 # '("Synctex" "/etc/scripts/synctex-emacs.sh %t %b %n" TeX-run-TeX nil t) t))
26 PDFFILE
="$(echo "$MAINFILE" | sed 's/\.tex/\.pdf/g')"
28 ########################################
30 ########################################
31 latexmk
-pdf "$MAINFILE"
33 ####################################
34 ## succesful latex compilation -> view with synctex
35 ####################################
37 SYNCTEX_RESULT
=$
( synctex view
-i "$LINE:$COLUMN:$FILE" -o "${PDFFILE}" -x "echo ::%{page}:%{h}:%{v}:%{width}:%{height}::" )
39 # Use bash built-in regex to parse data
40 [[ $SYNCTEX_RESULT =~
::([^
:]+):([^
:]+):([^
:]+):([^
:]+):([^
:]+):: ]]
43 if [ "${BASH_REMATCH[0]}" ]; then
44 # Get results from regex matching
45 page
=$
( expr ${BASH_REMATCH[1]} + 1 )
48 width
=${BASH_REMATCH[4]}
50 # height=$( expr $( echo ${BASH_REMATCH[5]} | grep -o ^[0-9] ) \* 2 )
51 nohup evince
--use-absolute-page --page-label "$page" --highlight-rect "${x}:${y}:${width}:${height}" "${PDFFILE}" >/dev
/null
&
53 echo "Synctex did not return usable results, viewing without synctex"
54 nohup evince
"${PDFFILE}" >/dev
/null
&