blob: ba6bd0d819509826bf8fb5f66e3a3c8f5f3e867c [file] [log] [blame]
Bram Moolenaar7dd54322022-08-26 18:01:12 +01001*ft_context.txt* For Vim version 9.0. Last change: 2022 Aug 12
2
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
26use |:ConTeXt|. This will invoke the `mtxrun` script that is found in $PATH.
27
28For more fine grained control over the command and its environment, you may
29invoke `context.Typeset()` directly (or `context#Typeset()` from legacy Vim
30script). For instance, if you have installed a version of ConTeXt in
31`~/context`, you may define a function to use it (you may put the following
32code in `~/.vim/after/ftplugin/context.vim`) similar to the following:
33>
34 import autoload 'context.vim'
35
36 def MyConTeXt()
37 const env = {'PATH':
38 printf("%s/context/tex/texmf-<os>-<arch>/bin:%s", $HOME, $PATH)}
39 context.Typeset("%", env)
40 enddef
41<
42and perhaps use it with a mapping:
43>
44 nnoremap <silent><buffer><leader>t <scriptcmd>MyConTeXt()<cr>
45<
46`context.Typeset()` accepts a third optional argument to specify a custom
47typesetting command. Such argument must be a function that takes a path and
48returns the command as a List. For example:
49>
50 def ConTeXtCustomCommand(path: string): list<string>
51 return ['mtxrun', '--script', 'context', '--nonstopmode, path]
52 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`;
82- `context-data-tex.vim`.
83
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'*
106`make` can be used to (synchronously) typeset a document. If a Makefile exists
107and 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<
112NOTE: before using `make`, set the working directory of the buffer to the
113directory of the file to be typeset.
114 *'b:context_include'*
115 *'g:context_include'*
116Dictionary of filetype/GROUP pairs for which syntax highlighting should be
117activated between \startGROUP and \stopGROUP. The default is to highlight XML
118between `\startXML` and `\stopXML`.
119>
120 g:context_include = {'xml': 'XML'}
121
122NOTE: Lua and MetaPost are always highlighted within the respective blocks.
123
124 *'g:no_context_maps'*
125When set, do not define any mappings.
126>
127 g:no_context_maps = 0
128<
129 *ft-context-mappings*
130Mappings ~
131
132tp "reflow TeX paragraph".
133
134i$ "inside inline math block".
135
136a$ "around inline math block".
137
138]] [count] start of sections forward.
139
140[[ [count] start of sections backward.
141
142][ [count] end sections forward.
143
144[] [count] end of sections backward.
145
146]} [count] end of blocks (\stop..., \setup...,
147 \define...) forward.
148
149[{ [count] begin of blocks (\start..., \setup...,
150 \define...) backward.
151
152 vim:tw=78:sw=4:ts=8:noet:ft=help:norl: