10

I was wondering if there was any command which would let me create a PDF from a LyTeX source in one step. Currently, I am first executing lilypond-book:

 lilypond-book --latex-program=pdflatex --pdf --lily-output-dir=./tmp ./thesis.lytex

and, when this is done, the usual PDFLaTeX call:

pdflatex ./thesis.tex

While this works fine, I was wondering if there was a way to execute this as a single command (I would like to create a single typesetting rule for this in TeXworks, but for this, I need to have all this in a single command). I know that I could create a custom shell script for this (in fact, this is what I actually have now). However, I was specifically wondering if there was a 'built-in' solution for this? I was thinking about a solution similar to the LaTeXMK approach, which allows to run BibTeX and LaTeX and a few other tools from within the same command, taking care of the right order of calling the different programs, etc.

doncherry
  • 54,637

1 Answers1

15

Let my try to solve your issue using arara

If you hear arara the first time here a small abstract:

arara allows the specification of the compilation steps from the main document

This small sentence isn't able to describe the whole power of the tool. Therefor you can have a look at the documentation or the short intro at the homepage: Homepage arara

The current stable version of arara is available at CTAN and it's part of TeX Live/MacTeX. If you are using MikTeX, you have to install arara. This is also explained in the documentation.

The following description expect two points:

  1. You have installed lilypond (I know you have ;-))
  2. You get the following output in the terminal if you call arara:

marco@imac:~/Desktop/test$arara
  __ _ _ __ __ _ _ __ __ _
 / _` | '__/ _` | '__/ _` |
