|
2 | 2 | PyLaTeX |
3 | 3 | ------- |
4 | 4 |
|
5 | | -PyLaTeX is a Python library for creating LaTeX files. The goal of this library |
6 | | -is being an easy, but extensible interface between Python and LaTeX. |
| 5 | +PyLaTeX is a Python library for creating and compiling LaTeX files. The goal of |
| 6 | +this library is being an easy, but extensible interface between Python and |
| 7 | +LaTeX. |
7 | 8 |
|
8 | 9 |
|
9 | 10 | Features |
10 | | -~~~~~~~~ |
11 | | -
|
12 | | -The library contains some basic features I have had the need for so far. |
13 | | -Currently those are: |
| 11 | +-------- |
14 | 12 |
|
15 | 13 | - Document generation and compilation |
16 | | -- Section, table, math and package classes |
| 14 | +- Section, table, math, figure and package classes |
17 | 15 | - A matrix class that can compile NumPy ndarrays and matrices to LaTeX |
18 | | -- An escape function |
19 | | -- Bold and italic functions |
20 | | -- Every class has a dump method, which writes the output to a filepointer |
| 16 | +- Very exstensible base classes that you can use to easily add new features |
| 17 | +- Contextmanager style class hierarchy |
| 18 | +- Functionality to escape special LaTeX characters |
| 19 | +- Bold, italic and verbatim functions |
| 20 | +- Every class has a dump method, which writes the output to a filepointer this way you can use snippets in in normal LaTeX files using \\input |
21 | 21 |
|
22 | 22 | Everything else you want you can still add to the document by adding LaTeX |
23 | | -formatted strings instead of classes or regular strings. |
| 23 | +formatted strings to the container class you want it to be in. |
24 | 24 |
|
25 | 25 |
|
26 | 26 | Dependencies |
27 | | -~~~~~~~~~~~~ |
| 27 | +------------ |
28 | 28 |
|
29 | 29 | - Python 3.x or Python 2.7 |
| 30 | +- ordered-set |
| 31 | +
|
| 32 | +Optional dependencies |
| 33 | +~~~~~~~~~~~~~~~~~~~~~ |
| 34 | +
|
30 | 35 | - pdflatex (only if you want to compile the tex file) |
31 | 36 | - NumPy (only if you want to convert it's matrixes) |
32 | | -- ordered-set |
| 37 | +- awkwardduet (only if you want to compile to python 2 source code yourself) |
33 | 38 |
|
34 | 39 |
|
35 | 40 | Installation |
36 | | -~~~~~~~~~~~~ |
| 41 | +------------ |
37 | 42 |
|
38 | 43 | :: |
39 | 44 |
|
40 | 45 | pip install pylatex |
41 | 46 |
|
42 | 47 |
|
43 | 48 | Example |
44 | | -~~~~~~~ |
| 49 | +------- |
| 50 | +
|
| 51 | +This is generated by the code below: |
| 52 | +
|
| 53 | +.. image:: https://raw.github.com/JelteF/PyLaTeX/master/docs/static/screenshot.png |
| 54 | +
|
45 | 55 |
|
46 | 56 | .. code:: python |
47 | 57 |
|
48 | 58 | import numpy as np |
49 | 59 |
|
50 | | - from pylatex import Document, Section, Subsection, Table, Math, TikZ, Axis, \ |
51 | | - Plot |
| 60 | + from pylatex import Document, Section, Subsection, Table, Math, TikZ, Axis, \\ |
| 61 | + Plot, Figure, Package |
52 | 62 | from pylatex.numpy import Matrix |
53 | | - from pylatex.utils import italic |
| 63 | + from pylatex.utils import italic, escape_latex |
54 | 64 |
|
55 | 65 | doc = Document() |
56 | | - section = Section('Yaay the first section, it can even be ' + italic('italic')) |
57 | | -
|
58 | | - section.append('Some regular text') |
59 | | -
|
60 | | - math = Subsection('Math that is incorrect', data=[Math(data=['2*3', '=', 9])]) |
61 | | -
|
62 | | - section.append(math) |
63 | | - table = Table('rc|cl') |
64 | | - table.add_hline() |
65 | | - table.add_row((1, 2, 3, 4)) |
66 | | - table.add_hline(1, 2) |
67 | | - table.add_empty_row() |
68 | | - table.add_row((4, 5, 6, 7)) |
69 | | -
|
70 | | - table = Subsection('Table of something', data=[table]) |
71 | | -
|
72 | | - section.append(table) |
| 66 | + doc.packages.append(Package('geometry', options=['tmargin=1cm', |
| 67 | + 'lmargin=10cm'])) |
| 68 | +
|
| 69 | + with doc.create(Section('The simple stuff')): |
| 70 | + doc.append('Some regular text and some ' + italic('italic text. ')) |
| 71 | + doc.append(escape_latex('\\nAlso some crazy characters: $&#{}')) |
| 72 | + with doc.create(Subsection('Math that is incorrect')) as math: |
| 73 | + doc.append(Math(data=['2*3', '=', 9])) |
| 74 | +
|
| 75 | + with doc.create(Subsection('Table of something')): |
| 76 | + with doc.create(Table('rc|cl')) as table: |
| 77 | + table.add_hline() |
| 78 | + table.add_row((1, 2, 3, 4)) |
| 79 | + table.add_hline(1, 2) |
| 80 | + table.add_empty_row() |
| 81 | + table.add_row((4, 5, 6, 7)) |
73 | 82 |
|
74 | 83 | a = np.array([[100, 10, 20]]).T |
75 | 84 | M = np.matrix([[2, 3, 4], |
76 | 85 | [0, 0, 1], |
77 | 86 | [0, 0, 2]]) |
78 | 87 |
|
79 | | - math = Math(data=[Matrix(M), Matrix(a), '=', Matrix(M*a)]) |
80 | | - equation = Subsection('Matrix equation', data=[math]) |
81 | | -
|
82 | | - section.append(equation) |
83 | | -
|
84 | | - tikz = TikZ() |
85 | | -
|
86 | | - axis = Axis(options='height=6cm, width=6cm, grid=major') |
87 | | -
|
88 | | - plot1 = Plot(name='model', func='-x^5 - 242') |
89 | | - coordinates = [ |
90 | | - (-4.77778, 2027.60977), |
91 | | - (-3.55556, 347.84069), |
92 | | - (-2.33333, 22.58953), |
93 | | - (-1.11111, -493.50066), |
94 | | - (0.11111, 46.66082), |
95 | | - (1.33333, -205.56286), |
96 | | - (2.55556, -341.40638), |
97 | | - (3.77778, -1169.24780), |
98 | | - (5.00000, -3269.56775), |
99 | | - ] |
100 | | -
|
101 | | - plot2 = Plot(name='estimate', coordinates=coordinates) |
102 | | -
|
103 | | - axis.append(plot1) |
104 | | - axis.append(plot2) |
105 | | -
|
106 | | - tikz.append(axis) |
107 | | -
|
108 | | - plot_section = Subsection('Random graph', data=[tikz]) |
109 | | -
|
110 | | - section.append(plot_section) |
111 | | -
|
112 | | - doc.append(section) |
| 88 | + with doc.create(Section('The fancy stuff')): |
| 89 | + with doc.create(Subsection('Correct matrix equations')): |
| 90 | + doc.append(Math(data=[Matrix(M), Matrix(a), '=', Matrix(M*a)])) |
| 91 | +
|
| 92 | + with doc.create(Subsection('Beautiful graphs')): |
| 93 | + with doc.create(TikZ()): |
| 94 | + plot_options = 'height=6cm, width=6cm, grid=major' |
| 95 | + with doc.create(Axis(options=plot_options)) as plot: |
| 96 | + plot.append(Plot(name='model', func='-x^5 - 242')) |
| 97 | +
|
| 98 | + coordinates = [ |
| 99 | + (-4.77778, 2027.60977), |
| 100 | + (-3.55556, 347.84069), |
| 101 | + (-2.33333, 22.58953), |
| 102 | + (-1.11111, -493.50066), |
| 103 | + (0.11111, 46.66082), |
| 104 | + (1.33333, -205.56286), |
| 105 | + (2.55556, -341.40638), |
| 106 | + (3.77778, -1169.24780), |
| 107 | + (5.00000, -3269.56775), |
| 108 | + ] |
| 109 | +
|
| 110 | + plot.append(Plot(name='estimate', coordinates=coordinates)) |
| 111 | +
|
| 112 | + with doc.create(Subsection('Cute kitten pictures')): |
| 113 | + with doc.create(Figure(position='h!')) as kitten_pic: |
| 114 | + kitten_pic.add_image('docs/static/kitten.jpg', width='120px') |
| 115 | + kitten_pic.add_caption('Look it\\'s on its back') |
113 | 116 |
|
114 | 117 | doc.generate_pdf() |
115 | 118 |
|
116 | | -This code will generate this: |
117 | | -
|
118 | | -.. image:: https://raw.github.com/JelteF/PyLaTeX/master/docs/static/screenshot.png |
119 | | -
|
120 | 119 |
|
121 | 120 | Future development |
122 | | -~~~~~~~~~~~~~~~~~~ |
| 121 | +------------------ |
123 | 122 |
|
124 | | -I will keep adding functionality I need to this library, an interface for |
125 | | -graphics and math will probably be added in a future version. |
| 123 | +I will keep adding functionality I need to this library. |
126 | 124 |
|
127 | | -If you add a feature yourself, or fix a bug, please send a pull request. |
| 125 | +If you add a feature yourself, or fix a bug, please send a pull request. The |
| 126 | +code is not very difficult and mostly speaks for itself. If you have a question |
| 127 | +just let me know. |
128 | 128 |
|
129 | | -You can submit issues, but it will not be my priority to fix them. My job and |
130 | | -education are a bit higher on the priority list. |
| 129 | +You can submit issues and I will probably respond quite quick. However, it might |
| 130 | +take a lot more time for me to fix something. I also have a job, education and a |
| 131 | +personal life to worry about. If you want something done try to fix it yourself |
| 132 | +as well. Accepting pull requests costs way less time. |
131 | 133 |
|
132 | 134 |
|
133 | 135 | Support |
134 | | -~~~~~~~ |
| 136 | +------- |
135 | 137 |
|
136 | 138 | This library is being developed in and for Python 3. Because of a conversion |
137 | | -script the current version also works in Python 2.7. For futere versions, no |
138 | | -such promise will be made. Uncompatible Python 3 features will not be headed to |
139 | | -keep supporting Python 2.7. |
| 139 | +script the current version also works in Python 2.7. For future versions, no |
| 140 | +such promise will be made. Python 3 features that are useful but incompatible |
| 141 | +with Python 2 will be used. If you find a bug for Python 2 and it is fixable |
| 142 | +without ugly hacks feel free to send a pull request. |
140 | 143 |
|
141 | 144 | The platform this library is developed for is Linux. I have no intention to |
142 | | -write fixes or test for platform specific bugs. Pull requests that fix those |
143 | | -are always welcome though. |
| 145 | +write fixes or test for platform specific bugs with every update. Pull requests |
| 146 | +that fix those issues are always welcome though. |
144 | 147 |
|
145 | 148 | Copyright and License |
146 | | -~~~~~~~~~~~~~~~~~~~~~ |
| 149 | +--------------------- |
147 | 150 |
|
148 | 151 | Copyright 2014 Jelte Fennema, under `the MIT license |
149 | 152 | <https://github.com/JelteF/PyLaTeX/blob/master/LICENSE>`_. |
150 | 153 |
|
151 | 154 | """ |
152 | 155 |
|
153 | | -from distutils.core import setup |
| 156 | +try: |
| 157 | + from setuptools import setup |
| 158 | +except ImportError: |
| 159 | + from distutils.core import setup |
154 | 160 | import sys |
155 | 161 |
|
156 | 162 |
|
|
167 | 173 | source_dir = 'python2_source' |
168 | 174 |
|
169 | 175 | setup(name='PyLaTeX', |
170 | | - version='0.5', |
| 176 | + version='0.6', |
171 | 177 | author='Jelte Fennema', |
172 | 178 | author_email='pylatex@jeltef.nl', |
173 | 179 | description='A Python library for creating LaTeX files', |
|
0 commit comments