> The (pdf|Xe|(dvi)?Lua)?(La)?TeX experts in the room are going to
> find this question ridiculous, but anyway: how do I use the code
> here?
> 
> https://lilypond.org/doc/v2.23/Documentation/usage/sharing-the-table-of-contents.html

Here is an enhanced replacement.  For simplicity I didn't convert the
code into a style file.

```
\usepackage{xifthen}
\usepackage{catchfile}
\usepackage{pdfpages}

% Include a LilyPond score with an optional table of contents.
% This macro is a wrapper for the `\includepdf` command from the
% 'pdfpages' LaTeX package.
%
% Syntax:
%
%   \includescore{scorefile}
%   \include[tocfile]{scorefile}
%
% `scorefile` is the name of a PDF file.  `tocfile` is the name
% of a file containing entries for the master file's table of
% contents; see option 'addtotoc' in the 'pdfpages'
% documentation for the exact syntax.

\newcommand{\includescore}[2][]{%
  \ifthenelse{\isempty{#1}}%
    {\includepdf[pages=-]{#2}}%
    {\CatchFileDef{\IStoclines}{#1}{}%
     \edef\includeit{%
       \noexpand\includepdf[pages=-,addtotoc={\IStoclines}]{#2}}%
     \includeit}%
}
```

Assuming the above is in a file called `includescore.tex` and the TOC
lines in file `bar.toclines`, an example call could be

```
\documentclass{article}

\include{includescore}


\begin{document}

\tableofcontents

\section{foo}

This is a test chapter, followed by a score without an associated
tocfile.


\includescore{foo.pdf}


\section{bar}

This is a test chapter, followed by a score with an associated
tocfile.


\includescore[bar.toclines]{bar.pdf}


\section{baz}

End of tests.

\end{document}
```

Reply via email to