forked from JelteF/PyLaTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
134 lines (91 loc) · 3.42 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""
PyLaTeX
-------
PyLaTeX is a Python library for creating LaTeX files. The goal of this library
is being an easy, but extensible interface between Python and LaTeX.
Features
~~~~~~~~
The library contains some basic features I have had the need for so far.
Currently those are:
- Document generation and compilation
- Section, table, math and package classes
- A matrix class that can compile NumPy ndarrays and matrices to LaTeX
- An escape function
- Bold and italic functions
- Every class has a dump method, which writes the output to a filepointer
Everything else you want you can still add to the document by adding LaTeX
formatted strings instead of classes or regular strings.
Dependencies
~~~~~~~~~~~~
- Python 3.3 (Python 3.x might work as well)
- pdflatex (only if you want to compile the tex file)
- NumPy (only if you want to convert it's matrixes)
Installation
~~~~~~~~~~~~
::
pip install pylatex
Example
~~~~~~~
.. code:: python
import numpy as np
from pylatex import Document, Section, Subsection, Table, Math
from pylatex.numpy import Matrix
from pylatex.utils import italic
doc = Document()
section = Section('Yaay the first section, it can even be ' + italic('italic'))
section.append('Some regular text')
math = Subsection('Math', data=[Math(data=['2*3', '=', 6])])
section.append(math)
table = Table('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))
table = Subsection('Table of something', data=[table])
section.append(table)
a = np.array([[100, 10, 20]]).T
M = np.matrix([[2, 3, 4],
[0, 0, 1],
[0, 0, 2]])
math = Math(data=[Matrix(M), Matrix(a), '=', Matrix(M*a)])
print(math.dumps())
equation = Subsection('Matrix equation', data=[math])
print(equation.dumps())
section.append(equation)
doc.append(section)
doc.generate_pdf()
This code will generate this:
.. image:: https://raw.github.com/JelteF/PyLaTeX/master/docs/static/screenshot.png
Future development
~~~~~~~~~~~~~~~~~~
I will keep adding functionality I need to this library, an interface for
graphics and math will probably be added in a future version.
If you add a feature yourself, or fix a bug, please send a pull request.
You can submit issues, but it will not be my priority to fix them. My job and
education are a bit higher on the priority list.
Support
~~~~~~~
This library is being developed for Python 3.3. It currently doesn't work for
Python 2.7, but it's mostly syntax and import changes that break it for 2.7.
It is also only tested on Linux, so it might not work on any different
platforms.
I have no intention of testing on any different platforms or with different
Python versions. I also don't have the intention to write fixes for platform or
environment specific bugs, but pull requests that fix those are always welcome.
Copyright and License
~~~~~~~~~~~~~~~~~~~~~
Copyright 2014 Jelte Fennema, under `the MIT license
<https://github.com/JelteF/PyLaTeX/blob/master/LICENSE>`_.
"""
from distutils.core import setup
setup(name='PyLaTeX',
version='0.3.1.1',
author='Jelte Fennema',
author_email='[email protected]',
description='A Python library for creating LaTeX files',
long_description=__doc__,
packages=['pylatex'],
url='https://github.com/JelteF/PyLaTeX',
license='MIT',
)