@@ -37,8 +37,8 @@ pytask-latex
37
37
pytask-latex allows you to compile LaTeX documents.
38
38
39
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.
40
+ bibliography files and other `` .tex `` files automatically to compile LaTeX documents
41
+ when it is possible.
42
42
43
43
44
44
Installation
@@ -72,7 +72,7 @@ popular LaTeX distributions, like `MiKTeX <https://miktex.org/>`_, `TeX Live
72
72
Usage
73
73
-----
74
74
75
- Here is an example where you want to compile `` document.tex `` to a PDF .
75
+ Compiling your PDF can be as simple as writing the following task .
76
76
77
77
.. code-block :: python
78
78
@@ -85,9 +85,9 @@ Here is an example where you want to compile ``document.tex`` to a PDF.
85
85
def task_compile_latex_document ():
86
86
pass
87
87
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 `` .
88
+ Use `` @pytask.mark.latex `` to indicate that this task compiles a LaTeX document.
89
+ ``@pytask.mark.depends_on `` points to the source file which is compiled and
90
+ `` @pytask.mark.produces `` is the path of the compiled PDF .
91
91
92
92
93
93
Multiple dependencies and products
@@ -139,39 +139,72 @@ The same applies to the compiled document which is either in the first position,
139
139
the key ``"document" `` or ``0 ``.
140
140
141
141
142
- Command Line Arguments
143
- ~~~~~~~~~~~~~~~~~~~~~~
142
+ Customizing the compilation
143
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
144
144
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.
145
+ pytask-latex uses latexmk by default to compile the document because it handles most
146
+ use-cases automatically. The following is equivalent to a bare ``@pytask.mark.latex ``
147
+ decorator.
147
148
148
149
.. code-block :: python
149
150
150
- @pytask.mark.latex ([ " --pdf " , " --interaction=nonstopmode " , " --synctex=1 " , " --cd " ] )
151
+ @pytask.mark.latex (build_steps = " latexmk " )
151
152
def task_compile_latex_document ():
152
- pass
153
+ ...
154
+
155
+ The ``@pytask.mark.latex `` decorator has a keyword argument called ``build_steps `` which
156
+ accepts which accepts strings or list of strings pointing to internally implemented
157
+ build steps. Using strings will use the default configuration of this build step. It is
158
+ equivalent to the following.
159
+
160
+ .. code-block ::
161
+
162
+ from pytask_latex import build_steps
163
+
164
+
165
+ @pytask.mark.latex(
166
+ build_steps=build_steps.latexmk(
167
+ options=("--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd")
168
+ )
169
+ )
170
+ def task_compile_latex_document():
171
+ ...
172
+
173
+ In this example, ``build_steps.latexmk `` is a build step constructor which accepts a set
174
+ of options and creates a build step function out of it.
153
175
154
- For example, to compile your document with XeLaTeX, use
176
+ You can pass different options to change the compilation process with latexmk. Here is
177
+ an example for generating a ``.dvi ``.
155
178
156
179
.. code-block :: python
157
180
158
- @pytask.mark.latex ([" --xelatex" , " --interaction=nonstopmode" ])
181
+ @pytask.mark.latex (
182
+ build_steps = build_steps.latexmk(
183
+ options = (" --dvi" , " --interaction=nonstopmode" , " --synctex=1" , " --cd" )
184
+ )
185
+ )
159
186
def task_compile_latex_document ():
160
- pass
187
+ ...
161
188
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.
189
+ ``build_step.latexmk(options) `` generates a build step which is a function with the
190
+ following signature:
165
191
166
- The `` @pytask.mark.latex `` accepts both, a string or a list of strings with options.
192
+ .. code-block ::
167
193
168
- For more options and their explanations, visit the ` latexmk manual
169
- <https://man.cx/latexmk> `_ or type the following commands.
194
+ from pathlib import Path
195
+ import subprocess
170
196
171
- .. code-block :: console
172
197
173
- $ latexmk -h
174
- $ latexmk -showextraoptions
198
+ def custom_build_step(path_to_tex: Path, path_to_document: Path) -> None:
199
+ ...
200
+ subproces.run(..., check=True)
201
+
202
+ Each build step receives the path to the LaTeX source file and the path to the final
203
+ document which it uses to call some program on the command line to run another step in
204
+ the compilation process.
205
+
206
+ In the future, pytask-latex will provide more build steps for compiling bibliographies,
207
+ glossaries and the like.
175
208
176
209
177
210
Parametrization
@@ -195,7 +228,8 @@ The following task compiles two latex documents.
195
228
196
229
If you want to compile the same document with different command line options, you have
197
230
to include the latex decorator in the parametrization just like with
198
- ``@pytask.mark.depends_on `` and ``@pytask.mark.produces ``.
231
+ ``@pytask.mark.depends_on `` and ``@pytask.mark.produces ``. Pass a dictionary for
232
+ possible build steps and their options.
199
233
200
234
.. code-block :: python
201
235
@@ -205,11 +239,19 @@ to include the latex decorator in the parametrization just like with
205
239
[
206
240
(
207
241
" document.pdf" ,
208
- (" --pdf" , " --interaction=nonstopmode" , " --synctex=1" , " --cd" ),
242
+ {
243
+ " build_steps" : build_steps.latexmk(
244
+ (" --pdf" , " --interaction=nonstopmode" , " --synctex=1" , " --cd" )
245
+ )
246
+ },
209
247
),
210
248
(
211
249
" document.dvi" ,
212
- (" --dvi" , " --interaction=nonstopmode" , " --synctex=1" , " --cd" ),
250
+ {
251
+ " build_steps" : build_steps.latexmk(
252
+ (" --dvi" , " --interaction=nonstopmode" , " --synctex=1" , " --cd" )
253
+ )
254
+ },
213
255
),
214
256
],
215
257
)
0 commit comments