Processing math: 0%
Ask Your Question
3

How to print trailing spaces?

asked 5 years ago

bso gravatar image

updated 5 years ago

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

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
2

answered 5 years ago

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)

Preview: (hide)
link

Comments

Very interesting. Thanks.

bso gravatar imagebso ( 5 years ago )
1

answered 5 years ago

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)

Preview: (hide)
link

Comments

Thanks. Extremely useful for fine grain control.

bso gravatar imagebso ( 5 years ago )
1

answered 5 years ago

azerbajdzan gravatar image

updated 5 years ago

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)

Preview: (hide)
link

Comments

Nice. Thanks!

bso gravatar imagebso ( 5 years ago )

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: 5 years ago

Seen: 1,033 times

Last updated: Jan 09 '20