lilypond.org (4621B)
1 # -*- org-confirm-babel-evaluate: nil -*- 2 #+TITLE: Org-mode as a Replacement for lilypond-book 3 #+AUTHOR: Jamie Beardslee 4 5 #+PROPERTY: header-args :noweb yes 6 #+OPTIONS: toc:nil date:nil 7 8 This is a document to help me remember the specifics of writing 9 lilypond in org-mode, and exporting to pdf/html. 10 11 * Boilerplate 12 13 The following is some boilerplate that sets version/language and 14 adjusts the paper size so that a line doesn't take up a whole page. 15 16 In actual use, you will likely want to use =:exports none= rather than 17 =:exports code= like I did here. This is just to show how it's done. 18 19 #+name: version-and-paper 20 #+begin_src LilyPond :exports code 21 \version "2.19" 22 \language "english" 23 \paper{ 24 indent=0\mm 25 line-width=170\mm 26 oddFooterMarkup=##f 27 oddHeaderMarkup=##f 28 bookTitleMarkup=##f 29 scoreTitleMarkup=##f 30 } 31 #+end_src 32 33 It is necessary to give this block a name, using the following: 34 #+begin_src org 35 ,#+name: version-and-paper 36 #+end_src 37 38 This section can be added to all lilypond source blocks using noweb 39 syntax. This can be done on each block you want to use it for, but 40 for lilypond it is a good idea to use noweb syntax globally. 41 42 #+begin_src org 43 ,#+PROPERTY: header-args :noweb yes 44 #+end_src 45 46 * This is a scale 47 48 Here is an 8 bar scale. Note the line fits the page properly. 49 50 - PDF: Write the file to a pdf (NOT eps). i.e. =:file scale.pdf= 51 - HTML: Write the file to a png. i.e. =:file scale.png= 52 53 #+begin_src lilypond :file scale.pdf 54 <<version-and-paper>> 55 \relative c' { 56 c d e f | 57 g a b c | 58 c b a g | 59 f e d c | 60 c d e f | 61 g a b c | 62 c b a g | 63 f e d c | 64 } 65 #+end_src 66 67 ** Line breaks 68 69 Here is the same scale with a line break in the middle. 70 71 #+begin_src lilypond :file line-break.pdf 72 <<version-and-paper>> 73 \relative c' { 74 c d e f | 75 g a b c | 76 c b a g | 77 f e d c | \break 78 c d e f | 79 g a b c | 80 c b a g | 81 f e d c | 82 } 83 #+end_src 84 85 * Another example 86 87 Following are the opening bars of Brahms' cello sonata in E minor. 88 Although it is a shorter snippet than the previous scale, it is 89 enlarged to fit the page. 90 91 #+begin_src lilypond :file brahms.pdf 92 <<version-and-paper>> 93 \relative c, { 94 \key e \minor 95 \clef "bass" 96 e2 g4. b8 | 97 c2 b | 98 a8 b16 a g8 a b4. g8 | 99 e2 fs | 100 } 101 #+end_src 102 103 #+begin_export latex 104 \pagebreak 105 #+end_export 106 107 * Size issues 108 109 There are times when one would want to show a single bar. The 110 previous method makes the music far too big. 111 112 #+begin_src lilypond :file massive.pdf 113 <<version-and-paper>> 114 \relative c { 115 \clef "bass" 116 c1 \bar "|." 117 } 118 #+end_src 119 120 ** Writing music that doesn't take up the whole line. 121 122 You may want to include a bar or two wrapped within the paragraph. 123 You can do this like so. 124 125 - Write the lilypond code with =:exports none= 126 127 There will be no code or output shown here in the output. 128 129 #+begin_src lilypond :file inline.pdf :exports none 130 <<version-and-paper>> 131 \relative c' { 132 c c g' g | 133 a a g2 | 134 } 135 #+end_src 136 137 #+RESULTS: 138 [[file:inline.pdf]] 139 140 - Link to the file using =ATTR_LATEX= with whatever options you need. 141 142 Proin quam nisl, tincidunt et, mattis eget, convallis nec, purus. 143 Nullam tristique diam non turpis. Praesent fermentum tempor tellus. 144 Nunc eleifend leo vitae magna. Nam euismod tellus id erat. 145 Suspendisse potenti. 146 #+ATTR_LATEX: :width 5cm :float wrap 147 [[file:inline.pdf]] Praesent augue. Nunc aliquet, augue nec adipiscing 148 interdum, lacus tellus malesuada massa, quis varius mi purus non odio. 149 Donec posuere augue in quam. Nullam tristique diam non turpis. 150 Suspendisse potenti. Fusce suscipit, wisi nec facilisis facilisis, 151 est dui fermentum leo, quis tempor ligula erat quis odio. 152 153 - NOTE: You will need to evaluate the block manually with =C-c C-c= 154 155 #+begin_export latex 156 \pagebreak 157 #+end_export 158 159 * General latex export tips 160 161 ** Full page 162 163 By default, LaTeX leaves a lot of whitespace on the sides of the page. 164 To use the full page, add the following at the top of the file. 165 166 #+begin_src org :exports code 167 ,#+LaTeX_HEADER: \usepackage[cm]{fullpage} 168 #+end_src 169 170 ** Table of contents, date, etc. 171 172 By default, org adds a timestamp and table of contents when exporting 173 to LaTeX. These can be removed using the following. 174 175 #+begin_src org 176 ,#+OPTIONS: toc:nil date:nil 177 #+end_src 178 179 ** Random bits of LaTeX throughout the document 180 181 At any point, you can add snippets of LaTeX. Earlier, I used this to 182 split the page. You can add anything you want using this method. 183 184 #+begin_src org 185 ,#+begin_export latex 186 \pagebreak 187 ,#+end_export 188 #+end_src