Georg Baum wrote:
Am Freitag, 8. September 2006 15:06 schrieb Helge Hafting:
There are indeed some gconvert-files there, but mostly
lilypond's intermediate files. If lilypond drops litters "current
directory" with such files, then perhaps a python script
doing a chdir to /tmp is the way to go?
Almost. It should chdir to the directory of the output file, that will also
be somewhere under /tmp, and it will make lilypond drop the output file to
the right directory. No need to copy then.
Version 2 of the lilypond inset is attached. Files:
external2.diff: Updates external_template with the inset
preferences2.diff: Update with the converters and filetype
convertLilyPond.py: conversion script for .lyx/scripts/
Differences from last time:
* The file type is now "lilypond" instead of "ly", more descriptive
* Conversion of instant preview image works now, see
http://www.aitel.hist.no/~helgehaf/lyx-lilypond.png
for an image of music in LyX
* The external inset documents the necessary lilypond versions
* All conversions use the script now. Therefore, they actually work
and don't litter the document directory with lilypond junk files.
* Unnecessary options removed from lilypond invocation.
* Tested with lilypond 2.6 and 2.9 this time.
Bugs is what we have 1.5svn for. Debug output with script:
Unfortunately the same code is in 1.4.3svn. I know the problem now and am
developing a fix.
I have a somewhat older version of lyx 1.5. There, the conversion
works. Lyx 1.5 from the week before unicode still have this error though.
Do you know what lilypond versions are in common use?
No. This was just what comes with SuSE 9.3. On my debian etch box I have
2.6.3.
The inset should work with your etch box then, as long as
you don't use pdflatex.
Helge Hafting
--- /usr/local/share/lyx/external_templates 2006-08-09 12:07:31.000000000
+0200
+++ external_templates 2006-09-09 17:51:37.000000000 +0200
@@ -33,7 +33,51 @@
\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
+ Using .eps require at least lilypond 2.6
+ Using .pdf require at least lilypond 2.8
+ HelpTextEnd
+ InputFormat "lilypond"
+ 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.
--- preferences.old 2006-09-08 21:38:12.000000000 +0200
+++ preferences 2006-09-09 17:24:43.000000000 +0200
@@ -124,12 +124,16 @@
# FORMATS SECTION ##########################
#
+\format "lilypond" "ly" "LilyPond music" "L" "" "xemacs" ""
#
# CONVERTERS SECTION ##########################
#
\converter "jpg" "eps" "sam2p $$i $$o" ""
+\converter "lilypond" "eps" "python -tt $$s/scripts/convertLilyPond.py $$i $$o
--ps" ""
+\converter "lilypond" "pdf2" "python -tt $$s/scripts/convertLilyPond.py $$i
$$o --pdf" ""
+\converter "lilypond" "png" "python -tt $$s/scripts/convertLilyPond.py $$i $$o
--png" ""
#
# COPIERS SECTION ##########################
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# file ly2png.py
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.
#
# \author Helge Hafting
#
# Full author contact details are available in file CREDITS
# This script converts a LilyPond file to png/eps/pdf, for
# displaying in LyX or inclusion by latex/pdflatex.
# Usage:
# python convertLilyPond.py inputfile.ly outputfile --ps|--pdf|--png
#
# This script checks if input and output files are in different
# directories. If they are, the input is copid to the output
# directory first, in order to work around lilypond limitations.
# One should hope the output directory is on /tmp, which usually is the
# case with LyX. Also, one should hope there is no other file
# with the same name as the input file there; it will be overwritten.
#
# After copying, lilypond is invoked on the input file, thereby
# producing the output file. The third parameter is passed on to
# lilypond unchanged, so any conversion lilypond supports is possible.
import os, sys
# We expect three args, the names of the input and output files.
# The third arg is the desired conversion.
if len(sys.argv) != 4:
sys.exit(1)
conversion = sys.argv[3];
input = os.path.realpath(sys.argv[1]);
output = os.path.realpath(sys.argv[2]);
# Fail silently if the file doesn't exist
if not os.path.isfile(input):
sys.exit(0)
outputdir= os.path.dirname(output);
#Work in the output dir from now on
os.chdir(outputdir);
# Strip the extension from ${output}
outbase = os.path.splitext(output)[0]
if os.system('lilypond -b eps %s -o %s %s' % (conversion, outbase, input)) != 0:
print 'lilypond fails'
sys.exit(1)