JunoLab / Weave.jl

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

New input format for Weave #256

Open sebastianpech opened 4 years ago

sebastianpech commented 4 years ago

I recently wrote a kind of textbook/script for a lecture I'm giving this winter term and used Weave for that. The final form is a pdf, so we needed the TeX based conversion for that (That's the reason I made a few PRs recently). With a simple document, everything was fine. However, adding footnotes, bibliography, graphics made using Weave very difficult (if not impossible). Nevertheless, we found a way by doing some additional parsing and conversion after generation of the TeX files and the result looks quite ok. Yet, this got me thinking: Why not just write a LaTeX document and just replace julia code blocks there without using markdown?

So the idea is as follows. One could use a LaTeX document, similar to the TeX-template file, as an input for Weave. The code chunks could look something like that:

\begin{julia}[term=true, tangle=true]
function foo()
end
\end{julia}

Inline chunks could also be possible with something like \jl{foo()}. Those wouldn't be actual latex commands, but Weave replaces them with lstlisting, so the final document renders correctly. The stylesheet could be added with the Mustache.jl syntax or maybe to stay texy with \usepackage{Weave.jl} (which is also just a placeholder). Everything that's not a code chunk would be added as text and is basically just forwarded to the final document.

I'll pretty sure start developing that, it's more of a questions if that feature should resided in Weave or a separate package. Let me know what you think.

BeastyBlacksmith commented 4 years ago

What would be the difference to pythontex ( which dispite its name also supports execution of julia-code )? That is what have been used in Algorithms for Optimization

sebastianpech commented 4 years ago

I tried pythontex and had the following concerns:

On the other hand pythontex is the more latex like way to go as you don't generate a new set of tex files and the compile process is similar to eg. biblatex.

mpastell commented 4 years ago

You can currently use the noweb format to do that, there is quite old example document that shows the idea: https://github.com/JunoLab/Weave.jl/blob/master/examples/julia_latex.texw (syntax hasn't been updated since Julia 0.4 I think...).

You only need to add the correct regular expressions for the input format that you propose here: https://github.com/JunoLab/Weave.jl/blob/72e7ccfe8ac68c7dfc1ecd0c77b93de81cd5f3c0/src/readers.jl#L23 so I think that should go into Weave and I guess the template is also quite small addition.