stepup.reprep.api¶
Application programming interface for StepUp RepRep.
add_notes_pdf(path_src, path_notes, path_dst, optional=False, block=False)
¶
Add a notes page at every even page of a PDF file.
Parameters:
-
path_src
(str
) –The original PDF document without notes pages.
-
path_notes
(str
) –A single-page PDF document with a page suitable for taking notes.
-
path_dst
(str
) –The output PDF with notes pages inserted.
-
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
cat_pdf(paths_inp, path_out, *, mutool=None, optional=False, block=False)
¶
Concatenate the pages of multiple PDFs into one document
Parameters:
-
paths_inp
(Collection[str]
) –The input PDF files.
-
path_out
(str
) –The concatenated PDF.
-
mutool
(str | None
, default:None
) –The path to the mutool executable. Defaults to
${REPREP_MUTOOL}
variable ormutool
if the variable is unset. -
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
check_hrefs(path_src, path_config=None, block=False)
¶
Check hyper references in a Markdown, HTML or PDF file.
Parameters:
-
path_src
(str
) –The source Markdown, HTML or PDF to check.
-
path_config
(str | None
, default:None
) –The configuration file. Defaults to
${REPREP_CHECK_HREFS_CONFIG}
variable orcheck_hrefs.yaml
if it is not set. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
convert_markdown(path_md, out=None, *, katex=False, path_macro=None, paths_css=None, optional=False, block=False)
¶
Convert a markdown to HTML.
Parameters:
-
path_md
(str
) –The markdown input file.
-
out
(str | None
, default:None
) –Output destination:
None
, a directory or a file. -
katex
(bool
, default:False
) –Set to
True
to enable KaTeX support. -
path_macro
(str | None
, default:None
) –A file with macro definitions for KaTeX. Defaults to
${REPREP_KATEX_MACROS}
if the variable is set. -
paths_css
(str | list[str] | None
, default:None
) –Path of a local CSS file, or a list of multiple such paths, to be included in the HTML header. Note that one may also specify CSS file in the markdown header. Defaults to
${REPREP_MARKDOWN_CSS}
if the variable is set, which is interpreted as a colon-separated list of files. -
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
convert_odf_pdf(path_odf, out=None, *, libreoffice=None, optional=False, block=False)
¶
Convert a file in OpenDocument format to PDF.
Parameters:
-
path_odf
(str
) –The input open-document file.
-
out
(str | None
, default:None
) –None, output directory or path. See
make_path_out
. -
libreoffice
(str | None
, default:None
) –The libreoffice executable. Defaults to
${REPREP_LIBREOFFICE}
variable orlibreoffice
if the variable is unset. -
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Notes
This function does not yet scan the source document for reference to external files. which should ideally be added as dependencies.
The conversion is executed in a pool of size 1, due to a bug in libreoffice. It cannot perform multiple PDF conversions in parallel.
Source code in stepup/reprep/api.py
convert_pdf(path_pdf, path_out, *, resolution=None, mutool=None, optional=False, block=False)
¶
Convert a PDF to a bitmap with mutool (from MuPDF).
Parameters:
-
path_pdf
(str
) –The input PDF file.
-
path_out
(str
) –The output image file.
-
resolution
(int | None
, default:None
) –The resolution of the output bitmap in dots per inch (dpi).
-
mutool
(str | None
, default:None
) –The path to the mutool executable. Defaults to
${REPREP_MUTOOL}
variable ormutool
if the variable is unset. -
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
convert_pdf_png(path_pdf, out=None, *, resolution=None, mutool=None, optional=False, block=False)
¶
Shorthand for convert_pdf
with the output file derived from the PDF file.
The out
argument can be None
, a directory or a file. See make_path_out
.
Source code in stepup/reprep/api.py
convert_svg(path_svg, path_out, *, inkscape=None, inkscape_args=None, optional=False, block=False)
¶
Convert an SVG figure to a PDF file, detecting dependencies of the SVG on other files.
Parameters:
-
path_svg
(str
) –The input SVG figure. It may contain tags referring to other files included in the figure.
-
path_out
(str
) –The output PDF or PNG file. Other formats are not supported.
-
inkscape
(str | None
, default:None
) –The path to the inkscape executable. Defaults to
${REPREP_INKSCAPE}
variable orinkscape
if the variable is unset. -
inkscape_args
(str | None
, default:None
) –Additional arguments to pass to inkscape. E.g.
-T
to convert text to glyphs in PDFs. Depending on the extension of the output, the default is${REPREP_INKSCAPE_PDF_ARGS}
or${REPREP_INKSCAPE_PNG_ARGS}
, if the environment variable is defined. -
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Notes
A wrapper around inkscape is used to carry out the conversion: stepup.reprep.convert_svg_pdf
.
The wrapper scans the SVG for dependencies, which may be a bit slow in case of large files.
Source code in stepup/reprep/api.py
convert_svg_pdf(path_svg, out=None, *, inkscape=None, inkscape_args=None, optional=False, block=False)
¶
Shorthand for convert_svg
with the output file derived from the SVG file.
The out
argument can be None
, a directory or a file.
Source code in stepup/reprep/api.py
convert_svg_png(path_svg, out=None, *, inkscape=None, inkscape_args=None, optional=False, block=False)
¶
Shorthand for convert_svg
with the output file derived from the SVG file.
The out
argument can be None
, a directory or a file. See make_path_out
.
Source code in stepup/reprep/api.py
convert_weasyprint(path_html, out=None, *, weasyprint=None, optional=False, block=False)
¶
Convert a HTML document to PDF.
Parameters:
-
path_html
(str
) –The HTML input file.
-
out
(str | None
, default:None
) –Output destination:
None
, a directory or a file. -
weasyprint
(str | None
, default:None
) –The path to the weasyprint executable. Defaults to
${REPREP_WEASYPRINT}
variable orweasyprint
if the variable is unset. -
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
latex(path_tex, *, run_bibtex=True, maxrep=5, workdir='./', latex=None, bibtex=None, bibsane=None, bibsane_config=None, optional=False, block=False)
¶
Create a step for the compilation of a LaTeX source.
Parameters:
-
path_tex
(str
) –The main tex source file. This argument may contain environment variables.
-
run_bibtex
–By default, when bib files are used, BibTeX is invoked. This can be overruled by setting this argument to False, which is useful when recompiling sources with fixed bbl files.
-
maxrep
(int
, default:5
) –The maximum number of repetitions of the LaTeX command in case the aux file keeps changing.
-
workdir
(str
, default:'./'
) –The working directory where the LaTeX command must be executed.
-
latex
(str | None
, default:None
) –Path to the LaTeX executable. Note that only PDF-producing LaTeX compilers are supported:
pdflatex
,xelatex
orlualatex
. Defaults to${REPREP_LATEX}
variable orpdflatex
if the variable is unset. -
bibtex
(str | None
, default:None
) –Path to the BibTeX executable. Defaults to
${REPREP_BIBTEX}
variable orbibtex
if the variable is unset. -
bibsane
(str | None
, default:None
) –Path to the BibSane executable. Defaults to
${REPREP_BIBSANE}
variable orbibsane
if the variable is unset. -
bibsane_config
(str | None
, default:None
) –Path to the BibSane configuration file. Defaults to
${REPREP_BIBSANE_CONFIG}
variable orbibsane.yaml
if it is unset. Note that when the config file is read from the environment variable, it is interpreted relative to${STEPUP_ROOT}
. One may define it globally withexport REPREP_BIBSANE_CONFIG='${HERE}/bibsane.yaml'
to refer to a local version of the file. (Mind the single quotes.) -
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
|
latex_diff(path_old, path_new, path_diff, *, latexdiff=None, latexdiff_args=DEFAULT_LATEXDIFF_ARGS, optional=False, block=False)
¶
Create a step to run latexdiff.
Parameters:
-
path_old
(str
) –The old tex or bbl source.
-
path_new
(str
) –The new tex or bbl source.
-
path_diff
(str
) –The diff output tex or bbl.
-
latexdiff
(str | None
, default:None
) –Path of the latexdiff executable. Defaults to
${REPREP_LATEXDIFF}
variable orlatexdiff
if the variable is unset. -
latexdiff_args
(str | None
, default:DEFAULT_LATEXDIFF_ARGS
) –Additional arguments for latexdiff. Defaults to
${REPREP_LATEXDIFF_ARG}
variable. If this variable is unset, the following default is used:--append-context2cmd=abstract,supplementary,dataavailability,funding, \ authorcontributions,conflictsofinterest,abbreviations
The option
--no-label
is always added because it is needed to make the file reproducible. -
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
latex_flat(path_tex, path_flat, *, optional=False, block=False)
¶
Flatten structured LaTeX source files (substitute \input
and friends by their content).
Parameters:
-
path_tex
(str
) –The main tex file to be converted.
-
path_flat
(str
) –The flattened output file.
-
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
make_inventory(paths, path_inventory, *, optional=False, block=False)
¶
Create an inventory.txt
file.
Parameters:
-
paths
(Collection[str]
) –Paths to include in the
inventory.txt
file. -
path_inventory
(str
) –The inventory file to write.
-
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
nup_pdf(path_src, path_dst, *, nrow=None, ncol=None, margin=None, page_format=None, optional=False, block=False)
¶
Put multiple pages per sheet using a fixed layout.
Parameters:
-
path_src
(str
) –The original PDF document (with normal pages).
-
path_dst
(str
) –The output PDF with (multiple pages per sheet).
-
nrow
(int | None
, default:None
) –The number of rows on each output sheet. The default is
${REPREP_NUP_NROW}
or 2 if the variable is not set. -
ncol
(int | None
, default:None
) –The number of columns on each output sheet. The default is
${REPREP_NUP_NCOL}
or 2 if the variable is not set. -
margin
(float | None
, default:None
) –The margin in mm between the pages on each sheet. (Also used as sheet margin.) The default is
${REPREP_NUP_MARGIN}
or 10.0 if the variable is not set. -
page_format
(str | None
, default:None
) –The output page format The default is
${REPREP_NUP_PAGE_FORMAT}
or A4-L if the variable is not set. -
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
raster_pdf(path_inp, out, *, resolution=None, quality=None, optional=False, block=False)
¶
Turn each page of a PDF into a rendered JPEG bitmap contained in a new PDF.
Parameters:
-
path_inp
(str
) –The input PDF file.
-
out
(str
) –None, output directory or path. See
make_path_out
. -
resolution
(int | None
, default:None
) –The resolution of the bitmap in dots per inch (pdi). The default value is taken from
${REPREP_RASTER_RESOLUTION}
or 100 if the variable is not set. -
quality
(int | None
, default:None
) –The JPEG quality of the bitmap. The default value is taken from
${REPREP_RASTER_QUALITY}
or 50 if the variable is not set. -
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
render(path_template, paths_variables, out, *, mode='auto', optional=False, block=False)
¶
Render the template with Jinja2.
Parameters:
-
path_template
(str
) –The source file to use as a template.
-
paths_variables
(list[str]
) –A list of Python files with variable definitions, at least one.
-
out
(str
) –An output directory or file.
-
mode
(str
, default:'auto'
) –The format of the Jinja placeholders. The default (auto) selects either plain or latex based on the extension of the template. The plain format is the default Jinja style with curly brackets: {{ }} etc. The latex style replaces curly brackets by angle brackets: << >> etc.
-
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
sync_zenodo(path_config, *, block=False)
¶
Synchronize data with an draft dataset on Zenodo.
Parameters:
-
path_config
(str
) –The YAML configuration file for the Zenodo upload.
-
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
unplot(path_svg, out=None, *, optional=False, block=False)
¶
Convert a plot back to data.
Parameters:
-
path_svg
(str
) –The SVG file with paths to be converted back.
-
out
(str | None
, default:None
) –An output directory or file.
-
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/reprep/api.py
zip_inventory(path_inventory, path_zip, *, optional=False, block=False)
¶
Create a ZIP file with all files listed in a inventory.txt
file + check digests before zip.
Parameters:
-
path_inventory
(str
) –A file created with the
make_inventory
API or with the command-line scriptreprep-make-inventory
. -
path_zip
(str
) –The output ZIP file
-
optional
(bool
, default:False
) –When
True
, the step is only executed when needed by other steps. -
block
(bool
, default:False
) –When
True
, the step will always remain pending.
Returns:
-
step_info
–Holds relevant information of the step, useful for defining follow-up steps.