Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
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 '13 at 16:37
add comment

2 Answers 2

up vote 11 down vote accepted

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

share|improve this answer
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 '13 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. –  Marco Daniel Mar 3 '13 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 '13 at 2:12
    
@cmhughes: Provide a new answer and accept the new one ;-) –  Marco Daniel Mar 4 '13 at 12:17
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.