On 12/04/2010 6:05 AM, Helge Hafting wrote:
Of course, embedding lilypond code in LyX would be even less work. But I
don't know a quick way to program that. Anything not supported directly
by latex, is kept in separate files. This is the way it is for graphics,
as well as music.

The current lilypond support in LyX takes care of running lilypond and
importing the resulting PDF automatically. So you can include music, but
you need to have each piece in a separate file.


What you want can be done though. Lilypond code could be stored in the
..lyx file, and LyX could write out a temporary .ly file and process it
with lilypond.

You may want to file an enhancement request for this at
http://www.lyx.org/trac/wiki/BugTrackerHome
so your idea is not forgotten. The idea is interesting, but I don't have
time right now.

Helge Hafting


Hi Bernardo, and others,

I just wrote a LyX module for basic Lilypond support within LyX. It works with LyX 2.0 (the development version) only. But if you feel adventurous, it would be a great help if you can test it out.

To developers: it is a simple idea. It is inspired by the literate programming frameworks. LyX produces a .lytex document (which is really just latex with some lilypond commands) and lilypond-book converts that to latex. The usual conversion chain ensues.

At the moment the features are minimal (just a single inset is available, and I don't know how to pass options to LaTeX environments). But it is usable; the patch includes an example document.

Regards,
Julien
Index: layouts/lilypond.module
===================================================================
--- layouts/lilypond.module     (revision 0)
+++ layouts/lilypond.module     (revision 0)
@@ -0,0 +1,34 @@
+#\DeclareLyXModule[lilypond-book->latex]{LilyPond}
+#DescriptionBegin
+#This module adds an inset to enter LilyPond code directly into LyX.
+#It will be processed in the output.
+#DescriptionEnd
+#Category: literate
+
+# Author: Julien Rioux <jri...@physics.utoronto.ca>
+
+Format 26
+OutputType             literate
+OutputFormat           lilypond-book
+
+InsetLayout LilyPond
+       LabelString           LilyPond
+       LatexType             Environment
+       LaTexName             lilypond
+       LyXType               Custom
+       Decoration            Classic
+       Font
+         Color               latex
+         Family              typewriter
+       EndFont
+       LabelFont
+         Color               latex
+         Size                Small
+       EndFont
+       MultiPar              true
+       CustomPars            false
+       ForcePlain            true
+       FreeSpacing           true
+       PassThru              true
+       ForceLTR              true
+End

Property changes on: layouts/lilypond.module
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

Index: configure.py
===================================================================
--- configure.py        (revision 34124)
+++ configure.py        (working copy)
@@ -506,6 +506,7 @@
 \Format literate   nw      NoWeb                  N  ""        "%%"    
"document"
 \Format sweave     Rnw    "Sweave"                S  "" "%%"    "document"
 \Format lilypond   ly     "LilyPond music"        "" ""        "%%"    "vector"
+\Format lilypond-book lytex "LilyPond book"       "" ""        "%%"    
"document"
 \Format latex      tex    "LaTeX (plain)"         L  ""        "%%"    
"document"
 \Format pdflatex   tex    "LaTeX (pdflatex)"      "" ""        "%%"    
"document"
 \Format xetex      tex    "LaTeX (XeTeX)"         "" ""        "%%"    
"document"
@@ -803,6 +804,25 @@
         else:
             logger.info('+  found LilyPond, but could not extract version 
number.')
     #
+    path, lilypond_book = checkProg('a LilyPond book -> LaTeX converter', 
['lilypond-book'])
+    if (lilypond_book != ''):
+        version_string = cmdOutput("lilypond-book --version")
+        match = re.match('^(\S+)$', version_string)
+        if match:
+            version_number = match.groups()[0]
+            version = version_number.split('.')
+            if int(version[0]) > 2 or (len(version) > 1 and int(version[0]) == 
2 and int(version[1]) >= 9):
+                addToRC(r'''\converter lilypond-book latex    "lilypond-book 
--pdf $$i"                          ""
+\converter lilypond-book pdflatex "lilypond-book --pdf 
--latex-program=pdflatex $$i" ""''')
+                logger.info('+  found LilyPond-book version %s.' % 
version_number)
+            elif int(version[0]) > 2 or (len(version) > 1 and int(version[0]) 
== 2 and int(version[1]) >= 1):
+                addToRC(r'\converter lilypond-book latex    "lilypond-book 
$$i"                                ""')
+                logger.info('+  found LilyPond-book version %s.' % 
version_number)
+            else:
+                logger.info('+  found LilyPond-book, but version %s is too 
old.' % version_number)
+        else:
+            logger.info('+  found LilyPond-book, but could not extract version 
number.')
+    #
     checkProg('a Noteedit -> LilyPond converter', ['noteedit --export-lilypond 
$$i'],
         rc_entry = [ r'\converter noteedit   lilypond   "%%"   ""', ''])
     #
Index: examples/lilypond.lyx
===================================================================
--- examples/lilypond.lyx       (revision 0)
+++ examples/lilypond.lyx       (revision 0)
@@ -0,0 +1,727 @@
+#LyX 2.0.0svn created this file. For more info see http://www.lyx.org/
+\lyxformat 385
+\begin_document
+\begin_header
+\textclass article
+\use_default_options true
+\begin_modules
+lilypond
+\end_modules
+\maintain_unincluded_children false
+\language english
+\inputencoding auto
+\fontencoding global
+\font_roman default
+\font_sans default
+\font_typewriter default
+\font_default_family default
+\use_xetex false
+\font_sc false
+\font_osf false
+\font_sf_scale 100
+\font_tt_scale 100
+
+\graphics default
+\default_output_format default
+\bibtex_command default
+\index_command default
+\paperfontsize default
+\spacing single
+\use_hyperref false
+\papersize default
+\use_geometry true
+\use_amsmath 1
+\use_esint 1
+\use_mhchem 1
+\cite_engine basic
+\use_bibtopic false
+\use_indices false
+\paperorientation portrait
+\suppress_date false
+\index Index
+\shortcut idx
+\color #008000
+\end_index
+\leftmargin 2cm
+\topmargin 2cm
+\rightmargin 2cm
+\bottommargin 2cm
+\secnumdepth 3
+\tocdepth 3
+\paragraph_separation indent
+\paragraph_indentation default
+\quotes_language english
+\papercolumns 1
+\papersides 1
+\paperpagestyle default
+\tracking_changes false
+\output_changes false
+\html_math_output 0
+\html_be_strict true
+\end_header
+
+\begin_body
+
+\begin_layout Section
+LilyPond-book + LyX
+\end_layout
+
+\begin_layout Standard
+This is an example file for mixing LilyPond and LyX.
+ First, let's try a simple scale:
+\end_layout
+
+\begin_layout Standard
+\begin_inset Flex LilyPond
+status open
+
+\begin_layout Plain Layout
+
+
+\backslash
+score{
+\end_layout
+
+\begin_layout Plain Layout
+
+  
+\backslash
+relative c' {c d e f g a b c}
+\end_layout
+
+\begin_layout Plain Layout
+
+} % this is a comment
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+LilyPond-book searches for the 
+\family typewriter
+
+\backslash
+score
+\family default
+ command when it decides if the code is only a fragment.
+ Thus, in the following code, it gets confused if you remove the braces:
+\end_layout
+
+\begin_layout Standard
+\begin_inset Flex LilyPond
+status open
+
+\begin_layout Plain Layout
+
+{c' e' g'} % no 
+\backslash
+score given
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+You can use the LyX-inset within a line: 
+\begin_inset Flex LilyPond
+status collapsed
+
+\begin_layout Plain Layout
+
+{c' e' g'}
+\end_layout
+
+\end_inset
+
+.
+ Granted, this looks funny, but it behaves as you would expect, even for
+ fragments which require multiple lines of LilyPond code: 
+\begin_inset Flex LilyPond
+status open
+
+\begin_layout Plain Layout
+
+
+\backslash
+relative c'' {
+\end_layout
+
+\begin_layout Plain Layout
+
+  a4 b c d
+\end_layout
+
+\begin_layout Plain Layout
+
+}
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Standard
+Using the LyX-inset is the same as writing in LaTeX:
+\end_layout
+
+\begin_layout LyX-Code
+
+\backslash
+begin{lilypond}
+\end_layout
+
+\begin_layout LyX-Code
+  c' e' g'
+\end_layout
+
+\begin_layout LyX-Code
+
+\backslash
+end{lilypond}
+\end_layout
+
+\begin_layout Standard
+LaTeX obeys your spacing, so if you want the fragment on its own line, it
+ will be.
+ The standard inline example is to display a chord 
+\begin_inset Flex LilyPond
+status collapsed
+
+\begin_layout Plain Layout
+
+{
+\backslash
+context Voice <<c' es' g'>>}
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Section
+LilyPond example
+\end_layout
+
+\begin_layout Subsection
+Editorial headword
+\end_layout
+
+\begin_layout Standard
+NR 1.7 Editorial annotations Beethoven, Op.
+ 31, No.
+ 3 Piano sonata 18, Movt II, Scherzo Measures 9--14.
+\end_layout
+
+\begin_layout Standard
+\begin_inset Flex LilyPond
+status collapsed
+
+\begin_layout Plain Layout
+
+
+\backslash
+new PianoStaff <<
+\end_layout
+
+\begin_layout Plain Layout
+
+  
+\end_layout
+
+\begin_layout Plain Layout
+
+  % RH Staff
+\end_layout
+
+\begin_layout Plain Layout
+
+  
+\backslash
+new Staff {
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+clef treble
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+key aes 
+\backslash
+major
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+time 2/4
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+set Staff.fingeringOrientations = #'(up)
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+set Score.currentBarNumber = #9
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+partial 8
+\end_layout
+
+\begin_layout Plain Layout
+
+    <aes''-4 c''>8
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    |
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+set doubleSlurs = ##t
+\end_layout
+
+\begin_layout Plain Layout
+
+    <bes''-5 des''-2>4(
+\end_layout
+
+\begin_layout Plain Layout
+
+    <aes''-4 c''>8
+\backslash
+staccato)
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+noBeam
+\end_layout
+
+\begin_layout Plain Layout
+
+    c''8-5
+\backslash
+staccato
+\backslash
+pp
+\end_layout
+
+\begin_layout Plain Layout
+
+    |
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+unset doubleSlurs
+\end_layout
+
+\begin_layout Plain Layout
+
+    bes'8..(
+\end_layout
+
+\begin_layout Plain Layout
+
+    aes'32
+\end_layout
+
+\begin_layout Plain Layout
+
+    g'8)
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    f'8
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    |
+\end_layout
+
+\begin_layout Plain Layout
+
+    e'4-2
+\end_layout
+
+\begin_layout Plain Layout
+
+    r8
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+once 
+\backslash
+override Script #'script-priority = #-100
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+afterGrace
+\end_layout
+
+\begin_layout Plain Layout
+
+    f'8(
+\backslash
+trill^
+\backslash
+markup { 
+\backslash
+finger "3-2" }
+\end_layout
+
+\begin_layout Plain Layout
+
+    { e'16[ f'16] }
+\end_layout
+
+\begin_layout Plain Layout
+
+    |
+\end_layout
+
+\begin_layout Plain Layout
+
+    g'8..-3
+\end_layout
+
+\begin_layout Plain Layout
+
+    f'32
+\end_layout
+
+\begin_layout Plain Layout
+
+    e'8-1)
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    d'8-2
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    |
+\end_layout
+
+\begin_layout Plain Layout
+
+    c'4
+\end_layout
+
+\begin_layout Plain Layout
+
+    r4
+\end_layout
+
+\begin_layout Plain Layout
+
+  }
+\end_layout
+
+\begin_layout Plain Layout
+
+  
+\end_layout
+
+\begin_layout Plain Layout
+
+  % LH Staff
+\end_layout
+
+\begin_layout Plain Layout
+
+  
+\backslash
+new Staff {
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+key aes 
+\backslash
+major
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+clef treble
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+override Fingering #'direction = #down
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+set Staff.fingeringOrientations = #'(down)
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+partial 8
+\end_layout
+
+\begin_layout Plain Layout
+
+    <aes' aes>8
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+set doubleSlurs = ##t
+\end_layout
+
+\begin_layout Plain Layout
+
+    <g'-2 ees'-3>4(
+\end_layout
+
+\begin_layout Plain Layout
+
+    <aes' aes>8)
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+noBeam
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+clef bass
+\end_layout
+
+\begin_layout Plain Layout
+
+    c'8-1
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    |
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+set doubleSlurs = ##f
+\end_layout
+
+\begin_layout Plain Layout
+
+    bes8..(
+\end_layout
+
+\begin_layout Plain Layout
+
+    aes32
+\end_layout
+
+\begin_layout Plain Layout
+
+    g8-1)
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    f8
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    |
+\end_layout
+
+\begin_layout Plain Layout
+
+    e4
+\end_layout
+
+\begin_layout Plain Layout
+
+    r8
+\end_layout
+
+\begin_layout Plain Layout
+
+    
+\backslash
+afterGrace
+\end_layout
+
+\begin_layout Plain Layout
+
+    f8(
+\backslash
+trill_
+\backslash
+markup { 
+\backslash
+finger "2-1" }
+\end_layout
+
+\begin_layout Plain Layout
+
+    { e16[ f16] }
+\end_layout
+
+\begin_layout Plain Layout
+
+    |
+\end_layout
+
+\begin_layout Plain Layout
+
+    g8..-1
+\end_layout
+
+\begin_layout Plain Layout
+
+    f32
+\end_layout
+
+\begin_layout Plain Layout
+
+    e8)
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    d8
+\backslash
+staccato
+\end_layout
+
+\begin_layout Plain Layout
+
+    |
+\end_layout
+
+\begin_layout Plain Layout
+
+    c4
+\end_layout
+
+\begin_layout Plain Layout
+
+    r4
+\end_layout
+
+\begin_layout Plain Layout
+
+  }
+\end_layout
+
+\begin_layout Plain Layout
+
+>>
+\end_layout
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+[from 
+\begin_inset Flex URL
+status collapsed
+
+\begin_layout Plain Layout
+
+http://lsr.dsi.unimi.it/LSR/Item?id=627
+\end_layout
+
+\end_inset
+
+]
+\end_layout
+
+\end_body
+\end_document

Property changes on: examples/lilypond.lyx
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

Reply via email to