4

I was wondering how I could use TEXINPUTS combined with either arara or TeXworks. To understand my point, I just received an answer on the thread `How to run LaTeX and lilypond-book in one command?', where the solution was done with a tool called arara (which seems to be a great tool, BTW). Now I'm trying to merge this solution into TeXworks. The problem is, that since lilypond-book creates a lot of garbage, I need to make sure that its output is put into a local temporal subfolder. But then, in order to process the .tex file (generated by lilypond-book) residing in the subfolder with the other related files (eg. BiBTeX files) in the main folder, I need to add the subfolder to TEXINPUTS. Apparently, I can't figure out how to do this either with arara itself or with TeXworks.

Any help is greatly appreciated

  • 1
    You can provide a rule which copies the required files to your folder. E.g.: % arara: copy: {pdf} – Marco Daniel Apr 27 '13 at 23:20
11

About TEXINPUTS and arara, I recommend Setting environment variable with arara as starting point. As pointed out, arara runs commands on subshells, in a self-contained environment, so it might be tricky to keep persistence between executions.

As Marco said in the comments, you can exploit the operating system's file operation commands in order to move, copy or delete certain files, but it's important to observe that, for security reasons, arara and its execution library don't like wildcards. That means that using them as bash expansion for copying, moving or deleting file patterns won't work. :( The solution would be to provide every file to be dealt with beforehand.

If you could expand a little which steps you need ararato perform, we might come up with either a couple of rules or a different compilation chain in order to achieve the desired result. As it is, I can only guess, and the more intricate the project, the more details we need. :)

Update: Thanks to Sam Whited, I managed to achieve an interesting setup for arara and lilypond. Sadly it's not 100% operating system independent, mostly because I spent almost all my 氣 trying to make TeX and friends resolve paths! :) Someday I might revisit this answer. Someday.

There we go, first things first. This is my current structure:

paulo@alexandria Projetos$ tree testes/
testes/
|-- arara
|   `-- lilypond.yaml
|-- build
|-- pdfs
`-- source
    |-- Greensleeves.lytex
    |-- SaddestMusic.lytex
    |-- SaddestMusicReprise.lytex
    |-- StrangeWateryNoises.lytex
    |-- SymphonyForTwelveInstruments.lytex
    |-- TangoToAcheron.lytex
    `-- TimeShifts.lytex

4 directories, 8 files

Sorry for the Brazilian Portuguese names, I was too lazy to change them to proper English counterparts. :)

All .lytex files used in here are courtesy of Sam Whited, thank you very much for sharing them with me, since I'm lilypond-illiterate. :)

I'll deliberately steal Marco's amazing answer in How to run LaTeX and lilypond-book in one command? and modify it a little in order to achieve a complete compilation chain. First of all, we need to tell arara how to process .lytex files - this is done by creating a file named araraconfig.yaml in your home folder:

!config

paths:
- /home/paulo/Projetos/testes/arara

filetypes:
- extension: lytex
  pattern: ^(\s)*%\s+

Note that I have a folder named arara inside testes; this is where I'll keep my lilypond.yaml rule, discussed as follows. Don't hate me for the complicated rule!

!config
identifier: lilypond
name: Lilypond
commands:
- <arara> lilypond-book @{isNotEmpty(output, "--include=".concat(output.replace('--output=','')))} @{format} @{options} @{output} "@{file}"
- <arara> @{engine} --shell-escape @{isNotEmpty(output, '"\\makeatletter\\def\\input@path{{'.concat(output.replace('--output=','')).concat(SystemUtils.FILE_SEPARATOR).concat('}}\\makeatother\\input{')concat(getBasename(file)).concat('}"'))}
- <arara> rm "@{getBasename(file)}.aux"
- <arara> rm "@{getBasename(file)}.log"
- <arara> mv "@{getBasename(file)}.pdf" "../pdfs/"
arguments:
- identifier: format
  flag: <arara> --format=@{parameters.format}
  default: <arara> --format=latex
- identifier: options
  flag: <arara> @{parameters.options}
- identifier: output
  flag: <arara> --output=@{parameters.output}
- identifier: engine
  flag: <arara> @{parameters.engine}
  default: <arara> pdflatex

Holy cow!

