jeltef / pylatex Goto Github PK
View Code? Open in Web Editor NEWA Python library for creating LaTeX files
Home Page: https://jeltef.github.io/PyLaTeX/
License: MIT License
A Python library for creating LaTeX files
Home Page: https://jeltef.github.io/PyLaTeX/
License: MIT License
Hi!
I wonder whether it would be interesting to implement unit tests like that:
doc = Document()
# ...
tex = """
...
"""
assert doc.dumps() == tex
Thanks!
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!
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
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."
I have written a couple of TODO's in the comments and those need to be fixed.
How to disable it and stuff. Maybe even a special example.
Deleting files does not work on Windows.
Because you're using linux command "rm'.
It is better to use os.remove:
https://docs.python.org/2/library/os.html#os.remove
This makes it much safer to use the PyLaTeX with untrusted content.
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?
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.
Hello!
Please tag your releases, so I can include them in MacPorts more easily.
Thanks,
Aljaž
I don't know if this is the right place for this, but I implemented a new class SubFigure for use with the subcaption package (http://texdoc.net/texmf-dist/doc/latex/caption/subcaption.pdf)
Should I make a pull request?
Good documentation is needed for the base classes, since they are the hardest to understand.
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.
It would be sweet if we could use multirow/multicol in tables somehow.
Cheers
I think the pip package is out of date as the API does not match the documentation. I spent quite a lot of time to find where is the Command and Options classes as they were not in the base_classes module.
https://jeltef.github.io/PyLaTeX/pylatex/pylatex.base_classes.command.html
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".
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
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 !
What should fix_filename("abc.def.fgh.ijk")
return?
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
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! :)
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
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
This makes it much easier to mix trusted and untrusted content.
Could it be feasible to implement support for characters such as é, è,ù ê, à and others?
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.
This will make it easier to change the internal API without breaking changes for users.
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
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
Numpy style docstrings are much more readable when reading the actual source code. It is important that this is consistantly used everywhere.
Would you be interested in a simple way to insert plots created with matplotlib? Just need to:
plot.pdf
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}
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.
Currently the only documentation are the examples. This should be changed.
Just making a notation here. The Scribus CLI is still under development ATM but it would seem advantageous to hook in pyLaTex as a way to satisfy different needs.
Latexmk is much better, since it compiles as often as needed for more complicated documents.
@sebastianhaas Could you write something on how to use this?
em... Where is the API reference?
A simple way to convert NumPy matrices and arrays to LaTeX formatted matrices or vectors.
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
This should not be hard, but should be done before the 1.0.0 release because it means removing the old Table class that is now renamed to Tabular.
If clean=True all files are removed correctly except of the filename.out file.
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
.
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!
Currently everything is passed on and on with *args
and **kwargs
, but this makes it very unclear what can be passed on.
Is there a reason BaseLaTeXNamedContainer
is currently only supporting a single argument?
According to this, environments can have up to 9 parameters:
http://www.emerson.emory.edu/services/latex/latex_19.html
I'm happy to provide a patch if this is unintentional.
So everything is in one place.
I can't write PDF file in cyrillic.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.