Is it possible to color a string in a list ?
is there a way to color a string inside a list say
L = ["1","2","3"]
and I want to display 2 in red
is there a way to color a string inside a list say
L = ["1","2","3"]
and I want to display 2 in red
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} " + latex(x) + "}") if x == "2" else x for x in L])
or
sage: show([LatexExpr(r"{\color{red} " + latex(x) + "}") if k == 1 else x for k, x in enumerate(L)])
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2024-03-15 10:20:50 +0100
Seen: 199 times
Last updated: Mar 15
How to make typeset output in sage display properly?
Can I display a list of equations aligned like latex eqnarray?
SAGETEX: Howto compute solution of a function
How change the "3D Display size" of jmol in show()
How well print a list of matrices ?
embeding a variable in some html code in cloud.sagemath
Nice display of a list of "matrices"