TheChymera / matrix2latex

Python/MATLAB matrix to LaTeX table converter, originally by Øystein Bjørndal
https://code.google.com/p/matrix2latex/
GNU General Public License v3.0
18 stars 8 forks source link

Build Status Matrix2LaTeX

Takes a Python or MATLAB matrix and outputs a LaTeX table, a LaTeX matrix, or a complete LaTeX document (and optionally calls latex for compilation). A number of configuration options are available. The default table output is geared towards the standard recommended by IEEE, and uses the latex package booktabs. Check out the documentation for more example output and usage.

Installation

From source:

pip install git+https://github.com/TheChymera/matrix2latex.git

Note that on some systems you may have to replace pip by pip3 to use Python 3 for the installation. Furthermore, if you only wish to install the package for the current user, you should supply the --user flag to the above command.

Example

The following python code:

from matrix2latex import matrix2latex
m = [[1, 1], [2, 4], [3, 9]] # python nested list
t = matrix2latex(m)
print(t)

or equivalent matlab code:

m = [1, 1; 2, 4; 3, 9];
filename = '' % do not write to file
t = matrix2latex(m, filename)

produces

\begin{table}[ht]
  \begin{center}
    \begin{tabular}{cc}
      \toprule
        $1$ & $1$\\
        $2$ & $4$\\
        $3$ & $9$\\
      \bottomrule
    \end{tabular}
  \end{center}
\end{table}

alt text

Various options are available to change the latex environment (e.g. to a matrix) or to provide header, footer, caption, label, format and/or alignment. Please see the documentation for details.

History

Inspired by the work of koehler@in.tum.de who has written a similar package only for matlab http://www.mathworks.com/matlabcentral/fileexchange/4894-matrix2latex

This project was moved from https://code.google.com/p/matrix2latex/ after code.google.com was discontinued.

Future goals

Feel free to contribute to any of the following improvements or open an issue if you want something done.

Author

Øystein Bjørndal