Weave.jl icon indicating copy to clipboard operation
Weave.jl copied to clipboard

Output markdown with math as images

Open cscherrer opened this issue 4 years ago • 6 comments

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?

cscherrer avatar Mar 08 '20 16:03 cscherrer

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.

rikhuijzer avatar Jun 12 '20 12:06 rikhuijzer

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

cscherrer avatar Jun 12 '20 13:06 cscherrer

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)

tlienart avatar Jun 12 '20 14:06 tlienart

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 :)

cscherrer avatar Jun 12 '20 15:06 cscherrer

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)

tlienart avatar Jun 12 '20 15:06 tlienart

@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.

rikhuijzer avatar Jun 12 '20 20:06 rikhuijzer