diff --git a/songbook-style.sty b/songbook-style.sty index 5acb613..8f7b335 100644 --- a/songbook-style.sty +++ b/songbook-style.sty @@ -54,7 +54,6 @@ chorus/named = false, chorus/numbered = false, after-song = \songendsection, - disable-measuring, } \setchords{ @@ -74,7 +73,9 @@ \tl_new:N \l__sb_mo_tl \tl_new:N \l__sb_pflb_tl \tl_new:N \l__sb_num_tl +\tl_new:N \l__sb_songid_tl \bool_new:N \g__sb_toc_opened_bool +\seq_new:N \g__sb_written_seq % Lazy-open: only truncate the file when first song writes to it % This ensures the TOC reads the PREVIOUS run's data before truncation @@ -94,21 +95,30 @@ \cs_new_protected:Npn \writesongtoc { - \__sb_ensure_toc_open: - \stepcounter{songnumber} + % Use leadsheets song ID to skip duplicate calls (measurement pass) + \tl_set:NV \l__sb_songid_tl \l_leadsheets_current_song_id_tl + \seq_if_in:NVF \g__sb_written_seq \l__sb_songid_tl + { + \seq_gput_right:NV \g__sb_written_seq \l__sb_songid_tl + \__sb_ensure_toc_open: + \stepcounter{songnumber} + \tl_set:Nx \l__sb_num_tl { \int_use:N \c@songnumber } + \tl_set:Nx \l__sb_title_tl { \songproperty{title} } + \tl_set:Nx \l__sb_mo_tl { \songproperty{mundorgel} } + \tl_set:Nx \l__sb_pflb_tl { \songproperty{pfadfinderliederbuch} } + \iow_now:Nx \g__sb_toc_iow + { + \exp_not:N \songtocrow + { \l__sb_title_tl } + { \l__sb_mo_tl } + { \l__sb_pflb_tl } + { \exp_not:N \pageref { song: \l__sb_num_tl } } + } + } + % Label MUST be outside guard: measurement pass label is discarded (inside vbox), + % but the real pass label survives and gets written to .aux \tl_set:Nx \l__sb_num_tl { \int_use:N \c@songnumber } \label{song:\tl_use:N \l__sb_num_tl} - \tl_set:Nx \l__sb_title_tl { \songproperty{title} } - \tl_set:Nx \l__sb_mo_tl { \songproperty{mundorgel} } - \tl_set:Nx \l__sb_pflb_tl { \songproperty{pfadfinderliederbuch} } - \iow_now:Nx \g__sb_toc_iow - { - \exp_not:N \songtocrow - { \l__sb_title_tl } - { \l__sb_mo_tl } - { \l__sb_pflb_tl } - { \exp_not:N \pageref { song: \l__sb_num_tl } } - } } \ExplSyntaxOff @@ -172,18 +182,13 @@ }% \endgroup \vspace{3mm}% - \begingroup\footnotesize - \noindent - \makebox[0.18\textwidth][c]{MO}% - \makebox[0.18\textwidth][c]{PfLB}% - \hfill\par\noindent - \makebox[0.18\textwidth][c]{% - \ifsongproperty{mundorgel}{\songproperty{mundorgel}}{}% - }% - \makebox[0.18\textwidth][c]{% - \ifsongproperty{pfadfinderliederbuch}{\songproperty{pfadfinderliederbuch}}{}% - }% - \hfill + \begingroup\footnotesize\centering + \begin{tabular}{ccc} + MO & PfLB & Liederbuch \\ + \ifsongproperty{mundorgel}{\songproperty{mundorgel}}{} & + \ifsongproperty{pfadfinderliederbuch}{\songproperty{pfadfinderliederbuch}}{} & + \thepage + \end{tabular}\par \endgroup \newpage }