# Replicating Lilypond titles in LaTeX

I'm working on a huge project that automatically and without any human intervention generates music scores. Most of the time this is with Lilypond. But some of the scores use graphical notation and for those I use TikZ and pdfLaTeX. The problem is that I want to match Lilypond's title header look in LaTeX but I am struggling.

First is Lilypond

Next is my effort:

And here is the LaTeX code that my software generates:

\documentclass[11pt]{memoir}
\usepackage{tikz}
\usepackage[top=5mm,left=15mm,right=15mm]{geometry}
\usepackage{parskip}
\usepackage{newcent}

\begin{document}
\begin{center}
(Dedication) \\
\smallskip\textbf{\LARGE{Title}} \\
\medskip\textbf{\large{Style}} \\
\end{center}
\vspace{-8pt}
\noindent
\begin{minipage}[t][0em][b]{0.33\textwidth}Poet \end{minipage}
\begin{minipage}[t][0em][b]   {0.33\textwidth}\begin{center}\textbf{\large{Instrument}}   \end{center}\end{minipage}
\begin{minipage}[t][0em][b]{0.33\textwidth}\hfill Composer\end{minipage}\\
\medskip
\noindent
\begin{minipage}[c][1em][b]{0.5\textwidth}Meter \end{minipage}
\begin{minipage}[c][1em][b]{0.5\textwidth}\hfill Arranger\end{minipage}\\
Piece

\end{document}


So there are a few issues:

1. My "Composer" does not appear to be flush right

2. I'm really not fond of the \vspace{-8pt} bit. The software will use different fonts and paper sizes and I worry that anything hardcoded like that will eventually look bad. I've never used minipages before so I don't know if I'm doing that stuff correctly. Basically I just experimented with the parameters till it looked OK.

3. I don't know why the "Piece" entry is spaced so awkwardly in the Lilypond example but I prefer the more even spacing in mine, so that's not an issue.

4. I can play around with the geometry more on my own but if anyone has any suggestions for the spacing I would appreciate that as well.

5. There will not always be entries for the "Poet", "Meter", and "Piece". So right now using \hfill seems to do the trick of keeping the same spacing. Is that the best way to handle that assuming I keep using minipages?

It doesn't need to be a perfect copy but I do want it to look the same to the casual observer.

I suggest, first of all, a key-value syntax. Then you can divide the space using a tabular with three equal size columns, with left, center and right alignment.

The dedication is typeset only if present, and in a unique center aligned column, so its width will not influence the positioning of the other elements.

\documentclass[11pt]{memoir}
\usepackage[top=5mm,left=15mm,right=15mm]{geometry}
\usepackage{newcent}
%\usepackage{array} % not needed with memoir
\usepackage{xparse}

\ExplSyntaxOn
{
dedication .tl_set:N = \l_bfootdave_lilytitle_dedication_tl,
title .tl_set:N = \l_bfootdave_lilytitle_title_tl,
style .tl_set:N = \l_bfootdave_lilytitle_style_tl,
instrument .tl_set:N = \l_bfootdave_lilytitle_instrument_tl,
poet .tl_set:N = \l_bfootdave_lilytitle_poet_tl,
composer .tl_set:N = \l_bfootdave_lilytitle_composer_tl,
arranger .tl_set:N = \l_bfootdave_lilytitle_arranger_tl,
meter .tl_set:N = \l_bfootdave_lilytitle_meter_tl,
piece .tl_set:N = \l_bfootdave_lilytitle_piece_tl,
}

{
\group_begin:
\keys_set:nn { bfootdav/lilyheader } { #1 }
\group_end:
}

{
\noindent\begin{tabular}
{
@{}
>{\raggedright}p{.33333\textwidth}
@{}
>{\centering}p{.33333\textwidth}
@{}
>{\raggedleft\arraybackslash}p{.33333\textwidth}
@{}
}
\tl_if_empty:NF \l_bfootdave_lilytitle_dedication_tl
{
\multicolumn{3}{@{}>{\centering}p{\textwidth}@{}}
{
( \l_bfootdave_lilytitle_dedication_tl )
}
\\
}
& \LARGE\bfseries\strut \l_bfootdave_lilytitle_title_tl &
\\
& \large\bfseries\strut \l_bfootdave_lilytitle_style_tl &
\\
\l_bfootdave_lilytitle_poet_tl &
\bfseries\l_bfootdave_lilytitle_instrument_tl &
\l_bfootdave_lilytitle_composer_tl
\\
\l_bfootdave_lilytitle_meter_tl && \l_bfootdave_lilytitle_arranger_tl
\\
\l_bfootdave_lilytitle_piece_tl &&
\end{tabular}
}
\ExplSyntaxOff

\begin{document}
dedication=Dedication,
title=Title,
style=Style,
poet=Poet,
instrument=Instrument,
composer=Composer,
meter=Meter,
arranger=Arranger,
piece=Piece
}

\end{document}


• This looks really good and I really appreciate the exceptional effort you put into this, but the process is confusing. My software, written in Lua, is already generating the LaTeX file and using variable names (like Instrument = "Piano") and then inserting the appropriate values into the generating LaTeX file, so if I understand what's going on here it looks like more than what I need. I'm going to try to extract the information I need. – bfootdav Oct 22 '14 at 21:41
• @bfootdav Just extract the information as argument to \makepieceheader: if you're able to make the script build that complicated set of boxes, the task should be much simpler. Note that, with a key-value syntax, the order of the keys is not important. – egreg Oct 22 '14 at 21:48
• Thank you very much. I've marked the question as answered. What I meant by "extracting the information" was to extract your tabular method and incorporate that into my software. My program already stores all those as keys and values so it seems a bit redundant to have LaTeX deal with all the same variables again. So I've now implemented your tabular method within my software and everything works and looks terrific. (Also, the Dedication wasn't actually optional but I was able to figure out how to use it like the rest of the entries.) – bfootdav Oct 22 '14 at 22:42