GeneralUsing a python plugin in sublime Text

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
thedreamshaper
Posts: 44
Joined: Wed Aug 04, 2010 7:00 pm

Using a python plugin in sublime Text

Post by thedreamshaper »

A work friend has sent me some python code for LaTex he made "once upon a time", and i wish to run it from Sublime text. How can i do this ? also can i compile from sublime text ?

the code:

Code: Select all

# Import packages
import sublime, sublimeplugin, os, os.path, re
# Import namespaces
from os.path import exists

# Code for inserting references
class TexCiteCommand(sublimeplugin.TextCommand):
	def run(self, view, args):
		print "Starter reference modul"
		currentDir=os.getcwd()
		dirFiles=os.listdir(currentDir)
		bibTex=[] # List of bibTex files
		for i in range(len(dirFiles)): # Looping all file entries trough
			if dirFiles[i].endswith(".bib"): 				
				bibTex.append(dirFiles[i])		
		if len(bibTex)>1: # Tjeck if there is more than one bibtex file. This will not matter anything for this function
			print "Notice that there exist several .bib tex files. We use them all"
		# Reading the bibtext files
		for i in range(len(bibTex)):
			try:
				bibFile=open(bibTex[0])
			except IOError:
				print "Unable to open the bibtex file.: ", bibTex[0], " The code stops"
				return
			else:
				textBibFil=bibFile.readlines()
				bibFile.close()
		# Looping all the lines trough. 
		referencer=[] # Empty list with references
		for i in range(len(textBibFil)):
			if textBibFil[i][0]=="@": # Here we have a reference
				stringStart=textBibFil[i].find("{") # Start char
				stringEnd=textBibFil[i].find(",")   # End char
				referencer.append(textBibFil[i][stringStart+1:stringEnd]) # Appending the pure reference		
		# Prints the entry
		def insertReference(i):								
			view.runCommand("insertCharacters", [referencer[i]])					
		# Show select panel
		view.window().showSelectPanel(referencer, insertReference, None, 0)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply