# Can arara detect a rule inside a \input file ?

I started to use the nice `arara` package to automate my compilation process for my thesis.

I know it is better to place the rules using e.g. `% arara : pdflatex` placed at the beginning of the `.tex` file to be compiled but I was wondering if it was possible to place this call inside an file called with `\input{...}`.

The reason is the following :

I would like to use `arara` on multiple files but these do not posess any rules. However, they share some `header.tex` file containing macro and style definitions, which is called with `\input{}` just after the `\documentclass[]{}` definition.

So I'd rather modify the common `header.tex` file instead of all my other files.

• I have no idea about arara, but I guess it doesn't parse the file at all, only the first n lines for `% arara`. – Skillmon Dec 12 '18 at 14:06
• @Skillmon Well, not only the first n lines in version 4, but at least no \input files. – TeXnician Dec 12 '18 at 14:08
• Since the file name that you `\input` can be built from TeX macros, arara would have to contain a complete TeX engine to do this completely. And then somebody is going to want to correctly handle `\include`s in `\if...\fi` constructions, rules in `\include` files taking account of `\includeonly`, etc - it's probably easiest for the developers to "just say no"! – alephzero Dec 12 '18 at 14:24
• @alephzero Clearly you don't know the developer. :) – Alan Munn Dec 12 '18 at 14:31
• @alephzero I think `\@filelist` keeps the heavy lifting within TeX. – StrongBad Dec 12 '18 at 16:31

I am sorry, `arara` limits the directive lookup scope to the current document. It would be quite challenging to detect special macros and process them accordingly, like following a file through `\input`, `\include` or similar streams. It is really by design.

That's being said, I've been thinking of adding a new feature in the near future called metadirective. That way, we can change the inner workings of the tool itself at runtime. Sorry if it sounds too vague for now, but your question seems to be one of the cases a metadirective could be used for external file reading. I still do not have the faintest idea of how it would be. `:)`

However, as alephzero mentioned in the comments, correctly parsing TeX would require a TeX engine in itself to resolve nontrivial scenarios. I want `arara` to be the emacs of the TeX world, but not quite the TeX engine of the TeX world (yet). `:)` Let me check how things go in the next weeks, so I can work on a new feature draft.

Regarding your scenario, perhaps the `--preamble` command line flag could be of interest. To quote my lovely user manual that took me a lifetime to write it: `:)`

Some TeX documents require the same automation steps, e.g, a set of articles. To this end, so as to avoid repeating the same preamble over and over in this specific scenario, `arara` has the possibility of setting predefined preambles in a special section of the configuration file identified by a unique key for later use. This command line option prepends the predefined preamble referenced by the `name` key to the current document and then proceeds to extract directives, as usual. For instance:

``````twopdftex: |
% arara: pdftex
% arara: pdftex
``````

Source file: `doc9.tex`:

``````Hello world.
\bye
``````

In this example, we have a preamble named `twopdftex` and a TeX file named `doc9.tex` with no directives. Of course, our tool will complain about missing directives, unless we deliberately inject the two directives from the predefined preamble into the current execution:

``````\$ arara -p twopdftex doc9.tex
....
(PDFTeX) PDFTeX engine .................................. SUCCESS
(PDFTeX) PDFTeX engine .................................. SUCCESS
Total: 0.96 seconds
``````

Hope it helps. `:)`

• It took much less time to write the user manual than your thesis. `:-)` – egreg Dec 12 '18 at 15:46
• @egreg that's accurate. `:)` – Paulo Cereda Dec 12 '18 at 16:03
• I was afraid it was not possible. As this is more of a laziness matter on my side, it is not such a big deal. Thank you very much for your advice anyway ! – BambOo Dec 12 '18 at 16:12

While `arara` cannot figure out what files are going to be read you can write a directive that will call `arara` on a different file. I think I have a workflow somewhat similar to yours where I want all my directives in a file called something like `header.tex` and I work on `body.tex`. I list all my directives in `header.tex` and in `body.tex` I have a single directive

``````% arara: mainfile: { rootfile: header.tex }
``````

This directive is defined as `mainfile.yaml`:

``````identifier: mainfile
name: MAINFILE
commands:
- name: Run Arara on file
command: >
@{
return getCommand('arara', '-v', rootfile);
}
arguments:
- identifier: rootfile
flag: >
@{
return parameters.rootfile;
}
``````

If you want to automatically deal with directives spread across arbitrary files that may or may not be included, you might be able to hack something together with `\listfiles` to output all the files that are loaded and then have a new directive that calls `mainfile` on all the sub files, but this sounds difficult and probably not worth it.

• ooh I like this approach! – Paulo Cereda Dec 12 '18 at 16:32