Skip to content

Instantly share code, notes, and snippets.

@lucaswerkmeister
Created April 11, 2018 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucaswerkmeister/17f1daeed0e6faae3366a4b08c1e29a9 to your computer and use it in GitHub Desktop.
Save lucaswerkmeister/17f1daeed0e6faae3366a4b08c1e29a9 to your computer and use it in GitHub Desktop.
Example of combining LilyPond, LaTeX, listings and beamer.
\relative c' {
c d e f |
g2 g |
}
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{txfonts}
\usepackage{xcolor}
\usepackage{subcaption}
\usepackage{listings}
\DeclareUnicodeCharacter{2665}{{\ensuremath\color{red}\varheartsuit}}
\beamertemplatenavigationsymbolsempty
\lstset{basicstyle=\ttfamily}
\begin{document}
\begin{frame}[fragile]
\frametitle{$\text{LilyPond} + \text{\LaTeX} = ♥$}
You can include LilyPond source code using \lstinline{listings}
and the corresponding musical notation using \lstinline{lilypond-book}.
\begin{figure}
\centering
\begin{subfigure}[b]{0.4\textwidth}
\lstinputlisting{entchen.ly}
\caption{The source code.}
\end{subfigure}
\begin{subfigure}[b]{0.4\textwidth}
\lilypondfile{entchen.ly}
\caption{The resulting notation.}
\end{subfigure}
\caption{A simple example melody.}
\end{figure}
The source code can be included inline
(\lstinline{lstlisting} and \lstinline{lilypond} environments)
or, even better, from a separate file
(\lstinline[language=tex]{\lstinputlisting} and \lstinline[language=tex]{\lilypondfile}).
\end{frame}
\end{document}
.PHONY: all
all: lilypond.pdf
%.tex: %.lytex
lilypond-book --pdf $<
%.pdf: %.tex
pdflatex $<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment