{ "info": { "author": "Jean-Samuel Leboeuf", "author_email": "jean-samuel.leboeuf.1@ulaval.ca", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Python2LaTeX: The Python to LaTeX converter\n\nDid you ever feel overwhelmed by the cumbersomeness of LaTeX to produce quality tables and figures? Fear no more, Python2LaTeX is here! Produce perfect tables automatically and easily, create figures and plots that integrates seamlessly into your tex file, or even write your complete article directly from Python! All that effortlessly (or almost) with Python2LaTeX.\n\n## Prerequisites\n\nThe package makes use of numpy and assumes a distribution of LaTeX that uses ``pdflatex`` is installed on your computer. Some LaTeX packages are used, such as ``booktabs``, ``tikz``, ``pgfplots`` and ``pgfplotstable``. Your LaTeX distribution should inform you if such package needs to be installed.\n\n## Installation\n\nTo install the package, simply run in your terminal the command\n\n pip install python2latex\n\n## Examples\n\n### Create a simple document\n\nThe following example shows how to create a document with a single section and some text.\n```python\nfrom python2latex import Document\n\ndoc = Document(filename='simple_document_example', filepath='./examples/simple document example', doc_type='article', options=('12pt',))\ndoc.set_margins(top='3cm', bottom='3cm', margins='2cm')\nsec = doc.new_section('Spam and Egg', label='spam_egg')\nsec.add_text('The Monty Python slays the Spam and eats the Egg.')\n\ntex = doc.build() # Builds to tex and compile to pdf\nprint(tex) # Prints the tex string that generated the pdf\n```\n\n
\n\n Click to unfold result \n\n

\n\"Simple\n

\n
\n\n\n### Create a table from a numpy array\n\nThis example shows how to generate automatically a table from data taken directly from a numpy array. The module allows to add merged cells easily, to add rules where you want and even to highlight the best value automatically inside a specified area and more! To ease these operations, the the square brackets ('getitem') operator have been repurposed to select an area of the table instead of returning the actual values contained in the table. Once an area is selected, use the 'format_spec', 'add_rule', 'multicell', 'apply_command', 'highlight_best' or 'divide_cell' methods or properties. To get the actual values inside the table, one can use the 'data' attribute of the table. See the examples for extensive coverage of possibilities. Here is a simple, working example to give a preview of the usage.\n```python\nfrom python2latex import Document, Table\nimport numpy as np\n\n# Create the document of type standalone\ndoc = Document(filename='simple_table_from_numpy_array_example', filepath='examples/table examples', doc_type='standalone', border='10pt')\n\n# Create the data\ncol, row = 4, 4\ndata = np.random.rand(row, col)\n\n# Create the table and add it to the document at the same time\ntable = doc.new(Table(shape=(row+2, col+1), as_float_env=False)) # No float environment in standalone documents\n\n# Set entries with a slice directly from a numpy array!\ntable[2:,1:] = data\n\n# Set a columns title as a multicell with a simple slice assignment\ntable[0,1:] = 'Col title'\n# Set whole lines or columns in a single line with lists\ntable[1,1:] = [f'Col{i+1}' for i in range(col)]\ntable[2:,0] = [f'Row{i+1}' for i in range(row)]\n\n# Add rules where you want\ntable[1,1:].add_rule()\n\n# Automatically highlight the best value(s) inside the specified slice, ignoring text\nfor r in range(2,row+2):\n table[r].highlight_best('high', 'bold') # Best per row\n\ntex = doc.build()\nprint(tex)\n```\n_Result:_\n

\n\"Table\n

\n\n\n\n### Create a simple plot\nYou can plot curves as easily as with `matplotlib.pyplot.plot` with the `Plot` environement that compiles it directly into pdf! This is a wrapper around the `pgfplots` and `pgfplotstable` LaTeX packages.\n```python\nfrom python2latex import Document, Plot\nimport numpy as np\n\n# Document type 'standalone' will only show the plot, but does not support all tex environments.\nfilepath = './examples/plot examples/simple plot example/'\nfilename = 'simple_plot_example'\ndoc = Document(filename, doc_type='standalone', filepath=filepath)\n\n# Create the data\nX = np.linspace(0,2*np.pi,100)\nY1 = np.sin(X)\nY2 = np.cos(X)\n\n# Create a plot\nplot = doc.new(Plot(X, Y1, X, Y2, plot_path=filepath, as_float_env=False))\n\ntex = doc.build()\n```\n_Result:_\n

\n\"Simple\n

\n\n\n\n### Create a more complex plot\nYou can make more complex plots with the options shown in this example.\n```python\nfrom python2latex import Document, Plot\nimport numpy as np\n\n# Create the document\nfilepath = './examples/plot examples/more complex plot example/'\nfilename = 'more_complex_plot_example'\ndoc = Document(filename, doc_type='article', filepath=filepath)\nsec = doc.new_section('More complex plot')\nsec.add_text('This section shows how to make a more complex plot integrated directly into a tex file.')\n\n# Create the data\nX = np.linspace(0,2*np.pi,100)\nY1 = np.sin(X)\nY2 = np.cos(X)\n\n# Create a plot\nplot = sec.new(Plot(plot_name=filename, plot_path=filepath))\nplot.caption = 'More complex plot'\n\nplot.add_plot(X, Y1, 'blue', 'dashed', legend='sine') # Add colors and legend to the plot\nplot.add_plot(X, Y2, 'orange', line_width='3pt', legend='cosine')\nplot.legend_position = 'south east' # Place the legend where you want\n\n# Add a label to each axis\nplot.x_label = 'Radians'\nplot.y_label = 'Projection'\n\n# Choose the limits of the axis\nplot.x_min = 0\nplot.y_min = -1\n\n# Choose the positions of the ticks on the axes\nplot.x_ticks = np.linspace(0,2*np.pi,5)\nplot.y_ticks = np.linspace(-1,1,9)\n# Choose the displayed text for the ticks\nplot.x_ticks_labels = r'0', r'$\\frac{\\pi}{2}$', r'$\\pi$', r'$\\frac{3\\pi}{2}$', r'$2\\pi$'\n\n# Use the tex environment 'axis' keyword options to use unimplemented features if needed.\nplot.axis.kwoptions['y tick label style'] = '{/pgf/number format/fixed zerofill}' # This makes all numbers with the same number of 0 (fills if necessary).\n\ntex = doc.build()\n```\n
\n\n Click to unfold result \n\n

\n\"More\n

\n
\n\n### Create a simple matrix plot AKA heatmap\nYou can also make heatmaps in a similar fashion as a plot.\n```python\nfrom python2latex import Document, Plot\nimport numpy as np\n\n# Create the document\nfilepath = './examples/plot examples/simple matrix plot example'\nfilename = 'simple_matrix_plot_example'\ndoc = Document(filename, doc_type='standalone', filepath=filepath, border='1cm')\n\n# Create the data\nX = np.linspace(-3, 3, 11)\nY = np.linspace(-3, 3, 21)\n\n# Create a plot\nplot = doc.new(Plot(plot_name=filename, plot_path=filepath, as_float_env=False,\n grid=False, lines=False,\n enlargelimits='false',\n width=r'.5\\textwidth', height=r'.5\\textwidth'))\n\nXX, YY = np.meshgrid(X, Y)\nZ = np.exp(-(XX**2+YY**2)/6).T # Transpose is necessary because numpy puts the x dimension along columns and y dimension along rows, which is the opposite of a standard graph.\nplot.add_matrix_plot(X, Y, Z)\n\n# Adding titles and labels\nplot.x_label = 'X axis'\nplot.y_label = 'Y axis'\nplot.title = 'Some title'\n\ntex = doc.build()\n```\n_Result:_\n

\n\"Simple\n

\n\nBe sure to check our more complex matrix plot example too!\n\n\n### Templating\nIf you do not want to write your whole document in python2latex, you can use our simple templating engine to insert parts of tex code directly inside your file.\nSimply write the command `%! python2latex-anchor = anchor_name_here` and the script will automatically insert the commands below it.\n\nSee our example folder for a simple usage example of the Template class.\n\n\n### Create an unsupported environment\nIf some environment is not currently supported, you can create one from the TexEnvironment base class.\n```python\nfrom python2latex import Document, TexEnvironment\n\ndoc = Document(filename='unsupported_env_example', doc_type='article', filepath='examples/unsupported env example', options=('12pt',))\n\nsec = doc.new_section('Unsupported env')\nsec.add_text(\"This section shows how to create unsupported env if needed.\")\n\nsec.add_package('amsmath') # Add needed packages in any TexEnvironment, at any level\nalign = sec.new(TexEnvironment('align', label='align_label'))\nalign.add_text(r\"\"\"e^{i\\pi} &= \\cos \\pi + i \\sin \\pi\\\\\n &= -1\"\"\") # Use raw strings to alleviate tex writing\n\ntex = doc.build()\nprint(tex)\n```\n
\n\n Click to unfold result \n\n

\n\"Unsupported\n

\n
\n\n\n### Binding objects to environments\nTo alleviate syntax, it is possible to bind TexObject classes to an instance of a TexEnvironment. This creates an alternative class that automatically append any new instance of the class to the environment.\n```python\nfrom python2latex import Document, Section, Subsection, TexEnvironment\n\ndoc = Document(filename='binding_objects_to_environments_example', filepath='./examples/binding objects to environments example', doc_type='article', options=('12pt',))\nsection = doc.bind(Section) # section is now a new class that creates Section instances that are automatically appended to 'doc'\n\nsec1 = section('Section 1', label='sec1') # Equivalent to: sec1 = doc.new(Section('Section 1', label='sec1'))\nsec1.add_text(\"All sections created with ``section'' will be automatically appended to the document body!\")\n\nsubsection, texEnv = sec1.bind(Subsection, TexEnvironment) # 'bind' supports multiple classes in the same call\neq1 = texEnv('equation')\neq1.add_text(r'e^{i\\pi} = -1')\n\neq2 = texEnv('equation')\neq2 += r'\\sum_{n=1}^{\\infty} n = -\\frac{1}{12}' # The += operator calls is the same as 'add_text'\n\nsub1 = subsection('Subsection 1 of section 1')\nsub1 += 'Text of subsection 1 of section 1.'\n\nsec2 = section('Section 2', label='sec2')\nsec2 += \"sec2 is also appended to the document after sec1.\"\n\ntex = doc.build() # Builds to tex and compile to pdf\nprint(tex) # Prints the tex string that generated the pdf\n```\n
\n\n Click to unfold result \n\n

\n\"Binding\n

\n
\n\n\n## How it works\n\nThis LaTeX wrapper is based on the TexEnvironment class. Each such environment possesses a body attribute consisting in a list of strings and of other TexEnvironments. The 'build' method then converts every TexEnvironment to a tex string recursively. This step makes sure every environment is properly between a '\\begin{env}' and a '\\end{env}'. Converting the document to a string only at the end allows to do operation in the order desired, hence providing flexibility. The 'build' method can be called on any TexEnvironment, return the tex string representation of the environment. However, only the Document class 'build' method will also compile it to an actual pdf.\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jsleb333/python2latex", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "python2latex", "package_url": "https://pypi.org/project/python2latex/", "platform": "", "project_url": "https://pypi.org/project/python2latex/", "project_urls": { "Homepage": "https://github.com/jsleb333/python2latex" }, "release_url": "https://pypi.org/project/python2latex/0.4.1/", "requires_dist": [ "numpy" ], "requires_python": ">=3.6", "summary": "A Python to LaTeX converter", "version": "0.4.1", "yanked": false, "yanked_reason": null }, "last_serial": 11840665, "releases": { "0.1.6": [ { "comment_text": "", "digests": { "md5": "475c8fc3b98ba035877041da57d95400", "sha256": "2d081deac8a9002ca7989ba6e0d309be336cf454fb945d49de852808b1ca22d9" }, "downloads": -1, "filename": "python2latex-0.1.6-py3-none-any.whl", "has_sig": false, "md5_digest": "475c8fc3b98ba035877041da57d95400", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 20434, "upload_time": "2019-10-21T19:07:25", "upload_time_iso_8601": "2019-10-21T19:07:25.719721Z", "url": "https://files.pythonhosted.org/packages/5e/4e/db1e9bc15b4292032569d4ceb86ce15654aba922e1d9644e056d9dedf0ce/python2latex-0.1.6-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "2def1feb9f92446f8ed2c822b8d6cde4", "sha256": "f1e13de2bc0f11231b3d584e526855915da875627e9f106ffe8ed8fcd9934ef3" }, "downloads": -1, "filename": "python2latex-0.1.6.tar.gz", "has_sig": false, "md5_digest": "2def1feb9f92446f8ed2c822b8d6cde4", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 19990, "upload_time": "2019-10-21T19:07:28", "upload_time_iso_8601": "2019-10-21T19:07:28.390966Z", "url": "https://files.pythonhosted.org/packages/5f/75/e514e90f785ee4d73256fc2216edf08dc347205ed497829919fa1d885681/python2latex-0.1.6.tar.gz", "yanked": false, "yanked_reason": null } ], "0.1.7": [ { "comment_text": "", "digests": { "md5": "3954caf60a05ae7e8472a7107cddb9db", "sha256": "0a9cfd0f5d81beb0b9991abf73029bd135acba7aa1231a4bb572c24958dd71ed" }, "downloads": -1, "filename": "python2latex-0.1.7-py3-none-any.whl", "has_sig": false, "md5_digest": "3954caf60a05ae7e8472a7107cddb9db", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 20877, "upload_time": "2019-11-21T15:36:10", "upload_time_iso_8601": "2019-11-21T15:36:10.492110Z", "url": "https://files.pythonhosted.org/packages/9c/17/145eaf6e850a8c16147d9aaadca24e832cd5bb6cf0c7bed0eddc14ff6cc6/python2latex-0.1.7-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "32d13f127f0c2c5a29eb58e9b7e4764b", "sha256": "ac3e3e5e1f0bf21c99cc169d3c53a62e22e7e95998d2292adcf7faaa92caee41" }, "downloads": -1, "filename": "python2latex-0.1.7.tar.gz", "has_sig": false, "md5_digest": "32d13f127f0c2c5a29eb58e9b7e4764b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 20503, "upload_time": "2019-11-21T15:36:15", "upload_time_iso_8601": "2019-11-21T15:36:15.298117Z", "url": "https://files.pythonhosted.org/packages/48/1d/bc83f35a2fecdc4535923b8b3c2889036b3704aa5ba1d1af01aeaf0c511f/python2latex-0.1.7.tar.gz", "yanked": false, "yanked_reason": null } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "4aa8d071e0768f3239482f9e3f7aa7af", "sha256": "8abe0befef8ad32262d8388f0f5f7353bb4e6de7903d53f461cbe4045f558a11" }, "downloads": -1, "filename": "python2latex-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "4aa8d071e0768f3239482f9e3f7aa7af", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 21502, "upload_time": "2019-11-21T15:36:12", "upload_time_iso_8601": "2019-11-21T15:36:12.254950Z", "url": "https://files.pythonhosted.org/packages/ae/43/c18bb4d6069ea95e4bec45caff42a0f93f2f978e2cec729cd20ddac9ee8d/python2latex-0.2.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "8c668c5fc5c8f7d92cfbceca03d50a62", "sha256": "3d75705d4cd9415746e94ff7d26f63e59200a8a37625d9bab3990a3d0df90782" }, "downloads": -1, "filename": "python2latex-0.2.0.tar.gz", "has_sig": false, "md5_digest": "8c668c5fc5c8f7d92cfbceca03d50a62", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 21515, "upload_time": "2019-11-21T15:36:17", "upload_time_iso_8601": "2019-11-21T15:36:17.175287Z", "url": "https://files.pythonhosted.org/packages/93/09/c683901eb787addf1d15f024dd2e4f73e449e394cef41c25f8ba7e735f6a/python2latex-0.2.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "80ab94328b2fb1ab9c3d99ef5ad886d5", "sha256": "cf982bc4f8d647365cd9d5738ea0a7b5b5713584ea2af18b5fe830483b3798e1" }, "downloads": -1, "filename": "python2latex-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "80ab94328b2fb1ab9c3d99ef5ad886d5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 25107, "upload_time": "2020-06-08T16:06:06", "upload_time_iso_8601": "2020-06-08T16:06:06.176692Z", "url": "https://files.pythonhosted.org/packages/81/39/6bc06cab39a364b236d430ebed245bbc576ab934742fb61fb5d9821cfea8/python2latex-0.3.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "b4ddc3c7e63f22431b3e82780b7240a3", "sha256": "6a26ac3d527a37fd32b4edb6095e4a0fdcbd3497e75640e2e9c97f27446d2088" }, "downloads": -1, "filename": "python2latex-0.3.0.tar.gz", "has_sig": false, "md5_digest": "b4ddc3c7e63f22431b3e82780b7240a3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 24046, "upload_time": "2020-06-08T16:06:07", "upload_time_iso_8601": "2020-06-08T16:06:07.366452Z", "url": "https://files.pythonhosted.org/packages/77/c8/a877246c84bc37fc469ab80b0a782ef774de2ea20e07f2cdb8be798dadb1/python2latex-0.3.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "e274213d85ea363d644f7279d19410ac", "sha256": "c0b253181f76b068490e25709f14b74a2a5f3c282585a9646bb54775a97e81f0" }, "downloads": -1, "filename": "python2latex-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "e274213d85ea363d644f7279d19410ac", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 34551, "upload_time": "2021-04-21T19:00:10", "upload_time_iso_8601": "2021-04-21T19:00:10.571790Z", "url": "https://files.pythonhosted.org/packages/f6/c8/91f089190be89e1a708c7b37a6376cb09ee523e135b60717ec4bcd63a5e7/python2latex-0.4.0-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "8f68b827764ee9f74283b427169e8de1", "sha256": "c86be8aac853656fa211345c2f208bf0a981735ec8d5a0aae03a84197fc667a0" }, "downloads": -1, "filename": "python2latex-0.4.0.tar.gz", "has_sig": false, "md5_digest": "8f68b827764ee9f74283b427169e8de1", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 33663, "upload_time": "2021-04-21T19:00:12", "upload_time_iso_8601": "2021-04-21T19:00:12.907862Z", "url": "https://files.pythonhosted.org/packages/94/00/17ca3746e53c2e9ab9d2301313b0e7f095170354dddf04db66334149c3de/python2latex-0.4.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "595b4d1d27ac1adefe717b4f56954131", "sha256": "b72d154500b369312f6969c8bb33684292ce2a573846becf78bee0b4dd707aad" }, "downloads": -1, "filename": "python2latex-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "595b4d1d27ac1adefe717b4f56954131", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 35654, "upload_time": "2021-10-26T21:48:03", "upload_time_iso_8601": "2021-10-26T21:48:03.792490Z", "url": "https://files.pythonhosted.org/packages/bc/d5/81181dd22ba3e09e538b0e3cfcd29d6523f7551bfe254da906dc65f6f5e7/python2latex-0.4.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "ba419295255ac08b022994b17599b113", "sha256": "cca84d282b03f47c8929be0ed900b063f77f6b35519fb91a7bb8ddac8d9d02d5" }, "downloads": -1, "filename": "python2latex-0.4.1.tar.gz", "has_sig": false, "md5_digest": "ba419295255ac08b022994b17599b113", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 34439, "upload_time": "2021-10-26T21:48:05", "upload_time_iso_8601": "2021-10-26T21:48:05.554391Z", "url": "https://files.pythonhosted.org/packages/c0/eb/dcaf4702dd25e6343dcd3e7190b527479b536838962924cb789a15f1f45b/python2latex-0.4.1.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "595b4d1d27ac1adefe717b4f56954131", "sha256": "b72d154500b369312f6969c8bb33684292ce2a573846becf78bee0b4dd707aad" }, "downloads": -1, "filename": "python2latex-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "595b4d1d27ac1adefe717b4f56954131", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 35654, "upload_time": "2021-10-26T21:48:03", "upload_time_iso_8601": "2021-10-26T21:48:03.792490Z", "url": "https://files.pythonhosted.org/packages/bc/d5/81181dd22ba3e09e538b0e3cfcd29d6523f7551bfe254da906dc65f6f5e7/python2latex-0.4.1-py3-none-any.whl", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "ba419295255ac08b022994b17599b113", "sha256": "cca84d282b03f47c8929be0ed900b063f77f6b35519fb91a7bb8ddac8d9d02d5" }, "downloads": -1, "filename": "python2latex-0.4.1.tar.gz", "has_sig": false, "md5_digest": "ba419295255ac08b022994b17599b113", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 34439, "upload_time": "2021-10-26T21:48:05", "upload_time_iso_8601": "2021-10-26T21:48:05.554391Z", "url": "https://files.pythonhosted.org/packages/c0/eb/dcaf4702dd25e6343dcd3e7190b527479b536838962924cb789a15f1f45b/python2latex-0.4.1.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }