Ramón's TeXShop Applescripts/Macros

The following are a few of applescripts that I wrote that might be useful when typing a document in TeXShop, which is a very nice front end for LaTeX on Mac Os X. They were tested with TeXShop version 2.26, on Mac Os X 10.5.6. Some of these Macros are as of version 2.26 part of TeXShop Big Grin (the versions in this page might be newer).

To use one of them select "Open Macro Editor…" from the "Macro" menu in TeXShop and create a new macro (assign each a key combination if you wish). Paste the text of the macros, which you can copy directly from your browser after clicking on "view source" below (for an easy way to install all of the TeXShop scripts at once see below).

  1. Close Begin/End 1.0 [view source]
    This script will close a TeX Begin/End environment. It will handle nested Begin/End environments correctly, and knows if an environment is already closed.
    For example, if an environment starts with \begin{equation*}, then an invocation of the script will close it with \end{equation*}.
  2. Insert Begin/End 1.0 [view source]
    One of the default TeXShop macros, called Begin/End, inserts an Begin/End environment, where the environment name is taken from the current selection. That entails having to type the environment name, select it and then invoke the macro. This script auto selects the environment name (the cursor can be anywhere from the beginning to the end of the word). It also does a better job of handling the situations when the environment name is at the beginning, end or the middle of a line.
  3. Program 1.2 [view source]
    This script improves on the old TeXShop default macro called "Program", i.e., % !TEX TS-program = #INS#, It assumes that engines are installed in ~/Library/TeXShop/Engines/
    (The default engine, if present, is "pdflatexmk", this can be changed by editing the beginning of the script)
  4. Encoding 1.2 [view source]
    Does for "Encoding" the same as the above script does for "Program"
    (The default encoding, if present, is "MacOSRoman", this can be changed by editing the beginning of the script)
  5. Root 1.1 [view source]
    Does for "Root" the same as the above two scripts do for "Program" and "Encoding".
    It has the nice feature of letting the user choose between an absolute or a relative path to the root document (it uses Perl to accomplish this).
  6. Format 1.0 [view source]
    This script adds a format specification to the document, e.g. %&pdflatex in the first line, by letting the user choose which format she/he wants to use. For example, Claus Gerhardt's excellent Flashmode uses these format specifications to know which method to use in typesetting. Its behavior can be customized by means of setting four different properties in the preamble of the script. For example, if the user wants it to search for all available formats set few to false and then only the formats in short_list will be used. For this to work the path to kpsewhich has to be in the variable PATH of the ~/.MacOSX/environment.plist or one must set the path to it in the script's kpsewhich_path property (currently set to /usr/texbin/kpsewhich). Notice, that one can get the path to kpsewhich by typing which kpsewhich in the Terminal. The script tries to do this but if the environment.plist's PATH is not set to include the paths to the TeX executables it will fail (the environmental variables and their values available to applications are different to those available to the shell, e.g. typing echo $PATH in the Terminal, and running do shell script "echo $PATH" in the Script Editor can yield different results. The preference pane RCEnvironment is a nice way to manage and explore environment.plist). There is an ingenous way of avoiding all this grief, download and install the TeX Distribution pane and TeX Distribution Helper (if you use TeXLive 2008 or gwTeX you may already have it installed, look in your System Preferences), using it will allow /usr/texbin to work with various installations.
  7. TeXCount 1.1 [view source]
    Invokes the TeXCount perl script, which it assumes is located at "/usr/texbin/texcount" to give some statistics for the front document. TeXCount is installed as part of MacTeX-2008.
  8. TeXCount to PDF or HTML 1.1 [view source]
    Invokes TeXCount to generate a full report that gets converted from HTML to a PDF that is then opened with TeXShop. Can be easily modified, by changing the property pdf to false in the script, so that it just generates an HTML file that gets opened by the default browser.
  9. TeXShop to BBEdit 1.0 [view source] and BBEdit to TeXShop 1.0 [view source]
    These scripts transfer a document back and forth between TeXShop and BBEdit preserving the current selection. To install BBEdit to TeXShop place it in BBEdit's Scripts folder (the easiest way to get to this folder is to go to BBEdit's Script menu and choose "Open Scripts Folder") or a subfolder of it. See BBEdit's manual for information on its Script Palette and Script Menu.
  10. TeXShop to RPN2TeX 1.1 [view source] and RPN2TeX to TeXShop 1.1 [view source]
    Wataru Maeda's RPN2TeX is a beautifully implemented and unique LateX equation editor (if you are using TeXLive you must change the paths in the preferences to /usr/texbin/). These are two scripts that integrate TeXShop and RPN2TeX. I assigned to the TeXShop to RPN2TeX Macro in TeXShop the F1 function key (via the System Preferences' Keyboard & Mouse panel, as TeXShop allows little else aside from alpha numeric assignments as shortcuts from its Macro Editor). I invoke RPN2TeX to TeXShop using the same F1 function key by pasting it inside an Applescript Smart Item in Peter Maurer's Butler (make sure to restrict the script to only work when RPN2TeX is the front application). As RPN2TeX has no Applescript support of its own I use UI Scripting. These scripts were tested with RPN2TeX 0.8.
  11. TeXShop to LaTeXiT 1.1 [view source] and LaTeXiT to TeXShop 1.0.1 [view source]
    Two way integration for LaTeXiT and TeXShop. Tested with LaTeXiT 1.16.1.
  12. TeXShop to TeX FoG 1.1 [view source] and TeX FoG to TeXShop 1.1 [view source]
    Two way integration for TeX FoG and TeXShop. Tested with TeX FoG 1.2.4 (recompiled from source to run natively on an Intel processor) and 1.3. Note: TeX FoG to TeXShop is now redundant as, among other things, TeX FoG 1.3 adds the capabilty to communicate with TeXShop (it uses the clipboard, whereas this script does not).
  13. Insert File Path 1.0 [view source]
    Script that inserts \input{•}, \include{•} or \includegraphics[]{•}, where • is either a relative or an absolute path to a file the user chooses. It tries to be smart about spaces in file paths (most likely an impossible task, so this feature can be turned off; see below). Beware that for \include{•} the path • can only be to the directory of the target document or a subdirectory thereof. Therefore, if an \include{•} is impossible, no choice will be presented, and an \input{•} will be automatically entered. This might be confusing to a user that does not know of this limitation.
    It is customizable by setting the values of "properties" at the beginning of the script:
  14. Now, for my personal use I like to have the possibility of spaces in file names (no_spaces: false), no absolute paths (absolute:false), I like to limit the kinds of graphic files it can handle (ignore_suffix:false), and to supress suffixes in graphics files (use_suffix:false).

