6

I am currently using arara to give compilation rules for my .tex files. I have a lot of tikz/pgfplots made files which share common settings hosted in a header file, so that I can easily modify a setting, then recompile everything using a for loop e.g.

@FOR /R "rootdir" %%G in (.) DO (
@ Pushd %%G
@ for %%x in (*.tex) do arara "%%x"
@ Popd )
@pause

as I am on a windows machine.

However, this starts/stops arara a big bunch of times and throws very ugly logging to the terminal. So is there a rule or can one be written so that arara is only started once and compiles all files in a specified directory tree.

BambOo
  • 8,801
  • 2
  • 20
  • 47
  • I've heard rumors that file globbing will be part of the next version ;) – TeXnician Oct 08 '19 at 18:09
  • @TeXnician Hmmm, sweet ! Any ideas on the release date ? – BambOo Oct 08 '19 at 20:36
  • Well, it's expected to be released somewhen next year, so probably not the best alternive for you. But what already works is using the listFilesByExtension function in a custom rule. – TeXnician Oct 09 '19 at 12:33
  • @TeXnician you mean something like % arara: ListFilesByExtensions(toFile('/directorypath'),'tex', true); ? – BambOo Oct 09 '19 at 14:29
  • No, you have to write a small rule that does (in MVEL, so that arara will process it) something like a for loop over the result of listFilesByExtension and returns something like getCommand('command', loopvariable). But I'm short of time right now, so let's hope Paulo will see your question (and canonically answer) :) – TeXnician Oct 09 '19 at 15:12

1 Answers1

5

It's as easy1 as writing an own rule using listFilesByExtensions (save this as all.yaml next to your files):

!config
identifier: all
name: All TeX files
commands:
- name: All
  command: >
    @{
        a = [];
        foreach(ref : listFilesByExtensions(".", ["tex"], true)) {
          a.add(getCommandWithWorkingDirectory(ref.parent, [command, ref.name]));
        }
        return a;
    }
arguments:
- identifier: command
  flag: >
    @{
      parameters.command
    }
  default: pdflatex

Then write an arararc.yaml like

!config
paths:
- ./

Your header.tex will then contain % arara: all and all TeX files within the directory tree will be compiled (sequentially). Please note that if you actually have your header.tex called header.tex it will be compiled as well. You could e.g. rename it to header.ltx to avoid it.

1 Actually, the first draft of this rule had to be revised. Thanks to Paulo Cereda for providing an updated rule.

TeXnician
  • 33,589
  • I just tested your solution (I could not this week-end). I created the all.yaml and arararc.yaml files in the root image folder of my main document. My header.tex is not a standalone file, so I never do something like arara header.tex. It is a file that is called with an \input{header} in each tikz/pgfplots graph. To apply what you propose, I created an allcompile.tex file so that I can call it with arara. I actually says that it compiles successfully but with a ridiculously small amount of time. Do you know why ? Is there a way to see what file is actually being compiled ? – BambOo Nov 04 '19 at 09:33
  • Already tried the -v option but it actually gave not much output. The allcompile.tex is in the root image folder and most tex files are contained in sub-folders. Is the listFilesByExtensions search recursive ? – BambOo Nov 04 '19 at 09:47
  • Yep in my case recursive search is fine as all tex files in the tree are graphs. However, the compilation fails, as the working directory is always the root one while it should be the folder containing the actual tex of the graph, hence the @ Pushd / @Popd of my original script. – BambOo Nov 04 '19 at 12:59
  • Well, I just noticed that I do not know enough about Windows bash to see these details. Actually, dealing with working directories is hard. Arara v5 will probably get working directory support but it will not support multiple working directories in one run for several reasons. I will try whether I can come up with a truly recursive logic. – TeXnician Nov 04 '19 at 13:24
  • Thanks for the update, though it does not seem to work. Compilation starts but not in the right directory. Is there a way to print the current value of a variable to the terminal ? I do not know much about yaml. I tried to add something like print path; in the rule but it throws an error. – BambOo Nov 04 '19 at 15:19
  • Run with --dry-run so we can see the working directory after the @ symbol (if applicable). – Paulo Cereda Nov 04 '19 at 15:30
  • @PauloCereda, thanks for the tip. The command built by arara looks like pdflatex .\image-src\image.tex. So basically it fails because it is not working in the right folder. In fact, in the .tex file I have pgfplots calls that try to read data files in the image-src folder, so there should be a current directory change before each pdflatex call. – BambOo Nov 04 '19 at 18:18
  • @TeXnician Just tried that, but it does not work either. I get a [Error: ref.toString().split("\\"): Unexpected internal error near index 1 message. I just checked and there are system independent commands for path splitting in java, e.g. https://stackoverflow.com/q/8075373/9576551 or https://stackoverflow.com/questions/1099859/how-to-split-a-path-platform-independent, but I could not make them work. – BambOo Nov 05 '19 at 09:06
  • @TeXnician, Man that works ! Awesome ! I still have two remarks though. Sorry if they seem dumb, I am not familiar with java and even less with arara custom rules. Is it possible to display the currently being compiled .tex file instead of 'all'. Also, how can I pass options to pdflatex, in the all.yaml ? – BambOo Nov 05 '19 at 09:48
  • @BambOo Unfortunately, the first point is impossible (from my knowledge) because they are within the same task. But for the second one you could try to pass something with options to the command parameter (it should accept command: "pdflatex -option -option"). – TeXnician Nov 05 '19 at 11:19