Skip to main content

Tools for writing latex papers

Project description

preprint

[!CAUTION] Python 3 Only: This project is now exclusively compatible with Python 3.10+. Python 2.x is no longer supported.

[!NOTE] Community Fork - This is a fork of the original jonathansick/preprint package, which appears to have been discontinued in 2015. Thank you jonathansick for the original work!

Tools for preparing scientific manuscripts in LaTeX.

Preprint lets you automatically compile, typeset document differences, and package the manuscript for publication.

Installation

Preprint requires:

Preprint also works well with:

  • latexmk for compiling LaTeX.
  • vc for adding version control metadata to compiled documents.

To install from PyPI:

pip install preprint

To install from source:

First, clone the repository:

git clone https://github.com/dotTHzTAG/preprint.git
cd preprint

Then, create a virtual environment and install it in editable mode:

python3 -m venv venv
source venv/bin/activate
pip install -e .

After installing, try preprint --help for more info.

Preprint currently supports the following commands (see below for a reference):

  • preprint make: Performs a one-off compilation of the paper.
  • preprint watch: Automatically compiles the paper if the source is changed.
  • preprint diff: Runs latexdiff against a commit in Git.
  • preprint pack: Packages the document for journals or the arXiv.
  • preprint init: Sets up your project with preprint.json configurations.

Check the GitHub Issues <https://github.com/dotTHzTAG/preprint/issues> to submit additional ideas.

A taste of preprint

Preprint is pretty easy to use. Here are a few commands to give a flavour of what it can do:

preprint init  # this is all the setup you need
preprint make  # compiles the doc according to your compile command
preprint watch --diff 8a42f2b  # live-updating latex diff against git history
preprint pack my_paper --style arxiv  # pack it up for arXiv submission

Configuration System / preprint.json

preprint configurations are determined from (in order of increasing precedence): internal defaults, a project-specific JSON file, and command line arguments.

To create a preprint.json configuration file for your project, from your paper's directory, simply run:

preprint init

It will automatically find the root LaTeX file for your paper. You can open preprint.json to review its format and further modify the configurations. Here is an example of its format:

{
    "cmd": "latexmk -f -pdf -bibtex-cond {master}",
    "exts": [
        "tex",
        "pdf",
        "eps",
        "png"
    ],
    "master": "article.tex"
}

If set in preprint.json, any command-line setting of the same name does not need to be repeated.

List of Configurations

master

  • (type: string) Name of the LaTeX document to be compiled (or the root LaTeX document containing \documentclass).
  • Defaults to 'article.tex', but preprint init will set this for you.

exts

  • (type: list of strings) List of file extensions used by the watch command.
  • If any file with this extension is changed in the project, preprint watchwill trigger a compile.
  • This setting is also used by preprint pack to figure out your preferences for figure file types.
  • For example, ["tex", "pdf", "eps", "png"] will try to include pdf figures before falling back to eps files, while ["tex", "eps", "pdf", "png"] will have the opposite behaviour.
  • Defaults to ["tex", "pdf", "eps", "png"].

cmd

  • (type: string) The command to run when making a document.
  • This is used by preprint make and preprint watch (preprint diff and preprint watch --diff will always use latexmk).
  • The command string can include {master} to interpolate the path of the master tex file. Defaults to "latexmk -f -pdf -bibtex-cond {master}".

Command Reference

init

preprint init will create a default preprint.json configuration file for your project.

Usage:

preprint init

After running, open preprint.json to edit the configuration. See 'Configuration System / preprint.json' (above) for more information.

make

preprint make will perform a one-off compilation of your paper.

Usage:

preprint [--master MASTER] make [--cmd CMD]

Optional arguments:

  • --master Name of the root LaTeX file (e.g., paper.tex)
  • --cmd Name of command to run for compilation

If preprint.json is set up, you can just run:

preprint make

[!TIP] If latexmk reports "Nothing to do" or you encounter unexpected compilation issues, try running latexmk -C in your manuscript directory before preprint make. This thoroughly cleans all temporary LaTeX files and often resolves stubborn compilation problems.

watch

preprint watch will automatically compile your paper if a TeX or graphics source file is changed.

Usage:

preprint [--master MASTER] watch [--exts EXT1, ..., EXTN; --cmd CMD; --diff [SHA]]

Optional arguments:

  • --master Name of the root LaTeX file (e.g., paper.tex)
  • --exts List of file extensions (defaults to pdf eps tex)
  • --cmd Name of command to run when a change occurs
  • --diff Run a latexdiff compile against the given commit SHA from the git repository (HEAD if blank).

