So I want to use LaTeX in sublime text 2, and I came across the plugin LaTeXTools. It works great, but it requires me to install Skim PDF Viewer. Is it possible to set it up so that when I compile the latex file it opens it in the PDF preview already installed on my mac?
UPDATE: This does not work as advertised.
I undeleted this post after @Bordaigorl posted the same solution. There are still some unresolved issues. Changing viewPDF.py
appears to work only if Skim is not installed.
The PDF-viewer in the LaTeXTools-package is configured in a file called viewPDF.py
— as @kgr already pointed out. For OSX you can change the viewer form skim
to preview
by changing line 44 from:
viewercmd = ["open", "-a", "Skim"]
to:
viewercmd = ["open", "-a", "Preview"]
But I would recommend against it. Skim is an excellent PDF viewer that takes under 10 MiB on your harddisk.
-
I already changed that line to
viewercmd = ["open", "-a", "Preview"]
inviewPDF.py
, but Sublime still opens skim rather than preview when I build my LaTeX project. I appreciate that Skim has its advantages, but there are nice things about the preview app, such a proper full screen support that allows me to do a multitouch swipe to quickly sqitch between my source and the preview. – Ubiquitous Nov 14 '13 at 10:15 -
The LaTeXTools plugin invokes the viewer from viewPDF.py
.
Line 39 to 44 is the code which is selecting the commands to invoke when running on OSX:
if s == "Darwin":
# for inverse search, set up a "Custom" sync profile, using
# "subl" as command and "%file:%line" as argument
# you also have to put a symlink to subl somewhere on your path
# Also check the box "check for file changes"
viewercmd = ["open", "-a", "Skim"]
As you can see the Skim
command is hard-coded in the script so there is no setting you can change to modify it from outside the script itself.
The simplest patch is replacing line 44 with
viewercmd = ["open", "-a", "preview"]
but be aware that if you installed Package Control
and LaTeXTool gets updated you loose your patch.
So the best solution would be to open an issue on github suggesting they could read the command to be launched from a setting instead of hard-coding it.
-
Have you really tried that? Did it really work? I thought that that was a solution, but it did never actually work . . . – DG' Nov 20 '13 at 19:00
-
@DG' I made it a community wiki so we can maybe make it work together. I do not have access to a machine running OSX at the moment so I can't debug it properly. In principle that is the solution, I am not actually sure how you should invoke
preview.app
– Bordaigorl Nov 20 '13 at 19:33 -
-
3Ok, maybe I know why. Are you sure you are actually invoking the
view_pdf
command? If you open the sublime console and typewindow.run_command("view_pdf")
does it work? If so it means that you were actually calling thejump_to_pdf
command which also has the invocation toSkim
hardcoded. – Bordaigorl Nov 20 '13 at 21:50 -
1I replaced line 341 in
makePDF.py
withwindow.run_command("view_pdf")
and it worked. I don't know if I broke something else, but so far it works. – arjenz Nov 29 '13 at 20:27
Skim doesn't work currently in OSX Yosemite, so it looks like we're stuck with Preview for the time being.
I'm not sure what line @arjenz is referring to in his comment, since the code may have changed, but I couldn't get his solution to work. Here's what I did:
Find the jumpToPDF.py file, and change the lines (62-70 in commit 517c5a3):
if plat == 'darwin':
options = ["-r","-g"] if keep_focus else ["-r"]
if forward_sync:
subprocess.Popen(["/Applications/Skim.app/Contents/SharedSupport/displayline"] +
options + [str(line), pdffile, srcfile])
else:
skim = os.path.join(sublime.packages_path(),
'LaTeXTools', 'skim', 'displayfile')
subprocess.Popen(['sh', skim] + options + [pdffile])
To this:
if plat == 'darwin':
subprocess.Popen(["open", "-a", "Preview"] + [pdffile])
I am also not sure what this breaks, if anything, but the package is working fine so far.
A more updated answer; the best shot for switching to Preview.app is, in viewPDF.py, to set:
if s == "Darwin":
viewercmd = ["open", "-a", "Preview"]
With this, after compiling, you should be able to execute window.run_command("view_pdf")
in the console and it should open the generated pdf with Preview. Then, in makePDF.py, change:
if can_switch_to_pdf:
self.window.active_view().run_command("jump_to_pdf", {"from_keybinding": False})
To:
if can_switch_to_pdf:
self.window.run_command("view_pdf")
In do_finish
method inside make_pdfCommand
class, or just change:
self.output_view.run_command("do_finish_edit")
To:
self.window.run_command("view_pdf")
In the previous line.
Hope it helps, tested it last night and it works!
PS: run_command
should be executed on self.window
, otherwise it woud not recognize window
object.
-
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Symbol 1 Aug 26 '15 at 9:28
The latest (2016) answer, following the addition of user-selectable viewers in bug fix #454, is to open your user preferences (Preferences → Package Settings → Latextools → Settings - User), and add the line with your previewer of choice.
In my case I added this to the main body of the preferences (i.e., not in the osx
section, that didn't seem to work):
{
"hide_build_panel":"no_errors",
"viewer": "preview",
....
}
This is documented in the Latextools 'manual' on Viewers. There is also a command viewer which will run your favorite viewer from the command line.
After installing Skim, I used package manager to uninstall LatexTools, then reinstall LatexTools and restarted Sublime. Then go into Skim-->Preferences-->Sync (tab), and click "Check for changes" and choose Sublime Text from the dropdown box. Finally, in Sublime Text when wanting to build you .tex file, click Tools--> Build System and there's one that LatexTools puts in called "LaTex". Use that to build and voila! upon building it opens the pdf in Skim. Also, upon rebuild it rebuilds and Skim doesn't lose your cursor placement upon the refresh.
It's quite simple actually. This solution is ST3 and I don't know if the same applies to ST2.
- Open Sublime Text 3
- Go to Preferences-->Package settings-->LateXTools
- Select Settings-user from the menu. If this hasn't been created, it will prompt you to do so.
- Use Ctrl + F to get a kind of search bar at the bottom. Type "viewer"(with the quotes)
You will see commented out viewer settings. Beneath you will see something like
"viewer": ",
Add preview there like this:
"viewer": "preview",
- After typing out your TEX, add
\preview
to it and build
Preferences -> Browse Packages...
, select LatexTools, and thenjumpToPdf.py
; this calls a shell script that calls applescript to get Skim to do its thing. There are various options for restructuring this. However, the reason this isn't an option is that preview doesn't have good support for reloading changed files (IIRC it varies by version too), and there is no API to make it as smooth as the interface with Skim. Basically, it's not worth it... – kgr Jul 22 '13 at 20:06