LaTeXStrings deletes strings in Julia JN

I am using Julia 1.7.0 in Jupyter Notebook. I am trying to print two equations in the notebook using:

println("Separation of variables")

L"""\dfrac{\text{d}y}{\text{d}\xi} \
    = \
    \dfrac{z}{\xi^2} \ """


L"""\dfrac{\text{d}z}{\text{d}\xi} \
    = \
    -\xi^2y^n \ """

However, when I run this, only the second equation is printed out. Is it overwriting the first equation?

Try putting the equations in different cells as a test. The cell is likely only displaying the last line.

A Jupyter notebook only displays the result of the last expression in any given cell. The other lines of code are executed, but their results are simply not displayed unless they call an explicit output function.

If you want to display both strings, you can (a) put then in separate Jupyter cells, or (b) manually call display (the multimedia analogue of println) on the things you want to show, e.g.

display(L"\sqrt{x}")
display(L"\frac{1}{x+1}")
1 Like

Alternatively, if you are just trying to show some text, you don’t need to execute Julia code at all — just change the cell type to “Markdown” and enter Markdown text with equations in $...$:

Separation of variables:

$$    
\dfrac{\text{d}y}{\text{d}\xi}   =  \dfrac{z}{\xi^2} 
$$
    
$$
\dfrac{\text{d}z}{\text{d}\xi}  = -\xi^2y^n
$$
3 Likes

Thanks. When I run the code

display("Separation of variables")

display(L"\dfrac{\text{d}y}{\text{d}\xi} \
    = \
    \dfrac{z}{\xi^2} \ ")


display(L"\dfrac{\text{d}z}{\text{d}\xi} \
    = \
    -\xi^2y^n \ ")

The Separation of Variables has quotes. If I remove the quotes, nothing is displayed at all after the cell. How can I display ‘Separation of Variables’ and the equations without any quotes?

display(Text("Separation of Variables"))

Note that you can also display a block of formatted text, including equations, using the Markdown module. For example:

using Markdown
display(md"""
## Separation of variables:

``
\dfrac{\text{d}y}{\text{d}\xi}   =  \dfrac{z}{\xi^2} 
``

``
\dfrac{\text{d}z}{\text{d}\xi}  = -\xi^2y^n
``
""")
1 Like