Ask Your Question
1

Display the name of an input inside a function

asked 2020-09-10 12:31:55 +0100

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 12:46:48 +0100

slelievre gravatar image

updated 2020-09-10 16:58:57 +0100

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 12:31:55 +0100

Seen: 157 times

Last updated: Sep 10 '20