sympy / sympy

A computer algebra system written in pure Python

Home Page:https://sympy.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

calling `latex` on `Array` with less rows than columns, and at least 10 columns, emit bad latex

kompre opened this issue · comments

Hello,

I stumble upon this odd thing: if I create an Array object with a number of rows that is less or equal to the number of columns, and the number of columns is at least 11, then the latex emitted by the latex function is wrong, because it is missing the preamble. A quick fix is to change the type to Matrix and then call the latex function. For array with more rows than columns there seems to be no issue.

from sympy import Array, Matrix, latex, ones

a = Array(ones(2, 11)); 

from sympy import collect

latex(a)

will produce a \begin{array} with empty preamble {} which is not valid latex:

'\\left[\\begin{array}{}1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\\\\1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\\end{array}\\right]'

for reference:

a = Array(ones(2, 10)); 
latex(a)

will produce a \begin{matrix}, which works:

'\\left[\\begin{matrix}1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\\\\1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\\end{matrix}\\right]'

changing the type to Matrix will give the correct preamble:

a = Matrix(ones(2, 11)); 
latex(a)
'\\left[\\begin{array}{ccccccccccc}1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\\\\1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1\\end{array}\\right]'