Skip to content

Commit 79807f7

Browse files
viochaeagleoflqj
authored andcommitted
add required argumets to latex array environment when print NDimArray
1 parent 6a04cdb commit 79807f7

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,7 @@ tools4origins <tools4origins@gmail.com>
14621462
user202729 <25191436+user202729@users.noreply.github.com>
14631463
vedantc98 <vedantc98@gmail.com>
14641464
vezeli <37907135+vezeli@users.noreply.github.com>
1465+
viocha <66580331+viocha@users.noreply.github.com>
14651466
vishal <vishal.panjwani15@gmail.com>
14661467
w495 <w495@yandex-team.ru>
14671468
wuyudi <wuyudi119@163.com>

sympy/printing/latex.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,8 @@ def _print_NDimArray(self, expr: NDimArray):
18741874
mat_str = 'array'
18751875
block_str = r'\begin{%MATSTR%}%s\end{%MATSTR%}'
18761876
block_str = block_str.replace('%MATSTR%', mat_str)
1877+
if mat_str == 'array':
1878+
block_str= block_str.replace('%s','{}%s')
18771879
if self._settings['mat_delim']:
18781880
left_delim: str = self._settings['mat_delim']
18791881
right_delim = self._delim_dict[left_delim]

sympy/printing/tests/test_latex.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from sympy import MatAdd, MatMul
1+
from sympy import MatAdd, MatMul, Array
22
from sympy.algebras.quaternion import Quaternion
33
from sympy.calculus.accumulationbounds import AccumBounds
44
from sympy.combinatorics.permutations import Cycle, Permutation, AppliedPermutation
@@ -3101,3 +3101,11 @@ def test_printing_latex_array_expressions():
31013101
M = MatrixSymbol("M", 3, 3)
31023102
N = MatrixSymbol("N", 3, 3)
31033103
assert latex(ArrayElement(M*N, [x, 0])) == "{{\\left(M N\\right)}_{x, 0}}"
3104+
3105+
def test_Array():
3106+
arr = Array(range(10))
3107+
assert latex(arr) == r'\left[\begin{matrix}0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\end{matrix}\right]'
3108+
3109+
arr = Array(range(11))
3110+
# added empty arguments {}
3111+
assert latex(arr) == r'\left[\begin{array}{}0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\end{array}\right]'

0 commit comments

Comments
 (0)