Blogging with Julia code blocks

question
web

#1

I started a blog (https://juliohm.github.io) where I am planning to use Julia for my examples. GitHub Pages and Jekyll are the recommended tools by GitHub and many people from the R community have developed plugins for running R code directly when the website is built:

I wonder if someone knows how to get Julia code working in a similar way, that is, I could write a snippet of Julia inside of a block like

```julia
```

and have the block and results printed on the webpage.


#2

AFAIK Nikola, another static site generator, works with Jupyter notebooks.


#3

You could also use Weave with a custom template.


#4

Is there an example that integrates Hugo with Weave.jl for blogging?


#5

Not that I know of. Probably the easiest way is just to convert to from .jmd format to markdown. There is a script for calling weave from command line https://github.com/mpastell/Weave.jl/blob/master/bin/weave.jl so that’s easier to use with Makefiles (although I need to update it to support all current input parameters, feel free to open an issue to remind me if you want to use it and something is missing).


#6

Thanks, I opened an issue. But I don’t insist on Hugo, so if there is an example of how to get Weave.jl to work with any static site generator (eg Jekyll) it would be useful.


#7

Thanks for sharing Weave @mpastell, I think it is my best bet. I have to figure out how to run it and paste the HTML in place. Also wondering how to make it work with GitHub pages, if I need to install Julia there too.


#8

@mpastell, Jekyll supports plugins in case we need to add one for Weave there. Do you have experience with it?


#9

Figured it out with Hugo. Will work out the quirks and make it public soon.


#10

If someone can figure out a solution with Jekyll, that would be highly appreciated.


#11

@oxinabox has a Jekyll blog which has syntax highlighting. You might want to look at his repo.

If there’s a way to use GeSHi with Jekyll, then a version of this would work.


#12

Thank you @ChrisRackauckas, my main concern is the output, I will see if someone has written a Jekyll plugin for that, I remember finding one for TiKZ that basically runs pdflatex and puts the output in HTML: https://gist.github.com/hack-ghost/6139753

Maybe we could adapt it to run Weave.jl instead.


#13

You can use something like this to transform Julia code from Jupyter notebooks to HTML, and use that?

But something from Weave.jl would likely be more elegant.

FYI, the output that comes out of this is quite horrid. The Jupyter auto-conversion creates some pretty nasty HTML and LaTeX to do it’s coloring, so I’d only use it if it’s copy/pasted


#14

Thank you @ChrisRackauckas, I am really hoping to find a cleaner way, maybe I should ask in Jekyll discourse…


#15

I took a look at @oxinabox 's setup and it’s pretty clean. You just say where to start and end highlighting. See this:

for this:

http://white.ucc.asn.au/2017/01/24/JuliaML-and-TensorFlow-Tuitorial.html

What is that missing? Maybe we can find a quick solution.


#16

It is awesome, and definitely better than what I have now, I was just wondering if we could make it literate: write the code and get the result in HTML directly. @oxinabox solution is pasting the output manually, I think I will go with it.


#17

I imagine that also with Jekyll you can write your code in literate .jmd files, with YAML front matter, call weave.jl to generate the .md files, and then use jekyll to generate the static pages. That’s my workflow with Hugo, the hard part was dealing with the paths of generated plots.


#18

This is how my Julia code is looking like:

The syntax isn’t quite right and I can’t have the output generated automatically :cry:


#19

Don’t forget to submit the feed to JuliaBloggers :slight_smile:


#20

Nice blog post! Maybe you can extend it to give an example of the continuous-time process?