6

I have to write some reports in which I will assign several actions to do to some people. I would like to simplify the creation of an action thanks to some macro and to automate the creation of a summary for all actions.

Next, there is an example of how I would like to use it. It could be adapted if this simplify the problem, of course.

\begin{document}
\section*{Actions Summary}
\tableofallactions % or \includecollection{allactions} or whatever

\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}

There is what I expect to create :


Actions Summary

  • Finn
    • Finn's first action
    • Finn's second action
    • Finn's third action
  • Jake
    • Jake's first action

1. First Adventure

Actions :

  • Finn
    • Finn's first action
  • Jake
    • Jake's first action

2. Second Adventure

Actions :

  • Finn
    • Finn's second action
    • Finn's third action

I learned how to write commands and environments. I read also, among others, about "collect" package to summarize actions like in this example : Content summaries - sections. However, I really don't know how to handle the fact that the same name could appear in many places and should be summarize on the same item like for Finn in the example.

Bichon
  • 163
  • Related? http://tex.stackexchange.com/questions/202574/extracting-the-structure-of-a-latex-document-including-comments – Steven B. Segletes Apr 07 '16 at 16:02
  • Not exactly, indeed the XYZecutive summary can help to summarize but the problem to merge several actions with the same people's name is still there. Thank you for the link, it gave me ideas. – Bichon Apr 07 '16 at 17:08
  • Yes, I was looking some more at your problem after I commented. The organizing of Finn's distributed actions into one place is definitely a more complicated problem. If I get an inspiration, I may attack the problem. – Steven B. Segletes Apr 07 '16 at 17:36
  • Please see my revised answer. – Steven B. Segletes Apr 08 '16 at 12:19

2 Answers2

4

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

egreg
  • 1,121,712
  • Thank you for your answer, this very looks like what I'm looking for. Sadly, I have some compilation troubles (may be linked to my installation). The \listofactions line raises : ! LaTeX Error: Something's wrong--perhaps a missing \item. – Bichon Apr 08 '16 at 08:51
  • @Bichon You're right, there is a problem at the first compilation that I overlooked. Fixed. – egreg Apr 08 '16 at 09:47
  • Thanks for your edit but I still have some compilation problems : ! Undefined control sequence. \bichon_write:nn #1#2->\iow_shipout:cn {@auxout}{\actionlisting {#1}{#2}} l.85 \action{Finn}{Finn's first action} Sadly, my knowledge in Latex3 functionalities is very limited so despite my trials I'm not able to know what is wrong (it could be my installation). – Bichon Apr 13 '16 at 09:41
  • @Bichon You have an outdated version of the l3 packages. – egreg Apr 13 '16 at 09:42
  • Thanks for help, indeed my l3packages was outdated (it was those on Ubuntu Trusty Tahr mirrors). – Bichon Apr 13 '16 at 09:56
2

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

  • Very sorry that I didn't answer before (I missed time). Your solution is very cool, the only thing is I would like to avoid this lines \writeaction{Finn} \writeaction{Jake} because I have potentially a fair number of people to list. Maybe, line 18, instead of \jobname.#1 as filename we could use #1.actions and then import all ".actions" files. I'm currently looking for something to do that. Thank you for your help =) – Bichon Apr 13 '16 at 09:22