# Retaining forward/inverse search when using Lilypond in Texstudio

When using the lilypond environment in LaTeX, you have to first run lilypond-book on yourdocument.lytex. This generates yourdocument.tex which you then run the rest of your build commands on (pdflatex, bibtex etc.). However, this means that you must do all your editing on the yourdocument.lytex file, which causes synctex not to work in tex studio. That is, ctrl-clicking a word in the embedded pdf viewer takes you not to the corresponding source code in the .lytex file but to the code in the .tex file instead, whereas ctrl clicking a word in the .lytex file open in the editor does nothing at all.

The main reasons I use texstudio rather than batchfiles + a text editor is that setting up synchronization between external viewers and notepad++ proved quite difficult, and most tex editors display the document structure, which I rely upon quite heavily to navigate documents. If there were a solution that provided said functionality I appreciate in sophisticated tex editors while using a program like notepad++, I'd be open to that too.

The way lilypond-book adds the music to the texdocument is by converting the code in the lilypond environment into a cropped pdf file, then replacing the lilypond environment in the .lytex file with `\includegraphics{croppedpdf.pdf}` (+ some alignment code) then saving the whole file as a .tex which can then be parsed by pdflatex. If there were some way to tell lilypond to generate this cropped file (without running lilypond book), this would provide a third possible solution as I could manually include the graphics using `\includegraphics`.

• In my experience `lilypond-book` works even if your main file isn't a `lytex` file, but a regluar `.tex` file. Maybe I just haven't discovered the real feature that the `ly` prefix triggers, but I think it's really just an organizational/visualization recommendation... – EngBIRD Mar 29 '16 at 20:08