Content: Overview · Features & usage · Two typesetting modes · Normal Mode · Product Mode · Activating/deactivating Product Mode · Hard-locking on a product file · User interface · Options screen (Settings) · Modifier keys · Tools · Notifications · Installation and setup · Basic installation · Launching the script with a hotkey · Using the modifier keys · First run · System requirements / other requirements ·
Main purpose of the script is to launch the typesetting command on a ConTeXt document. The behavior of the script is customizable and it can be adapted to many different use-cases.
You can apply the script either on a selected tex file in the Finder, or on a tex file currently open in the editor. It works with most editors, for example BBEdit, MacVim, TextMate, etc.
In addition the script provides easy access to some ConTeXt related tools.
Please note that the script assumes that you are working with ConTeXt “Minimals” (the standalone installation; ideally consisting of a ConTeXt Beta and a ConTeXt Current). It sets the paths via the setuptex file found in ‘tex/’ inside the Minimal. If you use a TeXLive installation the script will most certainly not work without modifications.[1]
This is the main and default mode. The script behaves adaptively:
Launch the script with an open ConTeXt document in your text editor to typeset the document, or …
Select a ConTeXt document in the Finder and launch the script on it.
While searching for an open ConTeXt document in your text editor the script will assume that the editor is the frontmost application. If it doesn’t find a suitable document it will fall back and test the current Finder selection.[2]
If you never work with product and component files you can skip this section.
The ConTeXt structure for more complex documents is one project file, one or more product files and several component files that belong to a product file. The product file usually represents the book and the component files the chapters (or sections). Normally you work on the component files and want to typeset the product file to review your changes.
Product mode basically allows you to typeset a project’s product file without activating it’s window, even without loading it into the text editor at all.
This way you can continue editing your component file without window switching while the script typesets the product file in the background.
You can activate/deactivate Product Mode either through the Options screen (permanently) or through the ‘option’ modifier key (temporarly).
You have to show the script once where the product file lives. You do this simply by selecting the product file in the Finder and running the script once on it. The script is now “soft-locked” on the product file.
Now, back in the editor with the open component files, if you launch the script in Product Mode it will always typeset the product file, no matter which file is currently active in the text editor. That is, for typesetting you don’t have to switch anymore between component and product file window in your text editor.
After the first typesetting run with the Finder-selected product file, the script will remember the target file, even if it gets unselected, or another non-TeX file is selected. This way you can work in the finder while typesetting, or between typesetting sessions, without the script losing focus on the product file (unless there is another TeX file selected at script launch).
If you find yourself “losing” the product file often, e.g. if you work with other, unrelated TeX files inbetween, or if you work on the same product for a longer time you have the option to hard-register a specific product file.
Registering means that the script will never lose focus on the product file, unless you unregister it or you register explicitely a new product file.
You can register a product file via the Options screen or via the ctrl-opt modifier keys. You can unregister a product file via the Options screen. For registering/unregistering the target file must either be frontmost in your text editor or selected in the Finder.
Of course, if you want to typeset a component file without the product file, you can do so at any moment by stepping out of Product Mode (modifier key or Options screen). The script will not forget the product file and will be back on it when you reactivate Product Mode.
If you are in Product Mode but don’t have any product file registered you are automatically in “soft-locking” Product Mode as described above.
Of course Product Mode also works with other file structures that are loaded
in the main file via \include
or similar macros.
The GUI comprises the Options screen and a Tools screen which is accessible from the Options screen.
You can access the Options screen by holding down the ctrl key at script launch.
You activate an option or launch a command by selecting the entry with the mouse. Use the cmd key to select/unselect multiple entries. Whenver it makes sense, an option is sticky. That means the setting (and also the visual selection in the Options screen) will be remembered until you deselect it or recompile the script.
The entries in the options window are pragmatically classified through their symbols:
Switches between typesetting in the standard shell (hidden) or in the Terminal. If you use the standard shell the error log will automatically be opened when an error occurs. Typesetting in the hidden shell is unobstrusive, while the Terminal might be preferable for larger documents as it gives you some progress information. However even in shell mode you will be notified on completion. Run mode can be toggled on the fly with a modifier key (see below).
Note: For Terminal mode you have set the Terminal to use bash (default on OS X). Setuptex doesn’t seem to work with zsh. (The Terminal setting does not affect the standard “hidden” typesetting mode.)
--synctex=zipped
switch to the typesetting command. That is,
it enforces SyncTeX regardless of the presence of the \enabledirectives
[system.synctex]
modline in your documents. It also works in cases where the
modline sometimes doesn’t work, for example in self-contained, single-file tex
documents (i.e. documents that don’t call external component or other input
files).Turn on or off automatic syntax checking with mtx-check. If on mtx-check will be launched after a typesetting error has occurred. The output will be appended to the log file which will open automatically after an error. (Only applies in standard shell mode.) Can also be launched manually (see Tools).[5]
Since the script applies the syntax check on the actually typeset file (not on the currently opened file in the editor) this option is only useful if you are not typesetting in Product Mode.[6]
By default the script writes an Extended Attribute to the output PDF file so that it will not get backed up by Time Machine.[7] This is meant to prevent unnecessary bloating of your backup, especially if you are producing large PDFs with every typesetting run. ConTeXt-generated PDFs are not “optimized” and can become ridiculously huge; a 150-page PDF can easily exceed 200MB.
This setting is activated by default because I’m assuming the following:
If this is not the case you should disable the backup exclusion (i.e. selecting the setting).
Note: ConTeXt itself writes the output PDF “in place”, that means if you have
excluded the PDF once from backup the attribute will not go away by simply
disabling the exclusion and typesetting again. After disabling the exclusion you
have to trash the formerly genarated PDF in order to get a TM-included file
again. Or, alternatively, execute
xattr -d com.apple.metadata:com_apple_backup_excludeItem <my-file.pdf>
[8]
Auxiliary files (.synctex.gz, .tuc, .log) receive always the backup-exclusion attribute. This is unaffected by this setting.
Independently from the main settings, some of the options can be changed on the fly by holding down a modifier key at script launch:
Note:
Usage of hotkeys and modifier keys is optional. The script is fully functional also when launched from the script menu. The Options screen can always be accessed by holding down the ctrl-key.
How to employ the modifier keys is explained below.
Some useful ConTeXt scripts and other things are available in the Tools submenu of the Options screen. The symbol semantics are the same as for the Options screen:
mtxrun texutil --purgefiles
(log and synctex files are deleted).mtxrun texutil --purgeallfiles
(log , synctex and tuc files are
deleted).Runs the install script first-setup.sh
either with --context=beta
or
--context=current
. Only the Mark IV part is updated (--engine=luatex
). At
first run – or if you have renamed the designated folder – you will be
presented with a folder selection dialog to choose the backup destination
folder (i.e. archive folder).
You will choose either your Beta or your Current installation for updating. Be careful if you have only one installation: it will be updated to the version you have selected (Current or Beta).[9]
This means also, if you have mapped for example an older ConTeXt Beta to the “Current” slot, it makes no sense to launch the update function on the “Current” slot. (By doing so you would “update” your Beta to the latest Current.)
In the settings section in the script you can change the archive format of the backup. Default is .tar.xz; archiving a complete ConTeXt Minimal folder takes about 20 seconds on my Mac Mini at a compression ratio of 28%. If this takes too long on your computer you may set it to .tar.gz (7s, 43%) or even to uncompressed .tar (3s). If you are like me and think that wasting food and disk space is a sin, of course xz is the only option ;-)
Please take into account that at the first run after an update ConTeXt will remake the formats which leads to considerably longer running time.
Makes the script forget the currently assigned ConTeXt installation directories (slots for Current/Beta). If you select this you will then be prompted to select the new ConTeXt locations (setuptex files) for “Current” and “Beta” (the same what happens at the first run of the script). Of course, this is only useful if you have at least three different ConTeXt Standalones on disk.
Keep in mind that if you use the integrated updater the content of the “Current” slot will always be updated to the latest ConTeXt Current and the content of the “Beta” slot to the latest ConTeXt Beta. (See above “Update ConTeXt”.)
mtxrun --script fonts --list --all
.mtxrun --selfupdate ; mtxrun --generate ; context --make cont-en
.
Mark II (“pdftex ConTeXt”) formats are not remade. (I consider Mark II
obsolete.) You have to choose either your Beta or your Current installation.
If you have only one ConTeXt it doesn’t matter.Note: Some of the tools will run in a Terminal window in the background. To see the progress/results bring the Terminal to the foreground.
Notifications will be sent to Notifications Center and will show you some information:
For basic installation place the script (or a symlink) into the Scripts menu
in the menu bar (Scripts folder at ~/Library/Scripts/
). If you don’t have the
Script menu you have to enable it in Script Editor’s preferences.
The script is fully functional if launched from the Script menu. The Options screen can always be accessed by holding down the ctrl key. However, launching the script with the mouse from the menu bar can become tedious and doesn’t allow the simultaneous use of modifier keys (see below).
See also the note concerning Accessibility in the System requirements / other requirements section.
Like any other script the script can also be launched through your preferred launcher, like LaunchBar, Keyboard Maestro, Alfred, etc.
If you are working regularly with ConTeXt you will likely prefer to launch the script through a hotkey.
This can be done in several ways. Two examples:
Install a service workflow to the service menu (place it into
~/Library/Services/
, or just double-click the workflow) and assign a hotkey to
the service in your Mac’s Keyboard preference pane. I’m using for example
cmd-F7. The workflow will act as script launcher and when you hit the hotkey
your document will be typeset.[11]
In the Extras folder you will find a preconfigured Service (Ctx Typeset – Standard.workflow). You just have to assign a hotkey.
Keyboard Maestro is an excellent application, specialized in assigning hotkeys. In the Extras folder you’ll find a macro example.
Modifer keys are completely optional (except for the ctrl key which opens the Options screen). But if you work with different files and have to switch often, for example, between Product Mode and Normal Mode and/or between two product files, you will highly appreciate them.
Basically you have to possibilities to use the modifier keys:
This is technically the easy way and also doesn’t require any further setup work. It works in combination with a hotkey launch (as described above) and even if the script is launched from the Scripts menu or with LaunchBar etc.
The script has a built-in delay of 0.6 seconds. This should be sufficient to quickly press the modifier key(s) after you have launched the script.
If you need more time, you can change the delay by editing the script, for example to 1 second. (Just search for “delay” in the script and you will see it.)
Or use the modifier keys simultaneously with the hotkey:
This is more comfortable and relaxed, but doesn’t work with all launch methods:
For example if you select the script from the Scripts menu while you hold down the option key, the script will be opened in Script Editor, instead of launched.
If the shift key is down, the script will not be launched either but revealed in the Finder. (As mentioned, the ctrl key works fine though; that means you can access the Options screen by holding down the ctrl key even when selecting the script from the Scripts menu.)
If you are launching the script via LaunchBar, Alfred etc. you will experience similar problems that make it impossible to use the modifier keys as simultaneous keys.
However there are at least two possibilities to apply the modifier keys in the “simultaneous” way:
Instead of installing just one Service workflow (as described above), you install several clones of the Service workflow, each one named differently.
Then you assign to each Service a modifier-hotkey combo, for example:
Service workflow name | Assigned hotkey |
---|---|
Ctx Typeset - Standard | cmd-F7 |
Ctx Typeset - Open Settings | ctrl-cmd-F7 |
Ctx Typeset - Normal / Product Mode | opt-cmd-F7 |
Ctx Typeset - PDF Launch On / Off | shift-cmd-F7 |
Ctx Typeset - Terminal / Shell | opt-shift-cmd-F7 |
Ctx Typeset - Register New Product File | ctrl-opt-cmd-F7 |
The script comes with preconfigured Service workflows (in the Extras folder). You can install them by double-clicking, then assign the hotkeys in System Preferences / Keyboard.
The six Service workflow clones do all the same: just launching the script. But the multiple instances allow you to assign hotkey combos that can be pressed simultaneously and which will affect the script’s behavior.
Note that you can freely choose the cmd-hotkey, the functions of the shift/ctrl/opt modifier keys however are hardcoded in the script.
Once again Keyboard Maestro. With this it is completely trivial to assign all the desired key combinations at once to just one launcher macro. No clones needed. See the screenshot in the Extras folder or import the macro I’ve prepared.
Note:
If you are exclusively using one of the simultaneous methods (multiple Service clones or Keyboard Maestro) you can reduce the delay in the script or even eliminate it. However, I’ve made the experience that without a minimum delay of maybe 0.2 seconds it happens that modifier keys are not reliably recognized. But this may depend on the system version, so just play around with the delay so that it works best for you.
If something doesn’t work as expected, please see the note concerning Accessibility in the System requirements / other requirements section.
At first run the script wants to know the path to the setuptex file(s). This file is located in the tex folder inside your ConTeXt Minimal.
Normally you don’t have to do this by hand. The script tries to locate the setuptex files:
In a first attempt it makes a Spotlight search. If this works the result will be presented almost instantly.
If the Spotlight search doesn’t yield any results the script will do a traditional search with the ‘find’ tool in some preset folders and at a preset depth. This will take considerably more time than the Spotlight search. (If you see this happen, it normally means that your ConTeXt installations are not in a Spotlight-searchable directory or that your system is somehow borked (wrong file UTIs).)
The script will then present you the found paths:
In the first results window select the path to your current ConTeXt Beta installation.
In the second results window select the path to your ConTeXt Current installation (or whichever ConTeXt installation you want to use in the “Current” role).
If you use only one ConTeXt installation you have to declare the same path for both.
If the script doesn’t find a valid path with either of the search methods it will show you the usual file selection dialogs. Even if it finds a path you can always overwrite it by forcing the file selection dialog (last line of the search results window).
The script will remember the paths unless you recompile (edit) the script.[12]
Immediately after the paths dialog the Main Options Window will pop up. Make your settings, click OK and launch the script again to start the actual typesetting run.
Of course, a ConTeXt Minimal (standalone) is required.[1]
The script is compatible with macOS 10.12 and 10.11, probably 10.10 and maybe 10.9, 10.8. On pre–10.9 systems notifications won’t work and you should disable notifications permanently in the settings section in the script.
awk must be installed for the version query.
If you compile the script as standalone application it should run properly, too. However execution may be slower. Not recommended.
For most tasks it is necessary to enable Accessibility rights in
System Preferences > Security & Privacy > Privacy > Accessibility, e.g.
for the Finder or for your text editor.
If you want to launch the script from the Scripts menu (in the menu bar) or from
FastScripts you have to give Accessibility rights to SystemUIServer.app! (It
will not show you a message window. After the first (failing) launch from the
Scripts menu open the Preferences Pane and set the checkmark.)
Thanks to the authors of these tools that are contained in the script bundle:
In order to make the script work with a TexLive installation you have to disable the path check (comment the line “testPaths()”) and you must adapt the actual typesetting command to your needs, i.e. eliminating the sourcing of ‘setuptex’ and instead calling ‘mtxrun’ with the complete path or exporting your path variable. However I think there is no reason not to use a Minimal of the latest ConTeXt. ↩
If no valid document is found in the frontmost application the script actually will also test the second frontmost application for a valid file, befor falling back to the Finder selection. This is to prevent failures in cases where the text editor unintentionally has been pushed away from frontmost position. (This can happen especially if the script was launched as standalone application, or through other launch methods.) ↩
However the slot (Beta or Current) affects how an installation will be updated. See the description of the update functions in “Tools”. ↩
Other log viewers can be set in the settings section in the script. ↩
If you prefer the script concheck instead of mtx-check you can set this in the settings section in the script. ↩
If you need a syntax check on a component file you can always start the syntax check manually from the Tools screen. ↩
The backup exclusion works also for CrashPlan. ↩
In the Extras folder you will find an Automator workflow that can do this for you. ↩
This will only work if you don’t have fiddled around with
your ConTeXt directories. The install script first-setup.sh
must be in its
original location relatively to the ConTeXt root. ↩
A click on the completion banner opens the log file (10.8 only). ↩
Depending on the system version it is possible that you have to restart your text editor in order to make a newly installed service hotkey work. ↩
The script file has a settings section where you can also hard-set the paths (and change other defaults, and access some detailed settings that are not available in the Options screen). ↩