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.

0

1 Answer 1

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:

18
  • 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. Apr 27, 2013 at 20:55
  • @SiskaÁdám: Which one? Apr 27, 2013 at 20:56
  • Sorry, I just pressed enter while editing my question and it recorded my comment. I just wanted a line-break... Apr 27, 2013 at 20:58
  • 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: <arara> @{copy} @{options} @{src} @{dst} arguments: - identifier: copy default: <arara> @{isWindows("cmd /c copy", "cp -f")} - identifier: options flag: <arara> @{parameters.options} - identifier: src flag: <arara> @{parameters.src} default: <arara> . - identifier: dst flag: <arara> @{parameters.dst} default: <arara> . Apr 28, 2013 at 0: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! Apr 28, 2013 at 0:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .