From ConTeXt wiki
Revision as of 12:55, 27 April 2017 by Koenich (Talk | contribs)
Jump to: navigation, search

< Text Editors



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

How to ConTeXt with Textadept (MS Windows)

(updated 2017/03)

Step 1: Install / Update ConTeXt

Installation and update of ConTeXt work the same way. If you only want to update ConTeXt you can start directly from point 3.

1. Download ConTeXt.

2. Extract the archive to a location of your choice.

3. Install / Update ConTeXt

3. Method 1: Write a batch file

Since at this point the installation and update of ConTeXt work the same way, the most effective solution is to create a batch file. To do so

 first-setup -engine=luatex -modules=all

3. Method 2: Type the command by hand

 first-setup -engine=luatex -modules=all

Step 2: Add ConTeXt's executables folder to Windows search Path

Note: you will need admin rights for this. On public machines for example you most probably won't be able to add ConTeXt to that machine's path. In that case skip this step and go to Step 3 respectively Step 4.1 directly.

1. Open Windows' System dialog

2. Click on Advanced System Settings ("System Properties").

3. Click on Advanced-Tab.

4. Click on Environment Variables....

5. Choose where to add ConTeXt's executables folder to:

6. Double-click on the respective variable called Path.

7. Add your ConTeXt executables to Windows path.

The location should look like this:


8. Save your changes. Usually no restart or re-login is needed after this operation, but to make sure, that the folder was added, you should restart your machine.

Optional: You can test whether it worked by starting your Command prompt and entering the following line, while being in a directory other than the one you just added.

 context -version

Step 3: Install Textadept

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

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

Step 4: 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 reload the changes without having to restart Textadept.

Step 4.1: Bind a PDF build command into Textadept

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

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"'
 textadept.run.compile_commands.tex = 'C:/ctx/tex/texmf-mswin/bin/mtxrun --autogenerate --script context --autopdf --purge --synctex=-1 "%f"'

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

4. Open or create a ConTeXt test document:

   hello world!

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.

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 4.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

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. Restart Textadept to reload init.lua.

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})

in which the expression dark is the filename of the theme located either in Textadept\themes or you can download and add new themes to USER\.textadept\themes (create the folder if it's not 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 they look like this:

 -- The first line is mandatory:
 snippets['context'] = snippets['context'] or {}
 -- Snippets start here:
 snippets.context['emph']        = '{\\em %<selected_text>%0}'
 snippets.context['bold']        = '{\\bf %<selected_text>%0}'
 snippets.context['start']       = '\\start%1\n%0\n\\stop%1'
 snippets.context['itemize']     = '\\startitemize\n\t%0\n\\stopitemize'
 snippets.context['item'] 	 = '\\startitem\n\t%0\n\\stopitem'
 snippets.context['enumerate']   = '\\startenumerate\n\t%0\n\\stopenumerate'
 snippets.context['chapter']     = '\\startchapter[title={%1},marking{%1}]\n%0\n\\stopchapter'
 snippets.context['section']     = '\\startsection[title={%1},marking{%1}]\n%0\n\\stopsection'
 snippets.context['ssection']    = '\\startsubsection[title={%1},marking{%1}]\n%0\n\\stopsubsection'
 snippets.context['title']       = '\\starttitle[title={%1},marking{%1}]\n%0\n\\stoptitle'
 snippets.context['subject']     = '\\startsubject[title={%1},marking{%1}]\n%0\n\\stopsubject'
 snippets.context['ssubject']    = '\\startsubsubject[title={%1},marking{%1}]\n%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