JunoLab / Weave.jl

Scientific reports/literate programming for Julia
http://weavejl.mpastell.com
MIT License
830 stars 96 forks source link

Output markdown with math as images #287

Open cscherrer opened 4 years ago

cscherrer commented 4 years ago

Weave is pretty great for quickly writing notes to go into a Github repo. Unfortunately, Github has decided not to support LaTeX of any sort.

Can Weave render math environments into images in a subfolder and then output markdown with math replaced with image links? This would make my life a lot easier, and I suspect many others would use it.

Or maybe this would be a pandoc thing?

rikhuijzer commented 4 years ago

You can do this with Pandoc and Haskell: https://github.com/liamoc/latex-formulae. I am using it for my website. A build image and an example use-case are at https://github.com/rikhuijzer/hugo-latex-as-image. I'm planning to create a Julia implementation of the functionality, which will be available at https://github.com/rikhuijzer/GenTex.jl. I don't think coupling it into Weave is necessary nor desired. It would be an project benefiting non-weave users as well. Currently, I read the Markdown generated by Weave and substitute all the equations.

cscherrer commented 4 years ago

This looks great, and I see you already have this connected to Hugo and Hakyll. Could be a really nice addition to Franklin.jl as well!

cc: @tlienart

tlienart commented 4 years ago

Hey @cscherrer thanks for the ping, I'm not sure I understand what would be the possible addition to Franklin? I mean Franklin allows pre-rendering of maths so that you don't have to load the JS lib and basically just have to use the katex css and the generated HTML; this works online and offline and looks much better than saved images (and is lighter). Sorry if I misunderstand the possible use case :)

(of course for Github readme I understand this would be useful as you can't load your own css I think but that's outside the scope of franklin)

cscherrer commented 4 years ago

I think the opportunity is for anything not supported by KaTeX, for example TikZ. But then I haven't had the chance to do much with Franklin yet, so I don't have a good sense of the design space :)

tlienart commented 4 years ago

oh right... yes that makes sense. Yes for that it would be very easy to add the hook that @rikhuijzer is suggesting to be used in Franklin; you would write something like this in utils.jl:

using GenTex

function lx_teximg(com, _)
    content = Franklin.content(com.braces[1])
    # here call an appropriate function from GenTeX and return the html to plug in the image
end

and you'd call that from any .md file with

\teximg{
<!-- here your Tikz code -->
}

Note: @rikhuijzer would GenTex support libraries like Tikz? if so how would you load those? (I should probably ask that on your repo, sorry)

rikhuijzer commented 4 years ago

@tlienart Similar to https://github.com/liamoc/latex-formulae. There Liam O'Connor lets users pass LaTeX packages. Demo at http://liamoc.net/posts/2013-11-13-imperativereasoning.html. Anyway, I'm not making any promises yet on whether I'll finish the package. I shouldn't have mentioned it here yet. EDIT: Can generate LaTeX to SVG and take the LaTeX baseline in account. Example output and project available at https://github.com/rikhuijzer/GenTex.jl.