Christian Brabandt | b4ddc6c | 2024-01-02 16:51:11 +0100 | [diff] [blame] | 1 | *ft_context.txt* For Vim version 9.1. Last change: 2024 Jan 01 |
Bram Moolenaar | 7dd5432 | 2022-08-26 18:01:12 +0100 | [diff] [blame] | 2 | |
| 3 | This is the documentation for the ConTeXt filetype plugin. |
| 4 | |
| 5 | NOTE: the plugin requires +vim9script. |
| 6 | |
| 7 | ============================================================================== |
| 8 | CONTENTS *context.vim* *ft-context* |
| 9 | |
| 10 | 1. Introduction |ft-context-intro| |
| 11 | 2. Commands |ft-context-commands| |
| 12 | 3. Settings |ft-context-settings| |
| 13 | 4. Mappings |ft-context-mappings| |
| 14 | |
| 15 | ============================================================================== |
| 16 | *ft-context-intro* |
| 17 | Introduction ~ |
| 18 | |
| 19 | ConTeXt, 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 | < |
| 24 | The ConTeXt plugin provides syntax highlighting, completion and support for |
| 25 | typesetting ConTeXt documents. The recommended way to typeset a document is to |
Bram Moolenaar | 9fbdbb8 | 2022-09-27 17:30:34 +0100 | [diff] [blame] | 26 | use |:ConTeXt|. This will invoke the `mtxrun` script that is found in `$PATH`. |
Bram Moolenaar | 7dd5432 | 2022-08-26 18:01:12 +0100 | [diff] [blame] | 27 | |
Bram Moolenaar | 9fbdbb8 | 2022-09-27 17:30:34 +0100 | [diff] [blame] | 28 | For more fine grained control over the command and its environment, |
| 29 | `context.Typeset()` can be used directly (or `context#Typeset()` from legacy |
| 30 | Vim 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 Moolenaar | 7dd5432 | 2022-08-26 18:01:12 +0100 | [diff] [blame] | 32 | > |
| 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 Moolenaar | 9fbdbb8 | 2022-09-27 17:30:34 +0100 | [diff] [blame] | 40 | |
| 41 | This code may go in `~/.vim/after/ftplugin/context.vim`. A mapping can then be |
| 42 | defined to invoke the custom command: |
Bram Moolenaar | 7dd5432 | 2022-08-26 18:01:12 +0100 | [diff] [blame] | 43 | > |
| 44 | nnoremap <silent><buffer><leader>t <scriptcmd>MyConTeXt()<cr> |
| 45 | < |
| 46 | `context.Typeset()` accepts a third optional argument to specify a custom |
Bram Moolenaar | 9fbdbb8 | 2022-09-27 17:30:34 +0100 | [diff] [blame] | 47 | typesetting command. That must be a function that takes a path and returns the |
| 48 | command as a List. For example: |
Bram Moolenaar | 7dd5432 | 2022-08-26 18:01:12 +0100 | [diff] [blame] | 49 | > |
| 50 | def ConTeXtCustomCommand(path: string): list<string> |
Bram Moolenaar | be4e016 | 2023-02-02 13:59:48 +0000 | [diff] [blame] | 51 | return ['mtxrun', '--script', 'context', '--nonstopmode', path] |
Bram Moolenaar | 7dd5432 | 2022-08-26 18:01:12 +0100 | [diff] [blame] | 52 | enddef |
| 53 | |
| 54 | context.ConTeXtTypeset("%", v:none, ConTeXtCustomCommand) |
| 55 | < |
| 56 | Large projects are often organized as a root document and various chapter |
| 57 | files. When editing a chapter file, it is convenient to invoke |:ConTeXt| |
| 58 | directly on it, rather than having to switch to the root file. A "magic line" |
| 59 | can be added at the beginning of each chapter file, which specifies the |
| 60 | relative path to the root file. For instance: |
| 61 | > |
| 62 | % !TEX root = ../MyRoot.tex |
| 63 | < |
| 64 | Vim searches for the magic line in the first ten lines of the current buffer: |
| 65 | if it is found, the document specified by that line is typeset rather than the |
| 66 | one in the current buffer. The root document does not have to be opened in |
| 67 | Vim. |
| 68 | |
| 69 | To extend completion and syntax highlighting, you may generate supporting |
| 70 | files using ConTeXt and add them to your configuration. If you configuration |
| 71 | resides 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 | < |
| 77 | The 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 Moolenaar | b59ae59 | 2022-11-23 23:46:31 +0000 | [diff] [blame] | 82 | - `context-data-tex.vim`. |
Bram Moolenaar | 7dd5432 | 2022-08-26 18:01:12 +0100 | [diff] [blame] | 83 | |
| 84 | The same command can be used to update those syntax files. |
| 85 | |
| 86 | *ft-context-commands* |
| 87 | Commands ~ |
| 88 | *:ConTeXt* |
| 89 | Start a background |job| to typeset the document in the current buffer. The |
| 90 | command accepts an optional buffer's name, if you want to typeset a document |
| 91 | that is in a different buffer. |
| 92 | |
| 93 | *:ConTeXtLog* |
| 94 | Edit the log file corresponding to the source in the current buffer. |
| 95 | |
| 96 | *:ConTeXtJobsStatus* |
| 97 | Echo the number of jobs currently running in the background. |
| 98 | |
| 99 | *:ConTeXtStopJobs* |
| 100 | Stop all the ConTeXt jobs currently running in the background. |
| 101 | |
| 102 | *ft-context-settings* |
| 103 | Settings ~ |
| 104 | *'b:context_ignore_makefile'* |
| 105 | *'g:context_ignore_makefile'* |
Christian Brabandt | 6c1afa3 | 2024-01-01 20:50:51 +0100 | [diff] [blame] | 106 | |:make| can be used to (synchronously) typeset a document. If a Makefile exists |
Bram Moolenaar | 7dd5432 | 2022-08-26 18:01:12 +0100 | [diff] [blame] | 107 | and 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 Brabandt | 6c1afa3 | 2024-01-01 20:50:51 +0100 | [diff] [blame] | 112 | NOTE: before using |:make|, set the working directory of the buffer to the |
Bram Moolenaar | 7dd5432 | 2022-08-26 18:01:12 +0100 | [diff] [blame] | 113 | directory of the file to be typeset. |
Bram Moolenaar | 9fbdbb8 | 2022-09-27 17:30:34 +0100 | [diff] [blame] | 114 | |
| 115 | *'g:context_extra_options'* |
| 116 | A list of additional options to pass to `mtxrun`. |
| 117 | > |
| 118 | g:context_extra_options = [] |
| 119 | < |
Bram Moolenaar | 7dd5432 | 2022-08-26 18:01:12 +0100 | [diff] [blame] | 120 | *'b:context_include'* |
| 121 | *'g:context_include'* |
| 122 | Dictionary of filetype/GROUP pairs for which syntax highlighting should be |
| 123 | activated between \startGROUP and \stopGROUP. The default is to highlight XML |
| 124 | between `\startXML` and `\stopXML`. |
| 125 | > |
| 126 | g:context_include = {'xml': 'XML'} |
| 127 | |
| 128 | NOTE: Lua and MetaPost are always highlighted within the respective blocks. |
| 129 | |
| 130 | *'g:no_context_maps'* |
| 131 | When set, do not define any mappings. |
| 132 | > |
| 133 | g:no_context_maps = 0 |
| 134 | < |
| 135 | *ft-context-mappings* |
| 136 | Mappings ~ |
| 137 | |
| 138 | tp "reflow TeX paragraph". |
| 139 | |
| 140 | i$ "inside inline math block". |
| 141 | |
| 142 | a$ "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: |