| (_| | | | (_| | | | (_| |
 \__,_|_|  \__,_|_|  \__,_|

arara 3.0 - The cool TeX automation tool
Copyright (c) 2012, Paulo Roberto Massa Cereda
All rights reserved.

usage: arara [file [--log] [--verbose] [--timeout N] [--language L] |
             --help | --version]
 -h,--help             print the help message
 -L,--language <arg>   set the application language
 -l,--log              generate a log output
 -t,--timeout <arg>    set the execution timeout (in milliseconds)
 -v,--verbose          print the command output
 -V,--version          print the application version

Now we can start. arara provides a lot of rules but not for lilypond. However writing a rule is nearly simple. The following rule can be taken as a starting point. Of course you can use the rule without any changes. Save the file as lilypond.yaml (the extension is important).

lilypond.yaml

!config
# Mainfile rule for arara
# author: Marco Daniel
# requires arara 3.0+
identifier: lilypond
name: Lilypond
command: <arara> lilypond-book @{format} @{options} @{output} "@{file}"
arguments:
- identifier: format
  flag: <arara> --format=@{parameters.latex-programm}
  default: <arara> --format=latex
- identifier: options
  flag: <arara> @{parameters.options}
- identifier: output
  flag: <arara> --output=@{parameters.output}

Next step is the new file extension lytex. arara supports tex, dtx, ltx but not yours. So you must tell arara to use a new extension. This can be done in a file named araraconfig.yaml which must be saved in your home directory. There you can add a path for the new rule and the new extension. In my System it looks like:

araraconfig.yaml

!config
# Config file to use texmfhome as search path
# author: Marco Daniel
# requires arara 3.0+
paths:
- /Users/marco/Library/texmf/scripts/arara/rules

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

Related to this configuration file you can save the provided rule in the folder

/Users/marco/Library/texmf/scripts/arara/rules

Do this. As you can see the filetype with a search pattern is also specified. You can read more about this in the documentation.


Now let us take an example. I saved the file as test.lytex:

test.lytex

% arara: lilypond
% arara: pdflatex: { files: [ test.tex ] }
\documentclass{scrartcl}

\begin{document}
Text
\begin{lilypond}[staffsize=12]
\relative c' {
  c2^"Text" g'2 \times 2/3 { f8 e d } c'2 g4
}
\end{lilypond}
\end{document}

After calling arara

marco@imac:~/Desktop/test$arara test.lytex
  __ _ _ __ __ _ _ __ __ _
 / _` | '__/ _` | '__/ _` |
| (_| | | | (_| | | | (_| |
 \__,_|_|  \__,_|_|  \__,_|

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

I get the following output:

Marco Daniel
  • 95,681
  • Hello and thank you for the effort, this is indeed very nice. However, I just can't figure out two things: (1) how can I put the config file to another place than my home folder? It looks very silly there; and (2) how can I add additional lilypond-book parameters to the call in, say, the testfile test.lytex? I've been trying to add the --latex-program=pdflatex and the -o ./tmp options, but I just can't figure out how to do that. Thank you indeed for your work, though. – Siska Ádám Apr 27 '13 at 20:55
  • @SiskaÁdám: Which one? – Marco Daniel Apr 27 '13 at 20:56
  • Sorry, I just pressed enter while editing my question and it recorded my comment. I just wanted a line-break... – Siska Ádám Apr 27 '13 at 20:58
  • @SiskaÁdám: to (1) With the current version you have no choice. With version 4.0 (it's on the way) you can use .araraconfig.yaml. So it isn't visible. Maybe a standard search path should be $TEXMF-HOME/scripts/arara/rules/. I will discuss this. (2) additional information can be given by % arara: lilypond: { format: pdflatex , output: ./tmp } These options are provided in the rule. – Marco Daniel Apr 27 '13 at 21:02
  • Thank you for the help again. It seems that something is going then wrong here. What you suggested for (2) was my original guess, but it gives me an error: I'm sorry, but the flag set for the argument 'format' of the 'lilypond' task (referencing the 'lilypond.yaml' file located at '/Users/sadam/Library/texmf/scripts/arara/rules') has an unavailable variable/method in the rule context: 'latex' – Siska Ádám Apr 27 '13 at 21:08
  • @SiskaÁdám: If you run lilypond-book --help you will get -f, --format=FORMAT use output format FORMAT (texi [default], texi-html,latex, html, docbook) So there is no pdflatex. – Marco Daniel Apr 27 '13 at 21:10
  • Sorry, you're right. Actually, I don't need to set the format option, but the --latex-program to pdflatex (or, the --pdf flag). – Siska Ádám Apr 27 '13 at 21:15
  • Actually, is it feasible with arara to allow the user to enter any lilypond-book option without specifying them one-by-one in the rule? – Siska Ádám Apr 27 '13 at 21:16
  • @SiskaÁdám: You can add any options via the key options. Eg: % arara: lilypond: { options: --here an option of lilypond } – Marco Daniel Apr 27 '13 at 21:24
  • I see. Thank you. I am going to accept your answer, as it solves the original problem of running the two commands in one step. On the other hand, I still have a question, as the "output" option currently doesn't seem to work. The problem is, that the new .tex file is created within the temporal folder, so before running the % arara: pdflatex: { files: [ test.tex ] } line, the process should somehow move the generated .tex file to the main folder. – Siska Ádám Apr 27 '13 at 21:32
  • @SiskaÁdám: If you call % arara: pdflatex: { files: [ test.tex ] } then the tex file must be located in the same folder. You can do: % arara: pdflatex: { files: [ path/test.tex ] } – Marco Daniel Apr 27 '13 at 23:16
  • Hi, that unfortunately gives an error, since pdflatex will not find the automatically generated files by lilypond-book (since pdflatex will still run in the parent folder). I realised that setting the TEXINPUTS macro before calling arara solves the problem. Unfortunately, I can't do that from TeXworks, at least I didn't find a solution to it. Another possibility would be if there was a rule in arara that I could use in order to move the resulting tex file one level higher, but I didn't find one yet. – Siska Ádám Apr 28 '13 at 00:01
  • @Marco: that's why you are the Cardinal Camerlengo of the Holy Bird. :) A possible workaround for the location problem would be a second rule called move which, well, moves the corresponding generated .tex file to the parent folder, and then pdflatex is invoked. Great answer, as usual. :) – Paulo Cereda Apr 28 '13 at 00:13
  • In the meantime, I made an attempt to create a copy command, and succeeded! ;-) However, it turns out that it still doesn't solve the problem, as the lilypond-book generated automated latex file expects the garbage generated by lilypond-book to reside in the same folder as the tex source itself. The only solution that I can currently imagine would be if I could invoke pdflatex by arara from inside the temporal subfolder created by lilypond-book, which I'm not sure whether it was possible or not at all... – Siska Ádám Apr 28 '13 at 00:21
  • 1
    Here's my copy command (by cloning clean): `!config

    Copy rule for arara

    author: Ádám Siska

    requires arara 3.0+

    identifier: copy name: CopyTool command: @{copy} @{options} @{src} @{dst} arguments:

    • identifier: copy default: @{isWindows("cmd /c copy", "cp -f")}
    • identifier: options flag: @{parameters.options}
    • identifier: src flag: @{parameters.src} default: .
    • identifier: dst flag: @{parameters.dst} default: .`
    – Siska Ádám Apr 28 '13 at 00:23
  • 1
    OK, with the above copy command I was able to sort it out. Now I created an auxiliary tex file thesis_main.tex, which consists of \usepackage{import} and a subimport to the thesis file in the temporal folder. Then, I created an arara workflow of 10 steps in my original lytex: (1) lilypond-book (creates tmp folder) (2) pdflatex (on thesis_main) (3-6) rename the aux file, run bibtex and rename the resulting bbl and blg files back (7-8) pdflatex, two times (9-10) rename the pdf and clean. This way I end up having thesis.lytex, thesis.bib, thesis.pdf, thesis_main.tex; no garbage! – Siska Ádám Apr 28 '13 at 00:55
  • @MarcoDaniel: Thank you again indeed for the very kind help, you saved my day with that script and with letting me know about this fascinating tool (arara). – Siska Ádám Apr 28 '13 at 00:56
  • @SiskaÁdám: Cool that everything works fine. – Marco Daniel Apr 28 '13 at 08:40