7

I'm working on an arara rule that makes use of the items identifier

% arara: myrule: {items: [lions, zebras]}

\documentclass{article}

\begin{document}

hello world

\end{document}

The rule, myrule.yaml, looks like this:

!config
identifier: myrule
name: myrule
commands: 
- <arara> @{ isTrue( myswitch, isWindows( "cmd /c echo", "echo" ) ) } @{item}
# can I toggle myswitch here?
arguments:
- identifier: myswitch
  flag: <arara> @{parameters.myswitch}
  default: true

I would like to toggle the myswitch identifier to false within the rule- how can I do this? :)

(The reason is for the rule I made for How to create individual chapter PDFs).

5

Sadly, it's not possible to have a switch in the rule context.

When using iterators like items/@{item} or files/@{file}, the rule is replicated to every item; the context is stateless, it has no previous memory of past expansions.

One possible dirty hack is to compare the current @{item} to a variable supplied by the directive and execute one of the commands if and only if they are equal:

!config
identifier: myrule
name: myrule
commands: 
- <arara> @{ isTrue( item == element, isWindows( "cmd /c echo", "echo" ) ) } @{item}
arguments:
- identifier: element
  flag: <arara> @{parameters.element}

And in the directive:

% arara: myrule: { items: [ lions, zebras ], element: lions }

Note that element applies to the first item of the list.

With the upcoming version of arara, we might be able to perform checks in directives with something we call conditionals. We are still working on it, but so far, it looks good.

I'll think of adding a internal map containing some useful info to rulemakers, like the item count, the current item, and other goodies. Of course, it will be properly documented. :)

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.