def show_output_panel(self, force=False): if force or self.hide_panel_level != 'always': f = functools.partial( self.window.run_command, "show_panel", {"panel": "output.exec"} ) run_on_main_thread(f, default_value=None)
def show_output_panel(self, force=False): if force or self.hide_panel_level != 'always': f = functools.partial( self.window.run_command, "show_panel", {"panel": "output.latextools"} ) run_on_main_thread(f, default_value=None)
def get_setting(setting, default=None, view=None): if default is not None: return run_on_main_thread(partial(_get_setting, setting, default, view), default_value=default) else: return run_on_main_thread(partial(_get_setting, setting, view=view))
def get_setting(setting, default=None, view=None): if default is not None: return run_on_main_thread( partial(_get_setting, setting, default, view), default_value=default) else: return run_on_main_thread( partial(_get_setting, setting, view=view))
def _preprocess_file(file_name): """ reads and preprocesses a file, return the raw content and the content without comments """ raw_content = utils.run_on_main_thread( partial(utils.get_file_content, file_name, force_lf_endings=True)) # replace all comments with spaces to not change the position # of the rest comments = [c for c in _RE_COMMENT.finditer(raw_content)] content = list(raw_content) for m in comments: for i in range(m.start(), m.end()): content[i] = ' ' content = "".join(content) return raw_content, content
def get_texpath(): ''' Returns the texpath setting with any environment variables expanded ''' def _get_texpath(): try: texpath = get_setting(sublime.platform(), {}).get('texpath') except AttributeError: # hack to reload this module in case the calling module was # reloaded exc_info = sys.exc_info try: reload(sys.modules[get_texpath.__module__]) texpath = get_setting(sublime.platform(), {}).get('texpath') except: reraise(*exc_info) return expand_vars(texpath) if texpath is not None else None # ensure _get_texpath() is run in a thread-safe manner return run_on_main_thread(_get_texpath, default_value=None)
def run(self): texpath = self.texpath results = [] env = copy.deepcopy(os.environ) if texpath is not None: env['PATH'] = texpath if self.build_env is not None: update_environment(env, self.build_env) table = [ ['Variable', 'Value'] ] table.append(['PATH', env.get('PATH', '')]) if self.uses_miktex: get_tex_path_variable = get_tex_path_variable_miktex should_run = which('findtexmf', path=texpath) is not None else: get_tex_path_variable = get_tex_path_variable_texlive should_run = which('kpsewhich', path=texpath) is not None if should_run: for var in ['TEXINPUTS', 'BIBINPUTS', 'BSTINPUTS']: table.append([var, get_tex_path_variable(var, env)]) if self.uses_miktex: for var in ['BIBTEX', 'LATEX', 'PDFLATEX', 'MAKEINDEX', 'MAKEINFO', 'TEX', 'PDFTEX', 'TEXINDEX']: value = env.get(var, None) if value is not None: table.append([var, value]) results.append(table) table = [ ['Program', 'Location', 'Status', 'Version'] ] # skip sublime_exe on OS X # we only use this for the hack to re-focus on ST # which doesn't work on OS X anyway if sublime.platform() != 'osx': sublime_exe = self.sublime_exe available = sublime_exe is not None if available: if not os.path.isabs(sublime_exe): sublime_exe = which(sublime_exe) basename, extension = os.path.splitext(sublime_exe) if extension is not None: sublime_exe = ''.join((basename, extension.lower())) version_info = get_version_info( sublime_exe, env=env ) if available else None table.append([ 'sublime', sublime_exe if available and version_info is not None else u'', (u'available' if available and version_info is not None else u'missing'), version_info if version_info is not None else u'unavailable' ]) # a list of programs, each program is either a string or a list # of alternatives (e.g. 32/64 bit version) programs = [ 'latexmk' if not self.uses_miktex else 'texify', 'pdflatex', 'xelatex', 'lualatex', 'biber', 'bibtex', 'bibtex8', 'kpsewhich' ] if _HAS_PREVIEW: # ImageMagick requires gs to work with PDFs programs += [['magick', 'convert']] for program in programs: if isinstance(program, list): program_list = program program = program_list[0] location = None for p in program_list: location = which(p, path=texpath) if location is not None: program = p break else: location = which(program, path=texpath) # convert.exe on Windows can refer to %sysroot%\convert.exe, # which should not be used; in that case, simple report magick.exe # as not existing if program == 'convert' and sublime.platform() == 'windows': system_root = get_system_root().lower() if location.lower().startswith(system_root): program = 'magick' location = None available = location is not None if available: basename, extension = os.path.splitext(location) if extension is not None: location = ''.join((basename, extension.lower())) version_info = get_version_info( location, env=env ) if available else None available_str = ( u'available' if available and version_info is not None else u'missing' ) if (available and program in ['magick', 'convert'] and not convert_installed()): available_str = u'restart required' table.append([ program, location if available and version_info is not None else u'', available_str, version_info if version_info is not None else u'unavailable' ]) program = 'ghostscript' location = get_gs_command() available = location is not None if available: basename, extension = os.path.splitext(location) if extension is not None: location = ''.join((basename, extension.lower())) version_info = get_version_info( location, env=env ) if available else None available_str = ( u'available' if available and version_info is not None else u'missing' ) if available and _HAS_PREVIEW and not ghostscript_installed(): available_str = u'restart required' table.append([ program, location if available and version_info is not None else u'', available_str, version_info if version_info is not None else u'unavailable' ]) results.append(table) # This really only works for the default template # Note that no attempt is made to find other packages that the # included package depends on if (_HAS_PREVIEW and ghostscript_installed() and get_setting('preview_math_template_file') is None and get_setting("preview_math_mode", view=self.view) != "none"): find_package_re = re.compile( r'\\usepackage(?:\[[^\]]*\])?\{(?P<pkg>[^\}]*)\}' ) packages = ["standalone.cls", "preview.sty", "xcolor.sty"] package_settings = get_setting( "preview_math_template_packages", [], view=self.view) # extract all packages from each package line for pkg_str in package_settings: # search for all \usepackage in the line for m in find_package_re.finditer(pkg_str): pkg_arg = m.group("pkg") # search for each package in the \usepackage argument for pkg in pkg_arg.split(","): pkg = pkg.strip() if pkg: packages.append(pkg + ".sty") if packages: table = [[u'Packages for equation preview', u'Status']] for package in packages: available = kpsewhich(package) is not None package_name = package.split(".")[0] table.append([ package_name, (u'available' if available else u'missing') ]) results.append(table) run_on_main_thread(partial(self._on_main_thread, results), timeout=30)
def run(self): texpath = self.texpath results = [] env = copy.deepcopy(os.environ) if texpath is not None: env['PATH'] = texpath if self.build_env is not None: update_environment(env, self.build_env) table = [ ['Variable', 'Value'] ] table.append(['PATH', env.get('PATH', '')]) if self.uses_miktex: get_tex_path_variable = get_tex_path_variable_miktex should_run = which('findtexmf', path=texpath) is not None else: get_tex_path_variable = get_tex_path_variable_texlive should_run = which('kpsewhich', path=texpath) is not None if should_run: for var in ['TEXINPUTS', 'BIBINPUTS', 'BSTINPUTS']: table.append([var, get_tex_path_variable(var, env)]) if self.uses_miktex: for var in ['BIBTEX', 'LATEX', 'PDFLATEX', 'MAKEINDEX', 'MAKEINFO', 'TEX', 'PDFTEX', 'TEXINDEX']: value = env.get(var, None) if value is not None: table.append([var, value]) results.append(table) table = [ ['Program', 'Location', 'Status', 'Version'] ] # skip sublime_exe on OS X # we only use this for the hack to re-focus on ST # which doesn't work on OS X anyway if sublime.platform() != 'osx': sublime_exe = self.sublime_exe available = sublime_exe is not None if available: if not os.path.isabs(sublime_exe): sublime_exe = which(sublime_exe) basename, extension = os.path.splitext(sublime_exe) if extension is not None: sublime_exe = ''.join((basename, extension.lower())) version_info = get_version_info( sublime_exe, env=env ) if available else None table.append([ 'sublime', sublime_exe, (u'available' if available and version_info is not None else u'missing'), version_info if version_info is not None else u'unavailable' ]) # a list of programs, each program is either a string or a list # of alternatives (e.g. 32/64 bit version) programs = [ 'latexmk' if not self.uses_miktex else 'texify', 'pdflatex', 'xelatex', 'lualatex', 'biber', 'bibtex', 'bibtex8', 'kpsewhich', ('gs' if sublime.platform() != 'windows' else ['gswin32c', 'gswin64c', 'gs']) ] if sublime.version() >= '3118': # ImageMagick requires gs to work with PDFs programs += [['magick', 'convert']] for program in programs: if isinstance(program, list): program_list = program program = program_list[0] location = None for p in program_list: location = which(p, path=texpath) if location is not None: program = p break else: location = which(program, path=texpath) available = location is not None if available: basename, extension = os.path.splitext(location) if extension is not None: location = ''.join((basename, extension.lower())) version_info = get_version_info( location, env=env ) if available else None available_str = ( u'available' if available and version_info is not None else u'missing') if (available and program in ['magick', 'convert'] and not convert_installed()): available_str = u'restart required' table.append([ program, location, available_str, version_info if version_info is not None else u'unavailable' ]) results.append(table) run_on_main_thread(partial(self._on_main_thread, results), timeout=30)
def run(self): texpath = self.texpath results = [] env = copy.deepcopy(os.environ) if texpath is not None: env['PATH'] = texpath if self.build_env is not None: update_environment(env, self.build_env) table = [['Variable', 'Value']] table.append(['PATH', env.get('PATH', '')]) if self.uses_miktex: get_tex_path_variable = get_tex_path_variable_miktex should_run = which('findtexmf', path=texpath) is not None else: get_tex_path_variable = get_tex_path_variable_texlive should_run = which('kpsewhich', path=texpath) is not None if should_run: for var in ['TEXINPUTS', 'BIBINPUTS', 'BSTINPUTS']: table.append([var, get_tex_path_variable(var, env)]) if self.uses_miktex: for var in [ 'BIBTEX', 'LATEX', 'PDFLATEX', 'MAKEINDEX', 'MAKEINFO', 'TEX', 'PDFTEX', 'TEXINDEX' ]: value = env.get(var, None) if value is not None: table.append([var, value]) results.append(table) table = [['Program', 'Location', 'Status', 'Version']] # skip sublime_exe on OS X # we only use this for the hack to re-focus on ST # which doesn't work on OS X anyway if sublime.platform() != 'osx': sublime_exe = self.sublime_exe available = sublime_exe is not None if available: if not os.path.isabs(sublime_exe): sublime_exe = which(sublime_exe) basename, extension = os.path.splitext(sublime_exe) if extension is not None: sublime_exe = ''.join((basename, extension.lower())) version_info = get_version_info(sublime_exe, env=env) if available else None table.append([ 'sublime', sublime_exe, (u'available' if available and version_info is not None else u'missing'), version_info if version_info is not None else u'unavailable' ]) # a list of programs, each program is either a string or a list # of alternatives (e.g. 32/64 bit version) programs = [ 'latexmk' if not self.uses_miktex else 'texify', 'pdflatex', 'xelatex', 'lualatex', 'biber', 'bibtex', 'bibtex8', 'kpsewhich' ] if _HAS_PREVIEW: # ImageMagick requires gs to work with PDFs programs += [['magick', 'convert']] for program in programs: if isinstance(program, list): program_list = program program = program_list[0] location = None for p in program_list: location = which(p, path=texpath) if location is not None: program = p break else: location = which(program, path=texpath) available = location is not None if available: basename, extension = os.path.splitext(location) if extension is not None: location = ''.join((basename, extension.lower())) version_info = get_version_info(location, env=env) if available else None available_str = (u'available' if available and version_info is not None else u'missing') if (available and program in ['magick', 'convert'] and not convert_installed()): available_str = u'restart required' table.append([ program, location, available_str, version_info if version_info is not None else u'unavailable' ]) program = 'ghostscript' location = get_gs_command() available = location is not None if available: basename, extension = os.path.splitext(location) if extension is not None: location = ''.join((basename, extension.lower())) version_info = get_version_info(location, env=env) if available else None available_str = (u'available' if available and version_info is not None else u'missing') if available and _HAS_PREVIEW and not ghostscript_installed(): available_str = u'restart required' table.append([ program, location, available_str, version_info if version_info is not None else u'unavailable' ]) results.append(table) # This really only works for the default template # Note that no attempt is made to find other packages that the # included package depends on if (_HAS_PREVIEW and convert_installed() and get_setting('preview_math_template_file') is None and get_setting("preview_math_mode", view=self.view) != "none"): find_package_re = re.compile( r'\\usepackage(?:\[[^\]]*\])?\{(?P<pkg>[^\}]*)\}') packages = ["standalone.cls", "preview.sty", "xcolor.sty"] package_settings = get_setting("preview_math_template_packages", [], view=self.view) # extract all packages from each package line for pkg_str in package_settings: # search for all \usepackage in the line for m in find_package_re.finditer(pkg_str): pkg_arg = m.group("pkg") # search for each package in the \usepackage argument for pkg in pkg_arg.split(","): pkg = pkg.strip() if pkg: packages.append(pkg + ".sty") if packages: table = [[u'Packages for equation preview', u'Status']] for package in packages: available = kpsewhich(package) is not None package_name = package.split(".")[0] table.append([ package_name, (u'available' if available else u'missing') ]) results.append(table) run_on_main_thread(partial(self._on_main_thread, results), timeout=30)