Ask Your Question
2

How to print trailing spaces?

asked 2020-01-08 11:07:11 -0600

bso gravatar image

updated 2020-01-08 11:19:15 -0600

Pretty_Print / show seems to delete trailing spaces:

reset()
var('x t')
Psi = function('Psi')(x, t)
V = function('V')(x)
show('Plug ', Psi, ', ', diff(Psi, t), ', ', diff(Psi, x, x), ' into ', V)

See after "Plug" and after "into" (screenshot taken from CoCalc Jupyter Sage 8.9 Kernel): image description

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2020-01-08 21:44:50 -0600

dsejas gravatar image

Since the show command uses LaTeX to typeset, you can use the ~ LaTeX command. Try this:

reset()
var('x t')
sp = LatexExpr('~')
Psi = function('Psi')(x, t)
V = function('V')(x)
show('Plug', sp, Psi, ', ', diff(Psi, t), ', ', diff(Psi, x, x), sp, 'into', sp, V)

The result is $\newcommand{\Bold}[1]{\mathbf{#1}}\verb|Plug| ~ \Psi\left(x, t\right) \verb|,| \frac{\partial}{\partial t}\Psi\left(x, t\right) \verb|,| \frac{\partial^{2}}{(\partial x)^{2}}\Psi\left(x, t\right) ~ \verb|into| ~ V\left(x\right)$

edit flag offensive delete link more

Comments

Very interesting. Thanks.

bso gravatar imagebso ( 2020-01-08 23:02:24 -0600 )edit
0

answered 2020-01-09 06:13:57 -0600

Juanjo gravatar image

You can gain more control on spacing and fonts if you also use the html function and the format method, since then you can employ the resources of the HTML language. Try this:

reset()
var('x t')
Psi = function('Psi')(x, t)
V = function('V')(x)
format_string = '<strong>Instructions</strong><br>Plug ${}$, ${}$ and ${}$ into ${}$'
terms = [latex(i) for i in [Psi, diff(Psi, t), diff(Psi, x, x), V]]
show(html(format_string.format(*terms)))

The output is:

Instructions
Plug $\Psi\left(x, t\right)$, $\frac{\partial}{\partial t}\Psi\left(x, t\right)$ and $\frac{\partial^{2}}{(\partial x)^{2}}\Psi\left(x, t\right)$ into $V\left(x\right)$

edit flag offensive delete link more

Comments

Thanks. Extremely useful for fine grain control.

bso gravatar imagebso ( 2020-01-09 14:39:08 -0600 )edit
0

answered 2020-01-08 11:35:24 -0600

azerbajdzan gravatar image

updated 2020-01-08 11:51:17 -0600

You can use tabulator character "\t":

show('Plug\t', Psi, ', ', diff(Psi, t), ', ', diff(Psi, x, x), ' into\t', V)

$\newcommand{\Bold}[1]{\mathbf{#1}}\verb|Plug | \Psi\left(x, t\right) \verb|,| \frac{\partial}{\partial t}\Psi\left(x, t\right) \verb|,| \frac{\partial^{2}}{(\partial x)^{2}}\Psi\left(x, t\right) \phantom{\verb!x!}\verb|into | V\left(x\right)$

Or if you want a bigger gap add as many spaces before "\t" as you want:

show('Plug     \t', Psi, ', ', diff(Psi, t), ', ', diff(Psi, x, x), ' into     \t', V)

$\newcommand{\Bold}[1]{\mathbf{#1}}\verb|Plug|\phantom{\verb!xxxxx!}\verb| | \Psi\left(x, t\right) \verb|,| \frac{\partial}{\partial t}\Psi\left(x, t\right) \verb|,| \frac{\partial^{2}}{(\partial x)^{2}}\Psi\left(x, t\right) \phantom{\verb!x!}\verb|into|\phantom{\verb!xxxxx!}\verb| | V\left(x\right)$

edit flag offensive delete link more

Comments

Nice. Thanks!

bso gravatar imagebso ( 2020-01-08 12:33:35 -0600 )edit

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-01-08 11:07:11 -0600

Seen: 44 times

Last updated: Jan 09