Ask Your Question
3

How to print trailing spaces?

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

bso gravatar image

updated 2020-01-08 18:19:15 +0200

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
2

answered 2020-01-09 04:44:50 +0200

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-09 06:02:24 +0200 )edit
1

answered 2020-01-09 13:13:57 +0200

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 21:39:08 +0200 )edit
1

answered 2020-01-08 18:35:24 +0200

azerbajdzan gravatar image

updated 2020-01-08 18:51:17 +0200

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

Question Tools

1 follower

Stats

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

Seen: 818 times

Last updated: Jan 09 '20