All Projects → TheChymera → matrix2latex

TheChymera / matrix2latex

Licence: GPL-3.0 License
Python/MATLAB matrix to LaTeX table converter, originally by Øystein Bjørndal

Programming Languages

python
139335 projects - #7 most used programming language
matlab
3953 projects
Makefile
30231 projects
TeX
3793 projects

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 [email protected] 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.

  • Clean up the code (object oriented?)
  • Make the matlab version identical to the python version
  • Add support for more advanced tables. Highlights and multirow.
  • Command line interface (say, read in a csv, take arguments on the command line)
  • Additional languages (R/perl/julia?)

Author

Øystein Bjørndal

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].