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
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.
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):
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
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
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.
131 ### The `compile_filetypes` option
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
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
144 compile_filetypes => '{
146 "build": "pdflatex %{basename}s",
147 "destname": "%{basename}s.pdf",
148 "depends": ["logo.png"],
152 "build": "latex %{basename}s",
153 "destname": "%{basename}s.pdf",
154 "depends": ["logo.eps"]
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
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`.
178 The build command used is (if defined, by priority order):
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).
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):
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`.
196 It is passed the following variables:
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).
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:
208 <img src="<TMPL_VAR DESTURL>">
212 Code and documentation can be found here : [[https://atelier.gresille.org/projects/gresille-ikiwiki/wiki/Compile]].