For example, to continuously compile the document whenever .tex or figures have changed, and assuming you've setup a preprint.json file with the name of your master document, just run:

preprint watch

To continuously run a latexdiff-based compile, showing all changes you've made against the HEAD of the git repository, run:

preprint watch --diff

The document will be saved to build/PAPER_NAME_diff.pdf. This is a nice way of keeping track of what you're doing.

Finally, to continuously run a latexdiff-based compile against an arbitrary commit in your git history, just copy the commit SHA fragment (say, b91688d) and run:

preprint watch --diff b91688d

diff

preprint diff will typeset the document with revisions highlighted between the currently checked-out version and a previous git commit.

  • This command is powered by the latexdiff <http://latexdiff.berlios.de> (which is probably installed with your TeX distribution).
  • The command also requires latexmk <http://users.phys.psu.edu/~collins/software/latexmk-jcc/> to compile the difference document.
  • This command is compatible with documents that use \input{} to combine text documents; in fact, included documents are inlined recursively.
  • preprint diff was inspired by this blog post <http://astrowizici.st/blog/2013/10/04/publishing-with-git/> by Andy Casey.

Usage:

preprint [--master MASTER] diff PREV_SHA [-n NAME]

Arguments:

  • PREV_SHA A SHA fragment or tag name pointing to the previous revision.

Optional arguments:

  • --master Name of the root LaTeX file (e.g., paper.tex)
  • -n Output name of the difference document (e.g., diff.tex)

pack

preprint pack prepares a preprint for submission to a journal. This pipeline includes:

  1. Creating a build directory and copying over just the required manuscript files.
  2. Inlining all input LaTeX files (either with \input{} or \InputIfFileExists syntax).
  3. Copying the .bbl bibliography or inlining it into the manuscript, as necessary.
  4. Moving figures to the root directory and updating the tex source.
  5. Deleting comments; don't be a tweet on @OverheardOnAph.
  6. Renaming figures to conform to AASTeX if necessary.
  7. Making JPEG versions of figures to fulfil arXiv file size requirements, if necessary. This requires imagemagick <http://www.imagemagick.org/script/index.php>.

This command is inspired by Erik Tollerud's Astropysics package <http://pythonhosted.org/Astropysics/coremods/publication.html>, but is designed around regular expressions for text transformation. The implementation should thus be easier.

Usage:

preprint [--master MASTER] pack NAME [--style STYLE; --exts EXT1, ..., EXTN]

Arguments:

  • NAME Name of the build. Products copied to build/NAME directory.

Optional arguments:

  • --master Name of the root LaTeX file (e.g., paper.tex)
  • --exts File format priority for figures (e.g., eps, pdf)
  • --style Style for the build (default is aastex, can also be arxiv).
  • --maxsize Maximum size of figure in MB before compressing into jpg (for arxiv). Default is 2.5 MB.

Note that the --exts option can be used to prefer a certain file format for the build if you maintain both EPS and PDF figure sets. For example, to generate a manuscript for a AAS journal, run:

preprint pack my_aas_build --style aastex --exts eps

And to build for the arxiv, where PDF figures are preferred, run:

preprint pack my_arxiv_build --style arxiv --exts pdf

About

Original author:

Preprint was originally developed on GitHub https://github.com/jonathansick/preprint.

Contributions and suggestions are welcome. Read the CONTRIBUTING guidelines for instructions on how to help.

Copyright 2014 Jonathan Sick, @jonathansick

Current Fork

This is a community fork to ensure the original package continues to work with Python 3. Any contributions are absolutely welcome.

Licensed BSD.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

preprint3-0.3.1.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

preprint3-0.3.1-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file preprint3-0.3.1.tar.gz.

File metadata

  • Download URL: preprint3-0.3.1.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for preprint3-0.3.1.tar.gz
Algorithm Hash digest
SHA256 541dbf7ef9d2b1adbefceaeb49fdb78c0fcda771bee3a3cfb6a5b598a2290d35
MD5 8b2fc0c2f0606f0bc9f0193a8e3e737b
BLAKE2b-256 20e62213db54d65f63e6549542c011e1c2f289377cce36920f17eea5f91f9352

See more details on using hashes here.

File details

Details for the file preprint3-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: preprint3-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for preprint3-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 03b0e4b778a5c7428cf37ce7e29a2d2768e65a2a97d5e7fc7a8503111feeda4b
MD5 f931f87cff8fd6c37e7740201847121b
BLAKE2b-256 b7c5422f1153f1018e44d8497967d8ca19a77ea29652897f812d053d7bb94a83

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page