Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
1

Iteration inside a LatexExpr

asked 3 years ago

CyrilleP gravatar image

For presentation reason I have a show like the following one :

show(LatexExpr(r"\text{The variable } x[i] \text{ takes the value :}"), x[i])

How could I have an iteration on on I to display in the text say x1, ...,x10 in place of the x[i].

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 3 years ago

slelievre gravatar image

updated 3 years ago

Something like this:

x = [i^2 for i in range(20)]  # for testing purposes
for i in range(1, 11):
    show(LatexExpr(fr"\text{{The variable }} x_{{{i}}} \text{{ takes the value :}}"),
         x[i])

Python formatted strings or f-strings can include things in {}.

Escaping that inclusion mechanism to get actual braces is done using {{}}.

Preview: (hide)
link

Comments

What means the f in front of the r and why the \text need double {{

CyrilleP gravatar imageCyrilleP ( 3 years ago )

The r stands for raw string and f for f-string. See here for the later case.

cav_rt gravatar imagecav_rt ( 3 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 3 years ago

Seen: 188 times

Last updated: Nov 21 '21