cgnieder / leadsheets

A LaTeX package for creating leadsheets and songbooks
56 stars 11 forks source link

Allow resetting print-tags option #30

Open iTeaMaster opened 2 years ago

iTeaMaster commented 2 years ago

Consider the following code:

\setleadsheets{print-tags={test}}

% Gets included, as expected:
\includeleadsheet{test1.tex}  % has tag 'test'

% Doesn't get included, as expected:
\includeleadsheet{test2.tex}  % has tags 'other1', 'other2'

% Impossible to include now:
% \setleadsheets{ ?? }
\includeleadsheet{test3.tex}  % has no tags

\setleadsheets{print-tags= }  % after this, any include will be filtered out

% Doesn't get included:
\includeleadsheet{test4.tex}  % has arbitrary tags

This results in only the inclusion of file test1.tex.

After a tag filter has ben set, there is no way to include a song that doesn't have any tags.

I would like to be able to reset the print-tags option to the initial state where included leadsheets are not filtered by tag. As far as I understand from reading the documentation as well as the code, this is currently not feasible without directly accessing package internals.

Setting an empty filter value would be an, in my opinion intuitive, syntax to disable the filtering. Even though I might find it intuitive, I'm aware that this probably isn't unambiguous.
Currently however, doing that sets the filter to an empty list. Consequently any included file will not match the filter and thus not be included.

Another option would be to pass a special value for that purpose. But then this value could never occur as an actual tag, which might pose complications of all sorts.

A third option would be to have a seperate command to switch the behaviour (e.g. \setleadsheets{print-all}).

After looking into the code, I believe that the relevant part in the code is this: https://github.com/cgnieder/leadsheets/blob/6fdc9fda64166b35fbcff736fa6938ba77a14233/leadsheets.library.songs.code.tex#L774-L776

What follows is my attempt at how either the first or the last option mentioned above could be implemented. It seems to be possible with little effort (though I only recently learned expl3 syntax and might have overlooked something).

First option: \setleadsheets{print-tags=} (empty value to reset):

    print-tags           .code:n     =
      \tl_if_blank:nTF {#1}
        { \bool_set_false:N \l__leadsheets_print_selected_bool }
        {
          \bool_set_true:N \l__leadsheets_print_selected_bool
          \clist_set:Nn \l__leadsheets_print_tags_clist {#1}
        } ,

Second option: \setleadsheets{print-all} (dedicated option key):

    print-all            .bool_set_inverse:N = \l__leadsheets_print_selected_bool ,

probably extended with the inverse key print-selected for completeness:

    print-selected       .bool_set:N = \l__leadsheets_print_selected_bool ,

If either of this looks good to you, I would be happy if this got implemented. If you would like, I can also submit a pull request. Thank you for providing this excellent package!