Summarize two item levels and combine first level if repetition

If you want to list the actions, you need a syntax like

\action{Finn}{Action}

or it would be more difficult to gather the text and store it.

With this change, here's an implementation. So long as the first argument remains the same, we just issue \item #2; when the first argument changes, we close the action itemize issue #1 (except at startup) and open an action itemize.

The two arguments are also stored in the aux file for retrieval at the next run, which will build sequences to be used by \listofactions.

The characters will be listed in “order of appearance”; sorting could be implemented, but for an extra fee. ;-)

\documentclass{article}

\usepackage{xparse,enumitem}

\ExplSyntaxOn
\NewDocumentEnvironment{actionlist}{}
 {
  \tl_gclear:N \g_bichon_current_character_tl
  \begin{itemize}[label=\textbullet]
 }
 {
  \end{itemize}
  \end{itemize}
 }

\NewDocumentCommand{\action}{mm}
 {
  \bichon_write:nn { #1 } { #2 }
  \tl_if_eq:VnF \g_bichon_current_character_tl { #1 }
   {
    \tl_if_empty:NF \g_bichon_current_character_tl
     {
      \end{itemize}
     }
    \item #1
    \tl_gset:Nn \g_bichon_current_character_tl { #1 }
    \begin{itemize}[label=\textbullet,nosep]
   }
  \item #2
 }

\cs_new_protected:Nn \bichon_write:nn
 {
  \iow_shipout:cn { @auxout } { \actionlisting{#1}{#2} }
 }
\AtEndDocument
 {
  \cs_set_eq:NN \actionlisting \use_none:nn
 }

\NewDocumentCommand{\actionlisting}{mm}
 {
  \seq_if_in:NnF \g_bichon_characters_seq { #1 }
   {
    \seq_gput_right:Nn \g_bichon_characters_seq { #1 }
    \seq_new:c { g_bichon_character_ \tl_to_str:n { #1 } _seq }
   }
  \seq_gput_right:cn { g_bichon_character_ \tl_to_str:n { #1 } _seq } { #2 }
 }
\NewDocumentCommand{\listofactions}{}
 {
  \section*{Actions ~ Summary}
  \seq_if_empty:NF \g_bichon_characters_seq
   {% do nothing if the sequence is empty
    \begin{itemize}[label=\textbullet]
    \seq_map_inline:Nn \g_bichon_characters_seq
     {
      \item ##1
      \bichon_list_character_actions:n { ##1 }
     }
    \end{itemize}
   }
 }
\cs_new_protected:Nn \bichon_list_character_actions:n
 {
  \begin{itemize}[label=\textbullet,nosep]
  \seq_map_inline:cn { g_bichon_character_ \tl_to_str:n { #1 } _seq }
   {
    \item ##1
   }
  \end{itemize}
 }

\cs_generate_variant:Nn \tl_if_eq:nnF { V }
\tl_new:N \g_bichon_current_character_tl
\seq_new:N \g_bichon_characters_seq
\ExplSyntaxOff

\begin{document}

\listofactions

\section{First Adventure}
\begin{actionlist}
\action{Finn}{Finn's first action}
\action{Jake}{Jake's first action}
\end{actionlist}

\section{Second Adventure}
\begin{actionlist}
\action{Finn}{Finn's second action}
\action{Finn}{Finn's third action}
\end{actionlist}

\end{document}

enter image description here


This method is to write out Finn's actions to a .Finn file and Jake's to a .Jake file, along with printing them out as they arise. In so doing, the actions summary can be itemized by person on the 2nd compile pass. By comparison, in the document proper, the actions are printed in the order in which they arise, regardless of ownership.

EDITED to fix compilation errors on first pass. Still requires two passes, but now compiles error free on both passes.

REVISED SOLUTION

This has an appearance more in line with the OP's request. The indents and the icons for levels 1 and 2 (that is, A and B) may be selected in the preamble.

\documentclass{article}
\usepackage{ifthen}
\def\IndentA{20pt}     \def\IconA{$\bullet$}
\def\IndentB{40pt}     \def\IconB{$-$}
\parskip 3pt
\def\CurrentActor{}
\def\theactor#1{\par\leftskip\IndentA\noindent\llap{\IconA~}#1\par\leftskip0pt}
\def\theaction#1{\par\leftskip\IndentB\noindent\llap{\IconB~}#1\par\leftskip0pt}
\newcommand\action[2]{%
  \ifthenelse{\equal{#1}{\CurrentActor}}
    {\theaction{#2}}{\def\CurrentActor{#1}\theactor{#1}\theaction{#2}}
  \addtocontents {#1}{\protect\actionsline {#2}}%
}
\newcommand\writeactions{\section*{Actions Summary}}
\newcommand\actionsline[1]{\theaction{#1}}
\makeatletter\let\starttoc\@starttoc\makeatother
\newcommand\writeaction[1]{%
  \theactor{#1}\IfFileExists{\jobname.#1}{}{\theaction{Please compile again}}\starttoc{#1}
}
\begin{document}
\writeactions
\writeaction{Finn}
\writeaction{Jake}
\noindent\hrulefill\par
\tableofcontents
\noindent\hrulefill\par
\section{First Adventure}
\action{Finn}{Finn's first action Finn's first action Finn's first action Finn's first action.}
\action{Jake}{Jake's first action}
\section{Second Adventure}
\action{Finn}{Finn's second action.}
\action{Finn}{Finn's third action Finn's third action Finn's third action Finn's third action Finn's third action Finn's third action.}
\end{document}

enter image description here

ORIGINAL SOLUTION

\documentclass{article}
\newcommand\action[2]{%
  \begin{itemize}\item[(#1)] #2\end{itemize}
  \addtocontents {#1}{\protect \actionsline {#2}}%
}
\newcommand\writeactions{\section*{Actions Summary}}
\newcommand\actionsline[1]{\item #1}
\makeatletter
\newcommand\writeaction[1]{%
  \begin{itemize} \item #1
    \begin{itemize}
      \IfFileExists{\jobname.#1}{}{\item Please Compile Again}
      \@starttoc{#1}
    \end{itemize}
  \end{itemize}
}
\makeatother
\begin{document}
\writeactions
\writeaction{Finn}
\writeaction{Jake}
\noindent\hrulefill\par
\tableofcontents
\noindent\hrulefill\par
\section{First Adventure}
\action{Finn}{Finn's first action}
\action{Jake}{Jake's first action}
\section{Second Adventure}
\action{Finn}{Finn's second action}
\action{Finn}{Finn's third action}
\end{document}

enter image description here