TransWikia.com

Automatic creation of caching directories

TeX - LaTeX Asked on January 26, 2021

The following MWE writes a cache file to the tikzcache directory

documentclass{article}
  usepackage{tikz}
  usetikzlibrary{external}
  tikzexternalize
  tikzsetexternalprefix{tikzcache/}
begin{document}
  tikzsetnextfilename{myfig}
begin{tikzpicture}
  node at (1,1) {test};
  node at (2,2) {test2};
end{tikzpicture}
end{document}

It seems I need to compile it with:

pdflatex -shell-escape ...

First of all, why -shell-escape is required?
Based on my knowledge, -shell-escape enables the TeX primitive write18{command} construct. This construct writes to the special stream 18, which is not an actual file, but a way of sending commands to the system shell. However, creating the cached file should be possible with the non-privileged TeX primitive write. Besides security, since one typically builds PDFs with some LaTeX editor, that requires -shell-escape to be set in the editor build commands, which makes the LaTeX file non-portable.

Also, to reduce clutter,

tikzsetexternalprefix{tikzcache/}

sets to write TikZ cached files in the tikzcache directory.
My problem is that this directory should already exist. I could create it automatically in LaTeX with an immediatewrite18{...} command. However, besides requiring a -shell-escape, the command would be far from simple.
In fact, to avoid the a failure, one should add the logic to skip file creation after the first build, that is when the directory already exist. In Linux that could be as simple simple as that:

immediatewrite18{mkdir -p tikzcache}

However, that would not work under different systems (Windows), again making the .tex file non-portable.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP