Ask Your Question
0

Printing latex

asked 2018-01-29 15:58:25 +0200

anonymous user

Anonymous

updated 2018-01-29 15:58:55 +0200

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
printlatex(a)

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

Comments

A plus instead of the comma...

dan_fulea gravatar imagedan_fulea ( 2018-01-29 17:51:20 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-01-29 18:22:17 +0200

slelievre gravatar image

Use Python string formatting.

Find more information about Python string formatting at https://pyformat.info.

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

Stats

Asked: 2018-01-29 15:58:25 +0200

Seen: 290 times

Last updated: Jan 29 '18