GithubHelp home page GithubHelp logo

jeltef / pylatex Goto Github PK

View Code? Open in Web Editor NEW
2.2K 69.0 288.0 5.91 MB

A Python library for creating LaTeX files

Home Page: https://jeltef.github.io/PyLaTeX/

License: MIT License

Shell 1.54% Python 98.46%

pylatex's Introduction

PyLaTeX Actions License PyPi Stable Docs Latest Docs

PyLaTeX is a Python library for creating and compiling LaTeX files or snippets. The goal of this library is being an easy, but extensible interface between Python and LaTeX.

Installation

Simply install using pip:

pip install pylatex

And then install a relevant LaTeX processor and other dependencies. Examples:

Ubuntu

sudo apt-get install texlive-pictures texlive-science texlive-latex-extra latexmk

Documentation

There are two versions of the documentation:

Contributing

Read the How to contribute page for tips and rules when you want to contribute.

Examples

The documentation contains a lot of examples that show the functionality. To give an impression of what can be generated see this picture:

Copyright 2014 Jelte Fennema, under the MIT license

pylatex's People

Contributors

beckmar avatar bjodah avatar brunosmmm avatar clarksmr avatar dgrigonis avatar fariza avatar freol35241 avatar georgesoateslarsen avatar haikalzain avatar hassenpy avatar ixjlyons avatar janpf avatar jarrahgos avatar jbzdak avatar jeltef avatar johnerlandsson avatar joshfinley avatar marcoforte avatar mcepl avatar mcnnowak avatar msf235 avatar neilo40 avatar rfilmyer avatar rutsky avatar s-wallace avatar sebastianhaas avatar vayel avatar vikpe avatar votti avatar vovchikthebest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pylatex's Issues

Fix_filename

What should fix_filename("abc.def.fgh.ijk") return?

jobname cannot read paths

pdflatex --jobname="/home/eleve/vincent.lefoulon/Documents/MPF/data/prod/filename" "/home/eleve/vincent.lefoulon/Documents/MPF/data/prod/filename.tex" does not work whereas pdflatex --jobname="filename" "/home/eleve/vincent.lefoulon/Documents/MPF/data/prod/filename.tex" does. But the second command saves the file in the working directory.

pdflatex --output-directory ~/Documents/MPF/data/prod "/home/eleve/vincent.lefoulon/Documents/MPF/data/prod/filename.tex" would do the job and save the file as ~/Documents/MPF/data/prod/filename.pdf

Add a Command object

Proposed in #2.
Syntax like this:

Command('includegraphics', option='scale=0.5', argument='chick.png')

Maybe also an options or arguments option, so it can make commands with multiple arguments or options.

Specifying where the PDF should reside

How do I specify where the generated PDF file should reside? Adding an argument to the constructor only seems to control where the temporary Latex files get put -- I'd like to specify (also) where the actual PDF files is written.

"-", "--" and "---" are not escaped

In LaTeX -, -- and --- are commands for hyphen, en-dash and em-dash correspondingly.
Currently these characters are not escaped.

If you think that such behavior is a feature, I think it should be documented.

rm_tmp called even if clean=False in generate_pdf

rm_tmp is called even if Document.generate_pdf is called with clean=False
Is this normal? if so, how do we compile several times to update cross references?

The problem are the graphics that are removed for the second call

What needs to be done for the next release?

Clearly a lot has been done since v0.8.0, and the current package/documentation is a lot different from what it was a few months ago.

What needs to be done before the next release can be pushed out?

pip install

Hello,
Thanks to have merged the pull request 3 days ago.
Could you also push this master version on pip?
pip show display version 0.5 of PyLateX I don't know if this one is the current or not :)
Thanks in advance !

setting the documentclass

Hi,

Is it possible to set the documentclass? For instance, I want to use the Springer layout. In LaTeX I would write this:

\documentclass[runningheads]{llncs}

Where there is an llncs.cls style file.

But there are lots of different style, e.g. the IEEE format.

Thanks,

Laszlo

Question

Hello,
I read your introduction/presentation and you're saying:
"Everything else you want you can still add to the document by adding LaTeX formatted strings to the container class you want it to be in."
Could you provide an example ?

I would like to add a Tittle page at the very beggining of a document created with PyLaTeX.
Is it possible to add directly "raw" latex command such as \newpage or a group of these kind of lines with PyLaTeX ?
Thank you in advance! :)

Tikz integration

This is an excellent project. I am currently generating latex using Python scripts for my work already.

Can I suggest that instead of generating tikz, we improve matplotlib so that it can generate comparable quality images with similar ease? I am working on it here: https://github.com/MisterSheik/matplotlib

Best,

Neil

Container.propegate_packages() is spelled wrong

It's minor, since it seems like the function is only intended for internal use and the misspelling is consistent, but I imagine it might lead to problems with collaboration down the line.

The spelling should be "propagate".

excape_latex does not repleace Nonbreaking spaces.

If a string contained the unicode character "x0A" ie the nonbreaking space,
Then this is passed through the to the output document.

It should be replaces with a ~ which is the latex character for the same

My work around is:
string.replace("\xA0", "~").

Running (certain) latex compilers on the output will result in:
"Package inputenc Error: Keyboard character used is undefined(inputenc) in inputencoding `utf8'. ...s who act together to save the planet."

TypeError: __init__() got an unexpected keyword argument 'argument', in "pylatex/numpy.py", line 20

Hi!

When using the VectorName class, I got that error:

