summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/leadsheets/leadsheets.library.templates.code.tex
blob: c6180d9ca357e5663e999e0132acfadf3840ad15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
% --------------------------------------------------------------------------
% the LEADSHEETS package
% 
%   typesetting leadsheets and songbooks
%
% --------------------------------------------------------------------------
% Clemens Niederberger
% E-Mail: contact@mychemistry.eu
% --------------------------------------------------------------------------
% Copyright 2014--2022 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Clemens Niederberger.
% --------------------------------------------------------------------------
\LeadsheetsExplLibrary{templates}
  {2014/08/10 template mechanism for song titles and verses}

\msg_new:nnn {leadsheets} {unknown-template}
  { Unknown~ #1~ template~ `#2'~ \msg_line_context: }

\tl_new:N    \l__leadsheets_songtitle_template_tl
\prop_new:N  \l__leadsheets_songtitle_template_prop

% \NewDocumentCommand \songtitle {} { \leadsheets_songtitle: }

% the following is shamelessly adapted from the `needspace' package by
% Peter Wilson and Herries Press:
\cs_new_protected:Npn \__leadsheets_needspace:n #1
  {
    \group_begin:
      \dim_set:Nn \l__leadsheets_tmpa_dim { #1 }
      \skip_vertical:n { \c_zero_dim + \l__leadsheets_tmpa_dim }
      \tex_penalty:D -100
      \skip_vertical:n { \c_zero_dim - \l__leadsheets_tmpa_dim }
      \skip_vertical:N \l__leadsheets_tmpa_dim
      \tex_penalty:D 9999
      \skip_vertical:n { - \l__leadsheets_tmpa_dim }
      \skip_vertical:N \c_zero_dim
    \group_end:
  }

\cs_new_protected:Npn \__leadsheets_songtitle:
  {
    \__leadsheets_use_songtitle_template:V \l__leadsheets_songtitle_template_tl
    \__leadsheets_needspace:n { 3\baselineskip }
  }

\cs_new_protected:Npn \__leadsheets_use_songtitle_template:n #1
  {
    \prop_get:NnNTF \l__leadsheets_songtitle_template_prop
      {#1}
      \l__leadsheets_tmpa_tl
      { \l__leadsheets_tmpa_tl }
      { \msg_error:nnnn {leadsheets} {unknown-template} {songtitle} {#1} }
  }
\cs_generate_variant:Nn \__leadsheets_use_songtitle_template:n { V }

\cs_new_protected:Npn \leadsheets_define_songtitle_template:nn #1#2
  { \prop_put:Nnn \l__leadsheets_songtitle_template_prop {#1} {#2} }


\NewDocumentCommand \definesongtitletemplate {m+m}
  { \leadsheets_define_songtitle_template:nn {#1} {#2} }

\NewDocumentCommand \expandcode {+m} { \use:x {#1} }


% verse-type templates
\prop_new:N \l__leadsheets_verse_begin_template_prop
\prop_new:N \l__leadsheets_verse_end_template_prop

% #1: template name
% #2: begin code
% #3: end code
\cs_new_protected:Npn \leadsheets_define_verse_template:nnn #1#2#3
  {
    \prop_put:Nnn \l__leadsheets_verse_begin_template_prop {#1} {#2}
    \prop_put:Nnn \l__leadsheets_verse_end_template_prop {#1} {#3}
  }

\cs_new_protected:Npn \leadsheets_use_verse_template:nn #1#2
  {
    \exp_args:Nnc
    \prop_get:cVNTF {l__leadsheets_verse_#1_template_prop}
      {l__leadsheets_#2_template_tl}
      \l__leadsheets_tmpa_tl
      { \tl_use:N \l__leadsheets_tmpa_tl }
      {
        \msg_error:nnxx {leadsheets} {unknown-template}
          {verse-type}
          {\use:c{l__leadsheets_#2_template_tl}}
      }
  }

\DeclareExpandableDocumentCommand \ifobeylines {}
  { \bool_if:NTF \l__leadsheets_obey_lines_bool }

\NewDocumentCommand \defineversetypetemplate {m+m+m}
  { \leadsheets_define_verse_template:nnn {#1} {#2} {#3} }

\file_input_stop: