1 [[!meta author="spalax"]]
2 [[!template id=plugin name=compile author="[[Louis|spalax]]"]]
6 The compile plugin provides the `compile` directive, used to on-the-fly compile
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.
19 Some important security notice.
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
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).
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.
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.
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.
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.
63 Basic usage of this plugin is:
65 \[[!compile files="foo.ext"]]
67 It renders file `foo.ext` according to rules defined in the setup file, and
68 publish the compiled version.
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.
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
92 - `template`: Name of the template to use (if set, the `source` option is
94 - `var_*`: Any argument with a name starting with ``var_`` is transmitted to the template. For instance, if directive has argument ``var_foo=bar``, then the template will have a variable named ``foo``, and ``<TMPL_VAR FOO>`` will be replaced by ``bar``.
98 Note: This directive does not work if source file name does not have an
99 extension (i.e. does not contain a dot). This should not be too hard to
100 implement, but I do not need it. Patches welcome.
104 Here are the setup options (most of them can be overloaded on a per-extension
105 basis by setup option `compile_filetypes`, or by directive arguments):
107 - `compile_source` (boolean): should sources be published with compiled file
108 (this only affect template choice; see warning)? Default is true.
109 - `compile_template_source` (string): name of the template to use for compiled
110 files when option `source` is true. Default is `compile_source.tmpl`.
111 - `compile_template_nosource` (string): name of the template to use for
112 compiled files when option `source` is false. Default is
113 `compile_nosource.tmpl`.
114 - `compile_filetypes` (string): Per extension configuration (see paragraph
116 - `compile_tmpdir` (string): Path of a directory to use to compile files:
117 source file (and dependency) are copied to this directory before being
118 compiled (to avoid messing the ikiwiki directory with compiled version or
119 auxiliary files). Default is `SOURCE_WIKI/.ikwiki/tmp/compile`.
120 - `compile_bindir` (string): Directory containing binaries to use to compile
121 files. Default is undefined.
122 - `compile_depends` (string): List of files all compiled files will depend on
123 (see *Compilation* section below).
124 - `compile_build` (string): Command to use to compile files. Default
126 - `compile_inline` (boolean): If true, wikilinks pointing to files with an
127 extension specified in `compile_filetypes` are treated as a directive
128 \[[!compile files="LINK"]]. For instance, if this is set globally (or just
129 for tex), a wikilink \[[foo.tex]] will compile file `foo.tex`, and publish
130 the compiled `foo.pdf` file.
132 ### The `compile_filetypes` option
134 This variable is a json string, representing a dictionary. Keys are source file
135 extensions, values are dictionary of options applying only to files with this
138 Keys of these new directory are `source`, `template_nosource`,
139 `template_source`, `build`, `depends`, `inline`, and overrides generic options
140 defined above. They are themselves overriden by directive arguments (excepted
145 compile_filetypes => '{
147 "build": "pdflatex %{basename}s",
148 "destname": "%{basename}s.pdf",
149 "depends": ["logo.png"],
153 "build": "latex %{basename}s",
154 "destname": "%{basename}s.pdf",
155 "depends": ["logo.eps"]
163 Before compilation, the source file and all dependencies are copied to the
164 temporary directory defined by option `compile_tmpdir`. For instance, if all
165 you LaTeX files are compiled using a custom class `foo.sty`, and a particular
166 file `bar.tex` uses the `logo.png` file, your setup option will contain
167 `foo.sty` as `depends`, and `compile` directive will be called using
168 `\[[!compile files="bar.tex logo.png"]]`. Then, before compilation, files
169 `foo.sty`, `bar.tex` and `logo.png` will be copied in the same temporary
172 Note that path are *flattened* when copied: before performing compilation of
173 directive `\[[!compile files="sub1/foo sub2/bar"]]`, files `foo` and `bar` will
174 be copied in the same directory: this temporary directory will contain failes
175 `foo` and `bar`, but not `sub1/foo` and `sub2/bar`.
179 The build command used is (if defined, by priority order):
181 - defined by argument `build` of directive;
182 - setup command ``compile_filetypes{TYPE}{build}``;
183 - setup command ``compile_build`` (if you have a generic build command);
184 - 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);
185 - 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).
189 The way links are rendered is defined in a template, which is (by order of
190 priority, some of them depends on whether ``source`` is true):
192 - argument `template` of directive;
193 - setup variable ``compile_filetypes{TYPE}{template_source}`` or ``compile_filetypes{TYPE}{template_nosource}``;
194 - setup variable ``compile_source`` or ``compile_nosource``;
195 - `compile_source.mdwn` or `compile_nosource.mdwn`.
197 It is passed the following variables:
199 - `DESTURL`: URL to the compiled file.
200 - `DESTNAME`: Name of the compiled file.
201 - `SRCURL`: URL to the source file.
202 - `SRCNAME`: Name of the source file (without directory).
203 - `ORIGNAME`: Name of the source file (with directory).
205 Note that templates can be used to display images (instead of a link to them).
206 For instance, if you have a `.tiff` file you want to convert to png before
207 displaying it on your website, you can use as a template:
209 <img src="<TMPL_VAR DESTURL>">
213 Code and documentation can be found here : [[https://atelier.gresille.org/projects/gresille-ikiwiki/wiki/Compile]].