]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/contrib/compile.mdwn
7ae4968ade6c52d350fe5010e91ef6f26435eb81
[ikiwiki.git] / doc / plugins / contrib / compile.mdwn
1 [[!meta author="spalax"]]
2 [[!template id=plugin name=compile author="[[Louis|spalax]]"]]
3
4 # Compile
5
6 The compile plugin provides the `compile` directive, used to on-the-fly compile
7 and publish documents.
8
9 For instance, if you want to publish files together with their sources (like
10 `.tex` and `.pdf` files), you can have the `.tex` file in your source wiki
11 directory, and command `\[[!compile files="foo.tex"]]` (or wikilink
12 `\[[foo.tex]]`, if the right option is set) will compile file and render as a
13 link to the `.pdf` file.
14
15 [[!toc startlevel=2]]
16
17 ## Warning
18
19 Some important security notice.
20
21 - This plugins allows user to execute arbitrary commands when compiling the
22   wiki.  Use at your own risk. If you use Ikiwiki as a static web site compiler
23   (and not a wiki), and you are the only one to compile the wiki, there is no
24   risk.
25
26 - Source files are published, wheter option `source` is true or not. If
27   `source` is false, source may not be *advertised*, but it is still available
28   somewhere on your website (most likely by replacing in the compiled file URL
29   the extension of the compiled file by the extension of the source file). So,
30   do not use this plugin if you do not want to publish your source files
31     (sorry: I designed this plugin to publish free stuff).
32
33 ## Rationale
34
35 I want to publish some latex files, both source (`.tex`) and compiled (`.pdf`)
36 version, but I do not want to maintain two versions of the same file.
37
38 Using this plugin, I only have to maintain the `.tex` files, and thoses files
39 are compiled on the fly, so that the `pdf` is published.
40
41 ## String formatting
42
43 Strings (destination name, template name and build command) accept python-like
44 syntax ``%{name}s``, which is replaced by the value of variable ``name``. The
45 following variables are abailable.
46
47 - `srcname`: Source name.
48 - `srcextension`: Extension of the source name.
49 - `filetype`: File type (extension of the source name, otherwise specified by directive).
50 - `dirname`: Directory of the source file.
51 - `wikiname`: Name of source file, relative to source wiki directory.
52 - `srcfullname`: Name of source file, relative to file system root.
53 - `basename`: Source name, without directory nor extension.
54 - `destname`: Destination name (without directory).
55 - `destextension`: Extension of the destination name.
56 - `targetname`: Destination name, relative to the destination directory.
57 - `destfullname`: Destination name, relative to file system root.
58
59 ## Directive
60
61 ### Usage
62
63 Basic usage of this plugin is:
64
65     \[[!compile files="foo.ext"]]
66
67 It renders file `foo.ext` according to rules defined in the setup file, and
68 publish the compiled version.
69
70 ### Arguments
71
72 All the arguments (but `source` and `filetype`) are string which are processed
73 using python-like string formatting, and described in the setup options section.
74
75 - `files`: List of files used in compilation, as space separated string. For
76   instance, to compile some tex file including a png image, you will have:
77   `files="foo.tex image.png"`. It is not possible to have filenames containing
78   spaces (unless you provide me a patch to recognize escaped spaces).
79 - `filetype`: By default, the source file extension is used to determine build
80   command and other configuration. If the same extension refer to different
81   type of files, you can enforce the filetype using this argument. For
82   instance, if some your LaTeX files have to be compiled with `pdflatex`, while
83   the other require `latex`, your `compile_filetypes` can contains two keys
84   `tex` and `texdvi`. By default, LaTeX files will be compiled using
85   configuration associated to `tex`, unless directive has argument
86   `filetype=texdvi`, in which case the latter configuration is used.
87 - `destname`: Name of the compiled file name.
88 - `build`: Build command.
89 - `source`: Boolean to choose whether to publish source file or not. The only
90   effect is the template choice: source is always published (but not always
91   advertised).
92 - `template`: Name of the template to use (if set, the `source` option is
93   irrelevant).
94
95 ### Extensions
96
97 Note: This directive does not work if source file name does not have an
98 extension (i.e. does not contain a dot). This should not be too hard to
99 implement, but I do not need it. Patches welcome.
100
101 ## Configuration
102
103 Here are the setup options (most of them can be overloaded on a per-extension
104 basis by setup option `compile_filetypes`, or by directive arguments):
105
106 - `compile_source` (boolean): should sources be published with compiled file
107   (this only affect template choice; see warning)? Default is true.
108 - `compile_template_source` (string): name of the template to use for compiled
109   files when option `source` is true. Default is `compile_source.tmpl`.
110 - `compile_template_nosource` (string): name of the template to use for
111   compiled files when option `source` is false. Default is
112   `compile_nosource.tmpl`.
113 - `compile_filetypes` (string): Per extension configuration (see paragraph
114   below).
115 - `compile_tmpdir` (string): Path of a directory to use to compile files:
116   source file (and dependency) are copied to this directory before being
117   compiled (to avoid messing the ikiwiki directory with compiled version or
118   auxiliary files). Default is `SOURCE_WIKI/.ikwiki/tmp/compile`.
119 - `compile_bindir` (string): Directory containing binaries to use to compile
120   files. Default is undefined.
121 - `compile_depends` (string): List of files all compiled files will depend on
122   (see *Compilation* section below).
123 - `compile_build` (string): Command to use to compile files. Default
124   is undefined.
125 - `compile_inline` (boolean): If true, wikilinks pointing to files with an
126   extension specified in `compile_filetypes` are treated as a directive
127   \[[!compile files="LINK"]]. For instance, if this is set globally (or just
128   for tex), a wikilink \[[foo.tex]] will compile file `foo.tex`, and publish
129   the compiled `foo.pdf` file.
130
131 ### The `compile_filetypes` option
132
133 This variable is a json string, representing a dictionary. Keys are source file
134 extensions, values are dictionary of options applying only to files with this
135 extension.
136
137 Keys of these new directory are `source`, `template_nosource`,
138 `template_source`, `build`, `depends`, `inline`, and overrides generic options
139 defined above. They are themselves overriden by directive arguments (excepted
140 `inline`).
141
142 Example:
143
144     compile_filetypes => '{
145       "tex": {
146         "build": "pdflatex %{basename}s",
147         "destname": "%{basename}s.pdf",
148         "depends": ["logo.png"],
149         "inline": "1"
150       },
151       "texdvi": {
152         "build": "latex %{basename}s",
153         "destname": "%{basename}s.pdf",
154         "depends": ["logo.eps"]
155       }
156     }'
157
158 ## Compilation
159
160 ### Dependencies
161
162 Before compilation, the source file and all dependencies are copied to the
163 temporary directory defined by option `compile_tmpdir`. For instance, if all
164 you LaTeX files are compiled using a custom class `foo.sty`, and a particular
165 file `bar.tex` uses the `logo.png` file, your setup option will contain
166 `foo.sty` as `depends`, and `compile` directive will be called using
167 `\[[!compile files="bar.tex logo.png"]]`. Then, before compilation, files
168 `foo.sty`, `bar.tex` and `logo.png` will be copied in the same temporary
169 directory.
170
171 Note that path are *flattened* when copied: before performing compilation of
172 directive `\[[!compile files="sub1/foo sub2/bar"]]`, files `foo` and `bar` will
173 be copied in the same directory: this temporary directory will contain failes
174 `foo` and `bar`, but not `sub1/foo` and `sub2/bar`.
175
176 ### Build command
177
178 The build command used is (if defined, by priority order):
179
180 - defined by argument `build` of directive;
181 - setup command ``compile_filetypes{TYPE}{build}``;
182 - setup command ``compile_build`` (if you have a generic build command);
183 - command ``$config{compile_bindir}/${extension}s %{srcname}s`` (if setup variable ``compile_bindir``is defined, is a directory, and contains an executable file matching the extension, it will be used);
184 - command ``make -f $config{compile_bindir}/make.${extension}s %{destname}s`` (if setup variable ``compile_bindir`` is defined, is a directory, and contains a readable makefile ``make.EXTENSION``, it will be used).
185
186 ## Template
187
188 The way links are rendered is defined in a template, which is (by order of
189 priority, some of them depends on whether ``source`` is true):
190
191 - argument `template` of directive;
192 - setup variable ``compile_filetypes{TYPE}{template_source}`` or ``compile_filetypes{TYPE}{template_nosource}``;
193 - setup variable ``compile_source`` or ``compile_nosource``;
194 - `compile_source.mdwn` or `compile_nosource.mdwn`.
195
196 It is passed the following variables:
197
198 - `DESTURL`: URL to the compiled file.
199 - `DESTNAME`: Name of the compiled file.
200 - `SRCURL`: URL to the source file.
201 - `SRCNAME`: Name of the source file (without directory).
202 - `ORIGNAME`: Name of the source file (with directory).
203
204 Note that templates can be used to display images (instead of a link to them).
205 For instance, if you have a `.tiff` file you want to convert to png before
206 displaying it on your website, you can use as a template:
207
208     <img src="<TMPL_VAR DESTURL>">