From 0c7873f9ffd7192fe2ad9c08c8f3a42bb7b9d71b Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Mon, 30 Sep 2019 21:49:53 +0000
Subject: enotez (30sep19)

git-svn-id: svn://tug.org/texlive/trunk@52225 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/enotez/enotez.sty | 379 ++++++++++++++------------
 1 file changed, 209 insertions(+), 170 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/enotez/enotez.sty')

diff --git a/Master/texmf-dist/tex/latex/enotez/enotez.sty b/Master/texmf-dist/tex/latex/enotez/enotez.sty
index ba26561827b..4e1738e74e7 100644
--- a/Master/texmf-dist/tex/latex/enotez/enotez.sty
+++ b/Master/texmf-dist/tex/latex/enotez/enotez.sty
@@ -8,7 +8,7 @@
 % Web:    https://bitbucket.org/cgnieder/enotez/
 % E-Mail: contact@mychemistry.eu
 % --------------------------------------------------------------------------
-% Copyright 2012-2017 Clemens Niederberger
+% Copyright 2012--2019 Clemens Niederberger
 % 
 % This work may be distributed and/or modified under the
 % conditions of the LaTeX Project Public License, either version 1.3
@@ -31,20 +31,12 @@
 \RequirePackage{ expl3 , xparse , l3keys2e , xtemplate , etoolbox , xpatch , scrlfile }
 \ProvidesExplPackage
   {enotez}
-  {2017/04/24}
-  {0.9a}
+  {2019/09/30}
+  {0.10}
   {Endnotes for LaTeX2e}
 
 % --------------------------------------------------------------------------
 % messages
