3

I am writing my thesis and I have main.tex that calls all other chapter.tex files.

Whenever I made change, the internal viewer of TexStudio highlight it. But I am not a fan of the internal viewer. The problem is when the file is already opened in Preview, the updated pdf goes back to the beginning after every compile/new edit which wastes my time scrolling all the way down to ToC and then to the text. I was using other Tex editors where even the Preview won't go back to the beginning.

Is there any setting to this? Hope the question is clear.

1

1 Answer 1

2

You may be out of luck with Preview (see, e.g., this question and this question on our Apple sister site). The fact is that Preview is not really designed for this type of situation.

This question on StackOverflow offers a solution that may work, by adding a script to forcibly close and then re-open the PDF when it is updated. Since Preview remembers the last location used, this may work, but it may run into a timing issue (does the script get the file event before or after Preview?) and seems to require having a terminal window open.

Alternatively, since TeXStudio can send file and line information to an external program, it wouldn't be impossible to write a script that takes this information, finds the corresponding PDF position using the synctex utility (included with MacTeX) and use something like the osascript commands in this script to at least get Preview to the right page. Something like this (this doesn't do any error checking and I haven't really tested it):

#!/bin/sh

PDFFILE=$1
TEXFILE=$2
LINE=$3

PAGE=$(synctex view -i "$LINE:0:$TEXFILE" -o "$PDFFILE" | grep 'Page' | head -n 1 | sed 's/Page://g')

if [$PAGE -eq '']; then PAGE=1; fi

open -a Preview "$PDFFILE"
sleep .5
osascript -e 'tell application "Preview" to activate' \
              -e 'delay 0.25' \
              -e 'tell application "System Events" to tell process "Preview" to click menu item "Go to Page…" of menu "Go" of menu bar 1' \
              -e 'delay 0.25' \
              -e "tell application \"System Events\" to keystroke \"$PAGE\"" \
              -e 'delay 0.25' \
              -e 'tell application "System Events" to key code 36'

Which could be save somewhere as open_preview, marked executable (chmod u+x open_preview) and then used from TeXStudio by setting the viewer command to:

</path/to/open_preview> ?am.pdf ?c:am.tex @

This won't keep the scroll position, but it should at least open the same page as the one you're working on in TeXStudio.

The sanest thing to do, however, is install Skim and use that for previewing the documents, as it implements the reload and stay in place feature and TeXStudio includes instructions for integrating with it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .