# Is it possible to write an arara rule which uses a bash script?

I've written a shell script to convert some of my files to different formats for use in my LaTeX files. Is it possible to write an arara rule which can use my shell scripts?

EDIT

I should note: the script is loaded through my bash profile file where it's defined along the lines

myscript () { <script contents> }


In other words, the script does not exist as an executable residing in some directory.

• I'm a little confused... I don't see how your first and last sentences can be true at the same time. Could you clarify? Jun 14, 2013 at 21:39
• @cmhughes Perhaps I'm using the wrong language? In my bash profile I define a number of functions which are callable from the command line. Jun 14, 2013 at 21:59

Yes, this can certainly be done. Thanks to Paulo (arara creator) for his help on this one :)

Let's say that your .bashrc contains the following

function hello() {
echo "Hello, $0!" } export -f hello  Note the use of export to make the hello function available from the command line. We can then make our arara rule to contain the line - <arara> bash -i -c hello @{name}  Note the use of the i and c flags. The rule can then be used either as % arara: hello  or % arara: hello: {name: Ellett}  # hello.yaml !config # Hello world # author: Chris Hughes, Paulo Cereda # last edited by: cmh, June 14th 2013 # requires arara 3.0+ # # Sample usage: # # % arara: hello # % arara: hello: {name: A.Ellett} # # This rule is really just a shortcut for commands like the following # # hello # or # hello A.Ellett # identifier: hello name: hello commands: - <arara> bash -i -c hello @{name} arguments: - identifier: name flag: <arara> @{parameters.name} default: "world"  # myfile.tex % arara: hello % arara: hello: {name: Ellett} \documentclass{article} \begin{document} test \end{document}  And here's the output from arara -v myfile.tex  __ _ _ __ __ _ _ __ __ _ / _ | '__/ _ | '__/ _ | | (_| | | | (_| | | | (_| | \__,_|_| \__,_|_| \__,_| Running hello... Hello, world! Status: SUCCESS Running hello... Hello, Ellett! Status: SUCCESS  • I've copied your example exactly and I when I run it I get bash: no job control in this shell following by Hello, followed by Status: SUCCESS. Notice that nothing followed Hello,; the line was just terminated. I'm doing this on Mac OS X. Is there something special I have to do there? Jun 15, 2013 at 3:12 • Two things: (1) if I got rid of the -i switch things worked. (2) I'd been using $* instead of $0. Jun 15, 2013 at 3:16 • I'm wondering if you can make a suggestion for how to get this to work if the bash command takes uses $* instead of $0. Jun 15, 2013 at 21:42 • @A.Ellett I'll look into it :) Jun 15, 2013 at 22:05 • An adaptation for arara 4.0 can be found at tex.stackexchange.com/a/341475/36296 Nov 29, 2016 at 12:22 In the next version of TeXlive there will be TrY, that is something similar to arara, but simpler. It uses simple bash commands into the TeX comments. The main use of TrY is to make explicit in the document the list of commands needed to compile it, something like this: % %$ xetex -shell-escape filename.tex
%$bibtex -min-crossref=3 filename.aux %$ xetex -shell-escape filename.tex
%$xetex -shell-escape filename.tex %  but you can call your script from the comments in the same way: % %$ ./myscript $0 %$ pdftex $0 %  where $0 is a placeholder standing for the parameter "this document".

You can also put a script into the comment:

%
%$while [$a -le "$LIMIT" ] %$ do
%$a=$(($a+1)) %$   if [ "$a" -eq 3 ] || [ "$a" -eq 11 ]
%$then %$     continue
%$fi %$   echo -n "$a " %$ done
%
%$pdftex$0
%


(the script is only an example and has not a particular function or meaning).

Then you have to compile the document in the obvious way:

\$ try mydocument.tex

• I'll look forward to trying this out. Jun 15, 2013 at 17:40
• Please allow me to wrote feedback to your answer. TrY is really a nice tool, however I am completely disagree with the statement: but simpler -- what is simpler than arara: pdflatex -- although I see some benefits of TrY. Jun 15, 2013 at 18:37
• @MarcoDaniel TrY has not rules, directives, and so on. texdoc arara gives a document 137 pages long; the full manual of TrY can be two pages long or so. Jun 16, 2013 at 0:02
• This looks interesting, but I have to agree with Marco. In addition to his comments, note that arara is a cross-platform tool; is the same true TrY`? Jun 16, 2013 at 0:32
• @JeanBaldraque: I agree -- 2 pages against 137 pages (the new version is longer) is a statement ;-)--It's the price for such a tool. Jun 16, 2013 at 8:33