[OS X TeX] Applescript sync for BBEdit-->TeXniscope

Claus Gerhardt gerhardt at math.uni-heidelberg.de
Sat Nov 27 13:29:49 CET 2004


Synchronization BBEdit--> TeXniscope works very well, if one considers 
only a single tex file. However, in case of included files some further 
work has to be done; since the reverse synchronization T-->B works fine 
in this case, the implementation seems feasible.

Below is a script for single tex files, that assumes that the packages 
pdfsync and color are loaded; moreover TeX-Scripts-BbEdit 2.0 and the 
new, separately downloadable, subroutine preview_bbedit have to be 
installed. The script can also be considered as standard pdflatex 
typesetting script. For having two latex runs simply uncomment the line
--do shell script shellScript

Claus




-- Applescript
-- To be used with BBEdit
-- sync
-- Claus Gerhardt, Nov. 2004

(* The subroutine setnamebbedit returns baseName, texName, pdfName, 
namePath, dirName, dirNameunquoted, and saves the document of window 
texName.
*)

--set previewer to "TeXShop"
set previewer to "TeXniscope"
--set previewer to "Acrobat  6.0.1 Professional"
--set previewer to "Preview"

if previewer is equal to "Acrobat  6.0.1 Professional" then
	set process_name to "acrobat"
else
	set process_name to previewer
end if

tell application "BBEdit"
	get file of window 1
	set filepath to result
	set fileName to POSIX path of filepath as string
	
	
	
	set scriptPath to (do shell script "dirname " & 
"~/Library/TeXShop/Scripts/ex")
	set scriptPath to scriptPath & "/setnamebbedit.scpt"
	set scriptName to POSIX file scriptPath as alias
	set scriptLiB to (load script scriptName)
	tell scriptLiB
		set {baseName, texName, pdfName, namePath, dirName, dirNameunquoted, 
logName, logPath, rtfName} to setnamebbedit(fileName)
	end tell
	select document texName
	set sourceLine to startLine of selection as number
	set current clipboard to "\\marginpar{\\textcolor{red}{sync}}" as 
string
	paste
	save document texName
	set texName1 to texName
	
	tell application "BBEdit"
		get file of window 1
		set filepath to result
		set fileName to POSIX path of filepath as string
		
		set scriptPath to (do shell script "dirname " & 
"~/Library/TeXShop/Scripts/ex")
		set scriptPath to scriptPath & "/setnamebbedit.scpt"
		set scriptName to POSIX file scriptPath as alias
		set scriptLiB to (load script scriptName)
		tell scriptLiB
			set {baseName, texName, pdfName, namePath, dirName, dirNameunquoted, 
logName, logPath, rtfName} to setnamebbedit(fileName)
		end tell
	end tell
end tell
set texPath to namePath & ".tex"
set texFile to texPath as POSIX file


try
	set shellScript to "cd " & dirName & ";"
	set shellScript to shellScript & "~/Library/TeXShop/bin/pdflatexc  " & 
texName
	do shell script shellScript
	--do shell script shellScript
end try

set logFile to logPath as POSIX file

set findString to "Emergency stop"

set findString to "'Emergency stop'"
set foundText to "no error"
try
	set shellScript to "cd " & dirName & ";"
	set shellScript to "/usr/bin/egrep -w -n  " & findString & " " & 
logPath
	do shell script shellScript
	
	set foundText to result as string
	set n to (number of characters of contents of foundText)
	set i to 1 as number
	
	repeat while i < (n + 1)
		if character i of foundText is equal to ":" then
			set k to i
			exit repeat
		else
			set i to (i + 1)
		end if
	end repeat
	set lineNumber to (characters 1 thru (k - 1) of foundText as string)
	set theLine to lineNumber as number
end try

if foundText is equal to "no error" then
	set thePDF to POSIX file pdfName as alias
	set scriptPath to (do shell script "dirname " & 
"~/Library/TeXShop/Scripts/ex")
	set scriptPath to scriptPath & "/preview_bbedit.scpt"
	set scriptName to POSIX file scriptPath as alias
	set scriptLiB to (load script scriptName)
	tell scriptLiB
		preview_bbedit(texName, thePDF, previewer, process_name)
	end tell
	tell application "TeXniscope"
		activate
		--open thePDF
		refresh of the front document
		the front document goto line sourceLine of source texPath
	end tell
else
	beep
	do shell script "bbedit " & "+" & theLine & " " & logPath
end if

tell application "BBEdit"
	select document texName1
	find "\\marginpar{\\textcolor{red}{sync}}" searching in text 1 of text 
window 1 options {search mode:literal, starting at top:true, wrap 
around:false, backwards:false, case sensitive:false, match words:false, 
extend selection:false} with selecting match
	set selection of window 1 to ""
	save document texName1
end tell

--------------------- Info ---------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
           & FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>





More information about the macostex-archives mailing list