Repository: sympy/sympy

Issue:
calling `latex` on `Array` with less rows than columns, and at least 10 columns, emit bad latex
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.

```py
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:
```py
'\\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:

```py
a = Array(ones(2, 10)); 
latex(a)
```
will produce a `\begin{matrix}`, which works:
```py
'\\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:
```py
a = Matrix(ones(2, 11)); 
latex(a)
```
```py
'\\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]'
```
 

Discussion:

Patch:
diff --git a/sympy/printing/latex.py b/sympy/printing/latex.py
index fa81c58d26..9164065bc4 100644
--- a/sympy/printing/latex.py
+++ b/sympy/printing/latex.py
@@ -1889,7 +1889,8 @@ def _print_NDimArray(self, expr: NDimArray):
         block_str = r'\begin{%MATSTR%}%s\end{%MATSTR%}'
         block_str = block_str.replace('%MATSTR%', mat_str)
         if mat_str == 'array':
-            block_str= block_str.replace('%s','{}%s')
+            block_str = block_str.replace('%s', '{' + 'c'*expr.shape[0] + '}%s')
+
         if self._settings['mat_delim']:
             left_delim: str = self._settings['mat_delim']
             right_delim = self._delim_dict[left_delim]


Test patch:
diff --git a/sympy/printing/tests/test_latex.py b/sympy/printing/tests/test_latex.py
index f647a98f17..28872fb3a7 100644
--- a/sympy/printing/tests/test_latex.py
+++ b/sympy/printing/tests/test_latex.py
@@ -3134,8 +3134,8 @@ def test_Array():
     assert latex(arr) == r'\left[\begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\end{matrix}\right]'
 
     arr = Array(range(11))
-    # added empty arguments {}
-    assert latex(arr) == r'\left[\begin{array}{}0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\end{array}\right]'
+    # fill the empty argument with a bunch of 'c' to avoid latex errors
+    assert latex(arr) == r'\left[\begin{array}{ccccccccccc}0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\end{array}\right]'
 
 def test_latex_with_unevaluated():
     with evaluate(False):