Ask Your Question
1

Display the name of an input inside a function

asked 2020-09-10 05:31:55 -0500

Cyrille gravatar image

Perhaps a stupid question. I have a function which is applied to a matrix say $A_1$. 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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-09-10 05:46:48 -0500

slelievre gravatar image

updated 2020-09-10 09:58:57 -0500

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:

edit flag offensive delete link more

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: 2020-09-10 05:31:55 -0500

Seen: 42 times

Last updated: Sep 10