My favorites | Sign in
Project Home Downloads Wiki Issues Source
Documentation of the code completion feature
Updated Feb 4, 2010 by

Using code completion

TeXworks comes with an expandable set of code templates that can easily be inserted into a (La)TeX document. To insert a code template, type the first few characters of the pattern name and press <Tab>. The code template best matching the characters you typed will be inserted and highlighted. If there are multiple code templates starting with the characters you typed press <Tab> to cycle through the possibilities.

Some code templates include bullet characters •. These act as placeholders where text should be inserted. Use <Ctrl>+<Tab> and <Shift>+<Ctrl>+<Tab> (<Alt>+<Tab> and <Alt>+<Shift>+<Tab> on Mac) to navigate between those placeholders.

Some of the most common code templates are listed below:

-- \textendash
--- \textemdash
lbl \label{}
ref \ref{}
sec \section{}
ssec \subsection{}
bf \textbf{}
em \emph{}
xa \alpha
xb \beta

Customizing code completion

The code completion templates are located in the completion sub-directory of your TeXworks resource directory.

The general syntax of a code completion template is the following:


The <alias>:= part can be omitted to turn the code text into its own alias. <text> must fit in a single line (see below for ways to produce a multi-line code template). Empty lines and lines starting with a % are ignored.

In <text> several special markers are allowed:

#RET# is replaced by a line break upon expansion of the template
#INS# upon expansion the cursor is placed at this position. Any additional #INS# markers are ignored
the Unicode character U+2022 (BULLET) is used as a placeholder where text should be entered; navigate through to the placeholders with <Ctrl>+<Tab> and <Shift>+<Ctrl>+<Tab> (<Alt>+<Tab> and <Alt>+<Shift>+<Tab> on Mac)

Please refer to the existing code completion template files for numerous examples.

Thanks to Stefan Löffler for this writeup.

Comment by, Oct 31, 2009

Customizing code completion

After installation of TeXworks? and the first startup of the program the resource directory ~/Library/TeXworks/completion/ is empty!

I'd like to suggest to place in here an example file, which should contain the most common code templates, including latex:=\LaTeX. Empty lines and commented lines should also be in this file. And it should be mentioned, that the name of this file is irrelevant. The only condition is that it must be a plain text file.

Last but not least, more than one text file can be placed in this directory. The lexicographical order in which they get listed after a call of the unix command ls is important. All files are considered, but if there are two files with different definitions for the same template symbol, than the file which comes first in lexicographical order gets preference over the second.

Comment by akelux, Jan 25, 2011

A trick to do regular word auto completion by Tab based on user dictionary.

  1. create a dictionary in ~/.TeXworks?/completion (under UNIX/LINUX,
  2. you can copy one dictionary from /usr/share/dict)
2. restart TexWorks?, then you can do auto completion for words in
the created dictionary by Tab.

Sign in to add a comment
Powered by Google Project Hosting