From ConTeXt wiki
Jump to: navigation, search

< Text Editors



Textadept is a programmable text editor for Linux, Mac OSX and Windows. It is fully extensible using Lua.

ConTeXt with Textadept (MS Windows)

(updated 2017/12)

Step 1: Install Textadept

1.1. Download and extract Textadept to a folder of your choice.

1.2. Use textadept.exe from the extracted folder to start Textadept.

Step 2: Tweak Textadept's settings

Note that almost all changes to Textadept are saved in the file init.lua. There is two of them, of which you should edit only one:

Usually you have to restart Textadept after changing its configuration files. Robert Gieseke created a code though, which you can add to your init.lua to circumvent having to restart Textadept whenever a change is made:

 -- Save and reset Lua state: F9
 keys['f9'] = function()    -- Mac OSX users might prefer:    keys[OSX and 'mf9' or 'f9']

Save init.lua and restart Textadept once. After doing so you can add changes to Textadept's configuration files and press F9-key afterwards to save and load the changes without having to restart Textadept.

Step 2.1: Bind a PDF build command into Textadept

2.1.1. Use Textadept to open your init.lua stored in SYSDRIVE:\users\USER\.textadept\.

2.1.2. Add an execute command for ConTeXt to Textadept's menu:

 textadept.run.compile_commands.tex = 'mtxrun --autogenerate --script context --autopdf --purge --synctex=-1 "%f"'

2.1.3. Restart Textadept to reload the modified init.lua.

2.1.4. Open or create a ConTeXt test document:

   hello world!

2.1.5. Use Textadept's Tools -> Compile to build a PDF with the options added to init.lua. A message buffer with compilation status will open in a seperate tab.

2.1.6. When you have a popular PDF reader installed already, it should pop up at the end of the process and show the created PDF output. Sumatra PDF is highly recommended for this.

Step 2.2: Lexing (command highlighting & code folding)

A lexer is a file that defines command highlighting and code folding keywords. Textadept comes with a ConTeXt lexer. In order to be able to use command highlighting and code folding when writing ConTeXt documents, you have to bind those documents to the lexer. To do so

2.2.1. add the following line to your USER/.textadept/init.lua and save it afterwards:

 textadept.file_types.extensions.tex = 'context'
 textadept.file_types.extensions.cxd = 'context'

2.2.2. Restart Textadept to reload init.lua.

2.2.3. Open a ConTeXt document and check Textadept's status bar in the lower right corner. It should say context. If it says latex make sure it really is a ConTeXt file or repeat the procedure.

Optional: Additional Textadept tweaks

Themes & editor font changes

You can change the theme, font and font size of Textadept with the following line

 ui.set_theme('dark', {font = 'Monospace', fontsize = 10})       -- Textadept v9
 buffer:set_theme('dark', {font = 'Monospace', fontsize = 10})   -- Textadept v10

in which the expression dark is the filename of the theme located in either Textadept\themes or USER\.textadept\themes (after you created or downloaded and added them; create the folder as it usually won't be there yet).


Snippets are predefined code or text blocks. Using snippets can save a lot of time as you won't have to retype often used commands and text passages. You add snippets to your USER/.textadept/init.lua. In Textadept snippets look like this:

 snippets.context['TRIGGERKEYWORD'] = 'PASTEDTEXT'

To get an idea how writing snippets (for ConTeXt) works, you can copy and paste the following list to your init.lua:

 -- The first line is mandatory:
 snippets['context'] = snippets['context'] or {}
 -- Snippets start here:
 snippets.context['emph']        = '{\\em %<selected_text>%0}' -- emphasized text/math
 snippets.context['ital']        = '{\\it %<selected_text>%0}' -- italic text/math
 snippets.context['bold']        = '{\\bf %<selected_text>%0}' -- bold text/math
 snippets.context['boldit']      = '{\\bi %<selected_text>%0}' -- bold italic text/math
 snippets.context['start']       = '\\start%1\n\t%0\n\\stop%1'
 snippets.context['itemize']     = '\\startitemize[packed]\n\t\\startitem\n\t\t%<selected_text>%0\n\t\\stopitem\n\\stopitemize' -- start itemization
 snippets.context['item'] 	 = '\\startitem\n\t%<selected_text>%0\n\\stopitem'
 snippets.context['enumerate']   = '\\startenumerate\n\t%0\n\\stopenumerate'
 snippets.context['chapter']     = '\\startchapter[title={%1},marking{%1}]\n\t%0\n\\stopchapter'
 snippets.context['section']     = '\\startsection[title={%1},marking{%1}]\n\t%0\n\\stopsection'
 snippets.context['ssection']    = '\\startsubsection[title={%1},marking{%1}]\n\t%0\n\\stopsubsection'
 snippets.context['title']       = '\\starttitle[title={%1},marking{%1}]\n\t%0\n\\stoptitle'
 snippets.context['subject']     = '\\startsubject[title={%1},marking{%1}]\n\t%0\n\\stopsubject'
 snippets.context['ssubject']    = '\\startsubsubject[title={%1},marking{%1}]\n\t%0\n\\stopsubsubject'

3rd party projects

A ConTeXt module for Textadept is being developed at ta-context-latex.

Note though, that if you plan to use Textadept without LaTeX with ConTeXt mkiv only (recommended), then you might not need the package mentioned above as it comes with literally only a hand full of ConTeXt snippets. It also needs additional software to be installed (Textredux, ctags), so that it's almost more comfortable to create own ConTeXt snippets with the ease of Textadept (see above).


Personal tools
External Help