2

I'm writing a Lilypond typesetting tutorial in Org to be published on a web page. I would like to exclude the line with set-default-paper-size from html export, cause it doesn't belong to the tutorial but is needed to shrink the size of the resulting png. How could this be done?

#+begin_src lilypond :file c-major.png :exports both
#(set-default-paper-size "a9" 'landscape) % How to exclude this line from export???

{ c d e f g a b c }
#+end_src
#+results:
[[file:c-major.png]]

An alternative would be if babel could invoke lilypond with the -e option when evaluating the code block. Any other ideas how to hide specific code lines are appreciated as well.

EDIT: The following solution works fine for a single code block:

#+begin_src lilypond :file c-major.png :exports both :prologue "#(set-default-paper-size \"a8landscape\")"
{ c d e f g a b c }
#+end_src

All I have to do is to escape the double quotes. Now I try the same for a default setting in .emacs:

(add-to-list 'org-babel-default-header-args:lilypond
             '((:prologue . "#(set-default-paper-size \"a8landscape\")")))

Then the following error message is thrown:

org-babel-exp process lilypond at line 38...
Wrong type argument: stringp, (:prologue . "#(set-default-paper-size \"a8landscape\")")

This is the full backtrace:

Debugger entered--Lisp error: (void-function stringp\?)
  (stringp\? "#(set-default-paper-size \"a8landscape\")")
  eval((stringp\? "#(set-default-paper-size \"a8landscape\")") nil)
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)
  • Why not change this to :export results? Or do you want the source and the results appear in a different export (s.a. LaTeX), but not in HTML? There's also a post-processing hook for exports. I.e. you could add an Emacs Lisp function to run on the contents of the generated file after it's exported. That's not a very general solution, but would work for a one-of case. – wvxvw Mar 18 '16 at 6:54
  • A notation typesetting tutorial with no typesetting code doesn't seem to be the most useful thing to me, does it? ;-) – barrios Mar 19 '16 at 16:44
3

Take a look at the prologue header argument for Babel source blocks. You can use it to prepend some text to a code block prior to execution, and, like any other header argument, it isn't included in HTML export.

For example:

#+NAME: prologue-example.sh
#+BEGIN_SRC sh :prologue "echo yep; exit 0"
echo "nope"
#+END_SRC

#+RESULTS: prologue-example.sh
: yep
  • This exactly does the trick! Even better your prologue link shows how to setup a default prologue for every specific source code block, in my case lilypond. – barrios Mar 19 '16 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.