Quick Install

A quick way to install all of the TeXShop scripts found here at the same time (note that BBEdit to TeXShop is a BBEdit script and RPN2TeX to TeXShop is an RPN2TeX script) is described in the TeXShop manual: "[t]o add macros created by others to your list of macros, open the Macro Editor and choose 'Add macros from file...'. Then use the Macro Editor to arrange the macros as you desire." Do this with the plist file found here.

Related Stuff

  1. New window for Flashmode.
    I like to use Flashmode for TeXShop by Claus Gerhardt; however due to my poor eyesight I use a low resolution on my monitor (a large wide screen TV). So the window he designed is too big for me to use. So I modified the nib file to make everything very compact. You might find it useful when using Flashmode on a laptop. Download MainMenu.nib here and install it by control clicking (right click) on the Flashmode application in the Finder and select Show Package Content in the context menu and replace the existing MainMenu.nib in /Contents/Resources/English.lproj/. Here is a preview.
  2. LaTable (for OS X, Intel only)
    Here is a table editor, LaTable by Alex A. Denisov, for LaTeX, which was made for Win32. I added an icon and a launcher application. To use it you need Darwine, which lets you run many windows applications on an Intel Mac for FREE (tested with version 1.1.18). I would also update X11 with the latest XQuartz. Double click LaTable (not LaTable.exe) to launch. You need a chm viewer, say iChm, to read the documentation. Here is a preview.
  3. Startup Items and Shutdown Items folders 1.1
    The BBEdit text editor has among its plethora of features Startup Items and Shutdown Items folders in the ~/Library/ApplicationSupport/BBEdit folder. For example, any applescript in the StartupItems folder gets executed upon BBEdit launching and any other kind of file, folder or application there gets opened. Now, such features can be implemented (with some caveats) with a preference pane called Do Something When and Applescript applications you can find here with examples (for TeXShop, but easily modifiable for any application) and detailed instructions.
  4. Drop RTF2LaTeX2e 1.0
    Here is RTF2LaTeX2e 1.0fc1 bundled as a droplet. The pref folder must be in the same directory as the application. I edited r2l-pref to my liking (e.g., use tabular instead of longtable for tables, use colors, and applemac for the font conversion).
  5. JasTeX 1.1 a program for drawing Graphs and Automata in LaTeX
    Here is JasTeX 1.1 (a GUI for GasTeX) bundled as an OS X application. The code was tweaked a little bit to meet my needs, for example, the LaTeX code it generates now suppresses page numbers and includes a TeXShop program directive that calls an engine called jastex.engine (which is included and generates a cropped PDF). A (poor, perhaps atrocious) translation of the French manual into English is also included. To install JasTeX copy the eponymous folder wherever you want. To install the jastex.engine place it in ~/Library/TeXShop/Engines/.

License

These scripts are free software; you can redistribute them and/or modify them under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

These scripts are distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Copyright

Copyright ©2007-2009 Ramón M. Figueroa-Centeno. All Rights Reserved.

Page updated: Wednesday, May 6, 2009 7:51 AM HST