There are actually 5 commands in the rule. Let's see what the heck these commands do:

  1. First of all, let's call the lilypond-book script. If the output parameter is specified, everything generated in this step will be inside of it! I'm sure this line is buggy, but hey, trust me, it will get worse. :) We will run lilypond-book on the provided .lytex file and generate the output to, well, output, if provided.

  2. Now let's run a TeX engine (default is pdflatex) on the generated files. For lilypond stuff, if you run stuff on restricted mode, make sure to enable --shell-escape or you will have a bad time. Now, thanks to David Carlisle, we make some crazy hacks by adding the output path instead of relying in the TEXINPUTS thingy, since arara has restrictions about it. Think of path hell in both cases. :)

  3. Now I get really mad, let's remove the .aux file which is actually located here, since it's generated in this very same level.

  4. Let's repeat the very same blood bath to the .log file; only these two files are actually generated by the .tex file; remember that all the lilypond stuff relies in the output directory.

  5. Of course, our beloved .pdf file is here as well, so let's move it to one level above, and put inside the pdfs/ folder. Neat isn't it? :)

Phew! I really need some beer right now. :)

We now need the .lytex file and the arara directive! Let's test it with our sample file Greensleeves.tex - wanna hear it?. :) I won't paste everything here, only the important parts:

paulo@alexandria testes$ head source/Greensleeves.lytex 
% arara: lilypond: { output: "/home/paulo/Projetos/testes/build" }
% !TEX encoding = UTF-8

\documentclass[a4paper,12pt]{article}
\usepackage{multicol}
\usepackage{textcomp}
\usepackage[margin=2cm]{geometry}

\begin{document}
\thispagestyle{empty}

...

So, now let's use arara to create some music!

paulo@alexandria source$ pwd
/home/paulo/Projetos/testes/source
paulo@alexandria source$ arara Greensleeves.lytex 
  __ _ _ __ __ _ _ __ __ _ 
 / _` | '__/ _` | '__/ _` |
| (_| | | | (_| | | | (_| |
 \__,_|_|  \__,_|_|  \__,_|

Running Lilypond... SUCCESS
Running Lilypond... SUCCESS
Running Lilypond... SUCCESS
Running Lilypond... SUCCESS
Running Lilypond... SUCCESS

Apparently, it worked. :) Let's see what happened:

paulo@alexandria Projetos$ tree testes/
testes/
|-- arara
|   `-- lilypond.yaml
|-- build
|   |-- ef
|   |   |-- lily-6ffeba6b-1.eps
|   |   |-- lily-6ffeba6b-1-eps-converted-to.pdf
|   |   |-- lily-6ffeba6b-2.eps
|   |   |-- lily-6ffeba6b-2-eps-converted-to.pdf
|   |   |-- lily-6ffeba6b-3.eps
|   |   |-- lily-6ffeba6b-3-eps-converted-to.pdf
|   |   |-- lily-6ffeba6b-4.eps
|   |   |-- lily-6ffeba6b-4-eps-converted-to.pdf
|   |   |-- lily-6ffeba6b-5.eps
|   |   |-- lily-6ffeba6b-5-eps-converted-to.pdf
|   |   |-- lily-6ffeba6b.eps
|   |   |-- lily-6ffeba6b.ly
|   |   |-- lily-6ffeba6b.midi
|   |   |-- lily-6ffeba6b-systems.count
|   |   |-- lily-6ffeba6b-systems.tex
|   |   |-- lily-6ffeba6b-systems.texi
|   |   `-- lily-6ffeba6b.txt
|   |-- Greensleeves.dep
|   |-- Greensleeves.tex
|   |-- snippet-map--1172401943.ly
|   `-- snippet-names--1172401943.ly
|-- pdfs
|   `-- Greensleeves.pdf
`-- source
    |-- Greensleeves.lytex
    |-- SaddestMusic.lytex
    |-- SaddestMusicReprise.lytex
    |-- StrangeWateryNoises.lytex
    |-- SymphonyForTwelveInstruments.lytex
    |-- TangoToAcheron.lytex
    `-- TimeShifts.lytex

5 directories, 30 files

Great, Greensleeves.pdf is in place! And look, the build/ folder has all the temporary files generated by lilypond-book, cached for future use. It's up to you to delete these files, we could always add a new command to the lilypond rule in order to get rid of them. :)

There we go, hope it helps! :)

| improve this answer | |

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.