How to interpolate variable into markdown codeblock in Pluto.jl?

778 Views Asked by At

In Pluto if I try to include an interpolated value in the markdown string, it renders the string without interpolating the value. enter image description here

I'd like the string to render as: My variable's value is: 10

2

There are 2 best solutions below

0
Stepan Zakharov On BEST ANSWER

Markdown itself isn't intended to interpolate variables. You may use Markdown.parse instead of md"" literal. This allows the string to interpolate the variables before passing to the Markdown parser.

Markdown.parse("""
My variable's value is: `$x`.
""")

enter image description here

0
a2k42 On

I had a little trouble combining this with math, which uses the $ symbol as a delimiter.

One solution was to use LaTeXStrings.jl

using LaTeXStrings

L"""\text{My variable's value is } %$(x)"""

Using @Stepan Zakharov's approach

Markdown.parse("""My variable's value is \$x\$""")

Markdown.parse("""\$\\mu\$ and \$x\$""")

but I found odd line breaking behaviour this way.