# How to print trailing spaces?

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):

edit retag close merge delete

Sort by ยป oldest newest most voted

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)$

more

Very interesting. Thanks.

( 2020-01-08 23:02:24 -0600 )edit

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)$

more

Thanks. Extremely useful for fine grain control.

( 2020-01-09 14:39:08 -0600 )edit

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)$

more

Nice. Thanks!

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