SublimeText / LaTeXTools

LaTeX plugin for Sublime Text
https://latextools.readthedocs.io/
2.01k stars 365 forks source link

open pdf when opening .tex file #979

Open ghost opened 7 years ago

ghost commented 7 years ago

newly_tex.py, in effect when sublime is not running and opening latex file for the first time

import sublime, sublime_plugin,os,subprocess

def plugin_loaded():
    view = sublime.active_window().active_view()
    fs=view.file_name()
    if fs is not None and len(fs)>4:
        fnm=fs[:-4]
        fext=fs[-4:]
        fsp=fnm+".pdf"

        if fext=='.tex' and os.path.isfile(fsp):
            subprocess.Popen(("open", "-a", "/Applications/Skim.app", fsp))

texpdf.py, in effect when sublime is running

import sublime, sublime_plugin,os,subprocess

class pdfopener(sublime_plugin.EventListener):
    def on_load(self, view):
        fs=view.file_name()
        if fs is not None and len(fs)>4:
            fnm=fs[:-4]
            fext=fs[-4:]
            fsp=fnm+".pdf"

            if fext=='.tex' and os.path.isfile(fsp):
                subprocess.Popen(("open", "-a", "/Applications/Skim.app", fsp))
tell application "System Events" to tell process "Sublime Text"
    tell window 1
        set position to {0, 0}
        set size to {648, 826}
    end tell
end tell

tell application "Skim" to activate

try
    tell application "System Events" to tell process "Skim"
        tell window 1
            set position to {648, 0}
            set size to {792, 826}
        end tell
    end tell
end try

the size/position is for 1440x900 resolution and a small dock size. adjust accordingly.

function appWatcher(appName, eventType, appObject)
    if (eventType == hs.application.watcher.terminated) then
        if (appName == "Sublime Text") then
            local skmapp=hs.appfinder.appFromName("Skim")
            if(skmapp ~= nil) then
                skmapp:kill()
                -- hs.alert.show("closed")
            end
        end
    end
end

-- local
lxwatcher = hs.application.watcher.new(appWatcher)
lxwatcher:start()

my code may not be robust, and there may be much better way to do that. are you interested in bringing that function into latextools? Thanks!

r-stein commented 7 years ago
ig0774 commented 7 years ago

I could see a use for including the "open the corresponding PDF when the TeX file is opened" part of things, but, as @r-stein said, the other parts are probably not things we'd be looking to add.