[OS X TeX] Working with a root file in BBEdit

Claus Gerhardt gerhardt at math.uni-heidelberg.de
Sat Nov 27 16:33:53 CET 2004


There is a bug in BBEdit 8 which causes some Applescripts that are 
triggered from the Palette not to work properly: Selecting a document 
and bringing it to the front doesn't work.

I already filed a report with BBEdit and they acknowledged the bug. 
When I posted the Applescript working with root files, I didn't pay 
attention to this bug. The script below, which is a simple pdflatex 
typesetting script, works on root files as well as single tex files. 
The pdf is viewed in TeXniscope. If you want a different magnification 
than 2.5, change the magnificationNumber.

Claus

-- Applescript
-- To be used with BBEdit, works on root files as well as single tex 
files.
-- pdflatexc
-- Claus Gerhardt, Nov. 2004

(* The root file has to be specified in the first three lines of the 
included documents in the form
%SourceDoc relativePath (ending ing in .tex), e.g.,
%SourceDoc ../master.tex
*)

--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

set magnificationNumber to 2.5 as real

tell application "BBEdit"
	get file of front document 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
	--set sourceLine to startDisplayLine of selection as number
	
	set foundboolean to "false"
	try
		find "%SourceDoc (.+\\.tex)" searching in lines 1 thru 3 of text 1 of 
text window 1 options {search mode:grep, starting at top:true, wrap 
around:false, backwards:false, case sensitive:false, match words:false, 
extend selection:false} with selecting match
		set {foundboolean, foundText} to {found of result as string, found 
text of result}
	end try
	
	if foundboolean is equal to "true" then
		set n to (number of characters of contents of foundText)
		set i to 2 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 texFile to (characters (k + 1) thru n of foundText as string)
		set dirName2 to do shell script "dirname " & texFile
		set texName to do shell script "basename " & texFile
		
		set shellScript to do shell script "/usr/bin/bbedit " & dirName & "/" 
& dirName2 & "/" & texName
		do shell script shellScript
		set fileName to dirNameunquoted & "/" & dirName2 & "/" & texName as 
string
		
	end if
	
	
	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 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
	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
			--refresh of the front document
			set magnification of front document to magnificationNumber
			--the front document goto line sourceLine of source texPath
		end tell
	else
		beep
		do shell script "bbedit " & "+" & theLine & " " & logPath
	end if
	
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