Skip to main content
https://badge.fury.io/py/array-to-latex.png/ https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg PyPi Download stats https://mybinder.org/badge_logo.svg

The module array_to_latex converts a NumPy/SciPy array or Pandas Numerical DataFrame to a LaTeX array or table using Python 3.x style formatting of the result or a format usable for plotting within LaTeX using pgfplots. Note that as of 0.83 it does add the column formatting arguments (for example, {ccc…}) when the user chooses to use array. I’m happy to have someone create a better solution but this at least makes a copied array immediately usable. I prefer bmatrix or similar. `

Play with it on mybinder.org!

A NumPy-focused re-envisioned converter based, in part, on this is numpyarray_to_latex. Also, available pip install. It incorporates more sophisticated “sub” markup capabilities. Check it out!

0.92: Allow np.array consisting of strings to be converted (Thanks to Tesla2000)
1.0.0: Validate arraytype, fix docstring/doctest inaccuracies, remove unused
nargout parameter (breaking), make clipboard an optional install
extra, add unit tests and GitHub Actions CI.

Recent updates follow, with a more complete list towards the end of this document. If you don’t see the current version in this list it’s likely because I (again) forgot to update it when pushing out a new version. Please see the readme on GitHub.

0.81: Bug fixes in requirements and to_clp
0.82: Raise ImportError exception when incorrect datatype used.
0.83: Now puts a default format in when returning as an array object.
0.90: Add coords format for use in plotting within LaTeX using pgfplots.
0.91: Improve the output for scientific e notation.
0.92: Allow np.array consisting of strings to be converted (Thanks to Tesla2000)

Install using pip install --user array_to_latex from your command prompt, not the Python prompt. If you want to use to_clp to copy results directly to your clipboard, install the optional extra with pip install --user array_to_latex[clipboard].

Please read the help. It explains all options. To try it, see the online mybinder.org demo. It documents illustrates application to numerical Pandas DataFrames.

import numpy as np
import array_to_latex as a2l
A = np.array([[1.23456, 23.45678],[456.23, 8.239521]])
a2l.to_ltx(A, frmt = '{:6.2f}', arraytype = 'array')

will print the LaTeX code to your output.

import numpy as np
import array_to_latex as a2l
A = np.array([[1.23456, 23.45678],[456.23, 8.239521]])
latex_code = a2l.to_ltx(A, frmt = '{:6.2f}', arraytype = 'bmatrix', print_out=False)

will put the LaTeX code into variable latex_code.

import numpy as np
import array_to_latex as a2l
A = np.array([[1.23456, 23.45678],[456.23, 8.239521]])
a2l.to_clp(A, frmt = '{:6.2f}', arraytype = 'bmatrix')

will put the array onto your clipboard.

If you will be using the same conversion over and over, you can define your own by using a lambda function:

to_tex = lambda A : a2l.to_ltx(A, frmt = '{:6.2f}', arraytype = 'bmatrix', mathform=True)
to_tex(A)

so you can now use your function to_tex repeatedly with your specified settings. More detailed information on usage is in the help.

import array_to_latex as a2l
help(a2l.to_ltx)

Interesting alternative approaches are np_array_to_latex and tab2latex (convert numpy array to longtable file).

Like this module, buy me a coffee!.

New in 0.37: Now handles complex arrays.
New in 0.38: Aligns columns neatly.
0.40: Critical upgrade- 0.37-0.38 formatted incorrectly.
0.41: Critical upgrade- 0.37-0.40 formatted incorrectly.
New in 0.43: Now handles 1-D Arrays. See new option row
New in 0.50: Now works with Pandas DataFrames
0.51: Bug fix- remove extra blank lines in DataFrame tabular output
0.52: A few documentation typos fixed. No code changed.
0.60: Now handles strings in Pandas Dataframes. Fixes bug in exponentials and handling of exponentials. Please report errors!
0.61: Minor documentation improvements. No code changed.
0.70: Added mathform. When set to True (default), returns 10 to superscript form.
0.71: Line breaks broke readme.rst on pypi. No code change.
0.72: Line breaks broke readme.rst on pypi. No code change.
0.73: pypi won’t handle mathjax. It makes me sad. No code change.
0.74: Not released
0.75: output improvements (short-lived release)
0.76: Printing made better, allows outputs, added print_out
boolean to turn off printing
0.80: Return to previous interface while still enabling returned
LaTeX string.
0.81: Bug fixes in requirements and to_clp
0.82: Raise ImportError exception when incorrect datatype used.
0.83: Add formatting defaults when using array versus bmatrix, etc.
0.90: Add coords format for use in plotting within LaTeX using pgfplots.
0.91: Improve the output for scientific e notation.
0.92: Allow np.array consisting of strings to be converted (Thanks to Tesla2000)
1.0.0: Validate arraytype, fix docstring/doctest inaccuracies, remove unused
nargout parameter (breaking), make clipboard an optional install
extra, add unit tests and GitHub Actions CI.

Download files

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

Source Distribution

array_to_latex-1.0.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

array_to_latex-1.0.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file array_to_latex-1.0.0.tar.gz.

File metadata

  • Download URL: array_to_latex-1.0.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for array_to_latex-1.0.0.tar.gz
Algorithm Hash digest
SHA256 49cf7d00b4d1e8fe844baa24bac76fd58ce5bee0038c8b67c625db9affd1b2ac
MD5 67054b95eadc39ef3d043e241eb0c844
BLAKE2b-256 668a5687fe6f5c714df37ea718592d9fcdbfb3c41041b340fba2a97346cd1925

See more details on using hashes here.

File details

Details for the file array_to_latex-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: array_to_latex-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for array_to_latex-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9edadd3ec3b587d0db0de5b3cec10afdd2df5bfb81b9b634e374a859a82028af
MD5 68a72bf35f77b18548098e3d2b8cc202
BLAKE2b-256 7c48c18044b12f6f9d9958e74504bd1218d5b6b588b5b769abb69cb52d15be79

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.1

2 files

This release

1.0.0 This release

2 files

0.92

1 file

0.91

1 file

0.90

1 file

0.83

1 file

0.82

1 file

0.81

1 file

0.80

1 file

0.76

1 file

0.75

1 file

0.73

1 file

0.72

1 file

0.71

1 file

0.70

1 file

0.61

1 file

0.60

1 file

0.52

2 files

0.51

1 file

0.50

1 file

0.43

1 file

0.42

1 file

0.41

1 file

0.40

1 file

0.38

1 file

0.37

1 file

0.36

1 file

0.35

1 file

0.10

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page