%%%==============================================================================
%% Copyright 2025-present by Alceu Frigeri
%%
%% This work may be distributed and/or modified under the conditions of
%%
%% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt) ,
%%   version 1.3c (or later) , and/or
%% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html) ,
%%   version 3 (or later)
%%
%% This work has the LPPL maintenance status *maintained*.
%%
%% The Current Maintainer of this work is Alceu Frigeri
%%
%% This is version {1.2} {2025/11/06}
%%
%% The list of files that compose this work can be found in the README.md file at
%% https://ctan.org/pkg/tikzcalendarnotes
%%
%%%==============================================================================
\NeedsTeXFormat{LaTeX2e}[2022/06/01]

\ProvidesExplPackage
    {tikzcalendarnotes}
    {2025/11/06}
    {1.2}
    {tikzcalendarnotes - calendar marks and notes}

%%%%%%%
%%%
%%% Just an attempt of having my package's info in a regular way
%%% \Pkginfograb_set:nn {<pkg-name>} { props} for each and all.
%%%
%%%%%%%
\RequirePackage{pkginfograb}
\pkginfograb_set:nn { tikzcalendarnotes }
  {
     name        = {tikzcalendarnotes} ,
     prefix      = {tikzcalendarnotes} ,
     date        = {2025/11/06} ,
     version     = {1.2} ,
     description = {tikzcalendarnotes~ - ~calendar~ marks~ and~ notes}
  }
%%%%%%%
%%% End of cut-n-paste
%%%%%%%

%\RequirePackage{etoolbox}



%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%

\cs_generate_variant:Nn \msg_error:nnnn {neee ,nVne}


