I made an external inset that includes gnu lilypond files.
For those that don't know, this is typeset sheet music.

Using a lyx 1.5svn from before the unicode merge, I can already
export postscript and pdf, the lilypond stuff gets
converted to .eps or .pdf as needed. Screenshot from xpdf:
http://www.aitel.hist.no/~helgehaf/lyx-lilypond-pdf.png

The big problem is instant preview. This ought to be really
simple, for lilypond have no problems making a .png
which lyx-qt is supposed to be able to load.

So I defined a lilypond->png converter, in addition
to the lilypond->eps and lilypond->pdf converters
I already had.

The first attempt simply called lilypond directly, with
the parameters needed for making a .png
This approach works fine for .eps and .pdf when
making output.

Lyx discovered the existence of a converter, invoked
lilypond which ran without error messages, but  then
lyx (using -dbg external,graphics) claimed that no
file was produced.  Very strange that. Note that
I don't actually tell lilypond where to put the output file,
but lilypond will then put it where it finds the
input file. There was no such file in the temp directory,
perhaps it got deleted somehow? The apprach worked
so well for .eps and .pdf, and of course I tested the
command on the command line too.

Unable to figure this out, I made a python script,
copying heavily from fig2pstex.py. Running
"python -tt ly2png file.ly file.png" on the
command line worked - seemingly no bugs in my python.

Putting the same command into the converter dialog,
making an entry very similiar to the fig2pstex one
did not work though. When the conversion runs, I get:
--------------------------------------
ForkedCallQueue: waking up
LoaderQueue: I'm going to sleep
 File "/tmp/lyx_tmpdir16969UzhNPg/lyxconvert7.py", line 18
if os.system(r'python -tt '/usr/local/share/lyx/scripts/ly2png.py' ' + '"' + infile + '"' + ' ' + '"' + outfile + '"' + '') != 0:
                                                                      ^
SyntaxError: invalid syntax
ForkedCallQueue: I'm going to sleep
Image conversion failed.
Unable to find converted file!


So what the hell is this "syntax error in lyxconvert7.py" business ???
I never touched such a file. And if a file shipped with lyx is broken,
why don't any of the existing converters break the same way?  I tested
a .fig file in the same document, and of course it worked. :-(

This is very frustrating - if I made a mistake, where is it?  The commands
and scripts work so well outside of lyx, and the converter setup
is so similiar to existing working converters . . .

Anyway, the external inset with .pdf and .eps converters is all that
is needed to use this for output, so here it is so you may consider
it for inclusion or ask for improvements:

Attached preferences.diff, which defines the file format and converters
Attached external.diff, which defines the external template
for lilypond.

Helge Hafting

--- preferences.old     2006-09-07 20:58:34.000000000 +0200
+++ preferences 2006-09-08 12:00:18.000000000 +0200
@@ -55,7 +55,7 @@
 # FILE SECTION ######################################
 #
 
-\template_path "/home/helgehaf/lyx-1.4cvs/templates/"
+\template_path "/home/helgehaf/.lyx/templates/"
 
 #
 # ASCII EXPORT SECTION ##############################
@@ -84,16 +84,20 @@
 # FORMATS SECTION ##########################
 #
 
+\format "tgif" "obj" "Tgif" "" "auto" "auto" ""
 \format "fen" "fen" "FEN" "" "auto" "auto" ""
-\format "pdf3" "pdf" "PDF (dvipdfm)" "m" "xpdf" "" "document"
-\format "pdf2" "pdf" "PDF (pdflatex)" "F" "xpdf" "" "document"
 \format "pdf" "pdf" "PDF (ps2pdf)" "P" "xpdf" "" "document"
-\format "tgif" "obj" "Tgif" "" "auto" "auto" ""
+\format "pdf2" "pdf" "PDF (pdflatex)" "F" "xpdf" "" "document"
+\format "pdf3" "pdf" "PDF (dvipdfm)" "m" "xpdf" "" "document"
+\format "ly" "ly" "LilyPond" "auto" "auto" "" ""
 
 #
 # CONVERTERS SECTION ##########################
 #
 
+\converter "ly" "eps" "lilypond -b eps --ps -dno-gs-font-load 
-deps-font-include $$i" ""
+\converter "ly" "pdf2" "lilypond -b eps --pdf -dno-gs-font-load 
-deps-font-include $$i" ""
+\converter "ly" "png" "lilypond -b eps --png -dno-gs-font-load 
-deps-font-include $$i" ""
 
 #
 # COPIERS SECTION ##########################
--- /usr/local/share/lyx/external_templates     2006-08-09 12:07:31.000000000 
+0200
+++ external_templates  2006-09-08 11:05:40.000000000 +0200
@@ -33,7 +33,49 @@
                \IfFileExists{#1}{\input{#1}}{\warnNotFound{#1}}}
 PreambleDefEnd
 
-
+Template LilyPond
+       GuiName "Lilypond typeset music"
+       HelpText
+               Sheet music typeset by GNU LilyPond,
+               converted to .pdf or .eps for inclusion
+       HelpTextEnd
+       InputFormat "ly"
+       FileFilter "*.ly"
+       AutomaticProduction true
+               Transform Rotate
+       Transform Resize
+       Transform Clip
+       Transform Extra
+       Format LaTeX
+               TransformOption Rotate RotationLatexOption
+               TransformOption Resize ResizeLatexOption
+               TransformOption Clip   ClipLatexOption
+               TransformOption Extra  ExtraOption
+               Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
+               Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
+               UpdateFormat eps
+               UpdateResult "$$AbsPath$$Basename.eps"
+               Requirement "graphicx"
+               ReferencedFile latex "$$AbsPath$$Basename.eps"
+               ReferencedFile dvi   "$$AbsPath$$Basename.eps"
+       FormatEnd
+        Format PDFLaTeX
+                TransformOption Rotate RotationLatexOption
+                TransformOption Resize ResizeLatexOption
+                TransformOption Clip   ClipLatexOption
+                TransformOption Extra  ExtraOption
+                Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
+                Product 
"\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
+                UpdateFormat pdf
+                UpdateResult "$$AbsPath$$Basename.pdf"
+                Requirement "graphicx"
+                ReferencedFile pdflatex "$$AbsPath$$Basename.pdf"
+        FormatEnd
+       Format LinuxDoc
+               Product "[LilyPond: $$FName]"
+       FormatEnd
+TemplateEnd
+                               
 Template RasterImage
        # By default, InsetExternal is displayed as a grey button
        # containing this text.

Reply via email to