34
34
pytask-latex
35
35
============
36
36
37
- pytask-latex allows you to compile LaTeX documents.
37
+ pytask-latex allows you to compile LaTeX documents with pytask
38
38
39
- It also tries to infer the dependency of the LaTeX document such as included images,
40
- bibliography files and other .tex files automatically to compile LaTeX documents when it
41
- is possible.
39
+ It also uses `latex-dependency-scanner
40
+ <https://github.com/pytask-dev/latex-dependency-scanner> `_ to automatically infer the
41
+ dependencies of the LaTeX document such as images, bibliographies and other ``.tex ``
42
+ files which are necessary to compile the LaTeX document.
42
43
43
44
44
45
Installation
@@ -65,14 +66,14 @@ following on the command line
65
66
$ latexmk --help
66
67
67
68
If an error is shown instead of a help page, you can install ``latexmk `` with one of the
68
- popular LaTeX distributions, like `MiKTeX <https://miktex. org/ >`_, `TeX Live
69
- <https://www.tug. org/texlive /> `_, `MacTeX <http://www.tug.org/mactex/ >`_ or others.
69
+ popular LaTeX distributions, like `TeX Live <https://www.tug. org/texlive/ >`_, `MiKTeX
70
+ <https://miktex. org/> `_, `MacTeX <http://www.tug.org/mactex/ >`_ or others.
70
71
71
72
72
73
Usage
73
74
-----
74
75
75
- Here is an example where you want to compile `` document.tex `` to a PDF .
76
+ Compiling your PDF can be as simple as writing the following task .
76
77
77
78
.. code-block :: python
78
79
@@ -85,9 +86,9 @@ Here is an example where you want to compile ``document.tex`` to a PDF.
85
86
def task_compile_latex_document ():
86
87
pass
87
88
88
- When the task is executed, you find a `` document.pdf `` in the same folder as your
89
- ``document.tex ``, but you could also compile the report into a another folder by
90
- changing the path in `` produces `` .
89
+ Use `` @pytask.mark.latex `` to indicate that this task compiles a LaTeX document.
90
+ ``@pytask.mark.depends_on `` points to the source file which is compiled and
91
+ `` @pytask.mark.produces `` is the path of the compiled PDF .
91
92
92
93
93
94
Multiple dependencies and products
@@ -139,46 +140,82 @@ The same applies to the compiled document which is either in the first position,
139
140
the key ``"document" `` or ``0 ``.
140
141
141
142
142
- Command Line Arguments
143
- ~~~~~~~~~~~~~~~~~~~~~~
143
+ Customizing the compilation
144
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
144
145
145
- To customize the compilation, you can pass some command line arguments to ``latexmk ``
146
- via the ``@pytask.mark.latex `` marker. The default is the following.
146
+ pytask-latex uses latexmk by default to compile the document because it handles most
147
+ use-cases automatically. The following is equivalent to a bare ``@pytask.mark.latex ``
148
+ decorator.
147
149
148
150
.. code-block :: python
149
151
150
- @pytask.mark.latex ([ " --pdf " , " --interaction=nonstopmode " , " --synctex=1 " , " --cd " ] )
152
+ @pytask.mark.latex (compilation_steps = " latexmk " )
151
153
def task_compile_latex_document ():
152
- pass
154
+ ...
155
+
156
+ The ``@pytask.mark.latex `` decorator has a keyword argument called ``compilation_steps ``
157
+ which accepts which accepts strings or list of strings pointing to internally
158
+ implemented compilation steps. Using strings will use the default configuration of this
159
+ compilation step. It is equivalent to the following.
160
+
161
+ .. code-block ::
162
+
163
+ from pytask_latex import compilation_steps
164
+
165
+
166
+ @pytask.mark.latex(
167
+ compilation_steps=compilation_steps.latexmk(
168
+ options=("--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd")
169
+ )
170
+ )
171
+ def task_compile_latex_document():
172
+ ...
153
173
154
- For example, to compile your document with XeLaTeX, use
174
+ In this example, ``compilation_steps.latexmk `` is a compilation step constructor which
175
+ accepts a set of options and creates a compilation step function.
176
+
177
+ You can pass different options to change the compilation process with latexmk. Here is
178
+ an example for generating a ``.dvi ``.
155
179
156
180
.. code-block :: python
157
181
158
- @pytask.mark.latex ([" --xelatex" , " --interaction=nonstopmode" ])
182
+ @pytask.mark.latex (
183
+ compilation_steps = compilation_steps.latexmk(
184
+ options = (" --dvi" , " --interaction=nonstopmode" , " --synctex=1" , " --cd" )
185
+ )
186
+ )
159
187
def task_compile_latex_document ():
160
- pass
188
+ ...
161
189
162
- The options ``--jobname ``, ``--output-directory `` and the ``.tex `` file which will be
163
- compiled are automatically handled and inferred from the ``@pytask.mark.depends_on `` and
164
- ``@pytask.mark.produces `` markers.
190
+ ``compilation_step.latexmk(options) `` generates a compilation step which is a function
191
+ with the following signature:
165
192
166
- The `` @pytask.mark.latex `` accepts both, a string or a list of strings with options.
193
+ .. code-block ::
167
194
168
- For more options and their explanations, visit the ` latexmk manual
169
- <https://man.cx/latexmk> `_ or type the following commands.
195
+ from pathlib import Path
196
+ import subprocess
170
197
171
- .. code-block :: console
172
198
173
- $ latexmk -h
174
- $ latexmk -showextraoptions
199
+ def custom_compilation_step(path_to_tex: Path, path_to_document: Path) -> None:
200
+ ...
201
+ subproces.run(..., check=True)
202
+
203
+ You can also pass your custom compilation step with the same signature to the
204
+ ``compilation_steps `` keyword argument of the decorator.
205
+
206
+ Each compilation step receives the path to the LaTeX source file and the path to the
207
+ final document which it uses to call some program on the command line to run another
208
+ step in the compilation process.
209
+
210
+ In the future, pytask-latex will provide more compilation steps for compiling
211
+ bibliographies, glossaries and the like.
175
212
176
213
177
214
Parametrization
178
215
~~~~~~~~~~~~~~~
179
216
180
- You can also parametrize the compilation, meaning compiling multiple .tex documents
181
- as well as compiling a .tex document with different command line arguments.
217
+ You can also parametrize the compilation, meaning compiling multiple `` .tex `` documents
218
+ as well as compiling a `` .tex `` document with different command line arguments.
182
219
183
220
The following task compiles two latex documents.
184
221
@@ -195,7 +232,8 @@ The following task compiles two latex documents.
195
232
196
233
If you want to compile the same document with different command line options, you have
197
234
to include the latex decorator in the parametrization just like with
198
- ``@pytask.mark.depends_on `` and ``@pytask.mark.produces ``.
235
+ ``@pytask.mark.depends_on `` and ``@pytask.mark.produces ``. Pass a dictionary for
236
+ possible compilation steps and their options.
199
237
200
238
.. code-block :: python
201
239
@@ -205,11 +243,19 @@ to include the latex decorator in the parametrization just like with
205
243
[
206
244
(
207
245
" document.pdf" ,
208
- (" --pdf" , " --interaction=nonstopmode" , " --synctex=1" , " --cd" ),
246
+ {
247
+ " compilation_steps" : compilation_steps.latexmk(
248
+ (" --pdf" , " --interaction=nonstopmode" , " --synctex=1" , " --cd" )
249
+ )
250
+ },
209
251
),
210
252
(
211
253
" document.dvi" ,
212
- (" --dvi" , " --interaction=nonstopmode" , " --synctex=1" , " --cd" ),
254
+ {
255
+ " compilation_steps" : compilation_steps.latexmk(
256
+ (" --dvi" , " --interaction=nonstopmode" , " --synctex=1" , " --cd" )
257
+ )
258
+ },
213
259
),
214
260
],
215
261
)
0 commit comments