[Tex/LaTex] Setting environment variable with arara

araratexinputs

I wanted to set my TEXINPUTS environment variable from with an arara rule/directive. For example my texinputs.yaml rule is

!config
identifier: texinputs
name: texinputs
command: export TEXINPUTS="@{mypaths}$TEXINPUTS:"
arguments:
- identifier: mypaths
  flag: "@{parameters.mypaths}"

and my test.tex file is

\documentclass{article}
\begin{document}
Hello world
\end{document}
% arara: texinputs: { mypaths: ".//:" }
% arara: pdflatex

When I run arara -v test from the directory in which test.tex is located, I get

Running texinputs…

I'm sorry, but the command from the 'texinputs' task could not be
found. Are you sure the command 'export TEXINPUTS=".//:$TEXINPUTS:"'
is correct, or even accessible from the system path?

What am I doing wrong? I am on Linux with TeX Live 2012.

Best Answer

I learned a lot in chat. Even if texinputs.yaml could be made to set the TEXINPUTS environment variable, this will have no affect on subsequent calls to the pdflatex directive since each directive runs in a self contained environment. The problem with texinputs.yaml as constructed is that in Linux export is a special commands built into the Bash shell and therefore "confuses" arara into thinking it is not a command.

The simplest, and possibly cleanest work around is to redefine the pdflatex.yaml rule to take a texinputs argument and then run pdflatex in env which allows setting of the environment variables. Specifically, the modified rule looks like

    !config
    # PDFLaTeX rule for arara
    # author: Marco Daniel
    # last edited by: Paulo Cereda
    # requires arara 3.0+
    identifier: pdflatex
    name: PDFLaTeX
    command: <arara> @{texinputs} pdflatex @{action} @{draft} @{shell} @{synctex} @{options} "@{file}"
    arguments:
    - identifier: action
      flag: <arara> --interaction=@{parameters.action}
    - identifier: shell
      flag: <arara> @{isTrue(parameters.shell,"--shell-escape","--no-shell-escape")}
    - identifier: synctex
      flag: <arara> @{isTrue(parameters.synctex,"--synctex=1","--synctex=0")}
    - identifier: draft
      flag: <arara> @{isTrue(parameters.draft,"--draftmode")}
    - identifier: options
      flag: <arara> @{parameters.options}
    - identifier: texinputs
      flag: "env TEXINPUTS=@{parameters.texinputs}"

There are at least two problems with this approach: it ignores previously set values of TEXINPUTS and cannot handle paths with spaces in them. It might be possible to work around both of these issues. A more general solution, but one that requires adding an additional script is to modify pdflatex.yaml to be

!config
# PDFLaTeX rule for arara
# author: Marco Daniel
# last edited by: Paulo Cereda
# requires arara 3.0+
identifier: pdflatex
name: PDFLaTeX
commands:
- <arara> @{texinputs} '@{action} @{draft} @{shell} @{synctex} @{options} "@{file}"'
arguments:
- identifier: action
  flag: <arara> --interaction=@{parameters.action}
- identifier: shell
  flag: <arara> @{isTrue(parameters.shell,"--shell-escape","--no-shell-escape")}
- identifier: synctex
  flag: <arara> @{isTrue(parameters.synctex,"--synctex=1","--synctex=0")}
- identifier: draft
  flag: <arara> @{isTrue(parameters.draft,"--draftmode")}
- identifier: options
  flag: <arara> @{parameters.options}
- identifier: texinputs
  flag: texinputs.sh "@{parameters.texinputs}"
  default: pdflatex

and define a texinputs.sh file as

#!/usr/bin/bash
TEMP=$(echo $1 | sed s#\"##g)
export TEXINPUTS=$TEMP:$TEXINPUTS
pdflatex $2

This handles the appending of a preexisting TEXINPUTS as well as spaces in the path. I am hoping that there is a cleaner approach which handles a preexisting TEXINPUTS as well as spaces and doesn't require an extra script file.

Related Question