blob: fa8316457b7039219be78cd9704a4b248f0b0d63 [file] [log] [blame]
Christian Brabandtb4ddc6c2024-01-02 16:51:11 +01001*ft_context.txt* For Vim version 9.1. Last change: 2024 Jan 01
Bram Moolenaar7dd54322022-08-26 18:01:12 +01002
3This is the documentation for the ConTeXt filetype plugin.
4
5NOTE: the plugin requires +vim9script.
6
7==============================================================================
8CONTENTS *context.vim* *ft-context*
9
101. Introduction |ft-context-intro|
112. Commands |ft-context-commands|
123. Settings |ft-context-settings|
134. Mappings |ft-context-mappings|
14
15==============================================================================
16 *ft-context-intro*
17Introduction ~
18
19ConTeXt, similarly to LaTeX, is a macro-based typesetting system built on TeX:
20>
21 https://wiki.contextgarden.net
22 https://wiki.contextgarden.net/Vim
23<
24The ConTeXt plugin provides syntax highlighting, completion and support for
25typesetting ConTeXt documents. The recommended way to typeset a document is to
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +010026use |:ConTeXt|. This will invoke the `mtxrun` script that is found in `$PATH`.
Bram Moolenaar7dd54322022-08-26 18:01:12 +010027
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +010028For more fine grained control over the command and its environment,
29`context.Typeset()` can be used directly (or `context#Typeset()` from legacy
30Vim script). For instance, if a version of ConTeXt is installed in
31`~/context`, you may define a function to use it similar to the following:
Bram Moolenaar7dd54322022-08-26 18:01:12 +010032>
33 import autoload 'context.vim'
34
35 def MyConTeXt()
36 const env = {'PATH':
37 printf("%s/context/tex/texmf-<os>-<arch>/bin:%s", $HOME, $PATH)}
38 context.Typeset("%", env)
39 enddef
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +010040
41This code may go in `~/.vim/after/ftplugin/context.vim`. A mapping can then be
42defined to invoke the custom command:
Bram Moolenaar7dd54322022-08-26 18:01:12 +010043>
44 nnoremap <silent><buffer><leader>t <scriptcmd>MyConTeXt()<cr>
45<
46`context.Typeset()` accepts a third optional argument to specify a custom
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +010047typesetting command. That must be a function that takes a path and returns the
48command as a List. For example:
Bram Moolenaar7dd54322022-08-26 18:01:12 +010049>
50 def ConTeXtCustomCommand(path: string): list<string>
Bram Moolenaarbe4e0162023-02-02 13:59:48 +000051 return ['mtxrun', '--script', 'context', '--nonstopmode', path]
Bram Moolenaar7dd54322022-08-26 18:01:12 +010052 enddef
53
54 context.ConTeXtTypeset("%", v:none, ConTeXtCustomCommand)
55<
56Large projects are often organized as a root document and various chapter
57files. When editing a chapter file, it is convenient to invoke |:ConTeXt|
58directly on it, rather than having to switch to the root file. A "magic line"
59can be added at the beginning of each chapter file, which specifies the
60relative path to the root file. For instance:
61>
62 % !TEX root = ../MyRoot.tex
63<
64Vim searches for the magic line in the first ten lines of the current buffer:
65if it is found, the document specified by that line is typeset rather than the
66one in the current buffer. The root document does not have to be opened in
67Vim.
68
69To extend completion and syntax highlighting, you may generate supporting
70files using ConTeXt and add them to your configuration. If you configuration
71resides in `~/.vim`, you may use these commands:
72>
73 mkdir -p ~/.vim/syntax/shared
74 cd ~/.vim/syntax/shared
75 mtxrun --script interface --vim
76<
77The last command will create the following syntax files:
78
79- `context-data-context.vim`;
80- `context-data-interfaces.vim`;
81- `context-data-metafun.vim`;
Bram Moolenaarb59ae592022-11-23 23:46:31 +000082- `context-data-tex.vim`.
Bram Moolenaar7dd54322022-08-26 18:01:12 +010083
84The same command can be used to update those syntax files.
85
86 *ft-context-commands*
87Commands ~
88 *:ConTeXt*
89Start a background |job| to typeset the document in the current buffer. The
90command accepts an optional buffer's name, if you want to typeset a document
91that is in a different buffer.
92
93 *:ConTeXtLog*
94Edit the log file corresponding to the source in the current buffer.
95
96 *:ConTeXtJobsStatus*
97Echo the number of jobs currently running in the background.
98
99 *:ConTeXtStopJobs*
100Stop all the ConTeXt jobs currently running in the background.
101
102 *ft-context-settings*
103Settings ~
104 *'b:context_ignore_makefile'*
105 *'g:context_ignore_makefile'*
Christian Brabandt6c1afa32024-01-01 20:50:51 +0100106|:make| can be used to (synchronously) typeset a document. If a Makefile exists
Bram Moolenaar7dd54322022-08-26 18:01:12 +0100107and this option is not set, standard `make` is used. If this option is set,
108`mtxrun` is invoked instead, even if a Makefile exists.
109>
110 g:context_ignore_makefile = 0
111<
Christian Brabandt6c1afa32024-01-01 20:50:51 +0100112NOTE: before using |:make|, set the working directory of the buffer to the
Bram Moolenaar7dd54322022-08-26 18:01:12 +0100113directory of the file to be typeset.
Bram Moolenaar9fbdbb82022-09-27 17:30:34 +0100114
115 *'g:context_extra_options'*
116A list of additional options to pass to `mtxrun`.
117>
118 g:context_extra_options = []
119<
Bram Moolenaar7dd54322022-08-26 18:01:12 +0100120 *'b:context_include'*
121 *'g:context_include'*
122Dictionary of filetype/GROUP pairs for which syntax highlighting should be
123activated between \startGROUP and \stopGROUP. The default is to highlight XML
124between `\startXML` and `\stopXML`.
125>
126 g:context_include = {'xml': 'XML'}
127
128NOTE: Lua and MetaPost are always highlighted within the respective blocks.
129
130 *'g:no_context_maps'*
131When set, do not define any mappings.
132>
133 g:no_context_maps = 0
134<
135 *ft-context-mappings*
136Mappings ~
137
138tp "reflow TeX paragraph".
139
140i$ "inside inline math block".
141
142a$ "around inline math block".
143
144]] [count] start of sections forward.
145
146[[ [count] start of sections backward.
147
148][ [count] end sections forward.
149
150[] [count] end of sections backward.
151
152]} [count] end of blocks (\stop..., \setup...,
153 \define...) forward.
154
155[{ [count] begin of blocks (\start..., \setup...,
156 \define...) backward.
157
158 vim:tw=78:sw=4:ts=8:noet:ft=help:norl: