diff options
author | Karl Berry <karl@freefriends.org> | 2023-03-29 20:00:15 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-03-29 20:00:15 +0000 |
commit | 9fa41d1fc8f435a890f121050e2920d593b9dfff (patch) | |
tree | 39a033bfc90c52a768050d474ce2d2907a9f4783 /Master/texmf-dist | |
parent | a995526c1114d8fef2fe8b1f065e7a4a06750908 (diff) |
songproj (28mar23)
git-svn-id: svn://tug.org/texlive/trunk@66704 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rwxr-xr-x | Master/texmf-dist/doc/latex/songproj/song2tex.py | 26 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/songproj/songproj.pdf | bin | 100783 -> 131017 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/songproj/Makefile | 8 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/songproj/songproj.dtx | 67 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/songproj/songproj.sty | 23 |
5 files changed, 95 insertions, 29 deletions
diff --git a/Master/texmf-dist/doc/latex/songproj/song2tex.py b/Master/texmf-dist/doc/latex/songproj/song2tex.py index dc32da2b3fa..270a9ef7214 100755 --- a/Master/texmf-dist/doc/latex/songproj/song2tex.py +++ b/Master/texmf-dist/doc/latex/songproj/song2tex.py @@ -8,6 +8,7 @@ import re # The following regexp match the typical markers of refrain and couplet: re_refrain = re.compile(r'(R(efrain)?|C(horus)?)( |[-./] ?)', re.IGNORECASE) re_couplet = re.compile(r'\d+( |[-./] ?)') +re_txt_ext = re.compile(r'\.te?xt$') def match_rest(regexp, s): @@ -41,35 +42,35 @@ def parse_song(lines, re_refrain, re_couplet): yield '\\begin{refrain}\n' state = State.REFRAIN line = rest - yield ' {} \\\\\n'.format(line) + yield ' {}'.format(line) elif (rest := match_rest(re_couplet, line)) is not None: # when a couplet start marker is found, enter a couplet. yield '\\begin{couplet}\n' state = State.COUPLET line = rest - yield ' {} \\\\\n'.format(line) + yield ' {}'.format(line) elif line != '': # when a non-empty line is found, also enter a couplet as all. yield '\\begin{couplet}\n' state = State.COUPLET - yield ' {} \\\\\n'.format(line) + yield ' {}'.format(line) elif state == State.REFRAIN: # We are in the refrain. Depending on what we find: if line != '': # when a non-empty line is found, stay in the refrain. - yield ' {} \\\\\n'.format(line) + yield ' \\\\\n {}'.format(line) else: # when an empty line is found, leave the refrain. - yield '\\end{refrain}\n\n' + yield '\n\\end{refrain}\n\n' state = State.LIMBO elif state == State.COUPLET: # We are in a couplet. Depending on what we find: if line != '': # when a non-empty line is found, stay in the couplet. - yield ' {} \\\\\n'.format(line) + yield ' \\\\\n {}'.format(line) else: # when an empty line is found, leave the couplet. - yield '\\end{couplet}\n\n' + yield '\n\\end{couplet}\n\n' state = State.LIMBO # No matter what we found, we have a song line, possibly empty, that we # have to check to see if it could not be the new longest line seen so far. @@ -78,9 +79,9 @@ def parse_song(lines, re_refrain, re_couplet): # The song text file is now finished. We may still be in the refrain or in a # couplet, that we have to close. if state == State.REFRAIN: - yield '\\end{refrain}\n\n' + yield '\n\\end{refrain}\n\n' elif state == State.COUPLET: - yield '\\end{couplet}\n\n' + yield '\n\\end{couplet}\n\n' # Now print the longest line of the entire song. yield '\\longest{{{}}}\n'.format(longest) @@ -92,8 +93,13 @@ def main(args=None): parser.add_argument("--couplet", '-c', type=re.compile, default=re_couplet, metavar="REGEXP", help="specify the couplet marker (regexp, default \"{}\")".format(re_couplet.pattern)) parser.add_argument("infile", help="input song text file", type=argparse.FileType('r')) - parser.add_argument("outfile", help="output LaTeX file", type=argparse.FileType('w')) + parser.add_argument("outfile", help="output LaTeX file", type=argparse.FileType('w'), nargs='?') args = parser.parse_args(args) + if args.outfile is None: + try: + args.outfile = open(re_txt_ext.sub('', args.infile.name) + '.tex', 'w') + except AttributeError: + parser.error("the following argument is required: outfile") for line in parse_song(args.infile, args.refrain, args.couplet): args.outfile.write(line) diff --git a/Master/texmf-dist/doc/latex/songproj/songproj.pdf b/Master/texmf-dist/doc/latex/songproj/songproj.pdf Binary files differindex 24216ce1505..1329f0e9863 100644 --- a/Master/texmf-dist/doc/latex/songproj/songproj.pdf +++ b/Master/texmf-dist/doc/latex/songproj/songproj.pdf diff --git a/Master/texmf-dist/source/latex/songproj/Makefile b/Master/texmf-dist/source/latex/songproj/Makefile index 48edf01b517..de8b57bc125 100644 --- a/Master/texmf-dist/source/latex/songproj/Makefile +++ b/Master/texmf-dist/source/latex/songproj/Makefile @@ -22,10 +22,12 @@ pdf: songproj.pdf mostlyclean: rm -f *.aux *.glo *.gls *.hd *.idx *.ilg *.ind *.log *.out +ctanclean: mostlyclean + rm -f *.sty + clean: mostlyclean rm -f *.pdf -maintainer-clean: clean - rm -f *.sty +maintainer-clean: ctanclean clean -.PHONY: all sty doc mostlyclean clean maintainer-clean +.PHONY: all sty doc mostlyclean ctanclean clean maintainer-clean diff --git a/Master/texmf-dist/source/latex/songproj/songproj.dtx b/Master/texmf-dist/source/latex/songproj/songproj.dtx index 7c1783fe15c..6ed09318c0d 100644 --- a/Master/texmf-dist/source/latex/songproj/songproj.dtx +++ b/Master/texmf-dist/source/latex/songproj/songproj.dtx @@ -34,7 +34,7 @@ %<package>\NeedsTeXFormat{LaTeX2e}[2020/10/01] %<package>\ProvidesPackage{songproj} %<*package> - [2022/11/07 v1.0.1 Song projection] + [2023/03/29 v1.2.0 Song projection] %</package> % %<*driver> @@ -52,7 +52,7 @@ %</driver> % \fi % -% \CheckSum{256} +% \CheckSum{269} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z @@ -75,6 +75,8 @@ % \changes{v0.3.0}{2021/09/26}{Use \textsf{expl3} naming conventions} % \changes{v1.0.0}{2021/11/07}{First public release} % \changes{v1.0.1}{2021/11/07}{Add the generated extension file to Git} +% \changes{v1.1.0}{2023/03/27}{Allow couplet numbering with \cs{numbercouplets}} +% \changes{v1.2.0}{2023/03/29}{Allow couplet numbering with \cs{inputsong*}} % % \GetFileInfo{songproj.dtx} % @@ -147,6 +149,16 @@ % is only used to compute and record its length, and will not be typeset. % \end{function} % +% \changes{v1.1.0}{2023/03/27}{Document the \cs{numbercouplets} command} +% \begin{function}{\numbercouplets} +% \label{doc-cs-numbercouplets} +% Inside a \env{song} environment, the \cs{numbercouplets} command can be used +% to enable couplet numbering. This can be useful when specific couplets have +% been selected but the lead singer has a score a lyrics sheet that includes +% all of them: indicating the couplet numbers in the projection will allow them +% to check which couplet to sing. +% \end{function} +% % \changes{v0.4.0}{2021/09/29}{Document \env{intro} and \env{final} environments} % % \paragraph{} @@ -215,10 +227,12 @@ % % \subsection{The \cs{inputsong} command} % \changes{v1.0.0}{2021/11/07}{Document the \cs{inputsong} command} +% \changes{v1.2.0}{2023/03/29}{Document the \cs{inputsong*} command} % -% \begin{function}{\inputsong} +% \begin{function}{\inputsong, \inputsong*} % \begin{syntax} % \cs{inputsong}\marg{file}\marg{stanzas per slide}\oarg{couplet list} +% \cs{inputsong*}\marg{file}\marg{stanzas per slide}\oarg{couplet list} % \end{syntax} % % The \cs{inputsong} command environment is used as a shortcut for @@ -235,6 +249,9 @@ % \end{verbatim} % \end{function} % +% The starred version \cs{inputsong*} enables couplet numbering, as described +% in \ref{doc-cs-numbercouplets}. +% % \subsection{The \env{refrain}, \env{couplet}, \env{intro} and \env{final} environments} % % \changes{v0.4.0}{2021/09/29}{Document \env{intro} and \env{final} environments} @@ -293,6 +310,7 @@ % \end{verbatim} % % \subsubsection{Importing text lyrics} +% \changes{v1.1.0}{2023/03/27}{Derivate output file name from input file name if not specified} % % Song lyrics are often found in text format with basic markup: % @@ -391,6 +409,8 @@ % % \changes{v0.2.0}{2021/09/23}{Use \texttt{sp} prefix for functions and % variables} +% \changes{v1.1.0}{2023/03/27}{Add the \cs{g__sp_show_numbers_bool} variable to +% number or not couplets} % % We define a number of internal variables, that are used when reading and % formatting a song. All of these variables are meant to be set globally: since @@ -402,6 +422,7 @@ \bool_new:N \g__sp_song_start_bool % are we at the start of a song? \bool_new:N \g__sp_refrain_first_bool % does current song start with the % refrain? +\bool_new:N \g__sp_show_numbers_bool % should we show the couplet numbers? \int_new:N \g__sp_stanzas_per_slide_int % number of stanzas to show on each % slide (1 or 2) \dim_new:N \g__sp_linewidth_dim % length of the longest line in current @@ -500,8 +521,9 @@ % \end{macro} % % \begin{macro}{\__sp_song_couplet:n} +% \changes{v1.1.0}{2023/03/27}{Print the couplet number when requested} % -% This macro uses the \env{__sp_couplet} environment to a specified couplet of +% This macro uses the \env{__sp_couplet} environment to format a specified couplet of % the current song. It takes a single argument: % % \begin{arguments} @@ -515,6 +537,9 @@ \dim_compare:nNnTF \g__sp_linewidth_dim {=} {0pt} { \begin{__sp_couplet} } { \begin{__sp_couplet} [\g__sp_linewidth_dim] } + \bool_if:NTF \g__sp_show_numbers_bool + { \flagverse{#1.} } + {} \seq_item:Nn \g__sp_couplets_seq {#1} \end{__sp_couplet} } @@ -832,7 +857,20 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}{\numbercouplets} +% \changes{v1.1.0}{2023/03/27}{New command to enable couplet numbering} +% +% This macro can be used within a song to indicate that its couplets should be +% numbered. +% +% \begin{macrocode} + \NewDocumentCommand {\numbercouplets}{} + { \bool_gset_true:N \g__sp_show_numbers_bool } +% \end{macrocode} +% \end{macro} +% % \begin{environment}{song} +% \changes{v1.1.0}{2023/03/27}{Do not number couplets by default} % % This environment is used as a container for entire songs. On opening, it does several things: % \begin{enumerate} @@ -847,6 +885,9 @@ % we are at the start of the song, which will allow the next % \env{refrain} or \env{couplet} to tell if the song starts with the % refrain or with a couplet; +% \item it sets the \cs{g__sp_show_numbers_bool} variable to false, to +% indicate that the couplets should not be numbered by default (the user +% will be able to override this with the \cs{numbercouplets} command). % \end{enumerate} % % This environment takes two arguments: @@ -877,6 +918,9 @@ % Indicate that we are in a song, and at its start \bool_gset_true:N \g__sp_song_bool \bool_gset_true:N \g__sp_song_start_bool + + % Couplets should not be numbered by default + \bool_gset_false:N \g__sp_show_numbers_bool } % \end{macrocode} % @@ -994,18 +1038,21 @@ % \end{environment} % % \begin{macro}{\inputsong} -% \changes{v1.0.0}{2021/11/07}{Add a \cs{inputsong} command} +% \changes{v1.0.0}{2021/11/07}{Add an \cs{inputsong} command} +% \changes{v1.2.0}{2023/03/29}{Add an \cs{inputsong*} command} % % This macro starts a \env{song} environment and \cs{input}s the song content % from an external file. % % \begin{macrocode} -\NewDocumentCommand {\inputsong} { m m o } +\NewDocumentCommand {\inputsong} { s m m o } { - \IfNoValueTF {#3} - { \begin{song} {#2} } - { \begin{song} {#2} [#3] } - \input{#1} + \IfNoValueTF {#4} + { \begin{song} {#3} } + { \begin{song} {#3} [#4] } + \IfBooleanT {#1} + { \numbercouplets } + \input{#2} \end{song} } % \end{macrocode} diff --git a/Master/texmf-dist/tex/latex/songproj/songproj.sty b/Master/texmf-dist/tex/latex/songproj/songproj.sty index adbaefcb695..7f6d2bd733b 100644 --- a/Master/texmf-dist/tex/latex/songproj/songproj.sty +++ b/Master/texmf-dist/tex/latex/songproj/songproj.sty @@ -36,7 +36,7 @@ %% \NeedsTeXFormat{LaTeX2e}[2020/10/01] \ProvidesPackage{songproj} - [2022/11/07 v1.0.1 Song projection] + [2023/03/29 v1.2.0 Song projection] \RequirePackage{expl3} \RequirePackage{xparse} \RequirePackage{verse} @@ -45,6 +45,7 @@ \bool_new:N \g__sp_song_start_bool % are we at the start of a song? \bool_new:N \g__sp_refrain_first_bool % does current song start with the % refrain? +\bool_new:N \g__sp_show_numbers_bool % should we show the couplet numbers? \int_new:N \g__sp_stanzas_per_slide_int % number of stanzas to show on each % slide (1 or 2) \dim_new:N \g__sp_linewidth_dim % length of the longest line in current @@ -99,6 +100,9 @@ \dim_compare:nNnTF \g__sp_linewidth_dim {=} {0pt} { \begin{__sp_couplet} } { \begin{__sp_couplet} [\g__sp_linewidth_dim] } + \bool_if:NTF \g__sp_show_numbers_bool + { \flagverse{#1.} } + {} \seq_item:Nn \g__sp_couplets_seq {#1} \end{__sp_couplet} } @@ -289,6 +293,8 @@ } {} \NewDocumentCommand {\longest} { m } { \settowidth {\g__sp_linewidth_dim} {#1} } + \NewDocumentCommand {\numbercouplets}{} + { \bool_gset_true:N \g__sp_show_numbers_bool } \NewDocumentEnvironment {song} { m o } % {number of stanzas per slide (1 or 2)} % [list of couplets to include (defaults to all)] @@ -309,6 +315,9 @@ % Indicate that we are in a song, and at its start \bool_gset_true:N \g__sp_song_bool \bool_gset_true:N \g__sp_song_start_bool + + % Couplets should not be numbered by default + \bool_gset_false:N \g__sp_show_numbers_bool } { % Have we been given indexes of specific couplets to use? @@ -407,12 +416,14 @@ % Indicate that we are no longer in a song \bool_gset_false:N\g__sp_song_bool } -\NewDocumentCommand {\inputsong} { m m o } +\NewDocumentCommand {\inputsong} { s m m o } { - \IfNoValueTF {#3} - { \begin{song} {#2} } - { \begin{song} {#2} [#3] } - \input{#1} + \IfNoValueTF {#4} + { \begin{song} {#3} } + { \begin{song} {#3} [#4] } + \IfBooleanT {#1} + { \numbercouplets } + \input{#2} \end{song} } \ExplSyntaxOff |