Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String interpolation fails on Markdown #144

Closed
sschmidhuber opened this issue Jun 4, 2024 · 2 comments
Closed

String interpolation fails on Markdown #144

sschmidhuber opened this issue Jun 4, 2024 · 2 comments

Comments

@sschmidhuber
Copy link

sschmidhuber commented Jun 4, 2024

Hello,
I'm not sure if I identified the issue correctly, so the title might be misleading...

But here my problem, I have the following cell in my qmd file:

using Markdown

foo = "Some string"
md"$foo"

Which worked with the old IJulia based renderer and execuutes as expected in the REPL. However, if I try to render a report with QNR I get the following error:

Error 1 of 1
@ C:\...\...\test.qmd:11
Error showing value of type Markdown.MD
MethodError: no method matching latex(::IOContext{IOBuffer}, ::String)

Closest candidates are:
  latex(::IO, ::Markdown.Paragraph)
   @ Markdown C:\Users\...\AppData\Local\Programs\Julia-1.10.0\share\julia\stdlib\v1.10\Markdown\src\render\latex.jl:48 
  latex(::IO, ::Markdown.Admonition)
   @ Markdown C:\Users\...\AppData\Local\Programs\Julia-1.10.0\share\julia\stdlib\v1.10\Markdown\src\render\latex.jl:69 
  latex(::IO, ::Markdown.HorizontalRule)
   @ Markdown C:\Users\...\AppData\Local\Programs\Julia-1.10.0\share\julia\stdlib\v1.10\Markdown\src\render\latex.jl:103
  ...

Stacktrace:
 [1] latex(io::IOContext{IOBuffer}, content::Vector{Any})
   @ Markdown C:\Users\...\AppData\Local\Programs\Julia-1.10.0\share\julia\stdlib\v1.10\Markdown\src\render\latex.jl:23
 [2] latex
   @ Markdown C:\Users\...\AppData\Local\Programs\Julia-1.10.0\share\julia\stdlib\v1.10\Markdown\src\render\latex.jl:19 [inlined]
 [3] show(io::IOContext{IOBuffer}, ::MIME{Symbol("text/latex")}, md::Markdown.MD)
   @ Markdown C:\Users\...\AppData\Local\Programs\Julia-1.10.0\share\julia\stdlib\v1.10\Markdown\src\render\latex.jl:174
 [4] show(io::IOContext{IOBuffer}, m::String, x::Markdown.MD)
   @ Base.Multimedia .\multimedia.jl:123

ERROR: Internal julia server error

Adding a leading blank like md" $foo", renders correctly.

I'm using Julia 1.10 and Quarto 1.5.40.

@MichaelHatherly
Copy link
Collaborator

Markdown has some weird behaviours around interpolation that tends to cause this kind of problem.

In a normal REPL:

julia> using Markdown

julia> foo = "Some string"
"Some string"

julia> latex(md"$foo")
MethodError: no method matching latex(::IOBuffer, ::String)

Closest candidates are:
  latex(::IO, ::Markdown.HorizontalRule)
   @ Markdown ~/.local/share/mise/installs/julia/1.10.3/share/julia/stdlib/v1.10/Markdown/src/render/latex.jl:103
  latex(::IO, ::Markdown.Paragraph)
   @ Markdown ~/.local/share/mise/installs/julia/1.10.3/share/julia/stdlib/v1.10/Markdown/src/render/latex.jl:48
  latex(::IO, ::Markdown.BlockQuote)
   @ Markdown ~/.local/share/mise/installs/julia/1.10.3/share/julia/stdlib/v1.10/Markdown/src/render/latex.jl:56
  ...

     (stacktrace)
      (user)
 >     Markdown
   +    latex @stdlib/Markdown/src/render/latex.jl:23
   +    latex @stdlib/Markdown/src/render/latex.jl:19
   +   Base
   +   [inlined]
   +   Markdown
   +   [top-level]
   +  (system)

julia> latex(md" $foo")
"Some string\n\n"

So I'd describe this as an upstream issue and not QNR-specific.

@MichaelHatherly
Copy link
Collaborator

There is nothing we can do directly in this package besides hacks around the issue. I'm going to close this one @sschmidhuber as unactionable. The place to fix this is in Markdown itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants