Skip to main content

A Python library to generate publication-ready documents with LaTeX.

Project description

CircleCI Documentation Status License PyPI

latexdocs - A document generation solution for LaTeX

latexdocs is a Python library with the goal of making the generation of LaTeX documents as easy as possible. It builds on PyLaTeX, but offers a different approach to structuring your document or writing custom extensions.

Documentation

Click here to read the documentation.

Installation

This is optional, but we suggest you to create a dedicated virtual enviroment at all times to avoid conflicts with your other projects. Create a folder, open a command shell in that folder and use the following command

>>> python -m venv venv_name

Once the enviroment is created, activate it via typing

>>> .\venv_name\Scripts\activate

latexdocs can be installed (either in a virtual enviroment or globally) from PyPI using pip on Python >= 3.7:

>>> pip install latexdocs

Installing latex on different operating systems is well described here.

Basic Example

The equivalent of the example provided by the folks at PyLaTeX would be the following:

from latexdocs import Document, TikZFigure, Image
from pylatex import Alignat, Matrix, Math, Tabular, Plot
from pylatex.utils import italic
import numpy as np

image_filename = 'image.png'

doc = Document()

doc['Some basic content'].append('Some regular text and some')
doc['Some basic content'].append(italic('italic text. '))
doc['Some basic content'].append('\nAlso some crazy characters: $&#{}')
doc['Some basic content', 'Math that is incorrect'].append((Math(data=['2*3', '=', 9])))

a = np.array([[100, 10, 20]]).T
M = np.matrix([[2, 3, 4],
                [0, 0, 1],
                [0, 0, 2]])

content = Math(data=[Matrix(M), Matrix(a), '=', Matrix(M * a)])
doc['Another section', 'Correct matrix equations'].append(content)

table = Tabular('rc|cl')
table.add_hline()
table.add_row((1, 2, 3, 4))
table.add_hline(1, 2)
table.add_empty_row()
table.add_row((4, 5, 6, 7))
doc['Some basic content', 'Table of something'].append(table)

agn = Alignat(numbering=False, escape=False)
agn.append(r'\frac{a}{b} &= 0 \\')
agn.extend([Matrix(M), Matrix(a), '&=', Matrix(M * a)])
doc['Another section', 'Alignat math environment'].append(agn)

fig = TikZFigure(plot_options='height=4cm, width=6cm, grid=major')
fig.append(Plot(name='model', func='-x^5 - 242'))
coordinates = [
    (-4.77778, 2027.60977),
    (-3.55556, 347.84069),
    (-2.33333, 22.58953),
    (-1.11111, -493.50066),
    (0.11111, 46.66082),
    (1.33333, -205.56286),
    (2.55556, -341.40638),
    (3.77778, -1169.24780),
    (5.00000, -3269.56775),
]
fig.append(Plot(name='estimate', coordinates=coordinates))
doc['Another section']['Beautiful graphs'].append(fig)

img = Image(filename=image_filename, position='h!', 
            caption='A simple structure.', width='350px')
doc['Another section']['An image'].append(img)

# doc.build() returns a pylatex.Document instance
doc.build().generate_pdf('basic_example', compiler='pdflatex')

Contributing

Since latexdocs builds on PyLaTeX, we suggest you to contribute to that package and enjoy the result here.

Testing

To run all tests, open up a console in the root directory of the project and type the following (requires the unittest library to be installed)

>>> python -m unittest

License

Copyright 2022 Bence Balogh, under the MIT license.

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

latexdocs-0.0.2.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

latexdocs-0.0.2-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file latexdocs-0.0.2.tar.gz.

File metadata

  • Download URL: latexdocs-0.0.2.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for latexdocs-0.0.2.tar.gz
Algorithm Hash digest
SHA256 76022799976551c4b0dfca0f15bac354502fda6e5712c99683c281a226057edb
MD5 32f2ccebee967aaf2c945728ffef0084
BLAKE2b-256 21107ad4f01d75735538f15fb03397e3980773e027f9112786ba3276f7c55a57

See more details on using hashes here.

File details

Details for the file latexdocs-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: latexdocs-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for latexdocs-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 08986704baee75fe886c2fde344b6220944c0b7f9115db71eb8520493a017a47
MD5 dd4d180b98d72c51d27e59cfdd25ad48
BLAKE2b-256 98f716c769a3631322f9a81187866e70966d349d135272b909eda80ba24d0697

See more details on using hashes here.

Supported by

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