[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to use LaTeX code from manual to include LilyPond-generated TOC?
From: |
Jean Abou Samra |
Subject: |
How to use LaTeX code from manual to include LilyPond-generated TOC? |
Date: |
Thu, 10 Mar 2022 22:57:14 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 |
Hi,
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
After reading that, I fired LilyPond 2.20 (since the Scheme code
is broken in 2.22 and I am writing code that will break it further)
to generate toc.toc:
1, section, 1, {A}, toc96,
1, section, 1, {B}, toc97
Then I tried to compile:
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \includescore{PossibleExtension}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Read in the TOC entries for a PDF file from the corresponding .toc file.
% This requires some heave latex tweaking, since reading in things from
a file
% and inserting it into the arguments of a macro is not (easily) possible
% Solution by Patrick Fimml on #latex on April 18, 2009:
% \readfile{filename}{\variable}
% reads in the contents of the file into \variable (undefined if file
% doesn't exist)
\newread\readfile@f
\def\readfile@line#1{%
{\catcode`\^^M=10\global\read\readfile@f to \readfile@tmp}%
\edef\do{\noexpand\g@addto@macro{\noexpand#1}{\readfile@tmp}}\do%
\ifeof\readfile@f\else%
\readfile@line{#1}%
\fi%
}
\def\readfile#1#2{%
\openin\readfile@f=#1 %
\ifeof\readfile@f%
\typeout{No TOC file #1 available!}%
\else%
\gdef#2{}%
\readfile@line{#2}%
\fi
\closein\readfile@f%
}%
\newcommand{\includescore}[1]{
\def\oly@fname{\oly@basename\@ifmtarg{#1}{}{_#1}}
\let\oly@addtotoc\undefined
\readfile{\oly@xxxxxxxxx}{\oly@addtotoc}
\ifx\oly@addtotoc\undefined
\includepdf[pages=-]{\oly@fname}
\else
\edef\includeit{\noexpand\includepdf[pages=-,addtotoc={\oly@addtotoc}]
{\oly@fname}}\includeit
\fi
}
\includescore{toc}
\end{document}
pdflatex complains:
! Undefined control sequence.
\includescore ...}} \let \oly @addtotoc\undefined
\readfile {\oly
@xxxxxxxxx...
l.50 \includescore{toc}
If I move the definitions before \begin{document}, I get
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.17 \newread\readfile@
f
How is this supposed to work?
Thanks,
Jean