Whyanes, first of all, thank you for your script and also the lead it provides into further capabilities. Very handy. And thanks to Sophie for the explanation showing how to extend the script to do multiple type setting passes on a document.
There was a comment made about the number of “passes” TeXShop needs to make on a document and I thought I would add my own experience. For the book I am writing, the following process is used. I keep this documented inside my Scrivener Manuscript as a page that is not included in the final document. A handy aid within Scrivener. Here are the steps I use:
To create a PDF file of this book:
1. compile this document (Command-Option-E)
2. open up the .tex file with TexShop
3. process the file the first time for latex (Command-Shift-L)
4. fix any errors and restart whole process if they happened
5. run latex processing again to create table of contents info (Command-Shift-L)
6. convert the index file (Command-Shift-I)
7. click back on main tex file in TexShop to continue
8. run one more time to include the index in the table of contents (Command-Shift-L)
9. run one latex again in case adding the index changed the length of the table of contents (Command-Shift-L)
10. click back on main tex document again in TexShop
11. clean up temporary files (Command-Control-A)
12. In the Finder you will find your completed PDF
The short version:
Scrivener:
Cmd-Opt-E
TexShop:
Cmd-Shift-L
Cmd-Shift-L
Cmd-Shift-I
Cmd-Shift-L
Cmd-Shift-L
Cmd-Cntrl-A
So you can see I actually make 4 LaTeX passes through the document and also perform an Index creation step. Automating all this would be awesome, so I was excited to read this forum thread.
However, things don’t seem to be working so smoothly for me. Just getting the 2nd pass with TeXShop seems to fail. I’ve tried a number of script ideas, here’s one that I thought would work:
on TypesetDoc(f)
set frontName to f's name
growl("Typesetting", frontName)
tell application "TeXShop"
close every document
open f
end tell
tell document frontName of application "TeXShop"
latexinteractive
growl("Just launched latex...", frontName)
repeat
delay 2
if taskdone then
exit repeat
end if
end repeat
growl(frontName, "First pass completed. Continue...")
latex
growl("Just launched 2nd pass latex...", frontName)
repeat
delay 2
if taskdone then
exit repeat
end if
end repeat
growl("Done", frontName)
end tell
end TypesetDoc
You can see some new things I learned from research. The issuing of the “latex” or “latexinteractive” command immediately returns to Applescript. You need to add in a check to see when TeXShop is completed, hence the repeat delay loop. However, it doesn’t work. I never see Growl report that the first pass completed.
Okay, figuring that maybe there’s a bug in the “taskdone” logic, I thought I could cheat by removing that bit of logic and just put in a long enough delay. That’s a bit of hack to depend in timing, but I’m troubleshooting. So I tried something like this:
latexinteractive
growl("Just launched latex...", frontName)
delay 15
growl(frontName, "First pass completed. Continue...")
latex
growl("Just launched 2nd pass latex...", frontName)
Still no luck.
If there’s an issue with installed software versions, here’s what I’m running:
OS X 10.5.6
Applescript 2.0.1
TeXShop 2.26
I’m beginning to think that I could probably just create a custom Macro inside TeXShop to run the process for me each time. The create Bibliography script shows how to do something like that. Here’s my new Macro in TeXShop:
--Applescript
set fileName to #FILEPATH#
if fileName is equal to ""
activate
display dialog "Please save the file first" buttons {"OK"} default button "OK"
return
end if
set frontName to #DOCUMENTNAME#
tell document frontName of application "TeXShop"
latexinteractive
repeat
delay 2
if taskdone
exit repeat
end if
end repeat
latex
repeat
delay 2
if taskdone
exit repeat
end if
end repeat
makeindex
repeat
delay 2
if taskdone
exit repeat
end if
end repeat
latex
repeat
delay 2
if taskdone
exit repeat
end if
end repeat
latex
repeat
delay 2
if taskdone
exit repeat
end if
end repeat
end tell
And guess what? When I run TeXShop and manually select that new Macro, it works. Maybe if I can get the Applescript folder watcher script to just tell TeXShop to run this Macro that would be great.
Any ideas?