Kramdown latex usepackage algorithm pseudocode

I am using kramdown and I am able to get latex formulas displayed correctly. Now I would like to add an algorithm using the latex package algorithm2e. This answer on the tex.stackexchange shows that it works with markdown and pandoc.

I added the package in a post on my jekyll site using minimal mistakes theme in the preamble and copied the example from stackexchange but the algorithm does not get rendered as expected.

How can I add extra latex packages using kramdown?

The answer of an issue in kramdown states to use a custom latex template. However, I have no idea how to use a new template.

Here is the link to the repo of my github page.
And here is the post with the rendering issues.

I don’t think that is going to work, the package you are trying to load is not a jekyll plugin (?) so I would not expect it to do anything.

I would google jekyll algorithm2e and see if you can find anyone that has done what you want - though I did that and did not see much.

It is possible someone has made a plugin to do what you want.

The other links you have look like they are not using jekyll - not sure what is generating their site, might be worth asking.

Jekyll is using kramdown, but you don’t exactly have direct access to it as jekyll is inbetween you and kramdown - at least as I understand it.

Thanks for looking at this issue.

As you suggested I googled already and could not find any helpful information on using latex packages with jekyll.

Your correct, the other links use pandoc and kramdown directly.

I also don’t know if this forum is the right place to ask this kind of question as it is kind of a feature request, I guess. I will post my question on github too.

you are probably in plugin territory - I don’t see this being a core thing jekyll would support, but can’t hurt to ask (I’m just a user)!

@fjp I see you were able to solve this issue. Would love it if you could share how you did it.

1 Like

It looks like @fjp used pseudocode.js, which requires KaTeX, to render the raw LaTeX pseudocode.

I can follow these steps through and build it manually, but

$ pandoc -f latex -t gfm my_file.tex -o

will strip all of the LaTeX code from an algorithm environment except for the basic $x+y$-type expressions. The links posted above re: custom templates only seem to apply when converting from markdown to LaTeX. The pandoc --filter option only works after the file is parsed. Pandoc parses out the surrounding \begin and \end statements, without making a Div to separate the algorithm environment, so it is nearly impossible to recreate the algorithm using a filter. Does anyone know how to “shield” an environment from pandoc to preserve the raw LaTeX? It would then be easy to run your file through pandoc and add a Liquid tag:

{% include pseudocode.html id="1" code="
" $}


I’ve answered my own question for the time being…

Following this answer + comment, you can wrap your algorithm environment like so:


which gets converted to

``` latex


This method will preserve the LaTeX file for compilation to pdf, but the \iffalse statements are ignored by pandoc. It’s sketchy since it seems to rely on a bug, but it works. All that is left is to clean up the \fi and \iffalse lines leftover.

It’d be nice to have a more robust way of telling pandoc how to handle unknown environments though, or at least have it wrap them in a Div so you can process them with a filter.