I am using the externalization library of tikz to have most of the pictures compiled only once and just included in later LaTeX runs.

Once in a while I would like to redo all the images, for example after making changes to the font. To achieve this I used to manually delete the externalized files, OR adding the line \tikzset{external/force remake} somewhere before my first picture and commenting it for the future runs.

Since I just discovered arara I would love to have myself some automation ;)

How do I achieve with arara to either

  • delete the content of an entire folder, not knowing how many files are in there or what they're called or
  • add a line of code in the .tex file for one single run, in this case: \tikzset{external/force remake}

Sorry, but I don't have a single clue on how to start with rules or directives. But this snippet could serve as a starting point

% arara: cleanfolder: { folder: tikzternalize }
% !arara: insertforceremake
% arara: pdflatex: { shell: yes }

After some copy/pasting from existing rules and research I came up with a working solution, although I am not entirely happy with it...

Instead of removing all the files from an exisiting folder, I simply delete the directory and recreate it in the same place. Empty, of course.

# Rule for deleting the contents of a folder with arara
identifier: cleanfolder
name: CleaningTool for a whole folder
 - <arara> @{ isWindows( "cmd /c rmdir /s/q", "rm -f" ).concat(' "').concat(folder).concat('"') }
 - <arara> @{ isWindows( "cmd /c md", "mkdir").concat(' "').concat(folder).concat('"') }
 - identifier: folder
   flag: <arara> @{parameters.folder}

I would be very happy with any comment on this, for I think the problem could be solved a lot more "elegantly" than with what I produced.


I even managed to address the second part of my question myself. Inspired by Chris' answer to Using arara to compile powerdot twice I modified the pdflatex rule that is shipped with arara to define some sort of switch command that triggers the desired action in the .tex file if the switch is correctly defined.

rule: pdflatexwithswitch

identifier: pdflatexwithswitch
name: run PDFLaTeX with specified switch and optional value
command: <arara> pdflatex @{action} @{draft} @{shell} @{synctex} @{options} "\def\@{switchname}{@{switchvalue}}\input{@{file}}"
- identifier: action
  flag: <arara> --interaction=@{parameters.action}
- identifier: shell
  flag: <arara> @{isTrue(parameters.shell,"--shell-escape","--no-shell-escape")}
- identifier: synctex
  flag: <arara> @{isTrue(parameters.synctex,"--synctex=1","--synctex=0")}
- identifier: draft
  flag: <arara> @{isTrue(parameters.draft,"--draftmode")}
- identifier: options
  flag: <arara> @{parameters.options}
- identifier: switchname
  flag: <arara> @{parameters.switchname}
- identifier: switchvalue
  flag: <arara> @{parameters.switchvalue}
  default: 0

The rule in action:


% arara: pdflatexwithswitch: { shell: yes, switchname: forceremake, switchvalue: doit }
\ifthenelse{\isundefined{\forceremake}}{}{\ifthenelse{\equal{\forceremake}{doit}}{\tikzset{external/force remake}}{}}

I am much more content with this one. Comments still welcome.

  • 2
    It may be more convenient to use mode=list and make for the external library, which creates a makefile for generating the figures. To force the figures to be re-created, you'd need to use the -B flag (if memory serves me right) when running the makefile. – sudosensei Mar 15 '14 at 17:20
  • @sudosensei : thanks for the input. I can't, however, seem to get it to work that way. I use Make for Windows and when running make -f demo.makefile I get an error. Any hints? – Huugo Mar 17 '14 at 15:18
  • I can try to help. :-) What error are you getting? – sudosensei Mar 17 '14 at 16:32
  • @sudosensei: here it is "process_begin: CreateProcess(NULL, cat demo.figlist, ...) failed. process_begin: CreateProcess(NULL, cat demo.figlist, ...) failed. All images exist now. Use make -B to re-generate them." – Huugo Mar 17 '14 at 16:52
  • That error looks closer to C than LaTeX -- weird. Maybe you should consider posting a new question? – sudosensei Mar 17 '14 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.