Traceback (most recent call last):
  File "latex.py", line 56, in <module>
    latex.save("./test")
  File "latex.py", line 35, in save
    self.draw()
  File "latex.py", line 28, in draw
    k, v = self.parse(k, v)
  File "latex.py", line 20, in parse
    return VectorName("wsd"), Matrix(v)
  File "/home/vincent/.local/share/virtualenvs/mpf/lib/python3.4/site-packages/pylatex/numpy.py", line 20, in __init__
    super().__init__('mathbf', argument=name)
TypeError: __init__() got an unexpected keyword argument 'argument'

Yet, the code on GitHub is correct. Is the version on Pypi up-to-date?

Thanks!

Fix all the TODO's

I have written a couple of TODO's in the comments and those need to be fixed.

Add unit tests

Hi!

I wonder whether it would be interesting to implement unit tests like that:

doc = Document()

# ...

tex = """
...
"""

assert doc.dumps() == tex

Thanks!

README example fails (l.9 \pgfplotsset{compat=newest})

When running the example from the README:

import numpy as np

from pylatex import Document, Section, Subsection, Table, Math, TikZ, Axis, \
    Plot, Figure, Package
from pylatex.numpy import Matrix
from pylatex.utils import italic, escape_latex

doc = Document()
doc.packages.append(Package('geometry', options=['tmargin=1cm',
                                                 'lmargin=10cm']))

with doc.create(Section('The simple stuff')):
    doc.append('Some regular text and some ' + italic('italic text. '))
    doc.append(escape_latex('\nAlso some crazy characters: $&#{}'))
    with doc.create(Subsection('Math that is incorrect')) as math:
        doc.append(Math(data=['2*3', '=', 9]))

    with doc.create(Subsection('Table of something')):
        with doc.create(Table('rc|cl')) as table:
            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))

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

with doc.create(Section('The fancy stuff')):
    with doc.create(Subsection('Correct matrix equations')):
        doc.append(Math(data=[Matrix(M), Matrix(a), '=', Matrix(M*a)]))

    with doc.create(Subsection('Beautiful graphs')):
        with doc.create(TikZ()):
            plot_options = 'height=6cm, width=6cm, grid=major'
            with doc.create(Axis(options=plot_options)) as plot:
                plot.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),
                ]

                plot.append(Plot(name='estimate', coordinates=coordinates))

    with doc.create(Subsection('Cute kitten pictures')):
        with doc.create(Figure(position='h!')) as kitten_pic:
            kitten_pic.add_image('docs/static/kitten.jpg', width='120px')
            kitten_pic.add_caption('Look it\'s on its back')

doc.generate_pdf()

my LaTeX fails with the following message:

! Package pgfkeys Error: I do not know the key '/pgfplots/compat' and I am goin
g to ignore it. Perhaps you misspelled it.

See the pgfkeys package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.9 \pgfplotsset{compat=newest}

followed by

CalledProcessError: Command 'pdflatex --jobname="default_filename" "default_filename.tex"' returned non-zero exit status 1

Is it some missing package? I am running on Ubuntu 12.04, equipped with texlive-full.

Add documentation

Currently the only documentation are the examples. This should be changed.

Create simpler subclassable version of command

A version of command that can be subclassed and that latex_name is then used as the name of the command. This can probably easily be done by creating a subclass of Command with an init function.

This should then also be used with the Package class and in the "Own commands" example.

xeLaTeX needed

I can not write in Chinese, cause my Mac need xeLaTeX as compiler.
e.g.

import pylatex

doc = pylatex.Document(maketitle=True)

with doc.create(pylatex.Section(r'第一节')):
    pass

doc.generate_pdf()

this can not generate .pdf successfully, the following code is needed for .tex

% !TEX program = xelatex

What's the point of `real_data` attribute in `BaseLaTeXContainer`?

Hello!

I don't understand what the real_data attribute is for in the BaseLaTeXContainer class. I would code the __init__ method like below but I don't know if real_data needs to be None.

def __init__(self, data=[], packages=None):
    self.data = data
    self.real_data = data  # Always the data of this instance

    super().__init__(packages=packages)

Thanks!

Cannot install from source

Installing on Python 2 from source fails with

$ pip install -e .
Obtaining file:///Users/me/Projekte/pylatex/PyLaTeX
    Complete output from command python setup.py egg_info:
    running egg_info
    error: error in 'egg_base' option: 'python2_source' does not exist or is not a directory

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /Users/me/Projekte/pylatex/PyLaTeX

Remove section and table base classes

There is no point in having these. TabularBase could just be Tabular and SectionBase could just be Section. There is no need to have pointless baseclasses.

Tag releases

Hello!
Please tag your releases, so I can include them in MacPorts more easily.

Thanks,
Aljaž

'./testall.sh' does not work if the system python version is still 2.*

If the system default python version is still 2.*, the testall.sh script will try to run the 'python2_source' tests, resulting in the test failing as the folder does not exist.

I propose to add an optional command line argument, which allows to indicate the python command to be used. This will also allow the user to test everything under different python versions,.
e.g. ./testall.sh -p python3

Insert matplotlib plots

Would you be interested in a simple way to insert plots created with matplotlib? Just need to:

  • Save the plot as plot.pdf
  • Include this file
  • Delete plot.pdf

Looks like:

import matplotlib.pyplot as plt

x = [0, 1, 2, 3, 4, 5, 6]
y = [15, 2, 7, 1, 5, 6, 9]

plt.plot(x, y)
plt.savefig("./plot.pdf")
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}


\begin{document}

Some text.

\begin{figure}[htbp]
  \centering
  \includegraphics[width=\textwidth]{plot}
  \caption{SVG sexy image}
\end{figure}

Some other text.

\end{document}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.