CompileTeX for BBEdit and TextWrangler
CompileTeX is an AppleScript/Shell script combination for use with BBEdit. It allows you to duplicate some TeXShop functionality in BBEdit (in particular the use of master documents through the %SourceDoc
comment or the newer #!TEX Root=file.tex
syntax). It also allows you to generate draft documents without touching the master document (by passing \PassOptionsToClass{draft}{your main documentclass}
to pdflatex before starting the TeX run).
You may need to adapt the script to your needs. In particular I include scripts to generate metapost graphics (and I assume that the figures reside in a folder "Figures" next to the master document). I use a separate script to translate the metapost figure into pdf if needed. Of course if you do not use metapost, the figure scripts are useless, since you aren't likely to edit your figures in a text editor anyway.
This version is for use with BBEdit 8/9/10/11/12. I did test the pdflatex script in both, so that should at least work.
The script-set have two main parts: a shell script that runs in the Terminal that does the actual processing. The AppleScripts merely call this shell-script with the correct parameters. I've taken this approach, because I really dislike the AppleScript syntax: I find it unclear, and I never seem to be able to find the correct syntax first time round. Because the work is actually done in your normal terminal, you just have to make sure that latex works from the terminal, and then you're set. This also means that you're not stuck with MacTeX, but could use a TeX installed with Fink or Macports, if you feel so inclined. I strongly recommend you use MacTeX though.
The current scripts prefer MacTeX 2008 or later, as synctex is enabled by default. When used with an older TeX you'll receive a harmless error message. The standard previewer which I suggest for SyncTex is Skim. I've tested with TeXLive 2017 and Skim 1.4.36 (Skim is current on 2018-08-19, I just haven't update TeXLive yet).
A list of descriptions is added at the end of this document.
How to install
- Mount this disk image.
- Copy the folder "ShellScripts" from the mounted disk image to your "Library" folder in your home folder. In Mac OS X 10.7 “Lion”, this folder is hidden. You can go there by holding the option key, and clicking the “Go” menu in the Finder. An item for the Library will then appear.
- Copy the folder "TeX Compilation" from the "AppleScripts" folder on the mounted disk image to the folder "Scripts" in the folder "BBEdit" in the folder "Application Support" in your "Library" folder.
Eh?
Exactly, in traditional Unix notation, that becomes '~/Library/Application Support/BBEdit/Scripts/
'. If you have run BBEdit once, this folder should have been created already. The destination folder path for TextWrangler is similar to the BBEdit version, at '~/Library/Application Support/TextWrangler/Scripts/
'. The same remark on your Library applies as above.
- [optional] You can alter the name of a script to move the item up or down in the menu: the number in front of the ")" will determine the sort order within the menu. The same is true for for the levels below. You may also want to set some shortcuts: From the "Windows" menu, go to the "Palettes" sub-menu and select "Scripts" from there. You can now select a script, and set a key for it. The BBEdit and TextWrangler help both contain a lot of extra information to, well, help you here.
- [optional] The script "File•Open Selection.scpt" is a menu script for BBEdit. It modifies the "Open Selection" command in the file menu so that it may work for LaTeX files. For more information on where to put this script refer to the section "Attaching Scripts to Menu Items" on page 280 in the BBEdit user manual (BBEdit 10.0).
Disclaimer
This software is in the public domain, entirely unsupported. It does what I (Maarten Sneep) need it to do, and is distributed in the hope that it might be useful to others. There is no warranty of any kind.
I disclaim all copyrights on these scripts.
The archive was last updated on July 23, 2011.
Latest changes
Remove support for TextWrangler, as this editor has been withdrawn by Bare Bones Software.
The TeXShop construction to indicate the wanted program for typesetting is supported as well, for additional control over the engine. The engine indicated in the master file is used (no other files are searched for a program meta-comment). The syntax is %!TEX TS-program = program
(see note below, the same variations are supported). Note that dvi engines are not fully supported, simpdftex
may be an alternative in some cases, although I do not use this myself. Update October 2009: the TS-
part is now optional.
(Again) Altered the search pattern for the master file in the shell script. ^%?% ?!TEX *[Rr]oot
is now use as the regular expression to find the correct pattern, and splits on the =
on that line. It is recommended to avoid %!
to prevent broken applications calling a TeX file a PostScript file (although I never encountered those). %%!TEX root = root
and % !TEX root = root
are now all recognised to indicate a program root, in addtion to %!TEX root = root
.
Added a check at the start of the script to see if tex
(the application) can actually be found. If not, the MacTeX default /usr/texbin
is added to the path to see if things improve. If not we bail out.
List of the supplied scripts with short descriptions
Most scripts will save all files currently open in BBEdit or TextWrangler, unless they haven't been saved yet, unless you are calling the script on an unsaved active document. Yes, I do like Monty Python.
- Run pdflatex.scpt
- Typeset the master document once.
- Run BibTeX.scpt
- Run bibtex on the master of the front document.
- Run MakeIndex.scpt
- Run makeindex on the front document. It assumes that a file with the same name as the master document, but with an .ist extension exists to stand in as an index style file.
- Show result.scpt
- Open the typeset result of the front file (metapost or (la)tex in your preferred pdf-viewer). The viewer to use is set near the top of the shell script.
- Synchronise with Skim.scpt
- You can use this to go to the point in the typeset document which corresponds to the insertion point. This assumes you use Skim as your viewer.
- Make draft version.scpt
- Pass the draft class option to the documentclass, allowing TeX to mark overful lines. Note that if used this way, the draft option does not reach any included packages (like graphics or hyperref). Figures are included in the normal way.
- Make fast draft version.scpt
- Pass the draft class option to the documentclass, allowing TeX to mark overful lines. In addition, the draft option is passed to hyperref and graphics as well, so figures are not included, and hyperlinks are not created. This speeds up pdflatex.
- Full document compilation.scpt
- The whole shebang: pdflatex, bibtex, pdflatex & pdflatex (for as long as there happen to be undefined references etc). Including makeindex in this cycle is left as an exercise to the reader… The first few runs are done in full draft mode to speed things up.
- Show figure mps.scpt
- Run the front document through metapost, and open the result in the preferred pdf viewer (a temporary pdf version is created for viewing). This requires the front most file to contain metapost source, with a single figure (number 0).
- Show figure pdf.scpt
- Very similar to the previous script, except that here the pdf version will be kept (and the mps version will be ditched).
- Make all figures mps.scpt
- This will run all .mp files in the figures directory next to the master document through metapost, and create the figures. Only generate .mps output
- Make all figures pdf.scpt
- Same as above, create pdf files.
- Open master file.scpt
- Search the front document for a master directive, and open the referenced file.
- Open selected file.scpt
- Search the current line for \input, \include and \includegraphics commands and open the document you find here. The \includegraphics command is assumed to reference a metapost figure, and will open the .mp associated file (or at least try to).
- Open all referenced files.scpt
- Same as above, except the complete document is searched for referenced files, and they are all opened.
- Open log file.scpt
- Open the log file of the master document to check for errors.
- Run xetex.scpt, Run xelatex.scpt, Run latex.scpt, Run pdftex.scpt, Run tex.scpt
- The scripts in the "Other TeX Engines" all run the current master document once through the respective engine. Other scripts/TeX engines can be added easily: as long as the command ends in "tex", you can just feed the command to the script. So if you have a command "froobletex", the switch -froobletex is acceptable, and there is no need to actually change the shell script.
- Run Make.scpt
- Run make pdf in the directory where the master document lives. Other targets are added easily, should the need arise.
- Run pdflatex+PP4.scpt
- Run pdflatex, followed by a run of pp4, for producing presentations. (Obsolete, use PowerDot or Beamer instead).
- Run latexdiff.scpt
- Run latexdiff, comparing the current document with an original version (
master.orig.tex
or master.submit.tex
in the same directory as master.tex
).