Ask Your Question

# 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

## 3 Answers

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

## Comments

Very interesting. Thanks.

( 2020-01-09 06:02:24 +0200 )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

## Comments

Thanks. Extremely useful for fine grain control.

( 2020-01-09 21:39:08 +0200 )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

## Comments

Nice. Thanks!

( 2020-01-08 19:33:35 +0200 )edit

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2020-01-08 18:07:11 +0200

Seen: 234 times

Last updated: Jan 09 '20