Debian Codegraph @

docs/xhtml/manual/sec-texpost.html

raw
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Latex post process script</title><link rel="stylesheet" type="text/css" href="manual.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="home" href="index.html" title="DocBook to LaTeX Publishing" /><link rel="up" href="sec-custom.html" title="Chapter 4. Customization" /><link rel="prev" href="sec-custom-latex.html" title="Customized LaTeX style" /><link rel="next" href="sec-specs.html" title="Dblatex Configuration File" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Latex post process script</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-custom-latex.html">Prev</a> </td><th width="60%" align="center">Chapter 4. Customization</th><td width="20%" align="right"> <a accesskey="n" href="sec-specs.html">Next</a></td></tr></table><hr /></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="sec-texpost"></a>Latex post process script</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="sec-texpost.html#idp2278">Post latex compilations</a></span></dt><dt><span class="section"><a href="sec-texpost.html#sec-texpost-py">Post processing with a Python Plugin</a></span></dt></dl></div><p>
3 Extra user actions can be processed on the latex file produced by the XSL stylesheets or on its temporary working files produced by the latex compilation.
4 </p><p>
5 For instance, in the documents I write the cover page must display the number of pages of the document, but written in full letters (e.g. 23 is written “twenty three”). The latex post process script is then helpfull, and in this particular case it patches the .aux file.
6 </p><p>
7 The post process script is called just before the last latex compilation, and takes one parameter, the latex file compiled by the tool.
8 </p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="idp2278"></a>Post latex compilations</h3></div></div></div><p>
9 The latex compilations done once the script is called depend on the return code
10 of the script:
11 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
12 When the return code is 0, <span class="command"><strong>dblatex</strong></span> continues the
13 compilation as many times as necessary.
14 </p></li><li class="listitem"><p>
15 When the return code is 1, no more compilation is done by dblatex.
16 This case is useful
17 if the script needs to control precisely the number of compilation to apply.
18 It is up to the script to perform the expected compilations.</p><p>To do so, the script can retrieve in the <code class="envar">LATEX</code> environment
19 variable the actual compiler used by <span class="command"><strong>dblatex</strong></span>.
20 </p></li><li class="listitem"><p>
21 When the return code is another value, an error is raised to signal
22 a failed post process script execution.
23 </p></li></ul></div><p>
24 </p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="sec-texpost-py"></a>Post processing with a Python Plugin</h3></div></div></div><p>You can use a python plugin instead of a script by prefixing
25 the plugin name with the string <code class="literal">"plugin:"</code>. When using a
26 plugin you must not put the python suffix in the plugin name. If the plugin
27 is in one of the Python system directories, or in the current directory where
28 you call dblatex, or in one of the directories of the
29 <code class="envar">PYTHONPATH</code>
30 environment variable, you don't need to specify a directory location.
31 Otherwise put the plugin directory path before the plugin name.
32 </p><p>Here are several plugin call examples:
33 </p><pre class="programlisting"># The texpost.py module is in one of the python paths
34 dblatex -r plugin:texpost file.xml
35
36 # The texpost.py module location is specified with an absolute path
37 dblatex -r plugin:/path/to/texpost file.xml
38
39 # The texpost.py module is specified through a relative path from current dir
40 dblatex -r plugin:relative/path/from/current/dir/texpost file.xml
41 </pre><p>
42 </p><p>The plugin must contain a <code class="function">main</code> entry point. <span class="command"><strong>Dblatex</strong></span> will pass the following parameters to the entry point: <em class="parameter"><code>latex_file</code></em> to specify the latex file to post process, and <em class="parameter"><code>stdout</code></em> to specify the output stream to use to be consistent with the dblatex verbosity.</p><div class="example"><a id="idp2304"></a><p class="title"><strong>Example 4.4. Texpost Python Plugin Example</strong></p><div class="example-contents"><pre class="programlisting">
43 import sys
44 import os
45
46 def main(latex_file, stdout):
47 """
48 Texpost Plugin Entry point
49 """
50 # Let's find out the backend used
51 tex_engine = os.environ["LATEX"]
52
53 # Let's log something
54 print &gt;&gt;stdout, "Plugin called on '%s' file" % (latex_file)
55
56 # Open the latex file and parse it
57 texfile = open(latex_file)
58 ...
59
60 # Now decide if a new compilation must occur
61 if has_changed:
62 sys.exit(0)
63 else:
64 sys.exit(1)
65
66 </pre></div></div><br class="example-break" /></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-custom-latex.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sec-custom.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sec-specs.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Customized LaTeX style </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Dblatex Configuration File</td></tr></table></div></body></html>