8

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.

StrongBad
  • 20,495

1 Answers1

7

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.

StrongBad
  • 20,495
  • 1
    +1 Thank you very much for sharing this answer, Daniel! :) – Paulo Cereda Jul 16 '13 at 01:23
  • texinputs.sh throws arguments $3 and further arguments away. Also I would put pdflatex as argument to texinputs.sh. Then the line pdflatex $2 can be replaced by the two lines shift and "$@". And the call in the rule would be @{texinputs} pdflatex @{action} @{draft} @{shell} @{synctex} @{options} "@{file}". – Heiko Oberdiek Jul 16 '13 at 08:01
  • @HeikoOberdiek that is much better, I couldn't figure out how to deal with the quotes and hence my use of sed. That said, this just seems like a hacky way to work around to the checking that arara does for valid commands. I am not sure why from a design standpoint it is beneficial to prevent running shell built-in functions. – StrongBad Jul 16 '13 at 10:46
  • @DanielE.Shub: It is a good design choice of arara not to pass the command line to a shell. First there are many operating systems with many shells. Each shell has its own features of variable substitutions, embedded command calls, ... -- a nightmare for portability and security. The command and its arguments has to be written to a string and the string is parsed by the shell to get the arguments. Again a nightmare to get the spaces and the quoting right. – Heiko Oberdiek Jul 16 '13 at 11:49
  • @StrongBad, Is there a way to do export LC_ALL="en_US" as a user command in TeXStudio? I need to be done before calling LuaLaTeX. – Royi May 27 '18 at 04:05