7

This solution works perfectly if the main is in the same directory of the chapter file.

But suppose I have:

maindirectory
  main.tex
  chapterdirectory
    chapter.tex

How can I compile main.tex from chapter.tex? (I'm using Windows 10).

I tried with:

% arara: pdflatex: { files: [ "C:\maindirectory\main.tex" ] }

and other various combinations but it seems that arara accepts only the file name.

This is the same naive question Diaa Abidou asked in his comment, which remained unanswered, unfortunately.

  • % arara: pdflatex: { files: [ "../main.tex" ] } works here (Linux) in that arara finds and runs main.tex in the directory above, but with \input{chapterdir/chapter} it fails in that pdflatex can't find the file, due to (I think) being run from the chapterdir folder, and not the maindir folder. – Torbjørn T. Mar 14 '18 at 8:11
  • @TorbjørnT. Tonight I'll try "../main.tex" or "..\main.tex" on Windows and let you know. – CarLaTeX Mar 14 '18 at 8:47
  • Finding the file is not enough. To compile successfully one should be in the folder of main.tex. So the question is, if arara is allowed to switch into the parent directory of the current directory and then run something there. I'm not sure that I would like it if this were possible. – Ulrike Fischer Mar 14 '18 at 9:36
  • @UlrikeFischer I didn't imagine it was so complicated – CarLaTeX Mar 14 '18 at 9:38
  • Paulo just said that in 3.0 it is not possible. arara 4.0 will be able to do it. But be aware that it is a security issue if you can switch to an outside folder. E.g. I have a test folder and if some filecontents-environment goes wrong and overwrites files there I don't care. But if it would delete files in a parallel folder it would be a real problem. – Ulrike Fischer Mar 14 '18 at 9:41
8

Version Status Documented

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! :)

  • im now using 4.0 and this does not work for me. Did this feature make it in to the last version bump? – novski Sep 11 '18 at 19:29
  • 1
    @novski Hi, which feature are you referring to? :) I updated the answer in order to cover the two aforementioned approaches, hope that helps. :) – Paulo Cereda Sep 12 '18 at 10:52
  • Eventually, I decided to compile from the main, I don't like to create a custom pdflatex directive, because I should create also a biber one and myanyother ones... – CarLaTeX Jan 19 at 10:14

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.