Ask Your Question

Revision history [back]

The Python identifier can't have brackets so this fails:

sage: var('x[0]')
Traceback (most recent call last)
...
ValueError: The name "x[0]" is not a valid Python identifier.

but the LaTeX name can, so you can do:

sage: X = [SR.var('x_{}'.format(i), latex_name='x[{}]'.format(i)) for i in (0 .. 7)]

and then you would have in the Sage REPL:

sage: X
[x_0, x_1, x_2, x_3, x_4, x_5, x_6, x_7]
sage: show(X)
\newcommand{\Bold}[1]{\mathbf{#1}}\left[{x[0]}, {x[1]}, {x[2]}, {x[3]}, {x[4]}, {x[5]}, {x[6]}, {x[7]}\right]

but in a Jupyter notebook, show(X) would give a LaTeX-rendered $$[x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7]]$$