Skip to content

Commit 1008772

Browse files
committed
Update readme.
1 parent 3eb10a1 commit 1008772

File tree

1 file changed

+69
-27
lines changed

1 file changed

+69
-27
lines changed

README.rst

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ pytask-latex
3737
pytask-latex allows you to compile LaTeX documents.
3838

3939
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.
4242

4343

4444
Installation
@@ -72,7 +72,7 @@ popular LaTeX distributions, like `MiKTeX <https://miktex.org/>`_, `TeX Live
7272
Usage
7373
-----
7474

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.
7676

7777
.. code-block:: python
7878
@@ -85,9 +85,9 @@ Here is an example where you want to compile ``document.tex`` to a PDF.
8585
def task_compile_latex_document():
8686
pass
8787
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.
9191

9292

9393
Multiple dependencies and products
@@ -139,39 +139,72 @@ The same applies to the compiled document which is either in the first position,
139139
the key ``"document"`` or ``0``.
140140

141141

142-
Command Line Arguments
143-
~~~~~~~~~~~~~~~~~~~~~~
142+
Customizing the compilation
143+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
144144

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.
147148

148149
.. code-block:: python
149150
150-
@pytask.mark.latex(["--pdf", "--interaction=nonstopmode", "--synctex=1", "--cd"])
151+
@pytask.mark.latex(build_steps="latexmk")
151152
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.
153175

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``.
155178

156179
.. code-block:: python
157180
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+
)
159186
def task_compile_latex_document():
160-
pass
187+
...
161188
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:
165191

166-
The ``@pytask.mark.latex`` accepts both, a string or a list of strings with options.
192+
.. code-block::
167193
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
170196
171-
.. code-block:: console
172197
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.
175208

176209

177210
Parametrization
@@ -195,7 +228,8 @@ The following task compiles two latex documents.
195228
196229
If you want to compile the same document with different command line options, you have
197230
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.
199233

200234
.. code-block:: python
201235
@@ -205,11 +239,19 @@ to include the latex decorator in the parametrization just like with
205239
[
206240
(
207241
"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+
},
209247
),
210248
(
211249
"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+
},
213255
),
214256
],
215257
)

0 commit comments

Comments
 (0)