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

Display the name of an input inside a function

asked 4 years ago

Cyrille gravatar image

Perhaps a stupid question. I have a function which is applied to a matrix say A1. Inside my fonction I call show(A_1) but I would like to call show(LatexExpr(r"A_1 ="A_1) without to be obliged to define a string for A_1.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 4 years ago

slelievre gravatar image

updated 4 years ago

Use Python string formatting.

There are three flavours of that.

Using %:

r"A = %s" % B

Using format:

r"A = {}".format(B)

Using f-strings:

fr"A = {B}"

Now combine with show(LatexExpr(...)):

show(LatexExpr(fr"A_1 = {latex(A_1)}")

See it in action on SageCell:

Preview: (hide)
link

Comments

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: 4 years ago

Seen: 167 times

Last updated: Sep 10 '20