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:
- You have installed
lilypond (I know you have ;-))
- 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:

.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:02lilypond-book --helpyou will get-f, --format=FORMAT use output format FORMAT (texi [default], texi-html,latex, html, docbook)So there is nopdflatex. – Marco Daniel Apr 27 '13 at 21:10options. Eg:% arara: lilypond: { options: --here an option of lilypond }– Marco Daniel Apr 27 '13 at 21:24% 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% arara: pdflatex: { files: [ test.tex ] }then thetexfile must be located in the same folder. You can do:% arara: pdflatex: { files: [ path/test.tex ] }– Marco Daniel Apr 27 '13 at 23:16:)A possible workaround for the location problem would be a second rule calledmovewhich, well, moves the corresponding generated.texfile to the parent folder, and thenpdflatexis invoked. Great answer, as usual.:)– Paulo Cereda Apr 28 '13 at 00:13clean): `!configCopy 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:23copycommand I was able to sort it out. Now I created an auxiliary tex filethesis_main.tex, which consists of\usepackage{import}and a subimport to thethesisfile in the temporal folder. Then, I created an arara workflow of 10 steps in my originallytex: (1)lilypond-book(creates tmp folder) (2)pdflatex(on thesis_main) (3-6) rename the aux file, runbibtexand 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