Skip to main content

Python module to facilitate input in LaTex from Python scripts

Project description

Python to LaTeX

This is a module provides several method to parse data from Python to LaTeX.

Author:

  • Sonja Stuedli

Installation

pip install --upgrade python_to_latex

Usage examples:

Below there are some small examples how to use the provided functions. Detailed explanation of each function can be found by using

  import python_to_latex as p2l
  help(p2l.<function_name>)

Printing a matrix:

      import python_to_latex as p2l
      import numpy as np
      mat2lat(np.eye(2),matrix_style='bmatrix')

This will print the code block below and return the string to produce it.

   \begin{bmatrix}
     1 &   0\\ 
     0 &   1\\ 
   \end{bmatrix}

Printing table output:

     import python_to_latex as p2l
     numeric_list_to_tabularx([[1,2,3],[4,5,6]],heading=['A','B','c'])
The above code will print the code block below and return the string to produce it.
      \begin{tabularx}{\linewidth}{S[table-auto-round,table-omit-exponent,fixed-exponent=0]S[table-auto-round,table-omit-exponent,fixed-exponent=0]S[table-auto-round,table-omit-exponent,fixed-exponent=0]} \toprule
      {A} & {B} & {C}\\ \midrule
      1 & 2 & 3\\
      4 & 5 & 6\\\bottomrule 
      \end{tabularx}

Saving a matplotlib figure:

     import python_to_latex as p2l
     import numpy as np
     import matplotlib
     import matplotlib.pyplot as plt

     x = np.arange(15)
     y1 = 2*x
     y2 = x+5
     y3 = x

     fig1,plt1 = plt.subplots(nrows=1,ncols=2)
     plt1[0].plot(x,y1)
     plt1[0].plot(x,y2,'.',label="line a")
     plt1[1].plot(x,y3,label="line 1")
     plt1[0].set_ylabel('$\lambda_2$')
     plt1[1].set_xlabel('$b$')
     plt1[1].set_ylabel('$\lambda_N$')
     plt1[1].set_xlabel('$N$')
     plt1[0].legend(loc=1)
     plt1[0].set_label("test")
     fig1.show()

     fig2pgf(fig1,"test",retain_color=True,retain_linestyle=True)

The code above generates a simgle matplotlib figure and then saves that figure in PGF format in a file called test.tikz. The saved file can be loaded in LaTex.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_to_latex-0.0.3.tar.gz (6.2 kB view hashes)

Uploaded Source

Built Distribution

python_to_latex-0.0.3-py3-none-any.whl (19.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page