\msg_new:nnnn {tikzcalendarnotes} {dataset already defined}
  {
    (ID:#1)~Dataset~ '#2'~already~defined!
  }
  {
    You~tried~to~create~an~already~defined~Dataset:~'#2'.
    ~Error~Code~ ID:<#1>.
  }

\msg_new:nnnn {tikzcalendarnotes} {invalid dataset}
  {
    (ID:#1)~Invalid~Dataset:~ '#2'
  }
  {
    You~tried~to~use~an~invalid~Dataset:~'#2'.
    ~Error~Code~ ID:<#1>.
  }


\msg_new:nnnn {tikzcalendarnotes} {date not set}
  {
    (ID:#1)~missing~date~key:~ '#2'
  }
  {
    You~should~set~a~date~before:~'#2'.
    ~Error~Code~ ID:<#1>.
  }

\msg_new:nnnn {tikzcalendarnotes} {range not set}
  {
    (ID:#1)~missing~from/to~keys:~ '#2'
  }
  {
    You~should~set~from/to~keys~before:~'#2'.
    ~Error~Code~ ID:<#1>.
  }





%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%

\tl_new:N \l__tikzcalendarnotes_msg_submodule_tl

\seq_new:N  \l__tikzcalendarnotes_dataset_seq
\tl_new:N   \l__tikzcalendarnotes_active_dataset_tl

\bool_new:N \l__tikzcalendarnotes_date_set_flag_bool
\bool_new:N \l__tikzcalendarnotes_hldates_set_flag_bool
\bool_new:N \l__tikzcalendarnotes_from_set_flag_bool
\bool_new:N \l__tikzcalendarnotes_to_set_flag_bool
\bool_new:N \l__tikzcalendarnotes_date_case_bool
\bool_new:N \l__tikzcalendarnotes_hldates_case_bool
\bool_new:N \l__tikzcalendarnotes_range_case_bool
\bool_new:N \l__tikzcalendarnotes_cntweek_case_bool 
\bool_new:N \l__tikzcalendarnotes_nocntweek_case_bool 

\bool_new:N \l__tikzcalendarnotes_keep_counters_pgfkey_bool

\bool_new:N \l__tikzcalendarnotes_year_policy_set_bool
\bool_new:N \l__tikzcalendarnotes_year_label_set_bool

\tl_new:N \l__tikzcalendarnotes_dayspacing_Xshift_key_tl
\tl_new:N \l__tikzcalendarnotes_weekspacing_Yshift_key_tl
\tl_new:N \l__tikzcalendarnotes_inter_month_space_key_tl %matrix column spacing


\tl_new:N \l__tikzcalendarnotes_hl_color_key_tl


\int_new:N \l__tikzcalendarnotes_year_int
\int_new:N \l__tikzcalendarnotes_month_int
\int_new:N \l__tikzcalendarnotes_cnta_int
\int_new:N \l__tikzcalendarnotes_cntb_int


\tl_new:N \l__tikzcalendarnotes_tmpa_tl
\tl_new:N \l__tikzcalendarnotes_tmpb_tl

\int_new:N \l__tikzcalendarnotes_tmpa_int

\bool_new:N \l__tikzcalendarnotes_tmpa_bool
\bool_new:N \l__tikzcalendarnotes_tmpb_bool

\clist_new:N \l__tikzcalendarnotes_tmpa_clist

\coffin_new:N \l__tikzcalendarnotes_tmpa_coffin


\tl_new:N \l__tikzcalendarnotes_begin_iso_tl


\tl_new:N \l__tikzcalendarnotes_remark_tmp_tl
\tl_new:N \l__tikzcalendarnotes_dateref_tmp_tl
\tl_new:N \l__tikzcalendarnotes_from_key_tl
\tl_new:N \l__tikzcalendarnotes_to_key_tl
\tl_new:N \l__tikzcalendarnotes_cnt_ifdate_temp_tl
\tl_new:N \l__tikzcalendarnotes_cnt_pgfcalifdate_temp_tl

\bool_new:N \g__tikzcalendarnotes_firstdraw_bool

\tl_new:N \l__tikzcalendarnotes_TXshift_tmp_tl
\tl_new:N \l__tikzcalendarnotes_TYshift_tmp_tl


\tl_new:N \l__tikzcalendarnotes_TXshift_scaled_tl
\tl_new:N \l__tikzcalendarnotes_TYshift_scaled_tl


\tl_new:N \l__tikzcalendarnotes_radius_tmp_tl
\tl_new:N \l__tikzcalendarnotes_radius_scaled_tl
\tl_new:N \l__tikzcalendarnotes_radius_adj_pgfkey_tl
\tl_new:N \l__tikzcalendarnotes_ref_fontsize_tl


\tl_new:N  \l__tikzcalendarnotes_weeklist_starts_on_tl
\tl_new:N  \l__tikzcalendarnotes_weeklist_ends_on_tl
\int_new:N \l__tikzcalendarnotes_weeklist_delta_int
\int_new:N \l__tikzcalendarnotes_weeklist_starts_on_int




\tl_new:N \l__tikzcalendarnotes_day_A_tl
\tl_new:N \l__tikzcalendarnotes_day_B_tl
\tl_new:N \l__tikzcalendarnotes_day_C_tl
\tl_new:N \l__tikzcalendarnotes_day_D_tl
\tl_new:N \l__tikzcalendarnotes_day_E_tl
\tl_new:N \l__tikzcalendarnotes_day_F_tl
\tl_new:N \l__tikzcalendarnotes_day_G_tl

\tl_new:N \l__tikzcalendarnotes_day_A_style_tl
\tl_new:N \l__tikzcalendarnotes_day_B_style_tl
\tl_new:N \l__tikzcalendarnotes_day_C_style_tl
\tl_new:N \l__tikzcalendarnotes_day_D_style_tl
\tl_new:N \l__tikzcalendarnotes_day_E_style_tl
\tl_new:N \l__tikzcalendarnotes_day_F_style_tl
\tl_new:N \l__tikzcalendarnotes_day_G_style_tl


%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%

\cs_generate_variant:Nn \dim_to_decimal:n {e}

\keys_define:nn {tikzcalendarnotes }
  {
    year .usage:n = general ,
    year .tl_set:N = \l__tikzcalendarnotes_year_key_tl ,
    year .default:n = {\year} ,
    
    starting~ at .usage:n = general ,
    starting~ at .tl_set:N = \l__tikzcalendarnotes_starting_at_key_tl ,
    starting~ at .default:n = {1} ,

    number~ of~ months .usage:n = general ,
    number~ of~ months .tl_set:N = \l__tikzcalendarnotes_nmonths_key_tl ,
    number~ of~ months .default:n = {12} ,

    per~ line .usage:n = general ,
    per~ line .tl_set:N = \l__tikzcalendarnotes_perline_key_tl ,
    per~ line .default:n  = {3} ,

    with~ notes .usage:n = general ,
    with~ notes .code:n =  
      {
        \tl_set:Nn \l__tikzcalendarnotes_dayspacing_Xshift_key_tl 
          {25}  % was 14ex
        \tl_set:Nn \l__tikzcalendarnotes_weekspacing_Yshift_key_tl 
          {36}      
        \bool_set_false:N \l__tikzcalendarnotes_compact_key_bool 
        \tl_set:Nn \l__tikzcalendarnotes_inter_month_space_key_tl 
          {20}  % was 14ex
      } ,
    with~ notes .value_forbidden:n = true ,

    without~ notes .usage:n = general ,
    without~ notes .code:n =  
      {
        \tl_set:Nn \l__tikzcalendarnotes_dayspacing_Xshift_key_tl 
          {15}
        \tl_set:Nn \l__tikzcalendarnotes_weekspacing_Yshift_key_tl 
          {17}
        \bool_set_true:N \l__tikzcalendarnotes_compact_key_bool 
        \tl_set:Nn \l__tikzcalendarnotes_inter_month_space_key_tl 
          {5} %was 7ex
      } ,
    without~ notes .value_forbidden:n = true ,
    
    compact .usage:n = general ,
    compact .meta:n = { without~ notes } ,
    compact .value_forbidden:n = true ,

    day~ spacing .usage:n = general ,
    day~ spacing .tl_set:N = \l__tikzcalendarnotes_dayspacing_Xshift_key_tl ,
    day~ spacing .value_required:n = true ,

    week~ spacing .usage:n = general ,
    week~ spacing .tl_set:N = \l__tikzcalendarnotes_weekspacing_Yshift_key_tl ,
    week~ spacing .value_required:n = true ,

    month~ spacing .usage:n = general ,
    month~ spacing .tl_set:N = \l__tikzcalendarnotes_inter_month_space_key_tl ,
    month~ spacing .value_required:n = true ,

    data~ set .usage:n = general ,
    data~ set .tl_set:N = \l__tikzcalendarnotes_dataset_key_tl ,
    data~ set .default:n  = {default} ,
    
    name .usage:n = general ,
    name .tl_set:N = \l__tikzcalendarnotes_cal_name_key_tl ,
    name .default:n  = {cal} ,
    
    defaults .usage:n = general ,
    defaults .meta:n = 
      {
        year , starting~ at , number~ of~ months , per~ line , compact , data~ set , 
        name ,
      } ,
    defaults .value_forbidden:n = true , 
  }


\cs_generate_variant:Nn \prop_put_from_keyval:Nn {ce}
\keys_define:nn {tikzcalendarnotes / base set }
  {
    north~ east .usage:n = general ,
    north~ east  .code:n = 
      {
        \__tikzcalendarnotes_keycode:nnn {keys~10}{north~east}
          {
            \prop_put_from_keyval:ce 
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ \l__tikzcalendarnotes_date_tl _prop}
              {
                remark posref = north~ east ,       
                remark anchor = south~ west ,       
                TX shift = -\exp_not:N\l__tikzcalendarnotes_TXshift_scaled_tl ,    
                TY shift = -\exp_not:N\l__tikzcalendarnotes_TYshift_scaled_tl ,    
                date ref = \l__tikzcalendarnotes_to_key_tl ,       
              }
          }
      } ,
    north~ east  .value_forbidden:n = true ,
    
    north~ west .usage:n = general ,
    north~ west  .code:n = 
      {
        \__tikzcalendarnotes_keycode:nnn {keys~09}{north~west}
          {
            \prop_put_from_keyval:ce 
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ \l__tikzcalendarnotes_date_tl _prop}
              {
                remark posref = north~ west ,       
                remark anchor = south~ east ,       
                TX shift = \exp_not:N\l__tikzcalendarnotes_TXshift_scaled_tl ,    
                TY shift = -\exp_not:N\l__tikzcalendarnotes_TYshift_scaled_tl ,    
                date ref = \l__tikzcalendarnotes_from_key_tl ,       
              }
          }
      } ,
    north~ west  .value_forbidden:n = true ,

    south~ east .usage:n = general ,
    south~ east  .code:n = 
      {
        \__tikzcalendarnotes_keycode:nnn {keys~08}{south~east}
          {
            \prop_put_from_keyval:ce 
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ \l__tikzcalendarnotes_date_tl _prop}
              {
                remark posref = south~ east ,       
                remark anchor = north~ west ,       
                TX shift = -\exp_not:N\l__tikzcalendarnotes_TXshift_scaled_tl ,    
                TY shift = \exp_not:N\l__tikzcalendarnotes_TYshift_scaled_tl ,    
                date ref = \l__tikzcalendarnotes_to_key_tl ,       
              }
          }
      } ,
    south~ east  .value_forbidden:n = true ,

    south~ west .usage:n = general ,
    south~ west  .code:n = 
      {
        \__tikzcalendarnotes_keycode:nnn {keys~07}{south~west}
          {
            \prop_put_from_keyval:ce
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ \l__tikzcalendarnotes_date_tl _prop}
              {
                remark posref = south~ west ,       
                remark anchor = north~ east ,       
                TX shift = \exp_not:N\l__tikzcalendarnotes_TXshift_scaled_tl ,    
                TY shift = \exp_not:N\l__tikzcalendarnotes_TYshift_scaled_tl ,    
                date ref = \l__tikzcalendarnotes_from_key_tl ,       
              }
          }
      } ,
    south~ west  .value_forbidden:n = true ,

    remark .usage:n = general ,
    remark .code:n = 
      {
        \__tikzcalendarnotes_keycode:nnnn {keys~06}{remark=#1}
          {remark}{#1}
      } ,
    remark .value_required:n = true ,
    
    notes .usage:n = general ,
    notes .code:n = 
      {
        \__tikzcalendarnotes_keycode:nnnn {keys~05}{notes=#1}
          {notes}{#1}
      } ,
    notes .value_required:n = true ,
      
    round .usage:n = general ,
    round .code:n =
      {
        \__tikzcalendarnotes_keycode:nnnn {keys~04}{round}
          {round}{round}
      } ,
    round .value_forbidden:n = true ,

    square .usage:n = general ,
    square .code:n =
      {
        \__tikzcalendarnotes_keycode:nnnn {keys~03}{square}
          {square}{square}
      } ,
    square .value_forbidden:n = true ,
    
    color .usage:n = general ,
    color .code:n =
      {
        \__tikzcalendarnotes_keycode:nnnn {keys~02}{color=#1}
          {day color}{#1}
      } ,
    color .value_required:n = true ,
    
    remark~ style .usage:n = general ,
    remark~ style .code:n =
      {
        \__tikzcalendarnotes_keycode:nnnn {keys~01}{remark~ style=#1}
          {remark style}{#1}
      } ,
    remark~ style .value_required:n = true ,
    
    note~ style .usage:n = general ,
    note~ style .code:n =
      {
        \__tikzcalendarnotes_keycode:nnnn {keys~11}{note~ style=#1}
          {note style}{#1}
      } ,
    note~ style .value_required:n = true ,   

    mark~ style .usage:n = general ,
    mark~ style .code:n =
      {
        \__tikzcalendarnotes_keycode:nnnn {keys~00}{mark~ style=#1}
          {draw style}{#1}
      } ,
    mark~ style .value_required:n = true ,
      
  }

\keys_define:nn {} 
  {
    tikzcalendarnotes / date set .inherit:n = 
      { tikzcalendarnotes / base set } 
  } 

\keys_define:nn {tikzcalendarnotes / date set }
  {
    date .usage:n = general ,
    date .code:n = 
      { 
        \bool_set_true:N \l__tikzcalendarnotes_date_set_flag_bool 
        \__tikzcalendarnotes_try_insert_date:nn 
          {#1}
          {} 
      } ,
    date .value_required:n = true ,
  }

\keys_define:nn {tikzcalendarnotes / hl dates set }
  {
    dates .usage:n = general ,
    dates .code:n = 
      {         
        \bool_set_true:N \l__tikzcalendarnotes_hldates_set_flag_bool 
        \bool_set_true:N \l__tikzcalendarnotes_date_set_flag_bool 
          
        \clist_map_inline:nn {#1}
          {
            \__tikzcalendarnotes_try_insert_date:nV 
              {##1}
              \l__tikzcalendarnotes_hl_color_key_tl
          }
      } ,
    dates .value_required:n = true ,

    color .usage:n = general ,
    color .tl_set:N = \l__tikzcalendarnotes_hl_color_key_tl ,
    color .value_required:n = true , 
  }



\keys_define:nn {} 
  {
    tikzcalendarnotes / range set .inherit:n = 
      { tikzcalendarnotes / base set } 
  }

\keys_define:nn {tikzcalendarnotes / range set }
  {
    from .usage:n = general ,
    from .code:n =
      {
        \tl_set:Nn \l__tikzcalendarnotes_from_key_tl 
          {#1}
        \bool_set_true:N \l__tikzcalendarnotes_from_set_flag_bool 
      } ,
    from  .value_required:n = true ,
    
    to .usage:n = general ,
    to .code:n =
      {
        \tl_set:Nn \l__tikzcalendarnotes_to_key_tl 
          {#1}
        \bool_set_true:N \l__tikzcalendarnotes_to_set_flag_bool 
      } ,
    to .value_required:n = true ,
  }

\keys_define:nn {tikzcalendarnotes / no cnt week set }
  {
    from .usage:n = general ,
    from .code:n =
      {
        \tl_set:Nn \l__tikzcalendarnotes_from_key_tl 
          {#1}
        \bool_set_true:N \l__tikzcalendarnotes_from_set_flag_bool 
      } ,
    from  .value_required:n = true ,
    
    to .usage:n = general ,
    to .code:n =
      {
        \tl_set:Nn \l__tikzcalendarnotes_to_key_tl 
          {#1}
        \bool_set_true:N \l__tikzcalendarnotes_to_set_flag_bool 
      } ,
    to .value_required:n = true ,
  }    

\keys_define:nn {tikzcalendarnotes / cnt week set }
  {
    from .usage:n = general ,
    from .code:n =
      {
        \tl_set:Nn \l__tikzcalendarnotes_from_key_tl 
          {#1}
        \bool_set_true:N \l__tikzcalendarnotes_from_set_flag_bool 
      } ,
    from  .value_required:n = true ,
    
    to .usage:n = general ,
    to .code:n =
      {
        \tl_set:Nn \l__tikzcalendarnotes_to_key_tl 
          {#1}
        \bool_set_true:N \l__tikzcalendarnotes_to_set_flag_bool 
      } ,
    to .value_required:n = true ,
    
    up .usage:n = general ,
    up  .code:n = 
      {
        \__tikzcalendarnotes_keycode:nnn {keys~11}{up}
          {
            \__tikzcalendarnotes_try_insert_cntweek:VV
              \l__tikzcalendarnotes_from_key_tl
              \l__tikzcalendarnotes_to_key_tl
            \prop_put_from_keyval:cn
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ \l__tikzcalendarnotes_date_tl _prop} 
              {
                cnt posref = north~ west ,       
                cnt anchor = south~ east ,       
                TX shift = \l__tikzcalendarnotes_TXshift_scaled_tl ,    
                TY shift = -\l__tikzcalendarnotes_TYshift_scaled_tl ,    
              }
          }
      } ,
      up .value_forbidden:n = true ,
    
    down .usage:n = general ,
    down  .code:n = 
      {
        \__tikzcalendarnotes_keycode:nnn {keys~12}{down}
          {
            \__tikzcalendarnotes_try_insert_cntweek:VV
              \l__tikzcalendarnotes_from_key_tl
              \l__tikzcalendarnotes_to_key_tl
            \prop_put_from_keyval:cn
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ \l__tikzcalendarnotes_date_tl _prop} 
              {
                cnt posref = south~ west ,       
                cnt anchor = north~ east ,       
                TX shift = \l__tikzcalendarnotes_TXshift_scaled_tl ,    
                TY shift = \l__tikzcalendarnotes_TYshift_scaled_tl ,    
              }
          }
      } ,
      down .value_forbidden:n = true ,

    center .usage:n = general ,
    center  .code:n = 
      {
        \__tikzcalendarnotes_keycode:nnn {keys~13}{center}
          {
            \__tikzcalendarnotes_try_insert_cntweek:VV
              \l__tikzcalendarnotes_from_key_tl
              \l__tikzcalendarnotes_to_key_tl
            \prop_put_from_keyval:cn
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ \l__tikzcalendarnotes_date_tl _prop} 
              {
                cnt posref = west ,       
                cnt anchor = east ,       
                TX shift = \l__tikzcalendarnotes_TXshift_scaled_tl ,    
                TY shift = 0 pt ,    
              }
          }
      } ,
      center .value_forbidden:n = true ,
      
    color .usage:n = general ,
    color  .code:n = 
      {
        \__tikzcalendarnotes_keycode:nnn {keys~13}{color=#1}
          {
            \__tikzcalendarnotes_try_insert_cntweek:VV 
              \l__tikzcalendarnotes_from_key_tl
              \l__tikzcalendarnotes_to_key_tl
            \prop_put:cnn 
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ \l__tikzcalendarnotes_date_tl _prop} 
              {color} {color=#1}       
          }
      } ,
    color .value_required:n = true ,
    
    starting~ at .usage:n = general ,
    starting~ at .code:n = 
      {
        \__tikzcalendarnotes_keycode:nnn {keys~14}{starting~ at=#1}
          {
            \__tikzcalendarnotes_try_insert_cntweek:VV
              \l__tikzcalendarnotes_from_key_tl
              \l__tikzcalendarnotes_to_key_tl
            \int_gset:cn {g__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ \l__tikzcalendarnotes_from_key_tl : \l__tikzcalendarnotes_to_key_tl _cnt _int}
              {#1 - 1}
          }
      } ,
    starting~ at .value_required:n = true ,
  }


%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%


\cs_new_protected:Npn \__tikzcalendarnotes_keycode:nnnn #1#2#3#4
  {
    \bool_if:nTF 
      {\l__tikzcalendarnotes_date_set_flag_bool || \l__tikzcalendarnotes_from_set_flag_bool && \l__tikzcalendarnotes_to_set_flag_bool}
      {
        \bool_if:NT \l__tikzcalendarnotes_range_case_bool
          {
            \__tikzcalendarnotes_try_insert_range:VV 
              \l__tikzcalendarnotes_from_key_tl 
              \l__tikzcalendarnotes_to_key_tl
          }
        \prop_put:cnn {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ \l__tikzcalendarnotes_date_tl _prop} 
          {#3} {#4}
      }
      {
        \msg_error:nVne {tikzcalendarnotes}{\l__tikzcalendarnotes_msg_submodule_tl}{#1}{#2}
      }  
  }

\cs_new_protected:Npn \__tikzcalendarnotes_keycode:nnn #1#2#3
  {
    \bool_if:nTF 
      {\l__tikzcalendarnotes_date_set_flag_bool || \l__tikzcalendarnotes_from_set_flag_bool && \l__tikzcalendarnotes_to_set_flag_bool}
      {
        \bool_if:NT \l__tikzcalendarnotes_range_case_bool
          {
            \__tikzcalendarnotes_try_insert_range:VV 
              \l__tikzcalendarnotes_from_key_tl
              \l__tikzcalendarnotes_to_key_tl
          }
        #3
      }
      {
        \msg_error:nVne {tikzcalendarnotes}{\l__tikzcalendarnotes_msg_submodule_tl}{#1}{#2}
      }  
  }

\cs_generate_variant:Nn \tl_set:Nn {Ne}
\cs_generate_variant:Nn \tl_gset:Nn {Ne}


\makeatletter 
\cs_new_protected:Npn \__tikzcalendarnotes_set_dim_constants: 
  {
    \tl_set:Ne \l__tikzcalendarnotes_ref_fontsize_tl {\f@size}
       
    \tl_set:Ne \l__tikzcalendarnotes_TXshift_scaled_tl 
      { 
        \fp_eval:n {0.6 * \l__tikzcalendarnotes_ref_fontsize_tl + 2pt} pt
      }
    \tl_set:Ne \l__tikzcalendarnotes_TYshift_scaled_tl 
      { 
        \fp_eval:n {0.35 * \l__tikzcalendarnotes_ref_fontsize_tl + 0.5pt} pt
      }
    
    \tl_set:Ne \l__tikzcalendarnotes_radius_scaled_tl 
      { 
        \fp_eval:n {(5.75pt * \l__tikzcalendarnotes_ref_fontsize_tl) / 10pt } pt
      }
  }
\makeatother




\cs_new_protected:Npn \__tikzcalendarnotes_reset_defaults:
  {
    \bool_set_false:N \l__tikzcalendarnotes_date_set_flag_bool 
    \bool_set_false:N \l__tikzcalendarnotes_hldates_set_flag_bool 
    \bool_set_false:N \l__tikzcalendarnotes_from_set_flag_bool 
    \bool_set_false:N \l__tikzcalendarnotes_to_set_flag_bool 
    \bool_set_false:N \l__tikzcalendarnotes_date_case_bool 
    \bool_set_false:N \l__tikzcalendarnotes_hldates_case_bool 
    \bool_set_false:N \l__tikzcalendarnotes_range_case_bool 
    \bool_set_false:N \l__tikzcalendarnotes_cntweek_case_bool  
    \bool_set_false:N \l__tikzcalendarnotes_nocntweek_case_bool  
      
    \tl_set:Nn \l__tikzcalendarnotes_hl_color_key_tl 
      {lightgray}  
  }



%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%

\cs_new_protected:Npn \__tikzcalendarnotes_markdraw:nnn #1#2#3
  {
    \draw [#1] 
      (#3.center) 
        ++(-#2 , -#2) 
        rectangle
    		++(2*#2 , 2*#2) ;
  }

\cs_generate_variant:Nn \__tikzcalendarnotes_markdraw:nnn {eee}

\cs_new_protected:Npn \__tikzcalendarnotes_markdraw_range:nnnn #1#2#3#4
  {
    \draw [#1] 
      (#3.center) 
        ++(-#2 , #2) coordinate(A)
        (#4.center)
        ++( #2 , -#2) 
        rectangle (A) ;
  }

\cs_generate_variant:Nn \__tikzcalendarnotes_markdraw_range:nnnn {eeee}


%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%


\cs_new_protected:Npn \__tikzcalendarnotes_new_dataset:n #1
  {
    \seq_if_exist:cTF {l__tikzcalendarnotes_ #1 _dataset_seq}
      {
        \msg_warning:nnne 
          {tikzcalendarnotes}{dataset already defined}
          {new~01}{#1}
      }
      { 
        \seq_new:c {l__tikzcalendarnotes_ #1 _dataset_seq}
        \seq_new:c {l__tikzcalendarnotes_ #1 _range_seq}
        \seq_put_right:Nn \l__tikzcalendarnotes_dataset_seq {#1}
        \seq_new:c {l__tikzcalendarnotes_ #1 _cnt week_seq}
        \seq_new:c {l__tikzcalendarnotes_ #1 _no cntweek_seq}
        \bool_new:c {l__tikzcalendarnotes_ #1 _cnt flag_bool} %for the 1st of every month
        \tl_new:c {l__tikzcalendarnotes_ #1 _cnt hack_tl} %for the 1st of every month
      }
  }  

\cs_new_protected:Npn \__tikzcalendarnotes_select_dataset:n #1
  {
    \seq_if_exist:cTF {l__tikzcalendarnotes_ #1 _dataset_seq}
    { 
      \tl_set:Nn \l__tikzcalendarnotes_active_dataset_tl {#1}
    }
    {  
      \msg_error:nnne 
        {tikzcalendarnotes}{invalid dataset}
        {select~01}{#1}
    }
  }

\__tikzcalendarnotes_new_dataset:n {default} 
\__tikzcalendarnotes_select_dataset:n {default} 


%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%



\cs_new_protected:Npn \__tikzcalendarnotes_try_insert_date:nn #1#2
  {
    \prop_if_exist:cF {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 _prop}
      {
        \prop_new:c {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 _prop}
        \seq_put_right:cn 
          { l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _dataset_seq }
          { #1 }    
%defaults   
        \prop_put_from_keyval:cn
          {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 _prop} 
          {
            remark posref = north~ east ,       
            remark anchor = south~ west ,      
            TX shift = -\l__tikzcalendarnotes_TXshift_scaled_tl ,    
            TY shift = -\l__tikzcalendarnotes_TYshift_scaled_tl ,    
            date ref = #1 ,       
          }
      }
    \tl_set:Nn \l__tikzcalendarnotes_date_tl {#1}

    \tl_if_blank:nF {#2}
      {
        \prop_put:cnn 
          {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ \l__tikzcalendarnotes_date_tl _prop} 
          {day color} {#2}  
      }
      
  }

\cs_generate_variant:Nn \__tikzcalendarnotes_try_insert_date:nn {nV}

\cs_new_protected:Npn \__tikzcalendarnotes_try_insert_range:nn #1#2
  {
    \prop_if_exist:cF {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 : #2 _range _prop}
      {
        \prop_new:c {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 : #2 _range _prop}
        \seq_put_right:cn 
          {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _range_seq}
          {#1 : #2 _range}        
        \tl_set:Nn \l__tikzcalendarnotes_date_tl 
          {#1 : #2 _range}

        \prop_put_from_keyval:cn          
          {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _  #1 : #2 _range _prop} 
          {
            from = #1 ,  
            to = #2 ,  
            remark posref = north~ east ,       
            remark anchor = south~ west ,      
            TX shift = -\l__tikzcalendarnotes_TXshift_scaled_tl ,    
            TY shift = -\l__tikzcalendarnotes_TYshift_scaled_tl ,    
            date ref = #2 ,       
          }
      }

  }

\cs_generate_variant:Nn \__tikzcalendarnotes_try_insert_range:nn {VV}



\cs_new_protected:Npn \__tikzcalendarnotes_try_insert_no_cntweek:nn #1#2
  {
    \prop_if_exist:cF {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 : #2 _ncnt _prop}
      {
        \prop_new:c {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 : #2 _ncnt _prop}
        \seq_put_right:cn 
          {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _nocntweek_seq}
          {#1 : #2 _ncnt }   
          
        \prop_put_from_keyval:cn          
          {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 : #2 _ncnt _prop} 
          {
            from = #1 ,  
            to = #2 ,  
          }
      }
    \tl_set:Nn \l__tikzcalendarnotes_date_tl 
      {#1 : #2 _ncnt }
  }

\cs_generate_variant:Nn \__tikzcalendarnotes_try_insert_no_cntweek:nn {VV}



\cs_new_protected:Npn \__tikzcalendarnotes_try_insert_cntweek:nn #1#2
  {
    \prop_if_exist:cF {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 : #2 _cnt _prop}
      {
        \prop_new:c {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 : #2 _cnt _prop}
        \seq_put_right:cn 
          {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _cntweek_seq}
          {#1 : #2 _cnt}     
             
        % the counter is global because months are typed in consecutive scopes, and not in a single go...
        \int_new:c {g__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 : #2 _cnt _int}

        \prop_put_from_keyval:cn
          {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ #1 : #2 _cnt _prop} 
          {
            from = #1 ,  
            to = #2 ,  
            cnt posref = west ,       
            cnt anchor = east ,       
            TX shift = \l__tikzcalendarnotes_TXshift_scaled_tl ,    
            TY shift = 0pt ,          
            color =  ,          
          }
      }
    \tl_set:Nn \l__tikzcalendarnotes_date_tl 
      {#1 : #2 _cnt}
  }

\cs_generate_variant:Nn \__tikzcalendarnotes_try_insert_cntweek:nn {VV}



%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%


\cs_new_protected:Npn \__tikzcalendarnotes_month_matrix:nnnn #1#2#3#4  %year ,first ,n months ,per line
  {
    \int_set:Nn \l__tikzcalendarnotes_year_int {#1}
    \int_set:Nn \l__tikzcalendarnotes_month_int {#2}
    \int_set:Nn \l__tikzcalendarnotes_cnta_int {0}
    \int_set:Nn \l__tikzcalendarnotes_cntb_int {0}
    \tl_set:Nn \l__tikzcalendarnotes_tmpb_tl {}
    
   
    \int_while_do:nNnn {\l__tikzcalendarnotes_cnta_int} < {#3}
      {
        \tl_put_right:Ne \l__tikzcalendarnotes_tmpb_tl 
          {
            \exp_not:N \calendar[
                        day~ xshift=\l__tikzcalendarnotes_dayspacing_Xshift_key_tl pt,
                        day~ yshift=\l__tikzcalendarnotes_weekspacing_Yshift_key_tl pt,
                        name=\l__tikzcalendarnotes_cal_name_key_tl ,
                        dates=\int_use:N\l__tikzcalendarnotes_year_int - \int_use:N\l__tikzcalendarnotes_month_int -01 
                               ~ to ~ 
                              \int_use:N\l__tikzcalendarnotes_year_int - \int_use:N\l__tikzcalendarnotes_month_int -last
                        ] ;
          }
        \int_incr:N \l__tikzcalendarnotes_cnta_int
        \int_compare:nNnTF {\l__tikzcalendarnotes_cnta_int} = {#3}
          {
            \tl_put_right:Nn \l__tikzcalendarnotes_tmpb_tl { \\ }
          }
          {
            \int_incr:N \l__tikzcalendarnotes_cntb_int
            \int_compare:nNnTF {\l__tikzcalendarnotes_cntb_int} < {#4} 
              {
                \tl_put_right:Nn \l__tikzcalendarnotes_tmpb_tl { ~ \pgfmatrixnextcell ~ }
              }
              {
                \tl_put_right:Nn \l__tikzcalendarnotes_tmpb_tl { \\ }
                \int_set:Nn \l__tikzcalendarnotes_cntb_int {0}
              }
            \int_incr:N \l__tikzcalendarnotes_month_int
            \int_compare:nNnTF {\l__tikzcalendarnotes_month_int} < {13}
              {}
              {
                \int_set:Nn \l__tikzcalendarnotes_month_int {1}
                \int_incr:N \l__tikzcalendarnotes_year_int
              }
          }
      }

    \l__tikzcalendarnotes_tmpb_tl
  }
  

\makeatletter
\cs_new_eq:NN \__tikzcalendarnotes_tikz_xshift \tikz@lib@cal@xshift
\makeatother

\cs_new_protected:Npn \__tikzcalendarnotes_ifdate_case_counting_tl_set:NNNnnnn #1#2#3#4#5#6#7
  {
    \bool_if:NF \l__tikzcalendarnotes_keep_counters_pgfkey_bool
      { \int_gzero:N #2 }
      
    \tl_put_right:Nn #1 
      {
        \ifdate{#7}
          {
            \int_gincr:N #2
            \draw (\pgfcalendarsuggestedname.#4) 
              ++(#6)
              node[#5](){ \int_use:N #2 } ;
            \tl_gput_right:Nn #3
              {
                \draw (\pgfcalendarsuggestedname.#4 |-  \l__tikzcalendarnotes_cal_name_key_tl - \pgfcalendarifdateyear - \pgfcalendarifdatemonth - 01.#4) 
                  ++(#6)
                  node[#5](){ \int_use:N #2 } ;                  
              }
          }
          {}                
      }
  }

\cs_generate_variant:Nn \__tikzcalendarnotes_ifdate_case_counting_tl_set:NNNnnnn {NccVeee}


\cs_new_protected:Npn \__tikzcalendarnotes_pgfcalifdate_case_counting_tl_set:NNNnnnn #1#2#3#4#5#6#7
  {
      
    \tl_put_right:Nn #1 
      {
        \pgfcalendarifdate{##1}{#7}
          {
            \int_compare:nNnT {\int_use:N #2} = {0}
              { \int_gincr:N #2 }             
            \tl_gput_right:Nn #3
              {
                \draw (\pgfcalendarsuggestedname.#4 |-  \l__tikzcalendarnotes_cal_name_key_tl - \pgfcalendarifdateyear - \pgfcalendarifdatemonth - 01.#4) 
                  ++(#6)
                  node[#5](){ \int_use:N #2 } ;                  
              }
          }
          {}                
      }
  }
\cs_generate_variant:Nn  \__tikzcalendarnotes_pgfcalifdate_case_counting_tl_set:NNNnnnn {NccVeee}


\cs_generate_variant:Nn \use:n {V}

\cs_new_protected:Npn \__tikzcalendarnotes_ifdate_case_no_tl_set:Nnn #1#2#3
  {
    \tl_set:Nn #1 
      {
        \ifdate{#3}
          {}
          { #2 }                
      }
  }

\cs_generate_variant:Nn \__tikzcalendarnotes_ifdate_case_no_tl_set:Nnn {NVe}




\cs_new_protected:Npn \__tikzcalendarnotes_pgfcalifdate_case_no_tl_set:Nnn #1#2#3
  {
    \tl_set:Nn #1 
      {
        \pgfcalendarifdate{##1}{#3}
          {}
          { #2 }                
      }
  }

\cs_generate_variant:Nn \__tikzcalendarnotes_pgfcalifdate_case_no_tl_set:Nnn {NVe}


\cs_new_protected:Npn \__tikzcalendarnotes_shift_adjust_tl_set:Nn #1#2
  {
    \fp_compare:nNnTF {#1} < {0}
      {
        \tl_set:Ne #1 
          {
            \fp_eval:n {#1 + (#2)} pt
          }
      }
      {
        \tl_set:Ne #1 
          {
            \fp_eval:n {#1 - (#2)} pt
          }
      }
  }

\cs_generate_variant:Nn   \__tikzcalendarnotes_shift_adjust_tl_set:Nn {NV}

\cs_new_protected:Npn \__tikzcalendarnotes_append_pgfcalifdate_test:n #1
  {
    \pgfkeys
      {
        tikz ,
        @calnotes@cnt@if@/.append~ code = {#1} ,
      }
  }
\cs_generate_variant:Nn \__tikzcalendarnotes_append_pgfcalifdate_test:n {V}


\cs_new_protected:Npn \__tikzcalendarnotes_set_ifdate_before_day:nn #1#2
  {
    \pgfkeys
      {
        tikz,
        @calnotes@cnt@if@/.code = {} ,
        execute~ before~ day~ scope = 
          {
            \ifdate{equals = #1}
              {
                \pgfkeys 
                  { tikz, 
                    @calnotes@cnt@if@ = 
                      { 
                        #1+ - \int_eval:n {\pgfcalendarcurrentweekday + #2} 
                      } 
                  }
              }
              {}
          }
      }
  }
\cs_generate_variant:Nn \__tikzcalendarnotes_set_ifdate_before_day:nn {Ve}






% #1 l__tikzcalendarnotes_ ##1 _cnt flag_bool
% #2 l__tikzcalendarnotes_ ##1 _cnt hack_tl
% #3  \l__tikzcalendarnotes_cnt_ifdate_temp_tl
%
% #1 => #3
% #2 => #1
% #3 => #2
%
\cs_new_protected:Npn \__tikzcalendarnotes_append_tikz_ifdate_after_day:NNn #1#2#3
  {
    \pgfkeys
      {tikz ,
        execute~ after~ day~ scope=
          {  
            \ifdate{\l__tikzcalendarnotes_weeklist_starts_on_tl} 
              { 
                \bool_if:NT #1
                  {
                    \tl_use:N #2
                    \bool_set_false:N #1
                  }
                \tl_gclear:N #2
                #3 
              }
              {
                \ifdate{day~ of~ month = 1}
                  { \bool_set_true:N #1 }
                  {} 
              }
          }
      }
  }

\cs_generate_variant:Nn \__tikzcalendarnotes_append_tikz_ifdate_after_day:NNn {ccV}


\cs_new_protected:Npn \__tikzcalendarnotes_append_every_calendar_if:nn #1#2
  {
    \pgfkeys
      {
        tikz ,
        every~ calendar/.append~ style=
          {
            if = { (#1) [#2] }
          }
      }
  
  }
\cs_generate_variant:Nn \__tikzcalendarnotes_append_every_calendar_if:nn {ee}


\prg_generate_conditional_variant:Nnn \fp_compare:nNn {V} {T, F, TF}

\cs_new_protected:Npn \__tikzcalendarnotes_set_ifdates:n #1
  {
    \__tikzcalendarnotes_set_ifdate_before_day:Ve 
      \l__tikzcalendarnotes_begin_iso_tl
      {\int_use:N \l__tikzcalendarnotes_weeklist_delta_int}


    \clist_set:Nn \l__tikzcalendarnotes_tmpa_clist {#1}
    \clist_map_inline:Nn \l__tikzcalendarnotes_tmpa_clist
      {
        \tl_clear:N \l__tikzcalendarnotes_cnt_ifdate_temp_tl
        \tl_clear:N \l__tikzcalendarnotes_cnt_pgfcalifdate_temp_tl
        \__tikzcalendarnotes_select_dataset:n {##1}
        \tl_clear:c {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _cnt hack_tl}
        \seq_map_inline:cn { l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _dataset_seq}
          {
            \prop_get:cnNT 
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ ####1 _prop}
              {day color} \l__tikzcalendarnotes_daycolor_tmp_tl
              {
                \__tikzcalendarnotes_append_every_calendar_if:ee
                  {equals=####1}
                  {color=\l__tikzcalendarnotes_daycolor_tmp_tl}
              }
          }

        \seq_map_inline:cn { l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _range_seq}
          {
            \prop_get:cnNT 
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ ####1 _prop}
              {day color} \l__tikzcalendarnotes_daycolor_tmp_tl
              {
                \prop_get:cnN 
                  {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ ####1 _prop}
                  {from} \l__tikzcalendarnotes_from_tmp_tl
                \prop_get:cnN 
                  {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ ####1 _prop}
                  {to} \l__tikzcalendarnotes_to_tmp_tl
                
                \__tikzcalendarnotes_append_every_calendar_if:ee
                  {between=\l__tikzcalendarnotes_from_tmp_tl and \l__tikzcalendarnotes_to_tmp_tl}
                  {color=\l__tikzcalendarnotes_daycolor_tmp_tl}  
              }
          }
          
        \seq_map_inline:cn { l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ cnt week_seq}
          {              
            \prop_map_inline:cn {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ ####1 _prop}
              {
                \tl_set:cn {l__tikzcalendarnotes_ ########1 _tmp_tl} {########2}
              }
              
            \__tikzcalendarnotes_shift_adjust_tl_set:NV
              \l__tikzcalendarnotes_TXshift_tmp_tl
              \l__tikzcalendarnotes_remark_Xshift_adj_pgfkey_tl
              
              
            \fp_compare:VNnF \l__tikzcalendarnotes_TYshift_tmp_tl = {0}
              {
                \__tikzcalendarnotes_shift_adjust_tl_set:NV
                  \l__tikzcalendarnotes_TYshift_tmp_tl
                  \l__tikzcalendarnotes_remark_Yshift_adj_pgfkey_tl
              }


            \__tikzcalendarnotes_ifdate_case_counting_tl_set:NccVeee
              \l__tikzcalendarnotes_cnt_ifdate_temp_tl 
              {g__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ ####1 _int}
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _cnt hack_tl}
              \l__tikzcalendarnotes_cntposref_tmp_tl
              {anchor=\l__tikzcalendarnotes_cntanchor_tmp_tl , every~ counter , \l__tikzcalendarnotes_color_tmp_tl}
              {0.7*\l__tikzcalendarnotes_TXshift_tmp_tl , 1.5*\l__tikzcalendarnotes_TYshift_tmp_tl}
              {between = \l__tikzcalendarnotes_from_tmp_tl+-6 and \l__tikzcalendarnotes_to_tmp_tl}
 
            \__tikzcalendarnotes_pgfcalifdate_case_counting_tl_set:NccVeee
              \l__tikzcalendarnotes_cnt_pgfcalifdate_temp_tl 
              {g__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ ####1 _int}
              {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _cnt hack_tl}
              \l__tikzcalendarnotes_cntposref_tmp_tl
              {anchor=\l__tikzcalendarnotes_cntanchor_tmp_tl , every~ counter , \l__tikzcalendarnotes_color_tmp_tl}
              {0.7*\l__tikzcalendarnotes_TXshift_tmp_tl , 1.5*\l__tikzcalendarnotes_TYshift_tmp_tl}
              {between = \l__tikzcalendarnotes_from_tmp_tl+-6 and \l__tikzcalendarnotes_to_tmp_tl}

          } % end of cntweek for this <dataset>
          
        \seq_map_inline:cn { l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ no cnt week_seq}
          {
            \prop_map_inline:cn {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ ####1 _prop}
              {
                \tl_set:cn {l__tikzcalendarnotes_ ########1 _tmp_tl} {########2}
              }
              
            \__tikzcalendarnotes_ifdate_case_no_tl_set:NVe 
              \l__tikzcalendarnotes_cnt_ifdate_temp_tl 
              \l__tikzcalendarnotes_cnt_ifdate_temp_tl
              {between = \l__tikzcalendarnotes_from_tmp_tl+-6 and \l__tikzcalendarnotes_to_tmp_tl}

            \__tikzcalendarnotes_pgfcalifdate_case_no_tl_set:NVe 
              \l__tikzcalendarnotes_cnt_pgfcalifdate_temp_tl 
              \l__tikzcalendarnotes_cnt_pgfcalifdate_temp_tl
              {between = \l__tikzcalendarnotes_from_tmp_tl+-6 and \l__tikzcalendarnotes_to_tmp_tl}

          } % end of no cntweek for this dataset

          \tl_if_empty:NF \l__tikzcalendarnotes_cnt_ifdate_temp_tl
            {
              \__tikzcalendarnotes_append_tikz_ifdate_after_day:ccV
                {l__tikzcalendarnotes_ ##1 _cnt flag_bool}
                {l__tikzcalendarnotes_ ##1 _cnt hack_tl}
                \l__tikzcalendarnotes_cnt_ifdate_temp_tl
                
              \__tikzcalendarnotes_append_pgfcalifdate_test:V 
                \l__tikzcalendarnotes_cnt_pgfcalifdate_temp_tl 
            }

      } % end of clist <datasets>
      
          
  }

\cs_generate_variant:Nn \__tikzcalendarnotes_set_ifdates:n {V}


%% from https://tex.stackexchange.com/questions/37709/how-can-i-know-if-a-node-is-already-defined/37713#37713
%% yickes
%% non portable, error prone if the underlining pgf scheme changes... :/
%%
\makeatletter
\cs_new_protected:Npn \__tikzcalendarnotes_setflag_ifdatenode_exist:Nn #1#2
  {
    \cs_if_exist:cTF {pgf@sh@ns@ \l__tikzcalendarnotes_cal_name_key_tl - #2}
      {
        \tl_if_eq:cNTF {pgf@sh@pi@ \l__tikzcalendarnotes_cal_name_key_tl - #2} \pgfpictureid
          { \bool_set_true:N #1  }
          { \bool_set_false:N #1  }
      }
      { \bool_set_false:N #1 }
  }
\makeatother

\cs_generate_variant:Nn \__tikzcalendarnotes_setflag_ifdatenode_exist:Nn {NV}


\cs_new_protected:Npn \__tizecalendarnotes_notes_typeset:nn #1#2 
  {
    \vcoffin_set:Nnn \l__tikzcalendarnotes_tmpa_coffin
      {\fp_eval:n{#1 - 0.75em}pt} {#2}
    \coffin_typeset:Nnnnn \l__tikzcalendarnotes_tmpa_coffin
      {l}{t}
      {0pt}{0pt}
  }

\cs_new_protected:Npn \__tikzcalendarnotes_draw_notes:n #1
  {
    \tl_set:Ne \l__tikzcalendarnotes_radius_tmp_tl 
      { 
        \fp_eval:n {\l__tikzcalendarnotes_radius_scaled_tl + \l__tikzcalendarnotes_radius_adj_pgfkey_tl} pt
      }      
      
    \clist_set:Nn \l__tikzcalendarnotes_tmpa_clist {#1}
    \clist_map_inline:Nn \l__tikzcalendarnotes_tmpa_clist
      {
        \__tikzcalendarnotes_select_dataset:n {##1}
        \seq_map_inline:cn { l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _dataset_seq}
          {
            \__tikzcalendarnotes_setflag_ifdatenode_exist:Nn \l__tikzcalendarnotes_tmpa_bool {####1}
            
            \bool_if:NT \l__tikzcalendarnotes_tmpa_bool
              { 
                \tl_clear:N \l__tikzcalendarnotes_drawstyle_tmp_tl
                \tl_clear:N \l__tikzcalendarnotes_round_tmp_tl
                \tl_clear:N \l__tikzcalendarnotes_square_tmp_tl
                \tl_clear:N \l__tikzcalendarnotes_remark_tmp_tl
                \tl_clear:N \l__tikzcalendarnotes_remarkstyle_tmp_tl
                \tl_clear:N \l__tikzcalendarnotes_notes_tmp_tl
                \tl_clear:N \l__tikzcalendarnotes_notestyle_tmp_tl
                
                \prop_map_inline:cn {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ ####1 _prop}
                  {
                    \tl_set:cn {l__tikzcalendarnotes_ ########1 _tmp_tl} {########2}
                  }             

                \tl_if_empty:NF \l__tikzcalendarnotes_round_tmp_tl
                  {
                    \__tikzcalendarnotes_markdraw:eee 
                      {
                        every~ mark , 
                        rounded~ corners=\l__tikzcalendarnotes_radius_tmp_tl , 
                        \l__tikzcalendarnotes_drawstyle_tmp_tl
                      }
                      {\l__tikzcalendarnotes_radius_tmp_tl}
                      {\l__tikzcalendarnotes_cal_name_key_tl - ####1}
                  }

                \tl_if_empty:NF \l__tikzcalendarnotes_square_tmp_tl
                  {
                    \__tikzcalendarnotes_markdraw:eee 
                      {
                        every~ mark , 
                        \l__tikzcalendarnotes_drawstyle_tmp_tl
                      }
                      {\l__tikzcalendarnotes_radius_tmp_tl}
                      {\l__tikzcalendarnotes_cal_name_key_tl - ####1}
                  }

                \tl_if_empty:NF \l__tikzcalendarnotes_remark_tmp_tl
                  {

                    \__tikzcalendarnotes_shift_adjust_tl_set:NV
                      \l__tikzcalendarnotes_TXshift_tmp_tl
                      \l__tikzcalendarnotes_remark_Xshift_adj_pgfkey_tl
                    

                    \__tikzcalendarnotes_shift_adjust_tl_set:NV
                      \l__tikzcalendarnotes_TYshift_tmp_tl
                      \l__tikzcalendarnotes_remark_Yshift_adj_pgfkey_tl
    
                    \use:e
                      {
                        \exp_not:N\draw
                          (\l__tikzcalendarnotes_cal_name_key_tl - ####1 . \l__tikzcalendarnotes_remarkposref_tmp_tl) 
                          ++(\l__tikzcalendarnotes_TXshift_tmp_tl , \l__tikzcalendarnotes_TYshift_tmp_tl) 
                          node
                            [anchor=\l__tikzcalendarnotes_remarkanchor_tmp_tl , every~ remark , \l__tikzcalendarnotes_remarkstyle_tmp_tl]
                            (\l__tikzcalendarnotes_cal_name_key_tl - ####1 - remark)
                            { \l__tikzcalendarnotes_remark_tmp_tl } ;
                      }
                  }
                  
                \bool_if:NF \l__tikzcalendarnotes_compact_key_bool
                  {
                    \tl_if_empty:NF \l__tikzcalendarnotes_notes_tmp_tl
                      {
                          
                        \tl_set:Nn \l__tikzcalendarnotes_TYshift_tmp_tl 
                          {\l__tikzcalendarnotes_TYshift_scaled_tl}
                          
                        \__tikzcalendarnotes_shift_adjust_tl_set:NV
                          \l__tikzcalendarnotes_TYshift_tmp_tl
                          \l__tikzcalendarnotes_remark_Yshift_adj_pgfkey_tl

                        \use:e
                          {
                            \exp_not:N\draw
                              (\l__tikzcalendarnotes_cal_name_key_tl - ####1 . south~ west) 
                              ++(0pt,\l__tikzcalendarnotes_TYshift_tmp_tl)
                              node
                                [anchor=north~ west , every~ note , \l__tikzcalendarnotes_notestyle_tmp_tl]
                                (\l__tikzcalendarnotes_cal_name_key_tl - ####1 - note)
                                {
                                  \exp_not:N\__tizecalendarnotes_notes_typeset:nn
                                    { \l__tikzcalendarnotes_dayspacing_Xshift_key_tl }
                                    {\exp_not:N\noindent \l__tikzcalendarnotes_notes_tmp_tl }
    
                                } ;
                          }
                      }  
                  }
              }
          }



        \seq_map_inline:cn { l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _range_seq}
          {
            \tl_clear:N \l__tikzcalendarnotes_drawstyle_tmp_tl
            \tl_clear:N \l__tikzcalendarnotes_round_tmp_tl
            \tl_clear:N \l__tikzcalendarnotes_square_tmp_tl
            \tl_clear:N \l__tikzcalendarnotes_remark_tmp_tl
            \tl_clear:N \l__tikzcalendarnotes_remarkstyle_tmp_tl
            
            \prop_map_inline:cn {l__tikzcalendarnotes_ \l__tikzcalendarnotes_active_dataset_tl _ ####1 _prop}
              {
                \tl_set:cn {l__tikzcalendarnotes_ ########1 _tmp_tl} {########2}
              }             
              
            \__tikzcalendarnotes_setflag_ifdatenode_exist:NV 
              \l__tikzcalendarnotes_tmpa_bool 
              \l__tikzcalendarnotes_from_tmp_tl
              
            \__tikzcalendarnotes_setflag_ifdatenode_exist:NV 
              \l__tikzcalendarnotes_tmpb_bool 
              \l__tikzcalendarnotes_to_tmp_tl

            \bool_lazy_and:nnT {\l__tikzcalendarnotes_tmpa_bool} {\l__tikzcalendarnotes_tmpb_bool}
              {
                \tl_if_empty:NF \l__tikzcalendarnotes_round_tmp_tl
                  {
                    \__tikzcalendarnotes_markdraw_range:eeee 
                      {
                        every~ mark , 
                        rounded~ corners=\l__tikzcalendarnotes_radius_tmp_tl , 
                        \l__tikzcalendarnotes_drawstyle_tmp_tl
                      }
                      {\l__tikzcalendarnotes_radius_tmp_tl}
                      {\l__tikzcalendarnotes_cal_name_key_tl - \l__tikzcalendarnotes_from_tmp_tl}
                      {\l__tikzcalendarnotes_cal_name_key_tl - \l__tikzcalendarnotes_to_tmp_tl}
                  }

                \tl_if_empty:NF \l__tikzcalendarnotes_square_tmp_tl
                  {
                    \__tikzcalendarnotes_markdraw_range:eeee 
                      {
                        every~ mark , 
                        \l__tikzcalendarnotes_drawstyle_tmp_tl
                      }
                      {\l__tikzcalendarnotes_radius_tmp_tl}
                      {\l__tikzcalendarnotes_cal_name_key_tl - \l__tikzcalendarnotes_from_tmp_tl}
                      {\l__tikzcalendarnotes_cal_name_key_tl - \l__tikzcalendarnotes_to_tmp_tl}
                  }
              }

            \__tikzcalendarnotes_setflag_ifdatenode_exist:NV 
              \l__tikzcalendarnotes_tmpa_bool 
              \l__tikzcalendarnotes_dateref_tmp_tl

            \bool_if:NT \l__tikzcalendarnotes_tmpa_bool 
            {
              \tl_if_empty:NF \l__tikzcalendarnotes_remark_tmp_tl
                {
                    
                  \__tikzcalendarnotes_shift_adjust_tl_set:NV
                    \l__tikzcalendarnotes_TXshift_tmp_tl
                    \l__tikzcalendarnotes_remark_Xshift_adj_pgfkey_tl
                    
                    
                  \__tikzcalendarnotes_shift_adjust_tl_set:NV
                    \l__tikzcalendarnotes_TYshift_tmp_tl 
                    \l__tikzcalendarnotes_remark_Yshift_adj_pgfkey_tl
  
                  \use:e
                    {
                      \exp_not:N\draw
                        (\l__tikzcalendarnotes_cal_name_key_tl -  \l__tikzcalendarnotes_dateref_tmp_tl . \l__tikzcalendarnotes_remarkposref_tmp_tl) 
                        ++(\l__tikzcalendarnotes_TXshift_tmp_tl ,\l__tikzcalendarnotes_TYshift_tmp_tl) 
                        node
                          [anchor=\l__tikzcalendarnotes_remarkanchor_tmp_tl , every~ remark , \l__tikzcalendarnotes_remarkstyle_tmp_tl]
                          (\l__tikzcalendarnotes_cal_name_key_tl - \l__tikzcalendarnotes_dateref_tmp_tl - remark)
                          { \l__tikzcalendarnotes_remark_tmp_tl } ;
                    }
                }
              }
%%%              
          }
      }      
  }
  
\cs_generate_variant:Nn \__tikzcalendarnotes_draw_notes:n {V}


%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%  End user's commands
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%


\NewDocumentCommand{\defnewdataset}{m}
  {
    \__tikzcalendarnotes_new_dataset:n {#1}
  }  


\NewDocumentCommand{\setdates}{O{default}m}
  {
    \__tikzcalendarnotes_reset_defaults:
    
    \bool_set_true:N \l__tikzcalendarnotes_date_case_bool 
    \tl_set:Nn \l__tikzcalendarnotes_msg_submodule_tl 
      {date not set}

    \__tikzcalendarnotes_select_dataset:n {#1}
    \keys_set:nn 
      {tikzcalendarnotes / date set}
      {#2}   
  }

\NewDocumentCommand{\sethighlightdates}{O{default}m}
  {
    \__tikzcalendarnotes_reset_defaults:
    
    \bool_set_true:N \l__tikzcalendarnotes_hldates_case_bool 

    \__tikzcalendarnotes_select_dataset:n {#1}
    \keys_set:nn 
      {tikzcalendarnotes / hl dates set}
      {#2}   
  }


\NewDocumentCommand{\setranges}{O{default}m}
  {
    \__tikzcalendarnotes_reset_defaults:
    
    \bool_set_true:N \l__tikzcalendarnotes_range_case_bool 
    \tl_set:Nn \l__tikzcalendarnotes_msg_submodule_tl 
      {range not set}

    \__tikzcalendarnotes_select_dataset:n {#1}
    \keys_set:nn 
      {tikzcalendarnotes / range set}
      {#2}   
  }



\NewDocumentCommand{\setcountingweeks}{O{default}m}
  {
    \__tikzcalendarnotes_reset_defaults:

    \bool_set_true:N \l__tikzcalendarnotes_cntweek_case_bool 
    \tl_set:Nn \l__tikzcalendarnotes_msg_submodule_tl 
      {range not set}

    \__tikzcalendarnotes_select_dataset:n {#1}
    \keys_set:nn 
      {tikzcalendarnotes / cnt week set}
      {#2}   

   \bool_if:nT 
    {\l__tikzcalendarnotes_from_set_flag_bool && \l__tikzcalendarnotes_to_set_flag_bool}
    {
      \__tikzcalendarnotes_try_insert_cntweek:VV 
        \l__tikzcalendarnotes_from_key_tl
        \l__tikzcalendarnotes_to_key_tl
    }   
  }

\NewDocumentCommand{\suppresscounting}{O{default}m}
  {
     \__tikzcalendarnotes_reset_defaults:
    \bool_set_true:N \l__tikzcalendarnotes_nocntweek_case_bool 
    \tl_set:Nn \l__tikzcalendarnotes_msg_submodule_tl 
      {range not set}

    \__tikzcalendarnotes_select_dataset:n {#1}
    \keys_set:nn 
      {tikzcalendarnotes / no cnt week set}
      {#2}   

   \bool_if:nT 
    {\l__tikzcalendarnotes_from_set_flag_bool && \l__tikzcalendarnotes_to_set_flag_bool}
    {
      \__tikzcalendarnotes_try_insert_no_cntweek:VV
        \l__tikzcalendarnotes_from_key_tl
        \l__tikzcalendarnotes_to_key_tl
    }
  }


\cs_new_protected:Npn \__tikzcalendarnotes_prepare_style:nn #1#2
  {

    \pgfkeys{tikz , #1}

    \__tikzcalendarnotes_set_dim_constants:
    
    \keys_set:nn
      {tikzcalendarnotes}
      {defaults , #2}
      
    \tl_set:Ne \l__tikzcalendarnotes_begin_iso_tl 
      {
        \l__tikzcalendarnotes_year_key_tl -
        \l__tikzcalendarnotes_starting_at_key_tl - 01
      }
      
  }


\NewDocumentCommand{\calendarnotesprepare}{O{}m}
  {
    \__tikzcalendarnotes_prepare_style:nn 
      {#1}{#2}
  }

\NewDocumentCommand{\calendarnotessetifs}{}
  {
    \__tikzcalendarnotes_set_ifdates:V 
      \l__tikzcalendarnotes_dataset_key_tl
  }

\NewDocumentCommand{\calendarnotesdraw}{}
  {
    \__tikzcalendarnotes_draw_notes:V 
      \l__tikzcalendarnotes_dataset_key_tl
  }
  
\NewDocumentCommand{\calendarnotesmatrix}{}
  {
    \matrix[column~ sep=\l__tikzcalendarnotes_inter_month_space_key_tl pt, 
            row~ sep=0.7*\l__tikzcalendarnotes_inter_month_space_key_tl pt] 
      {
        \__tikzcalendarnotes_month_matrix:nnnn
          {\l__tikzcalendarnotes_year_key_tl}
          {\l__tikzcalendarnotes_starting_at_key_tl}
          {\l__tikzcalendarnotes_nmonths_key_tl}
          {\l__tikzcalendarnotes_perline_key_tl} 
      } ;
  }  
  
\NewDocumentCommand{\calendarnotes}{O{}m}
  {
    \__tikzcalendarnotes_prepare_style:nn {#1}{#2}
    
    \__tikzcalendarnotes_set_ifdates:V
      \l__tikzcalendarnotes_dataset_key_tl

    \matrix[column~ sep=\l__tikzcalendarnotes_inter_month_space_key_tl pt, 
            row~ sep=0.7*\l__tikzcalendarnotes_inter_month_space_key_tl pt] 
      {
        \__tikzcalendarnotes_month_matrix:nnnn
          {\l__tikzcalendarnotes_year_key_tl}
          {\l__tikzcalendarnotes_starting_at_key_tl}
          {\l__tikzcalendarnotes_nmonths_key_tl}
          {\l__tikzcalendarnotes_perline_key_tl} 
      } ;
      
    \__tikzcalendarnotes_draw_notes:V 
      \l__tikzcalendarnotes_dataset_key_tl

  }


%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%



\cs_new_protected:Npn \__tikzcalendarnotes_test_jan_first: 
  {
    \int_compare:nNnT {\pgfcalendarifdateday} = {1}
      {
        \int_compare:nNnT {\pgfcalendarifdatemonth} = {1}
          { \pgfcalendarmatchestrue }
      }
  }


\cs_new_protected:Npn \__tikzcalendarnotes_test_year_start: 
  {
    \bool_if:NTF \g__tikzcalendarnotes_firstdraw_bool
      { 
        \bool_gset_false:N \g__tikzcalendarnotes_firstdraw_bool 
        \pgfcalendarmatchestrue 
      }
      { \__tikzcalendarnotes_test_jan_first: }
  }


\cs_new_protected:Npn \__tikzcalendarnotes_test_week_start_or_first:n #1
  {
    \bool_lazy_or:nnTF 
      {
        \int_compare_p:nNn {\pgfcalendarifdateweekday} = {#1}
      } 
      {
        \int_compare_p:nNn {\pgfcalendarifdateday} = {1}
      }
      { \pgfcalendarmatchestrue }
      {}
  }


\cs_generate_variant:Nn \str_range:nnn {e}

\cs_new_protected:Npn \__tikzcalendarnotes_set_day_acro:NNn #1#2#3
  {
    \int_set:Nn \l__tikzcalendarnotes_tmpa_int {#3}
    \int_sub:Nn \l__tikzcalendarnotes_tmpa_int {\l__tikzcalendarnotes_weeklist_delta_int}
    \int_compare:nNnT {\l__tikzcalendarnotes_tmpa_int} < {0}
      {
        \int_add:Nn \l__tikzcalendarnotes_tmpa_int {7}
      }   
    \tl_set:Ne #1 {\str_range:enn {\pgfcalendarweekdayname{\int_use:N \l__tikzcalendarnotes_tmpa_int}}{1}{2}}
    \int_compare:nNnTF {\l__tikzcalendarnotes_tmpa_int} > {4}
      {
        \int_compare:nNnTF {\l__tikzcalendarnotes_tmpa_int} = {5}
          {
            \tl_set:Nn #2 {@calnotes@saturday~ fmt}
          }
          {
            \tl_set:Nn #2 {@calnotes@sunday~ fmt}
          }
      }
      {
        \tl_set:Nn #2 {}
      }
  }


\cs_new_protected:Npn \__tikzcalendarnotes_weeklist_set:nnnn #1#2#3#4
  {
    \int_set:Nn \l__tikzcalendarnotes_weeklist_delta_int {#1}
    \tl_set:Nn \l__tikzcalendarnotes_weeklist_starts_on_tl {#2}
    \tl_set:Nn \l__tikzcalendarnotes_weeklist_ends_on_tl {#3}
    \int_set:Nn \l__tikzcalendarnotes_weeklist_starts_on_int {#4}
    
    \__tikzcalendarnotes_set_day_acro:NNn \l__tikzcalendarnotes_day_A_tl \l__tikzcalendarnotes_day_A_style_tl {0}
    \__tikzcalendarnotes_set_day_acro:NNn \l__tikzcalendarnotes_day_B_tl \l__tikzcalendarnotes_day_B_style_tl {1}
    \__tikzcalendarnotes_set_day_acro:NNn \l__tikzcalendarnotes_day_C_tl \l__tikzcalendarnotes_day_C_style_tl {2}
    \__tikzcalendarnotes_set_day_acro:NNn \l__tikzcalendarnotes_day_D_tl \l__tikzcalendarnotes_day_D_style_tl {3}
    \__tikzcalendarnotes_set_day_acro:NNn \l__tikzcalendarnotes_day_E_tl \l__tikzcalendarnotes_day_E_style_tl {4}
    \__tikzcalendarnotes_set_day_acro:NNn \l__tikzcalendarnotes_day_F_tl \l__tikzcalendarnotes_day_F_style_tl {5}
    \__tikzcalendarnotes_set_day_acro:NNn \l__tikzcalendarnotes_day_G_tl \l__tikzcalendarnotes_day_G_style_tl {6}

  }

%
% make at letter needed due the many pfg variables/constants at use.
%
\makeatletter


\cs_new_protected:Npn \__tikzcalendarnotes_drawyear:
  {
    \pgftransformxshift{-\tikz@lib@cal@xshift}
    \tikzyearcode  % \tikzyearcode is defined by default
    \pgftransformxshift{\tikz@lib@cal@xshift}
  }

\cs_new_protected:Npn \__tikzcalendarnotes_day_xshift:
  {
    \int_set:Nn \l__tikzcalendarnotes_tmpa_int {\pgfcalendarcurrentweekday + \l__tikzcalendarnotes_weeklist_delta_int}
    \int_compare:nNnT {\l__tikzcalendarnotes_tmpa_int} > {6}
      { \int_sub:Nn \l__tikzcalendarnotes_tmpa_int {7} }
    \pgftransformxshift{ \int_use:N\l__tikzcalendarnotes_tmpa_int * \tikz@lib@cal@xshift }
  }


\cs_new_protected:Npn \__tikzcalendarnodes_daynames_draw:
  {
    \begin{scope}
    \node[every~ day,every~ day~ name,\l__tikzcalendarnotes_day_A_style_tl]{\l__tikzcalendarnotes_day_A_tl};
    \pgftransformxshift{ \tikz@lib@cal@xshift }
    \node[every~ day,every~ day~ name,\l__tikzcalendarnotes_day_B_style_tl]{\l__tikzcalendarnotes_day_B_tl};
    \pgftransformxshift{ \tikz@lib@cal@xshift }
    \node[every~ day,every~ day~ name,\l__tikzcalendarnotes_day_C_style_tl]{\l__tikzcalendarnotes_day_C_tl};
    \pgftransformxshift{ \tikz@lib@cal@xshift }
    \node[every~ day,every~ day~ name,\l__tikzcalendarnotes_day_D_style_tl]{\l__tikzcalendarnotes_day_D_tl};
    \pgftransformxshift{ \tikz@lib@cal@xshift }
    \node[every~ day,every~ day~ name,\l__tikzcalendarnotes_day_E_style_tl]{\l__tikzcalendarnotes_day_E_tl};
    \pgftransformxshift{ \tikz@lib@cal@xshift }
    \node[every~ day,every~ day~ name,\l__tikzcalendarnotes_day_F_style_tl]{\l__tikzcalendarnotes_day_F_tl};
    \pgftransformxshift{ \tikz@lib@cal@xshift }
    \node[every~ day,every~ day~ name,\l__tikzcalendarnotes_day_G_style_tl]{\l__tikzcalendarnotes_day_G_tl};
    \end{scope}
    \pgftransformyshift{ -0.85*\tikz@lib@cal@yshift}
  }


\pgfkeys{tikz , 
	calendar~ notes/.style =
    {
  		remember~ picture , 
  		every~ calendar/.style =
        { week~ starts~ on~ x } ,
      month~ text = {\%mt} ,
      every~ month/.style =
        {
          font = \bfseries\itshape ,
        } ,
      day~ text = 
        { \%d0 } ,
  	} , 
  }
  
\pgfkeys{tikz , 
    % 'execute before day scope' is cumulative. 'new style' needed to fully change calendar's behaviour
  day~ names~ on~ top/.style =
    {
     	week~ starts~ on~ x/.append~ style =
        {
          execute~ before~ day~ scope =
            {
              \ifdate{ day~ of~ month = 1 }
                { \__tikzcalendarnodes_daynames_draw: }
                {}
            } ,
        } ,
    } ,
  every~ day~ name/.style =
    {
      font = {\scriptsize\itshape}
    } ,
  }
  
\pgfkeys{tikz , 
	week~ starts~ on~ x/.style =
    {
      execute~ before~ day~ scope =
        {
    			\ifdate{ day~ of~ month = 1 }
            { % On first of month , except when first date in calendar.
      				\ifdate{ equals = \pgfcalendarbeginiso }
                {}
                { \pgftransformyshift{ -\tikz@lib@cal@month@yshift } }
    			  }
            {}
        } , 
        % glancing from the source code.
      tikz@lib@cal@width = 7 , 
      %
      execute~ at~ begin~ day~ scope =
        { \__tikzcalendarnotes_day_xshift: } , 
      execute~ after~ day~ scope =
        {      % shift to the next line , if end of weeklist
          \ifdate{ \l__tikzcalendarnotes_weeklist_ends_on_tl }
            { \pgftransformyshift{ -\tikz@lib@cal@yshift } }
            {}
        } , 
    } , 
    %
    %
  week~ starts~ monday/.code =
    {
      \__tikzcalendarnotes_weeklist_set:nnnn{0}{Monday}{Sunday}{0}
    } ,
  week~ starts~ sunday/.code =
    {
      \__tikzcalendarnotes_weeklist_set:nnnn{1}{Sunday}{Saturday}{6}
    } ,
  week~ starts~ sunday ,
    %
  }
  
\pgfkeys{tikz , 
  @calnotes@sunday~ fmt/.style = 
    {} ,
    %
  every~ sunday/.style = 
    {
      every~ calendar/.append~ style =
        {
          if = {(Sunday)~ [#1]}
        } ,
      @calnotes@sunday~ fmt/.append~ style = {#1} ,
    } ,
    %
  @calnotes@saturday~ fmt/.style =
    {} ,
    %
  every~ weekend/.style = 
    {
      every~ calendar/.append~ style =
        {
          if = {(weekend)~ [#1]}
        } ,
      @calnotes@saturday~ fmt/.append~ style = {#1} ,
      @calnotes@sunday~ fmt/.append~ style = {#1} ,
    } ,
  }
  
  

\pgfkeys{tikz , 
    % hidden style for drawing the year , 
    % it draws it for January and "first month drawn" (which depends on a _bool variable)
	/pgf/calendar/@calnotes@start~ @of~ @year/.code =
    { \__tikzcalendarnotes_test_year_start: } , 
    %
   
  @calnotes@set~ firstdraw~ flag~ @true/.code =
    {
      \bool_gset_true:N \g__tikzcalendarnotes_firstdraw_bool 
    } ,
    
  @calnotes@set~ firstdraw~ flag~ @false/.code =
    {
      \bool_gset_false:N \g__tikzcalendarnotes_firstdraw_bool 
    } ,
    
  @calnotes@set~ year~ policy~ true@/.code =
    {
      \bool_set_true:N \l__tikzcalendarnotes_year_policy_set_bool
    } ,
    
  @calnotes@set~ year~ policy~ if~ not~ set@/.code =
    {
      \bool_if:NF \l__tikzcalendarnotes_year_policy_set_bool
        {
          \bool_set_true:N \l__tikzcalendarnotes_year_policy_set_bool
          \pgfkeys{tikz,year~ label~ by~ january~ and~ start}
        }
    } ,
    
  @calnotes@set~ year~ label~ true@/.code =
    {
      \bool_set_true:N \l__tikzcalendarnotes_year_label_set_bool
    } ,
    
  @calnotes@set~ year~ label~ if~ not~ set@/.code =
    {
      \bool_if:NF \l__tikzcalendarnotes_year_label_set_bool
        {
          \bool_set_true:N \l__tikzcalendarnotes_year_label_set_bool
          \pgfkeys{tikz,year~ label~ left}
        }
    } ,
    
  year~ label~ by~ january~ and~ start/.style = 
    {
      @calnotes@set~ firstdraw~ flag~ @true ,
      @calnotes@set~ year~ policy~ true@ ,
      @calnotes@set~ year~ label~ if~ not~ set@ ,
      execute~ before~ day~ scope =
        {
          \ifdate{@calnotes@start~ @of~ @year}
            { \__tikzcalendarnotes_drawyear: }
            {}
        } , 
    } ,
    
  year~ label~ by~ january~ only/.style =
    {
      @calnotes@set~ firstdraw~ flag~ @false ,
      @calnotes@set~ year~ policy~ true@ ,
      @calnotes@set~ year~ label~ if~ not~ set@ ,
      execute~ before~ day~ scope =
        {
          \ifdate{@calnotes@start~ @of~ @year}
            { \__tikzcalendarnotes_drawyear: }
            {}
        } , 
    } ,
    
    % Style forcing an year label.
	year~ label~ every~ month/.style=
    {
      @calnotes@set~ year~ policy~ true@ ,
      @calnotes@set~ year~ label~ if~ not~ set@ ,
  		execute~ before~ day~ scope =
        {
  			  \ifdate{day~ of~ month = 1}
            { \__tikzcalendarnotes_drawyear: }
            {}
        }
    } , 
  
	year~ label~ left/.style =
    {
      @calnotes@set~ year~ label~ true@ ,
      @calnotes@set~ year~ policy~ if~ not~ set@ ,
      every~ year/.append~ style =
        { 
          anchor = north~ east ,
        } , 
  	} , 
  
	year~ label~ left~ vertical/.style =
    {
      @calnotes@set~ year~ label~ true@ ,
      @calnotes@set~ year~ policy~ if~ not~ set@ ,
      every~ year/.append~ style =
        { 
          anchor = south ,
          rotate = 90 ,
        } , 
  	} , 
    
	year~ label~ left~ corner/.style =
    {
      @calnotes@set~ year~ label~ true@ ,
      @calnotes@set~ year~ policy~ if~ not~ set@ ,
      every~ year/.append~ style =
        { 
          anchor = south ,
          rotate = 45 ,
        } , 
  	} , 
  
  every~ year/.style = 
    { font = \Large\sffamily\bfseries, green!50!black } ,
  }
  
\pgfkeys{tikz , 
  every~ mark/.style =
    { thin , gray } ,
  every~ remark/.style =
    { 
      font = 
        \fontsize{3.5}{4.2}
        \selectfont 
    } ,    
  every~ counter/.style =
    {
      every~ remark
    } ,
  keep~ counters/.code =
    {
      \bool_set_true:N \l__tikzcalendarnotes_keep_counters_pgfkey_bool
    } ,
  @calnotes@note@fontsize/.code = 
    {
      \tl_set:Nn \l__tikzcalendarnotes_notes_fontsize_pgfkey_tl {#1}
    } ,
  every~ note/.style =
    { 
      font = 
        \fontsize{4.5}{4.95}
        \selectfont 
    } ,    
  @calnotes@note@fontsize = 4.5 ,
  remarks~ font size/.style =
    {
      every~ remark/.append~ style =
        {
          font = 
            \fontsize{#1}{\fp_eval:n {1.1*#1}}
            \selectfont 
        }
    } ,
  remarks~ font size/.value~ required ,
  %
  notes~ font size/.style =
    {
      @calnotes@note@fontsize = {#1} ,
      every~ note/.append~ style =
        {
          font = 
            \fontsize{#1}{\fp_eval:n {1.1*#1}}
            \selectfont 
        }
    } ,
  notes~ font size/.value~ required ,
  %
  }
  
\pgfkeys{tikz , 
  Xshift~ adjust/.code =
    {
      \tl_set:Nn \l__tikzcalendarnotes_remark_Xshift_adj_pgfkey_tl {#1 pt}
    } ,
  Xshift~ adjust/.value~ required ,
  %
  Yshift~ adjust/.code =
    {
      \tl_set:Nn \l__tikzcalendarnotes_remark_Yshift_adj_pgfkey_tl {#1 pt}
    } ,
  Yshift~ adjust/.value~ required ,
  %
  radius~ adjust/.code =
    {
      \tl_set:Nn \l__tikzcalendarnotes_radius_adj_pgfkey_tl {#1 pt}
    } ,
  radius~ adjust/.value~ required ,
  %
  radius~ adjust = 0,
  Xshift~ adjust = 0,
  Yshift~ adjust = 0,
 }


