5

This is a more general version of Adam Liter's question about setting up an arara rule for knitr.

The basic question is this:

How can I enable support for customised extensions and directives in araraconfig.yaml?

The answer would be straightforward if it were not that the documentation is apparently rather buggy. The problem is that using the syntax modelled in the manual results in the following error when arara is run:

I didn't find any directives in 'myfile.XXX', and so didn't do anything. Is that what you really wanted?

where XXX is the extension you tried to enable. Adam's question includes a fully documented example of the error for the case of knitr.

5

The solution included in Adam Liter's question worked for the case I was concerned with, as far as I can establish so far.

I am posting what I used to enable support for the mp extension in the hope that this will work more generally and/or help isolate the issue which Adam is still experiencing. Following discussion with Adam, we decided it was best to post a new generic question rather than including a more general answer in response to a knitr-specific question. (I cannot test the knitr bit.) Really, the solution here is all the result of Adam's efforts. I was just lucky enough to find that it worked perfectly with my configuration and for metapost.

Possibly relevant background information: I am using GNU/Linux with TeX Live 2013. (We don't know if it works for me because I use Linux or because I was concerned with metapost.)

Here is my araraconfig.yaml:

!config
paths:
- <arara> @{userhome}/.arara/rules
filetypes:
- extension: tex
- extension: mp
  pattern: ^(\s)*%\s+
- extension: dat
  pattern: ^(\s)*%\s+
- extension: dtx
- extension: ltx
- extension: sk
  pattern: ^(\s)*[%#]\s+
# vim: set nospell:

Crucial note: as Adam documents, you need \s where the documentation specifies \\s. (I am assuming \s means something like 'space' although the manual doesn't really explain this. Since regular expressions vary in syntax, this is a bit frustrating.)

This is the rule I am using for metapost. The rule is in .arara/rules/mpost.yaml:

!config
# metapost rule for arara
identifier: mpost
name: metapost
command: <arara> mpost @{action} @{options} "@{file}"
arguments:
- identifier: action
  flag: <arara> -interaction=@{parameters.action}
- identifier: options
  flag: <arara> @{parameters.options}
# vim: set nospell:

I then add the following directive line in my mp source file:

% arara: mpost

This enables me to run either

arara figs.mp

or

arara figs

and have arara do the right thing. Either way, I get a 'success' and figs.1 is produced. (That's the expected result in this case and converting to PDF shows that the result contains what I'd expect as well.)

  • (Sorry for the short comment, I am on mobile right now) There is an error in the documentation when telling you to use ‛\\s‛, it's actually ‛\s‛. I apologize for such error (and also for missing your question). I will add a new section about regex in the new manual, it sounds like a good plan. The upcoming version will hopefully provide a better control on extensions and rules in general. That is a good way to improve the tool: learning from its userbase. ‛:)‛ – Paulo Cereda Jun 2 '14 at 18:24
  • 1
    @PauloCereda Thanks for commenting. This question-and-answer was a follow up to another user's question and is really here to make the information hopefully a bit easier to find. I'm actually used to using regexes but everything uses a slightly different syntax and the documentation was so consistent, I tended to believe it! – cfr Jun 2 '14 at 20:50
2

(Apologies if this would be better as a comment. I do not have sufficient reputation to post comments.)

The following rule seems to work well when called with just the base file name. It is also possible to have arara compile the Rnw source all the way to PDF with a single rule, see below.

!config
identifier: knitr
name: knitr
command: <arara> RScript -e "library(knitr); knit('"@{source}"', output='"@{target}"')"
arguments: 
- identifier: source
  flag: <arara> "@{parameters.source}"
  default: <arara> "@{getBasename(file)}".Rnw
- identifier: target
  flag: <arara> "@{parameters.target}"
  default: <arara> "@{getBasename(file)}".tex

Unfortunately, I was not able to resolve the error in the original question when calling arara on my source Rnw file. In this case, arara complains that the file is not found. This is a problem with the rule above, because I want to call arara again to compile the .tex file to PDF. The directive

% arara: knitr

still exists as line 1 of the .tex file. Therefore, a subsequent call actually runs arara on the source Rnw file again, rather than what is intended. (I'm not sure why, since I have the Rnw extension listed last in my configuration file, reproduced below.) Of course one could edit the directive manually, but this is clumsy and inconvenient.

So we are still in need of a solution. Here is a simple workaround. This rule first calls knitr, then the xelatex engine.

!config
identifier: knitr
name: knitr
commands: 
- <arara> RScript -e "library(knitr); knit('"@{source}"', output='"@{target}"')"
- <arara> xelatex "@{target}"
arguments: 
- identifier: source
  flag: <arara> "@{parameters.source}"
  default: <arara> "@{getBasename(file)}".Rnw
- identifier: target
  flag: <arara> "@{parameters.target}"
  default: <arara> "@{getBasename(file)}".tex

Here is my configuration file that I am using with this rule.

!config
paths:
- <arara> /path/to/my/knitr/rule
filetypes:
- extension: tex
- extension: dtx
- extension: ltx
- extension: Rnw
  pattern: ^(\s)*%\s+
  • I am not sure if all your problems are solved. (It is up to you.) If not, consider update your situation by editing your original problem. – Symbol 1 Sep 22 '14 at 3:40
  • @Symbol1 It might be better to suggest asking a new question since this question was not asked by the person who posted this answer. – cfr Sep 22 '14 at 12:24
  • @cfr Sorry I did not see that is you. This answer seems like a self-answering... So, dear Dave Rosoff, would you like to ask a new problem about your situation? – Symbol 1 Sep 22 '14 at 12:27
  • @Symbol1 I was actually the person who asked the original question that Dave links to in this answer. cfr's question is a more general version of my more specific question about knitr and arara. Perhaps this would be more appropriate as an answer to my question? I'm not sure. – Adam Liter Sep 22 '14 at 19:23

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.