
This has been a discussion since the dawn of time, whether we should use only the file name or the entire reference. Hence, version 4.0 has two variables for that:
file refers to the the file name, as main.tex (no directory reference), and
reference refers to the full (normalized, canonical) path.
Note: You can take a look at the list of extracted directives in the log file (namely, arara.log, enabled with the --log command line option) and see the actual values for file and reference. Also observe that, for each element of files, the tool will add a directive of its own.
Sometimes we are restricted to the coverage of TeX tools, so we opted for the easiest solution. However, I must point out that version 4.0 allows project-based rules, so the cleanest solution in your case is to have:
- an
arara configuration file, and
- a custom
pdflatex rule with reference instead of file
Then
% arara: pdflatex: { files: [ 'chapters/main.tex' ] }
will work as expected. Another possibility (way more advanced) is to keep file but change the working directory during command creation. I will present both solutions as follows.
Regarding security issues, we have a Turing-complete environment in the rule scope, so little to nothing could be done in this case. Deeply sorry. :)
So let us cover the possibilities. Here is a possible solution using a project-based configuration file and a modified engine rule (in this example, I will use pdflatex). First, I create the following configuration file (version 4.0 allows 4 names for the configuration file: araraconfig.yaml, .araraconfig.yaml, arararc.yaml and .arararc.yaml. I will use the first option. Note that there is a lookup order, so take a look at the user manual for more details):
araraconfig.yaml (placed at the root level of your project)
!config
paths:
- '.'
Now, let us copy the original pdflatex.yaml rule to the root level of the project. Now, pdflatex directives will refer to this rule instead of the default one (as the paths key in the configuration file sets the current directory to be searchable first).
First approach: replace file by reference
This is the easiest solution. Simply replace lines 16 and 17 of pdflatex.yaml
return getCommand('pdflatex', interaction, draft, shell,
synctex, options, file);
by these two:
return getCommand('pdflatex', interaction, draft, shell,
synctex, options, reference);
Note that we simply replaced file by reference. That should suffice. The directive usage would be as follows:
% arara: pdflatex: { files: [ 'chapters/main.tex' ] }
Second approach: add a working directory option
This solution involves adding an extra argument to our rule (we can append these lines to pdflatex.yaml):
- identifier: directory
flag: >
@{
parameters.directory
}
Now we should replace lines 16 and 17 of pdflatex.yaml
return getCommand('pdflatex', interaction, draft, shell,
synctex, options, file);
by these:
if (isEmpty(directory)) {
return getCommand('pdflatex', interaction, draft, shell,
synctex, options, file);
}
else {
return getCommandWithWorkingDirectory(directory, 'pdflatex',
interaction, draft, shell, synctex, options, file);
}
And then the directive usage should be along those lines:
% arara: pdflatex: { files: [ 'main.tex' ], directory: chapters }
Hope that helps! :)
% arara: pdflatex: { files: [ "../main.tex" ] }works here (Linux) in thatararafinds and runsmain.texin the directory above, but with\input{chapterdir/chapter}it fails in thatpdflatexcan't find the file, due to (I think) being run from thechapterdirfolder, and not themaindirfolder. – Torbjørn T. Mar 14 '18 at 08:11