I'm developing a plugin in Jekyll that inserts a new Liquid Tag (a block tag) named latex
. It's purpose is to insert a block of LaTeX source code inside a post source file this way:
... post file contents ...
{% latex density=300 usepackages=pstricks-all, %}
\pspicture(5,5)
\psframe(0,0)(5,5) \psline(0,0)(5,5) \psline(0,5)(5,0)
\endpspicture
{% endlatex %}
... post file contents ...
The output post will contain a <img>
tag instead of the Liquid Tag block once compiled and the LaTeX source will be compiled by a chained execution of latex
, dvips
, convert
. So it will depend on external programs (TexLive and ImageMagick).
I've not found any issue with the explained so far. I can take the block of LaTeX, put it in a temporary file, and finally compile it to PNG. The rendered files must be put in the same folder of the post.
But just there I'm stuck: I want to put the generated PNG image to this folder inside the destination
output folder. No problem defining a site-config variable to define the folder (in fact, I do that), nor put a file there. The problem is simple: I can write to the source
folder, but the generated files will not be copied to the destination
folder.
I know the reason: Jekyll generates first and renders afterwards. The copy process happens before the render part, so the generated files will not be copied.
I've found this SO entry: "How to generate files from Liquid blocks in Jekyll?", but the answer doesn't feel right: You must make a two-pass build for the files to be copied.
Also found "Generate file inside _site with Jekyll plugin", but this is not applicable because I don't want to render documents by templates.
The solution I've been planning is this:
- Keep a folder with all the generated files and some index strategy for their final placement.
Implement a
Site
wide method for the final placement procedure, something like:class Site def generate_latex_adds // Code that copies the generated files to destination folders end end
Add
self.generate_latex_adds
calling that method inside thesite_process.rb
script just before theself.cleanup
andself.write
calls.
This will probably solve the problem, but I feel wrong to modify the site_process.rb
. I'm considering pull this Liquid Tag to the community as a GitHub project, and as such, I must document this manual edit of site_process.rb
to the users of this plugin. I know it's probably a common situation and a common solution, but I wonder if there is a better way to pospone the copy of the generated files without modifying core files. I'd like to keep the plugin simple: just copy the plugin file to the _plugins
directory.
Any ideas?
EDIT: I'm more interested in the reasoning that on the actual code. I want to learn, not asking for a code solution.