# -*- org-confirm-babel-evaluate: nil -*- #+TITLE: Org-mode as a Replacement for lilypond-book #+AUTHOR: Jamie Beardslee #+PROPERTY: header-args :noweb yes #+OPTIONS: toc:nil date:nil This is a document to help me remember the specifics of writing lilypond in org-mode, and exporting to pdf/html. * Boilerplate The following is some boilerplate that sets version/language and adjusts the paper size so that a line doesn't take up a whole page. In actual use, you will likely want to use =:exports none= rather than =:exports code= like I did here. This is just to show how it's done. #+name: version-and-paper #+begin_src LilyPond :exports code \version "2.19" \language "english" \paper{ indent=0\mm line-width=170\mm oddFooterMarkup=##f oddHeaderMarkup=##f bookTitleMarkup=##f scoreTitleMarkup=##f } #+end_src It is necessary to give this block a name, using the following: #+begin_src org ,#+name: version-and-paper #+end_src This section can be added to all lilypond source blocks using noweb syntax. This can be done on each block you want to use it for, but for lilypond it is a good idea to use noweb syntax globally. #+begin_src org ,#+PROPERTY: header-args :noweb yes #+end_src * This is a scale Here is an 8 bar scale. Note the line fits the page properly. - PDF: Write the file to a pdf (NOT eps). i.e. =:file scale.pdf= - HTML: Write the file to a png. i.e. =:file scale.png= #+begin_src lilypond :file scale.pdf <> \relative c' { c d e f | g a b c | c b a g | f e d c | c d e f | g a b c | c b a g | f e d c | } #+end_src ** Line breaks Here is the same scale with a line break in the middle. #+begin_src lilypond :file line-break.pdf <> \relative c' { c d e f | g a b c | c b a g | f e d c | \break c d e f | g a b c | c b a g | f e d c | } #+end_src * Another example Following are the opening bars of Brahms' cello sonata in E minor. Although it is a shorter snippet than the previous scale, it is enlarged to fit the page. #+begin_src lilypond :file brahms.pdf <> \relative c, { \key e \minor \clef "bass" e2 g4. b8 | c2 b | a8 b16 a g8 a b4. g8 | e2 fs | } #+end_src #+begin_export latex \pagebreak #+end_export * Size issues There are times when one would want to show a single bar. The previous method makes the music far too big. #+begin_src lilypond :file massive.pdf <> \relative c { \clef "bass" c1 \bar "|." } #+end_src ** Writing music that doesn't take up the whole line. You may want to include a bar or two wrapped within the paragraph. You can do this like so. - Write the lilypond code with =:exports none= There will be no code or output shown here in the output. #+begin_src lilypond :file inline.pdf :exports none <> \relative c' { c c g' g | a a g2 | } #+end_src #+RESULTS: [[file:inline.pdf]] - Link to the file using =ATTR_LATEX= with whatever options you need. Proin quam nisl, tincidunt et, mattis eget, convallis nec, purus. Nullam tristique diam non turpis. Praesent fermentum tempor tellus. Nunc eleifend leo vitae magna. Nam euismod tellus id erat. Suspendisse potenti. #+ATTR_LATEX: :width 5cm :float wrap [[file:inline.pdf]] Praesent augue. Nunc aliquet, augue nec adipiscing interdum, lacus tellus malesuada massa, quis varius mi purus non odio. Donec posuere augue in quam. Nullam tristique diam non turpis. Suspendisse potenti. Fusce suscipit, wisi nec facilisis facilisis, est dui fermentum leo, quis tempor ligula erat quis odio. - NOTE: You will need to evaluate the block manually with =C-c C-c= #+begin_export latex \pagebreak #+end_export * General latex export tips ** Full page By default, LaTeX leaves a lot of whitespace on the sides of the page. To use the full page, add the following at the top of the file. #+begin_src org :exports code ,#+LaTeX_HEADER: \usepackage[cm]{fullpage} #+end_src ** Table of contents, date, etc. By default, org adds a timestamp and table of contents when exporting to LaTeX. These can be removed using the following. #+begin_src org ,#+OPTIONS: toc:nil date:nil #+end_src ** Random bits of LaTeX throughout the document At any point, you can add snippets of LaTeX. Earlier, I used this to split the page. You can add anything you want using this method. #+begin_src org ,#+begin_export latex \pagebreak ,#+end_export #+end_src