25

I am really enjoying the arara tool for automating the compilations of my documents- thanks Paulo and the team :)

I work on a few projects that have a main file (say myfile.tex) that \includes its 'chapter' files. A typical example is

myfile.tex

% arara: pdflatex
\documentclass{article}

\begin{document}

\include{lions}

\end{document}

I can run arara on this file just fine, and pass options to it (such as -v for verbose mode).

I would like to be able to run arara on my 'chapter' file

lions.tex

% arara: mainfile: {name: myfile}
hello world

My first attempt at a 'rule' for arara is as follows

mainfile.yaml

!config
# compile mainfile rule for arara
# author: Chris Hughes
# requires arara 3.0+
identifier: mainfile
name: The main file is ...
command: arara @{name}
arguments:
- identifier: name
  flag: <arara> @{parameters.name}

Although this does work, it isn't really perfect because even if I run

arara -v lions.tex

the -v (and any other options) are ignored because I haven't passed the options through to the command.

So, how can I make an arara rule to compile the main file from within a chapter file? If there's a better way of doing this in arara I'd like to see that too :)

1
  • 1
    This should be a task for the editor. If, in TeXshop, I type the "magic lines" % !TEX root = ./myfile.tex and % !TEX TS-program = arara, while in myfile.tex there are the arara directives, it all works flawlessly. I added an engine file for arara to TeXShop, of course.
    – egreg
    Mar 2, 2013 at 16:37

2 Answers 2

16

First of all, thank you very much for your kind words, Chris. :)

I'm really impressed with Marco's answer suggesting an arara inception. :) Personally, I prefer a more spartan solution, presented as follows.

As egreg suggested in the comments, if the editor provides % !TEX root = ..., arara will be executed with the file described in that directive. It's probably the cleanest solution.

I'd suggest to override the files directive argument in order to achieve something similar, say

main.tex

% arara: pdflatex
\documentclass{article}

\begin{document}

\include{lions}

\end{document}

lions.tex

% arara: pdflatex: { files: [ main.tex ] }
hello world

I simply repeated the rule from the main file, overriding the original reference to the current file and pointing to my main file. The files argument directive must be overriden for every arara directive.

When calling

$ arara lions.tex

arara will run pdflatex on main.tex instead of lions.tex.

Hope it helps. :)

4
  • 1
    I like this very much: when one is editing a secondary file, probably full typesetting with all the directives in the main file is not required. Just turn to the main file when the full set of directives is wanted.
    – egreg
    Mar 3, 2013 at 14:44
  • 1
    @egreg and '@'Paulo: In my deleted comment I had the same idea. Egred pointed out that this solution unfortunately doesn't handle all compilation rules of the main file. This is the reason for the new rule. Mar 3, 2013 at 15:02
  • +1 brilliant, thanks Paulo! I agree with @egreg's comment (although I hadn't originally thought of it). Both solutions are great, and I can see value in both approaches :) I have no idea which one to accept though... :)
    – cmhughes
    Mar 4, 2013 at 2:12
  • I am afraid my question is naive, but when the main file in a some parent directory, how can I point to it? Does ../ for example apply here?
    – Diaa
    Aug 12, 2017 at 13:39
14

I want to provide a small solution.

First I want to show your my yaml rule:

!config
# Mainfile rule for arara
# author: Marco Daniel
# requires arara 3.0+
identifier: mainfile
name: Mainfile
command: <arara> arara @{options} "@{rootfile}"
arguments:
- identifier: rootfile
  flag: <arara> @{parameters.rootfile}
- identifier: options
  flag: <arara> @{parameters.options}

As you can see, you have to options.

  1. You can declare the filename of the root file.
  2. You can pass options to arara.

To use araras options like -v the main executing must allow the argument.

With the following files:

mainfile.tex

% arara: pdflatex
\documentclass{article}
\begin{document}
\include{lions}
\end{document}

lions.tex

% arara: mainfile: { rootfile: mainfile , options: --verbose}
hello world as

you can execute with:

localhost:test marco$ arara -v lions

And you will get the following output:

  __ _ _ __ __ _ _ __ __ _ 
 / _` | '__/ _` | '__/ _` |
| (_| | | | (_| | | | (_| |
 \__,_|_|  \__,_|_|  \__,_|

Running Mainfile... 

  __ _ _ __ __ _ _ __ __ _ 
 / _` | '__/ _` | '__/ _` |
| (_| | | | (_| | | | (_| |
 \__,_|_|  \__,_|_|  \__,_|

Running PDFLaTeX... 

This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012)
 restricted \write18 enabled.
entering extended mode
(./mainfile.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2012-05-30, ngerman-x-2012-05-30, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnis
h, french, friulan, galician, german, ngerman, swissgerman, monogreek, greek, h
ungarian, icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, ma
rathi, oriya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian, 
kurmanji, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk,
 piedmontese, polish, portuguese, romanian, romansh, russian, sanskrit, serbian
, serbianc, slovak, slovenian, spanish, swedish, turkish, turkmen, ukrainian, u
ppersorbian, welsh, loaded.
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/size10.clo)) (./mainfile.aux
 (./lions.aux)) (./lions.tex) [1{/usr/local/texlive/2012/texmf-var/fonts/map/pd
ftex/updmap/pdftex.map}] (./mainfile.aux (./lions.aux)) )</usr/local/texlive/20
12/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on mainfile.pdf (1 page, 11949 bytes).
Transcript written on mainfile.log.
Status: SUCCESS

Status: SUCCESS

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .