ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

simple_Con​Te​Xt

by SQbQxeKd3JHD8 ST3

A Sublime Text 3 package for working with ConTeXt

Details

Installs

  • Total 139
  • Win 63
  • OS X 41
  • Linux 35
Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10 Mar 9 Mar 8 Mar 7
Windows 2 1 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0
OS X 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 2 0 0 0 1 0 0 0 0 0 0
Linux 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 2 0 1 0 0 0 0 0 0 0 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

Simple ConTeXt

Contents

Introduction

This Sublime Text 3 package provides some support for working with the ConTeXt program.

I started this project for my personal use, because I wanted some quality of life features for writing ConTeXt documents in Sublime Text. Since there were no packages that fit the bill, I started to write my own. Over time I felt that the result was looking pretty good, so I put it out into the world for the hopeful benefit of other ConTeXt users.

That said, I can only test that things work on my machine, so some bugs are to be expected. Furthermore I only have so much spare time to work on it, and it's a hobby project. Don't expect a robust, polished experience!

Currently the features are:

  • Syntax file(s).
  • Builder(s).
  • Command auto-completions.
  • Command pop-ups.
  • Handling of references. (Not citations.)
  • Snippets.
  • Other miscellany.

(I should say that I only use ConTeXt MkIV, and so the package is designed and tested with MkIV only. In other words, if MkII stuff works then it is a happy accident. However, the syntax file should work perfectly well (I speculate) for MkII, and some of the other parts might work e.g. the references. I would certainly not be opposed to adding stuff for MkII. It's just not something I use, so I am not interested in spending my free time working on it.)

(Also, the multilingual interface in ConTeXt is not something that I have really considered. I only use the English interface; indeed, I would hardly know where to start with supporting the other languages. Again, I would be more than happy if it were supported, it's just not something that makes sense for me to put my time into.)

Installation/Setup

Install via package control, under the name simple_ConTeXt. (Alternatively, git clone the repository into your Sublime Text (ST) packages directory.) Afterwards, there are some optional things to set up.

Builder

Open the simple ConTeXt settings file via Preferences: simple_ConTeXt Settings in the command palette or Preferences ▶ Package Settings ▶ simple_ConTeXt ▶ Settings from the menu bar. Under the paths key, put in a key-value entry for the ConTeXt installation on your machine: the key is just a name for that installation, and the value should be the path to the context binaries. For example: if you have the context program located at /some-path/context/tex/texmf-linux-64/bin/context (so the ConTeXt installation tree's root is at /some-path/context/), then you should write something like

{
  "program_locations.ConTeXt_paths": {
    "example": "/home/user-name/.local/context/tex/texmf-linux-64/bin"
  }
}

If you have multiple versions of ConTeXt installed (e.g. a couple different TeX Live versions and the ConTeXt Standalone) then you can put a name-path entry for each one, and they can happily coexist in simple ConTeXt.

PDFs

For opening PDFs after building a ConTeXt file, and for opening the manuals, the current.PDF/viewer entry is consulted. It should be the name of one of the keys in program_locations.PDF_viewers.

Similarly to the previous, the keys in program_locations.PDF_viewers can be any string, but each value should be the name of a PDF viewer program. (In the case of Sumatra PDF viewer, this could be simply sumatraPDF if it's on your environment path, or else an explicit path like /usr/bin/sumatraPDF.)

Auto-Completion

Add the following entry to your general ST settings, in order to get automatic completions for ConTeXt commands on typing the initial backslash \.

{
  "auto_complete_triggers": [
    {
      "characters": "\\",
      "selector": "text.tex.context"
    }
  ]
}

Symbol List

Consider adding the following to your key bindings: it will (for ConTeXt files only) replace the binding for the local symbol list (Ctrl+R) with a custom variation of it. The idea is to make it easier to navigate/filter between headings, definitions, references, and so on.

{
  "keys": ["ctrl+r"],
  "command": "simple_context_show_combined_overlay",
  "args": {
    "selectors": ["definition", "file_name", "heading", "reference"],
    "active_selectors": ["definition", "file_name", "heading", "reference"]
  },
  "context": [
    {
      "key": "selector",
      "operator": "equal",
      "operand": "text.tex.context"
    }
  ]
}

Otherwise, the default local symbol list contains all these things with suitable prefixes.

Spell Checking

Consider adding the following to your ConTeXt syntax specific settings:

{
  "spell_check": true,
  "spelling_selector":
    "text.tex.context - (meta.control-word.context, meta.environment.math.context, meta.brackets.context, source, markup.raw, comment)"
}

This should do a pretty decent job at limiting spell check to the appropriate places only (e.g. not in maths or code blocks).

Bracket Highlighter

If you use the excellent BracketHighlighter package, then adding the following to the BracketHighlighter settings will provide some support for ConTeXt start/stop commands.

{
  "user_brackets": [
    {
      "name": "context_env",
      "open": "(\\\\start[a-zA-Z]*)",
      "close": "(\\\\stop[a-zA-Z]*)",
      "style": "tag",
      "scope_exclude": ["- meta.structure"],
      "language_filter": "whitelist",
      "language_list": ["ConTeXt"],
      "plugin_library":
        "simple_ConTeXt.bracket_highlighter.context_environments",
      "enabled": true
    }
  ]
}

The file context_environments.py simply checks that the start and stop tags match.

Builders

The main builder is of course the ConTeXt one, that is a wrapper around the context binary. In order to find context it consults the path specified in the settings.

As it's easy to do so, there are a couple other builders:

  • Lua (using LuaTeX as a Lua interpreter);
  • MetaPost. There are two variants: firstly, just use the version of mpost that ships with the ConTeXt installation. Alternatively, use context itself: when called on a MetaPost file, it will compile it (using the MetaFun format) into a PDF.

Snippets

There are various snippets for ConTeXt (and a couple for MetaPost as well). You can find these by typing snippet in the command palette in a ConTeXt file, but here is a quick summary.

  • Samples, analogous to the built-in snippet lorem. These are: bryson, carey, carrol, darwin, davis, dawkins, douglas, greenfield, hawking, jojomayer, khatt, klein, knuth, linden, montgomery, reich, sapolsky, thuan, tufte, waltham, ward, weisman, and zapf.
  • Headings, for part/chapter/section and so on: chap, part, title, sec, sub, sec2, sub2, sec3 and sub3.
  • For item groups: items and item
  • For mark-up: bf, em, emph, it, and sl.
  • For tables: tabn, tabln, tabu, and tabx.
  • For math: align, form, forma, pform, pforma, and math.
  • For Lua: lua, ctx, and lmx.
  • For projects/modules: mod, comp, env, and prod.
  • For placing things: place, pfig, and ptab.
  • Others: start, text, doc, and page.

Quick Settings

In the command palette there is a command called simple_ConTeXt: Quick change the settings. It brings up an interactive menu for browsing and modifying the current settings. Some things (e.g. adding new settings) need to be done by opening up the settings the traditional ST way, but especially for modifying existing options this command can be very useful.

Scripts

We provide a command simple_ConTeXt: Run a ConTeXt script in the ST palette. It is a straightforward wrapper around a command line, with the environment path modified to include the path to the ConTeXt binaries currently chosen in the settings (the one named current.path). It also expands the default ST variables (e.g. $file). (Note that it is very basic at the moment, it simply waits for the script to finish and only then reports the result. Also, if the script has an error of some kind then this command can get stuck; in this way it is quite fragile.)

This can be a convenience if you have multiple installations of ConTeXt on one machine, as it takes care of setting up your PATH for you. Then you can do things like

mtxrun --generate --force

to (re)generate the file database for the version of ConTeXt currently active in simple ConTeXt (typically takes a few seconds), and

mtxrun --script font --list --pattern=*latinmodern* --all

to look up all the Latin Modern fonts that ConTeXt is aware of.

Misc

Completions should play well with others, e.g. the completions provided by the UnicodeCompletion package. (Although UnicodeCompletion is intended for LaTeX, I still find it useful for ConTeXt as many of the command names are the same.)

Features To Work On

Things that I'm interested in setting up, that should be relatively easy to do.

  • Add auto-build functionality. It should have the ability to pass different options to the auto-builder, e.g. --flags=draft. It should have options for when to run:
    • at one or both of:
    • on save,
    • at regular time intervals;
    • never.
  • Handle syntax embedding better. Currently we have many different embeddings that work reasonably well. However, there is definite room for improvement in terms of the end result, and also it would be nice for the code to be more principled.

Future Features

Features I would like to have, but may be harder to implement or lower priority.

  • Add back in, in a more robust way, the key=val autocompletion stuff. If we can get it set up right, it'll be really awesome. For example, on typing \setuphead[c we would have the possible keys starting with c suggested: catcodes, color, command, commandafter, commandbefore, continue, conversion, coupling, criterium. Moreover, if we choose criterium and start typing in the value, we could have the possible values (all, positive, and strict) come up as suggestions.
  • Add support for multi file documents. This is not something I do very much, so I'm not sure what it should look like. Have the builder figure out the master file? What other things would be useful?
  • Add support for the syntax \start[foo] ... \stop as a valid alternative to \startfoo ... \stopfoo.
  • Add option for return focus to ST after opening PDF on build.
  • SyncTeX support. (Forward and backward jump to PDF.) What's the situation with SyncTeX in ConTeXt?
  • Code formatter.
  • Extend the command auto-complete/pop-up system to allow for user-defined commands. Easiest would probably be to define them in the .xml style that the ConTeXt interface files use.
  • Fix up the documentation browser. I saw some discussion on the mailing list about using commands like mtxrun --launch cld-mkiv.pdf to open the docs, which would be ideal for this.
  • Checker/linter. (The checks provided by mtxrun --script check are quite basic, last I 'checked'. I don't know that chktex has much ConTeXt support, seems to be targeted at LaTeX.)
  • Citation handler. (We handle references well enough, similar support would be nice for \cite[...]. I expect we would try to keep it simple, and I would like to handle the .lua, .xml and .bib formats.)
  • Robust log parsing, esp. for reporting warnings/errors. Related to this, put phantom errors back in.
  • Word count. (Could be nice to have, but lots of difficulties with it.)