-% \msg_new:nnnn {enotez} {captions}
-%   { Endnotes~might~not~work~in~captions. }
-%   {
-%     Endnotes~might~not~work~inside~captions.~You~might~try~to~use~the~caption~
-%     package~if~you~encounter~problems~but~that's~not~a~promise~that~things~
-%     will~work~then.
-%   }
-
 \msg_new:nnnn {enotez} {deprecated}
   { The~#1~`#2'~is~deprecated.~Use~`#3'~instead~\msg_line_context:. }
   {
@@ -53,10 +45,17 @@
     forever~I~encourage~you~to~switch.
   }
 
-\cs_new:Npn \enotez_option_deprecated:nn #1#2
+\msg_new:nnn {enotez} {totoc}
+  {
+    You've~ set~ `totoc~ =~ auto'.~ However,~ I'm~ unbale~ to~ determine~ the~
+    toc~ level~ automatically.~ Please~ choose~ the~ level~ yourself.
+  }
+
+
+\cs_new_protected:Npn \enotez_option_deprecated:nn #1#2
   { \msg_warning:nnnnn {enotez} {deprecated} {option} {#1} {#2} }
 
-\cs_new:Npn \enotez_command_deprecated:NN #1#2
+\cs_new_protected:Npn \enotez_command_deprecated:NN #1#2
   {
     \msg_warning:nnnnn {enotez} {deprecated} {command}
       { \token_to_str:N #1 } { \token_to_str:N #2 }
@@ -65,7 +64,9 @@
 % --------------------------------------------------------------------------
 % variants of kernel functions
 \cs_generate_variant:Nn \tl_if_eq:nnTF { Vn , nx }
-\cs_generate_variant:Nn \tl_if_eq:nnT  { xx }
+\cs_generate_variant:Nn \tl_if_eq:nnT  { xx , V }
+\cs_generate_variant:Nn \str_if_in:nnT { o }
+\cs_generate_variant:Nn \cs_set:Npn    { cpV }
 
 % --------------------------------------------------------------------------
 % variables:
@@ -76,9 +77,6 @@
 \bool_new:N \l__enotez_hyperfootnotes_bool
 \bool_new:N \l__enotez_hyperbackref_bool
 \bool_new:N \l__enotez_split_bool
-% \bool_new:N \l__enotez_caption_patched_bool
-% \bool_new:N \l__enotez_koma_patched_bool
-% \bool_new:N \l__enotez_memoir_patched_bool
 \bool_new:N \l__enotez_disable_bool
 
 \tl_new:N   \l__enotez_tmpa_tl
@@ -88,7 +86,7 @@
 \tl_new:N   \l__enotez_totoc_tl
 \tl_new:N   \l__enotez_list_name_tl
 \tl_set:Nn  \l__enotez_list_name_tl {Notes}
-\tl_new:N   \l__enotez_endnote_text_tl
+\tl_new:N   \g__enotez_endnote_text_tl
 \tl_new:N   \l__enotez_endnote_mark_tl
 \tl_new:N   \l__enotez_list_instance_tl
 \tl_set:Nn  \l__enotez_list_instance_tl {plain}
@@ -131,7 +129,18 @@
 \prop_new:N \g__enotez_endnote_sect_id_prop
 \prop_new:N \g__enotez_endnote_man_prop
 
-\cs_new_protected:Npn \enotez_nobreak: { \tex_penalty:D \c_ten_thousand }
+\seq_new:N \l__enotez_tmpa_seq
+\seq_new:N \l__enotez_sectioning_seq
+\seq_put_right:Nn \l__enotez_sectioning_seq {part}
+\seq_put_right:Nn \l__enotez_sectioning_seq {chapter}
+\seq_put_right:Nn \l__enotez_sectioning_seq {section}
+\seq_put_right:Nn \l__enotez_sectioning_seq {subsection}
+\seq_put_right:Nn \l__enotez_sectioning_seq {subsubsection}
+\seq_put_right:Nn \l__enotez_sectioning_seq {paragraph}
+
+\str_new:N \l__enotez_tmpa_str
+
+\cs_new_protected:Npn \enotez_nobreak: { \tex_penalty:D 10000 \scan_stop: }
 
 % --------------------------------------------------------------------------
 % options:
@@ -141,7 +150,6 @@
     footnotes        .bool_set:N         = \l__enotez_footnotes_tl ,
     list-name        .tl_set:N           = \l__enotez_list_name_tl ,
     reset            .bool_set:N         = \l__enotez_reset_bool ,
-    % TODO: add symbols and other possible formats, use cntformats?
     counter-format   .choice: ,
     counter-format / arabic  .code:n = \cs_set:Npn \theendnote {\arabic{endnote}} ,
     counter-format / alph    .code:n = \cs_set:Npn \theendnote {\alph{endnote}} ,
@@ -152,27 +160,28 @@
     mark-format      .code:n             = \cs_set:Npn \enmarkstyle {#1} ,
     mark-cs          .code:n             = \cs_set:Npn \enotezwritemark {#1} ,
     totoc            .choices:nn         =
-      { section , chapter , false }
+      { subsection , section , chapter , part , auto , false }
       {
-        \tl_if_eq:VnTF \l_keys_choice_tl { false }
+        \tl_if_eq:VnTF \l_keys_choice_tl {false}
           { \bool_set_false:N \l__enotez_totoc_bool }
           {
             \bool_set_true:N \l__enotez_totoc_bool
             \tl_set_eq:NN \l__enotez_totoc_tl \l_keys_choice_tl
           }
       } ,
+    totoc            .default:n          = auto ,  
     list-heading     .code:n             =
       \cs_set:Npn \enotezlistheading ##1 {#1} ,
     split            .choices:nn          =
       { section , chapter , false }
       {
-        \tl_if_eq:VnTF \l_keys_choice_tl { false }
+        \tl_if_eq:VnTF \l_keys_choice_tl {false}
           { \bool_set_false:N \l__enotez_split_bool }
           { \bool_set_true:N \l__enotez_split_bool }
         \tl_set_eq:NN \l__enotez_split_tl \l_keys_choice_tl
       } ,
     split-sectioning .code:n             =
-      \enotez_option_deprecated:nn { split-sectioning } { split-heading }
+      \enotez_option_deprecated:nn {split-sectioning} {split-heading}
       \cs_set:Npn \enotezsplitlistheading ##1 {#1}
       \bool_set_true:N \l__enotez_splitted_list_heading_bool ,
     split-heading    .code:n             =
@@ -190,6 +199,7 @@
 % #2: mark
 \cs_new_protected:Npn \enotez_write_mark:nn #1#2
   {
+    % but what if #2 is the reference to a different mark?
     \bool_if:NTF \l__enotez_hyperfootnotes_bool
       {
         \enotezwritemark { \hyperlink {enz.#1} { \enmarkstyle #2 } }
@@ -203,6 +213,10 @@
   }
 \cs_generate_variant:Nn \enotez_write_mark:nn {x}
 
+% % #1: argument to \ref
+% \cs_new_protected:Npn \enotez_ref_note:n #1
+%   { \enotezwritemark { \enmarkstyle { \ref {#1} } } }
+
 % the internal endnote:
 \cs_new_protected:Npn \enotez_endnote:nn #1#2
   {
@@ -215,16 +229,13 @@
     \int_gincr:N \g__enotez_endnote_id_int
     \quark_if_no_value:nTF {#1}
       {
-        \stepcounter {endnote}% problem with option `reset'
-        % \show \theendnote
-        \cs_gset:cpx {@currentlabel} {\theendnote}
+        \refstepcounter {endnote}
         \enotez_write_mark:xn
           { \int_use:N \g__enotez_endnote_id_int }
           { \theendnote }
       }
       {
-        \cs_gset:cpn {@currentlabel} {#1}
-        % \cs_gset_eq:NN \theendnote \@currentlabel
+        \cs_gset:cpn {@currentlabel} {\p@endnote#1}
         \enotez_write_mark:xn { \int_use:N \g__enotez_endnote_id_int } {#1}
       }
     \bool_if:NT \l__enotez_disable_bool
@@ -254,22 +265,20 @@
             \enotez_save_note:xxxxxnn
               { \int_use:N \g__enotez_endnote_id_int }
               { \theendnote }
-              % { \int_use:N \g__enotez_endnote_mark_int }
               { \int_use:N \g__enotez_list_printed_int }
               { \thechapter }
               { \int_eval:n { \value{chapter} } }
-              { a }
+              {a}
               {#2}
           }
           {
             \enotez_save_note:xxxxxnn
               { \int_use:N \g__enotez_endnote_id_int }
               { \theendnote }
-              % { \int_use:N \g__enotez_endnote_mark_int }
               { \int_use:N \g__enotez_list_printed_int }
               { \thesection }
               { \int_eval:n { \value{section} } }
-              {a }
+              {a}
               {#2}
           }
       }
@@ -287,7 +296,7 @@
               { \int_use:N \g__enotez_list_printed_int }
               { \thechapter }
               { \int_eval:n { \value{chapter} } }
-              { m }
+              {m}
               {#2}
           }
           {
@@ -297,7 +306,7 @@
               { \int_use:N \g__enotez_list_printed_int }
               { \thesection }
               { \int_eval:n { \value{section} } }
-              { m }
+              {m}
               {#2}
           }
       }
@@ -313,7 +322,10 @@
 % #6: a/m (automatic/manually)
 % #7: text
 \cs_new_protected:Npn \enotez_save_note:nnnnnnn #1#2#3#4#5#6#7
-  { \iow_now:Nn \@auxout { \enotez@note {#1} {#2} {#3} {#4} {#5} {#6} {#7} } }
+  {
+    \legacy_if:nT {@filesw}
+      { \iow_now:Nn \@auxout { \enotez@note {#1} {#2} {#3} {#4} {#5} {#6} {#7} } }
+  }
 \cs_generate_variant:Nn \enotez_save_note:nnnnnnn { xxxxx , xnxxx }
 
 \cs_new_protected:Npn \enotez@note #1#2#3#4#5#6#7
@@ -372,153 +384,188 @@
       { \enotez_endnote_text:nn { \q_no_value } }
   }
 
+% \cs_new_protected:Npn \refendnote #1
+%   { \enotez_ref_note:n {#1} }
+  
 \cs_new:Npn \enotez_endnote_text_aux:w [#1]#2
   { \enotez_endnote_text:nn {#1} {#2} }
 
 % --------------------------------------------------------------------------
 % the list of notes
-\cs_if_exist:cTF { chapter }
+\cs_if_exist:cTF {chapter}
   { \cs_new:Npn \enotezlistheading { \chapter* } }
   { \cs_new:Npn \enotezlistheading { \section* } }
 
 \tl_new:N \enotezsplitlistheading
 \bool_new:N \l__enotez_splitted_list_heading_bool
-% \cs_new:Npn \enotezsplitlistheading
-%   { \use:c { \l__enotez_splitted_list_sectioning_tl } }
+
+\cs_new_protected:Npn \enotez_set_totoc:
+  {
+    \bool_if:NT \l__enotez_totoc_bool
+      {
+        \bool_if:NT \l__enotez_hyperref_bool { \phantomsection }
+        \bool_set_false:N \l__enotez_tmpa_bool
+        \tl_if_eq:VnTF \l__enotez_totoc_tl {auto}
+          {
+            \seq_map_inline:Nn \l__enotez_sectioning_seq
+              {
+                \str_if_in:onT { \enotezlistheading{} } {##1}
+                  {
+                    \bool_set_true:N \l__enotez_tmpa_bool
+                    \tl_set:Nn \l__enotez_totoc_tl {##1}
+                  }
+              }
+            \bool_if:NF \l__enotez_tmpa_bool
+              {
+                \tl_set:Nn \l__enotez_totoc_tl {false}
+                \msg_warning:nn {enotez} {totoc}
+              }
+          }
+          { \bool_set_true:N \l__enotez_tmpa_bool }
+        \bool_if:NT \l__enotez_tmpa_bool
+          {
+            \addcontentsline
+              {toc}
+              { \l__enotez_totoc_tl }
+              { \l__enotez_list_name_tl }
+          }
+      }
+  }
+
+\cs_new_protected:Npn \enotez_build_print_list:nnnn #1#2#3#4
+  {
+    \int_zero:N \l__enotez_tmpa_int
+    \bool_if:nTF {#1}
+      {
+        \prop_map_inline:Nn \g__enotez_endnote_mark_prop
+          {
+            \enotez_get_note:nn {#1} {##1}
+            \bool_if:NT \l__enotez_print_note_bool {#3}
+          }
+      }
+      {
+    \int_do_while:nn { \l__enotez_tmpa_int <= \g__enotez_list_printed_int }
+      {
+        \seq_clear:N \l__enotez_tmpa_seq
+        \prop_map_inline:Nn \g__enotez_endnote_mark_prop
+          {
+            \tl_if_eq:xxT
+              { \int_use:N \l__enotez_tmpa_int }
+              { \prop_item:Nn \g__enotez_endnote_split_prop {##1} }
+              { \seq_put_right:Nn \l__enotez_tmpa_seq {##1} }
+          }
+        \seq_if_empty:NF \l__enotez_tmpa_seq
+          {
+            \enotez_get_split_title:x { \seq_item:Nn \l__enotez_tmpa_seq {1} }
+            #2
+          }
+        \seq_map_inline:Nn \l__enotez_tmpa_seq
+          {
+            \enotez_get_note:nn {#1} {##1}
+            \bool_if:NT \l__enotez_print_note_bool {#3}
+          }
+        \seq_if_empty:NF \l__enotez_tmpa_seq {#4}
+        \int_incr:N \l__enotez_tmpa_int
+      }
+    }
+  }
 
 \DeclareObjectType {enotez-list} {1}
 
 \DeclareTemplateInterface {enotez-list} {paragraph} {1}
   {
-    heading       : function 1 = \enotezlistheading{#1}   ,
-    format        : tokenlist  = \footnotesize   ,
-    number        : function 1 = \enmark{#1}     ,
-    number-format : tokenlist  = \normalfont     ,
-    notes-sep     : length     = .5\baselineskip ,
+    heading       : function 1 = \enotezlistheading {#1} ,
+    format        : tokenlist  = \footnotesize           ,
+    number        : function 1 = \enmark{#1}             ,
+    number-format : tokenlist  = \normalfont             ,
+    notes-sep     : length     = .5\baselineskip
   }
 
 \DeclareTemplateCode {enotez-list} {paragraph} {1}
   {
-    heading       = \enotez_list_heading:n          ,
+    heading       = \enotez_list_heading:n           ,
     format        = \l__enotez_list_format_tl        ,
-    number        = \enotez_list_number:n           ,
+    number        = \enotez_list_number:n            ,
     number-format = \l__enotez_list_number_format_tl ,
-    notes-sep     = \l__enotez_list_notes_sep_dim    ,
+    notes-sep     = \l__enotez_list_notes_sep_dim
   }
   {
     \AssignTemplateKeys
-    \bool_if:NT \l__enotez_totoc_bool
-      {
-        \bool_if:NT \l__enotez_hyperref_bool { \phantomsection }
-        \addcontentsline {toc} { \l__enotez_totoc_tl } { \l__enotez_list_name_tl }
-      }
+    \enotez_set_totoc:
     \enotez_list_heading:n { \l__enotez_list_name_tl }
     \enotez_list_preamble:
-      \int_zero:N \l__enotez_tmpa_int
-      \int_do_while:nn { \l__enotez_tmpa_int <= \g__enotez_list_printed_int }
-        {
-          \prop_map_inline:Nn \g__enotez_endnote_mark_prop
+    \enotez_build_print_list:nnnn {#1}
+      {}
+      {
+        \par\noindent
+        \group_begin:
+          \tl_use:N \l__enotez_list_format_tl
+          \hbox_overlap_left:n
             {
-              \tl_if_eq:xxT
-                { \int_use:N \l__enotez_tmpa_int }
-                { \prop_item:Nn \g__enotez_endnote_split_prop { ##1 } }
-                {
-                  \enotez_get_split_title:n { ##1 }
-                  \enotez_get_note:nn {#1} { ##1 }
-                  \bool_if:NT \l__enotez_print_note_bool
-                    {
-                      \par\noindent
-                      \group_begin:
-                      \tl_use:N \l__enotez_list_format_tl
-                      \llap
-                        {
-                          \enotez_list_number:n
-                            { \enotez_write_list_number:n { ##1 } }
-                          \tl_use:N \c_space_tl
-                        }
-                      \tl_use:N \l__enotez_endnote_text_tl
-                      \par
-                      \group_end:
-                    }
-                }
-              \par
-              \dim_compare:nT { \l__enotez_list_notes_sep_dim != 0pt }
-                { \addvspace { \l__enotez_list_notes_sep_dim } }
+              \enotez_list_number:n
+                { \enotez_write_list_number:n {##1} }
+              \tl_use:N \c_space_tl
             }
-          \int_incr:N \l__enotez_tmpa_int
-        }
+          % \cs_set:cpn {@currentlabel}
+          %   { \p@endnote \l__enotez_endnote_mark_tl }
+          \tl_use:N \g__enotez_endnote_text_tl
+          \par
+          \dim_compare:nT { \l__enotez_list_notes_sep_dim != 0pt }
+            { \addvspace { \l__enotez_list_notes_sep_dim } }
+        \group_end:
+      }
+      {}
     \enotez_list_postamble:
   }
 
 \DeclareTemplateInterface {enotez-list} {list} {1}
   {
-    heading       : function 1 = \enotezlistheading{#1} ,
-    format        : tokenlist  = \footnotesize ,
-    number        : function 1 = \enmark{#1}   ,
-    number-format : tokenlist  = \normalfont   ,
-    list-type     : tokenlist  = description   ,
+    heading       : function 1 = \enotezlistheading {#1} ,
+    format        : tokenlist  = \footnotesize           ,
+    number        : function 1 = \enmark{#1}             ,
+    number-format : tokenlist  = \normalfont             ,
+    list-type     : tokenlist  = description
   }
 
 \DeclareTemplateCode {enotez-list} {list} {1}
   {
-    heading       = \enotez_list_heading:n          ,
+    heading       = \enotez_list_heading:n           ,
     format        = \l__enotez_list_format_tl        ,
-    number        = \enotez_list_number:n           ,
+    number        = \enotez_list_number:n            ,
     number-format = \l__enotez_list_number_format_tl ,
     list-type     = \l__enotez_list_type_tl
   }
   {
     \AssignTemplateKeys
-    \bool_if:NT \l__enotez_totoc_bool
-      {
-        \bool_if:NT \l__enotez_hyperref_bool { \phantomsection }
-        \addcontentsline { toc } { \l__enotez_totoc_tl } { \l__enotez_list_name_tl }
-      }
+    \enotez_set_totoc:
     \enotez_list_heading:n { \l__enotez_list_name_tl }
     \enotez_list_preamble:
-      \int_zero:N \l__enotez_tmpa_int
-      \int_do_while:nn { \l__enotez_tmpa_int <= \g__enotez_list_printed_int }
-        {
-          \prop_map_inline:Nn \g__enotez_endnote_mark_prop
-            {
-              \tl_clear:N \l__enotez_tmpc_tl
-              \tl_if_eq:xxT
-                { \int_use:N \l__enotez_tmpa_int }
-                { \prop_item:Nn \g__enotez_endnote_split_prop { ##1 } }
-                { \tl_put_right:Nn \l__enotez_tmpc_tl { ##1 } }
-              \tl_if_blank:VF \l__enotez_tmpc_tl
-                {
-                  \enotez_get_split_title:n { ##1 }
-                  \group_begin:
-                    \tl_use:N \l__enotez_list_format_tl
-                    \begin{\l__enotez_list_type_tl}
-                }
-              \tl_if_eq:xxT
-                { \int_use:N \l__enotez_tmpa_int }
-                { \prop_item:Nn \g__enotez_endnote_split_prop { ##1 } }
-                {
-                  \enotez_get_note:nn {#1} { ##1 }
-                  \bool_if:NT \l__enotez_print_note_bool
-                    {
-                      \item
-                        [
-                          \enotez_list_number:n
-                            { \enotez_write_list_number:n { ##1 } }
-                        ]
-                      \tl_use:N \l__enotez_endnote_text_tl
-                    }
-                }
-              \tl_if_blank:VF \l__enotez_tmpc_tl
-                { \end{\l__enotez_list_type_tl} \group_end: }
-            }
-          \int_incr:N \l__enotez_tmpa_int
-        }
+    \enotez_build_print_list:nnnn {#1}
+      {
+        \group_begin:
+          \tl_use:N \l__enotez_list_format_tl
+          \begin{\l__enotez_list_type_tl}
+      }
+      {
+        \item
+          [
+            \enotez_list_number:n
+              { \enotez_write_list_number:n {##1} }
+          ]
+        % \cs_set:cpn {@currentlabel}
+        %   { \p@endnote \l__enotez_endnote_mark_tl }
+        \tl_use:N \g__enotez_endnote_text_tl
+      }
+      {
+          \end{\l__enotez_list_type_tl}
+        \group_end:
+      }
     \enotez_list_postamble:
   }
 
 % some default styles:
-\DeclareInstance {enotez-list} {plain} {paragraph } {  }
-\DeclareInstance {enotez-list} {description} {list} {  }
+\DeclareInstance {enotez-list} {plain} {paragraph } { }
+\DeclareInstance {enotez-list} {description} {list} { }
 \DeclareInstance {enotez-list} {itemize} {list} { list-type = itemize }
 
 % --------------------------------------------------------------------------
@@ -528,8 +575,7 @@
     \bool_if:NT \l__enotez_hyperfootnotes_bool
       { \box_move_up:nn {1em} { \hbox:n { \hypertarget {enz.#1} { } } } }
     \tl_use:N \l__enotez_list_number_format_tl
-    \tl_if_eq:nxTF {a}
-      { \prop_item:Nn \g__enotez_endnote_man_prop {#1} }
+    \tl_if_eq:nxTF {a} { \prop_item:Nn \g__enotez_endnote_man_prop {#1} }
       {
         \bool_if:nTF
           { \l__enotez_hyperfootnotes_bool && \l__enotez_hyperbackref_bool }
@@ -559,7 +605,10 @@
     \bool_if:nTF {#1}
       {
         \prop_get:NnN \g__enotez_endnote_mark_prop {#2} \l__enotez_endnote_mark_tl
-        \prop_get:NnN \g__enotez_endnote_text_prop {#2} \l__enotez_endnote_text_tl
+        \prop_get:NnN \g__enotez_endnote_text_prop {#2} \g__enotez_endnote_text_tl
+        \tl_gset_eq:NN
+          \g__enotez_endnote_text_tl
+          \g__enotez_endnote_text_tl
         \bool_set_true:N \l__enotez_print_note_bool
       }
       {
@@ -569,14 +618,8 @@
             \bool_set_true:N \l__enotez_print_note_bool
             \tl_set:Nx \l__enotez_endnote_mark_tl
               { \prop_item:Nn \g__enotez_endnote_mark_prop {#2} }
-            \tl_set:Nx \l__enotez_endnote_text_tl
+            \tl_gset:Nx \g__enotez_endnote_text_tl
               { \prop_item:Nn \g__enotez_endnote_text_prop {#2} }
-            % \prop_gpop:NnN \g__enotez_endnote_mark_prop
-            %   {#2}
-            %   \l__enotez_endnote_mark_tl
-            % \prop_gpop:NnN \g__enotez_endnote_text_prop
-            %   {#2}
-            %   \l__enotez_endnote_text_tl
           }
           {
             \int_compare:nTF { \l__enotez_tmpa_tl = \g__enotez_list_printed_int }
@@ -584,14 +627,8 @@
                 \bool_set_true:N \l__enotez_print_note_bool
                 \tl_set:Nx \l__enotez_endnote_mark_tl
                   { \prop_item:Nn \g__enotez_endnote_mark_prop {#2} }
-                \tl_set:Nx \l__enotez_endnote_text_tl
+                \tl_gset:Nx \g__enotez_endnote_text_tl
                   { \prop_item:Nn \g__enotez_endnote_text_prop {#2} }
-                % \prop_gpop:NnN \g__enotez_endnote_mark_prop
-                %   {#2}
-                %   \l__enotez_endnote_mark_tl
-                % \prop_gpop:NnN \g__enotez_endnote_text_prop
-                %   {#2}
-                %   \l__enotez_endnote_text_tl
                 \prop_gremove:Nn  \g__enotez_endnote_split_prop {#2}
               }
               { \bool_set_false:N \l__enotez_print_note_bool }
@@ -676,7 +713,7 @@
             \bool_if:NTF \l__enotez_splitted_list_heading_bool
               { \exp_args:No \enotezsplitlistheading }
               {
-                \tl_if_eq:VnTF \l__enotez_split_tl { section }
+                \tl_if_eq:VnTF \l__enotez_split_tl {section}
                   { \exp_args:NNo \subsection* }
                   { \exp_args:NNo \section* }
               }
@@ -686,6 +723,7 @@
       }
     \prop_get:NnN \g__enotez_endnote_split_prop {#1} \l__enotez_last_split_id_tl
   }
+\cs_generate_variant:Nn \enotez_get_split_title:n {x}
 
 % --------------------------------------------------------------------------
 % the marks in the list:
@@ -697,6 +735,8 @@
 
 % --------------------------------------------------------------------------
 % internal printendnotes:
+% #1: boolean
+% #2: list style
 \cs_new_protected:Npn \enotez_print_endnotes:nn #1#2
   {
     \enotez_if_endnotes:T
@@ -708,30 +748,29 @@
         \bool_if:NF \l__enotez_split_bool
           {
             \bool_if:NT \l__enotez_reset_bool
-              {
-                \setcounter {endnote} {0}
-                % \int_gzero:N \g__enotez_endnote_mark_int
-              }
+              { \setcounter {endnote} {0} }
             \int_gincr:N \g__enotez_list_printed_int
           }
+        \bool_if:NT \l__enotez_reset_bool
+          { \setcounter {endnote} {0} }
       }
   }
 
 \prg_new_conditional:Npnn \enotez_if_endnotes: {p,T,F,TF}
   {
-    \int_compare:nTF { \value {endnote} > 0 }
+    \int_compare:nTF { \g__enotez_endnote_id_int > 0 }
       { \prg_return_true: }
       { \prg_return_false: }
   }
 
 % the user command:
-\NewDocumentCommand \printendnotes { so }
+\NewDocumentCommand \printendnotes {so}
   {
     \IfNoValueTF {#2}
       {
         \bool_if:NTF \l__enotez_split_bool
-          { \enotez_print_endnotes:nn { \BooleanFalse } {  } }
-          { \enotez_print_endnotes:nn {#1} {  } }
+          { \enotez_print_endnotes:nn { \BooleanFalse } { } }
+          { \enotez_print_endnotes:nn {#1} { } }
       }
       {
         \bool_if:NTF \l__enotez_split_bool
@@ -839,8 +878,6 @@
 \cs_new:Npn \EnotezCurrentSplitTitle {}
 
 % --------------------------------------------------------------------------
-% process the options:
-\ProcessKeysOptions {enotez}
 
 \AtBeginDocument
   {
@@ -852,10 +889,7 @@
               {
                 \int_gincr:N \g__enotez_list_printed_int
                 \bool_if:NT \l__enotez_reset_bool
-                  {
-                    \setcounter {endnote} {0}
-                    % \int_gzero:N \g__enotez_endnote_mark_int
-                  }
+                  { \setcounter {endnote} {0} }
               }
           }
           {
@@ -863,10 +897,7 @@
               {
                 \int_gincr:N \g__enotez_list_printed_int
                 \bool_if:NT \l__enotez_reset_bool
-                  {
-                    \setcounter {endnote} {0}
-                    % \int_gzero:N \g__enotez_endnote_mark_int
-                  }
+                  { \setcounter {endnote} {0} }
               }
           }
       }
@@ -984,6 +1015,14 @@
 2016/11/08 v0.9  - fix issues #6, #7, and #8
                  - remove caption patching and add \endnotemark and \endnotetext
 2017/04/24 v0.9a - fix wrong format of number in list
+2019/09/30 v0.10 - fix issus #14
+                 - don't allow package options any more
+                 - implement issue #17: new choices for the totoc option:
+                   `auto', `subsection' and `part'
+                 - fix issue #18
+                 - implement issue #13
+                 % - new command \refendnote, fix issue #19
+                 - implement issue #9
 
 % --------------------------------------------------------------------------
 % TODO:
-- 
cgit v1.2.3

