Julia: Markdown strings and interpolation

Created on 4 May 2016  Â·  6Comments  Â·  Source: JuliaLang/julia

How to do interpolation in markdown strings? Is the intended way to do it using dollars like in ordinary strings?
If so it seems that interpolation dollars and latex dollars are sometimes confused in markdown strings. For example the following snipped works:

x = "3"
md"""This works $(x) 

* a
* b
"""

This works 3

  • a
  • b

While

md"""This works not 

* a $(x)
* b
"""

Throws an error:

MethodError: `latexinline` has no method matching latexinline(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Symbol)
Closest candidates are:
  latexinline(::IO, !Matched::Base.Markdown.LaTeX)
  latexinline(::IO, !Matched::Base.Markdown.Code)
  latexinline(::IO, !Matched::Array{T,1})
  ...
bug docsystem

Most helpful comment

37130

All 6 comments

This is because the $ is both used for string interpolation and LaTeX, that is why it is throwing the error, I have no idea how to get around it though.

I think a related problem is that md"- $(10/2)" prints as * :(10 / 2) (no error here) while `md"$(10/2)" is printed as 5.0.
So it seems the $ is interpreted differently when in a keypoint.

String interpolations fails inside table entries as well

julia> x=3
3
julia> md"""
       this works

       x=$x

       this doesn't work

       | name | value |
       |------|-------|
       |  x   |  $x   |

       """
  this works

  x=3

  this doesn't work

  name value
  –––– –––––
     x    $x

Bump! Is this a hard thing to fix? It's holding back some really nice uses within Pluto.jl: https://github.com/fonsp/Pluto.jl/issues/208.

Perhap using Markdown.parse instead of md is a possibility.

37130

Was this page helpful?
0 / 5 - 0 ratings