Ask Your Question

Printing latex

asked 2018-01-29 08:58:25 -0600

anonymous user


updated 2018-01-29 08:58:55 -0600

I am using sage and would like to implement a function that prints a variable in latex, so I can copy and paste it directly into my latex file. However I am unsure how to do this. This is what I have attempted:

def printlatex(a):
    return '$', latex(a), '$'
a = 1*2

This returns the tuple ('$', 2, '$'), which I don't want.

How would I implement the function so it returns $2$

edit retag flag offensive close merge delete


A plus instead of the comma...

dan_fulea gravatar imagedan_fulea ( 2018-01-29 10:51:20 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-01-29 11:22:17 -0600

slelievre gravatar image

Use Python string formatting.

Find more information about Python string formatting at

For your example, you could use: '${a}$'.format(a=2).

edit flag offensive delete link more

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


Asked: 2018-01-29 08:58:25 -0600

Seen: 31 times

Last updated: Jan 29