This is a followup question for this question, where Christian Hupfer provided me a great solution for a certain problem: I wanted to list the occurrences of special commands within a section at the beginning of that section. That works perfectly well.

Now I want to expand the scope of this thing a bit by displaying the contents of all those lists on one page, preferably at the beginning of the document. I see that the code works by using local lists that have limited scope. Is it somehow possible to add a global lists for each section, so these could be accessed from outside the section? I couldn't find any helpful information on this on the net.

Thanks a lot in advance!

  • With other words, you want to have some kind of a List of Persons for the whole document? – user31729 Feb 14 '18 at 7:46
  • Yes and no, I mean some kind of overview which person occurs in which scene (section) of the document. Like the Output of \DisplayPersons in each section aggregated on page. Maybe it would be enough to know how to create a token list for each section, like including the section number in the token list name, and how to iterate over these... Or maybe where these token lists are documeted... Thanks in advance! – LukeLR Feb 14 '18 at 23:40
  • I'll take a look later on. Basically, you're requesting an index – user31729 Feb 15 '18 at 10:58
  • @ChristianHupfer Do you think, you might find the time to give me some hints or point me to the right direction? :) – LukeLR Mar 14 '18 at 20:57
  • I haven't forgot this question, but I am little bit short of time ... – user31729 Mar 14 '18 at 20:59

This extends the previous solution I gave in the answer linked to by the O.P.

Basically, I apply the same strategy as storing the appearance of a person on a per section base again, by collection the section numbers in which a person appears with labels and then extract this list again and setting up a \ListOfPersons table, made with long table, with hyperlinks to the relevant sections.

I think, the code can be condensed a little bit, but here you go:





\seq_new:N \g_luke_listofpersons_seq
\seq_new:N \l_luke_listofpersons_seq 

  \seq_if_in:NnF \g_luke_listofpersons_seq {#1} {
    \seq_gput_right:Nn \g_luke_listofpersons_seq {#1}
    \seq_gremove_duplicates:N \g_luke_listofpersons_seq
    \seq_new:c {g_luke_#1_scene_seq }
  \int_compare:nNnT {\number\value{section}} > {0} {
    \seq_gput_right:cx {g_luke_#1_scene_seq } {\thesection}

  \seq_gput_right:Nn \l_luke_listofpersons_seq {#1}
  \int_compare:nNnT {\number\value{section}} > {0} {
    \seq_gput_right:cx {g_luke_#1_scene_seq } {\thesection}
%  \seq_show:c {g_luke_#1_scene_seq }

\cs_new:Npn \IfPersonCalledAlreadyF #1#2 {%
  \seq_if_in:NnF \l_luke_listofpersons_seq {#1} {#2}

  \seq_clear:N \l_luke_listofpersons_seq
  \seq_clear:N \l_tmpa_seq
  \seq_map_inline:Nn \g_luke_listofpersons_seq {%
      \seq_put_right:Nn \l_tmpa_seq {\use:c{##1h}}
   \seq_if_empty:NF \l_tmpa_seq {
     \seq_use:Nn \l_tmpa_seq {,~} 

\cs_generate_variant:Nn \seq_set_from_clist:Nn {Nx}

% This creates the table entry line per person, by 'cracking' the stored list of sections into the relevant section number and then provides a hyper link
\cs_new:Npn \generatelistofpersonstableline {
  \seq_map_inline:Nn \g_luke_listofpersons_seq  {
    \seq_set_from_clist:Nx \l_tmpa_seq {\getrefnumber{person::##1}}
    \seq_if_empty:NF \l_tmpa_seq {
    \use:c{##1h} &     \seq_set_from_clist:Nx \l_tmpa_seq {\getrefnumber{person::##1}}
    \int_set:Nn \l_tmpa_int {\seq_count:N \l_tmpa_seq} 
    \int_zero:N \l_tmpb_int
    \seq_map_inline:Nn \l_tmpa_seq {
      \int_incr:N \l_tmpb_int
      \int_compare:nNnF {\l_tmpa_int} = {\l_tmpb_int} {

   \bfseries Person & \bfseries Sections \tabularnewline

  \seq_map_inline:Nn \g_luke_listofpersons_seq  {
    \protected@edef\@currentlabel{\seq_use:cn {g_luke_##1_scene_seq}{,}}
    % ##1 \space \seq_use:cn {g_luke_##1_scene_seq}  {,}
    % \par






  {\large \bfseries Persons in Section \thesection}


  % Add this person to the global list
  % Now define the personal \...x command 
  \expandafter\NewDocumentCommand\csname #1x\endcsname{+m}{%
    %Check if the person has been called in the local section already
      % Add the personal to the local list, i.e. per section
      % Check whether the label has been defined already
    \textsc{#1:} ##1%
  }% End of the \...x command
  \expandafter\NewDocumentCommand\csname #1h\endcsname{}{%
}% End of \NewPerson





\section{In the supermarket}
\tomx{Hi, I'm Tom!}

\frodox{Hi, I'm Frodo!}

\section{At TeX.SE}


\frodox{Hi, I'm Frodo!}

\frodox{I am going to Mordor}

\Gandalfx{Cast the ring into the fire!}

\tomx{Waiting for Godot}

\section{In TeX.SE Chat}




\Davidx{I've got a recipe for Duck in Orange Sauce}

\tomx{That's marvellous}

\frodox{Pineapple pizza!}


enter image description here

| improve this answer | |
  • 2
    ahahah The lord of the rings :-)+1. – Sebastiano Mar 19 '18 at 0:27
  • 2
    @Sebastiano I didn't know that Paulo and David played a role in that movie :) – CarLaTeX Mar 19 '18 at 17:44
  • 1
    @CarLaTeX: Don't you know Tolkien's Duck Chronicles of Middle Earth? ;-) – user31729 Mar 19 '18 at 17:46
  • @ChristianHupfer Ooooh, I immediately search for it on Amazon :) – CarLaTeX Mar 19 '18 at 17:46
  • @CarLaTeX ahahahahahahaah. – Sebastiano Mar 19 '18 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.