Ask Your Question

Revision history [back]

If you're using an interface that supports LaTeX output, such as a Jupyter notebook:

sage: show(["1", LatexExpr(r"{\color{red} 2}"), "3"])

$$\displaystyle \left[1, {\color{red} 2}, 3\right]$$

To automate it, you could do e.g.

sage: show([LatexExpr(r"{\color{red} " + x + "}") if x == "2" else x for x in L])

or

sage: show([LatexExpr(r"{\color{red} " + x + "}") if k == 1 else x for k, x in enumerate(L)])

If you're using an interface that supports LaTeX output, such as a Jupyter notebook:

sage: show(["1", LatexExpr(r"{\color{red} 2}"), "3"])

$$\displaystyle \left[1, {\color{red} 2}, 3\right]$$

To automate it, you could do e.g.

sage: show([LatexExpr(r"{\color{red} " + x latex(x) + "}") if x == "2" else x for x in L])

or

sage: show([LatexExpr(r"{\color{red} " + x latex(x) + "}") if k == 1 else x for k, x in enumerate(L)])