ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 14 Dec 2021 21:09:19 +0100Iterate on a LatexExprhttps://ask.sagemath.org/question/60259/iterate-on-a-latexexpr/ This is certainly a question I have already asked, but I don't find any source.
I have a list of indexed variables up to 2 digits (for example $x_{13}$) and I want to loop on a `LatexExp()' of the sort :
show(LatexExpr(r"\text{blabla } p_i = ", some stuff)
The result should be
$\text{blabla } p_1 = 10$
$\text{blabla } p_{20} = 10$
Hope my question is not too unclear
Tue, 14 Dec 2021 17:07:23 +0100https://ask.sagemath.org/question/60259/iterate-on-a-latexexpr/Answer by cav_rt for <p>This is certainly a question I have already asked, but I don't find any source.</p>
<p>I have a list of indexed variables up to 2 digits (for example $x_{13}$) and I want to loop on a `LatexExp()' of the sort :</p>
<p>show(LatexExpr(r"\text{blabla } p_i = ", some stuff)</p>
<p>The result should be</p>
<p>$\text{blabla } p_1 = 10$</p>
<p>$\text{blabla } p_{20} = 10$</p>
<p>Hope my question is not too unclear</p>
https://ask.sagemath.org/question/60259/iterate-on-a-latexexpr/?answer=60264#post-id-60264Why not put the variables in a list?
some_variables = [var(f'p_{k}{l}') for k in range(5) for l in range(4,8)]
for v in some_variables:
show(LatexExpr(r"\text{blabla } "), v, "\t = \t", "some stuff")Tue, 14 Dec 2021 21:09:19 +0100https://ask.sagemath.org/question/60259/iterate-on-a-latexexpr/?answer=60264#post-id-60264