4

How would it be possible to make an editorial list/table?

I'm not asking how to create a list or table, but if it is possible to attach something to \section's and \subsection's in the form of a \label or the like, to be able to generate the following:

+-----------+-------------+-------------+---------+
| Section   | Subsection  | Responsible | Helpers |
+-----------+-------------+-------------+---------+
| Section 1 |             | Bob         |         |
| Section 2 |             |             |         |
|           | Section 2.1 | Jimmy       |         |
|           | Section 2.2 | Carl        |         |
| Section 3 |             | Bob         | Carl    |
|           | Section 3.1 | Jimmy       | Bob     |
| Section 4 |             | Everybody   |         |
+-----------+-------------+-------------+---------+

So basically is it possible to use something \foreach \section and \subsection to generate a table like the above. Followed by having added the information along with the sections.

Crude examples:

\section{Section 1}{Bob}{}
\section{Section 2}{}{}
\section{Section 3}{Bob}{Carl}
\subsection{Section 3.1}{Jimmy}{Bob}

Also is this a bad approach to the problem, if so is there a better one?

3
  • 1
    this is possible with etoc package
    – touhami
    May 23, 2016 at 10:53
  • 1
    @touhami would love an example of how to use it.
    – vallentin
    May 23, 2016 at 10:57
  • 1
    @Vallentin will try. May be one can do this easily without any package. Where the table will be displayed in the begin of document or in the end?
    – touhami
    May 23, 2016 at 11:14

2 Answers 2

3

Here is a solution

\documentclass{article}
\usepackage{lipsum}

\newcommand*\editorialtable{%
\beforeeditorialtable
\begin{tabular}{|l|l|l|l|}
\hline
\multicolumn{1}{|c}{Section} & \multicolumn{1}{|c}{Subsection} &
\multicolumn{1}{|c}{Responsible}&\multicolumn{1}{|c|}{Helpers}\\
\hline
\makeeditorialtable
\end{tabular}
\aftereditorialtable}

\newcommand*\beforeeditorialtable{\par}
\newcommand*\aftereditorialtable{\par}
\newcommand*\makeeditorialtable{}

\makeatletter
\newcommand{\mtsection}[3]{%
\section{#1}
\addtocontents{toc}{\protect\g@addto@macro\protect\makeeditorialtable{#1&&#2&#3\\\protect\hline}}}
\newcommand{\mtsubsection}[3]{%
\subsection{#1}
\addtocontents{toc}{\protect\g@addto@macro\protect\makeeditorialtable{&#1&#2&#3\\\protect\hline}}}
\makeatother
\begin{document}
\tableofcontents %  necessary 
\editorialtable
\mtsection{Section 1}{Bob}{}
\mtsection{Section 2}{}{}
\mtsection{Section 3}{Bob}{Carl}
\mtsubsection{Section 3.1}{Jimmy}{Bob}
\editorialtable
\end{document}
4
  • This at least works, but isn't as fancy (not that that's a bad thing).
    – vallentin
    May 26, 2016 at 19:42
  • this is just a tabular you can make it fancy (may be this is a new question)
    – touhami
    May 26, 2016 at 19:46
  • My point was just in relation to the other answer. Nothing bad! :)
    – vallentin
    May 26, 2016 at 19:48
  • @Vallentin: You could have sent the document to me and I could have make it working, but now you've made the decision. (+1 for touhami anyway)
    – user31729
    May 30, 2016 at 19:16
2

See the updated and better version at the end, please!

A preliminary version with expl3 features and key-value interface, only working for a table at the end at the moment!

\documentclass{article}

\usepackage{xparse}

\usepackage{xkeyval}

\makeatletter
\let\latex@@section\section
\let\latex@@subsection\subsection


\define@key{editorial}{helper}{%
  \def\kveditorial@helper{#1}%
}

\define@key{editorial}{responsible}{%
  \def\kveditorial@responsible{#1}
}

\ExplSyntaxOn

\seq_new:N \g_vallentin_editorial_seq


\NewDocumentCommand{\EditorialBoard}{}{%
   \begin{tabular}{*{4}{p{3cm}}}
     \bfseries Section & \bfseries subsection & \bfseries Responsible & \bfseries Helper \tabularnewline
     \hline
     \seq_use:Nn \g_vallentin_editorial_seq {\tabularnewline}
  \end{tabular}
}



\RenewDocumentCommand{\section}{somo}{%
  \IfBooleanTF{#1}{%
    \latex@@section*{#3}%
  }{%
    \IfValueTF{#2}{%
      \latex@@section[#2]{#3}%
    }{%
      \latex@@section{#3}%
    }%
    \IfValueTF{#4}{%
      \typeout{Some value:#4}
      \setkeys{editorial}{#4}%
      \seq_gput_right:Nx \g_vallentin_editorial_seq {#3\space\thesection & & \kveditorial@responsible  & \kveditorial@helper}%
    }{%
      \typeout{No value:#4}
      \seq_gput_right:Nn \g_vallentin_editorial_seq {#3}
    }
  }%
}


\RenewDocumentCommand{\subsection}{somo}{%
  \IfBooleanTF{#1}{%
    \latex@@subsection*{#3}%
  }{%
    \IfValueTF{#2}{%
      \latex@@subsection[#2]{#3}%
    }{%
      \latex@@subsection{#3}%
    }%
    \IfValueTF{#4}{%
      \setkeys{editorial}{#4}%
      \seq_gput_right:Nx \g_vallentin_editorial_seq {& #3\space\thesubsection & \kveditorial@responsible  & \kveditorial@helper}%
    }{%
      \seq_gput_right:Nn \g_vallentin_editorial_seq {& #3}
    }
  }%
}


\ExplSyntaxOff

\makeatother

\begin{document}
\tableofcontents

\section{Foo}[helper=Harpo,responsible=Chico]

\section{Foo bar}[helper=Gummo,responsible=Groucho]

\section{Other foo bar}

\subsection{Some subsection}[helper={some blokes from TeX.SX},responsible=You!]


\EditorialBoard


\end{document}

Update

This version allows to place EditorialBoard anywhere in the document body. The content is always stored at the end of the document and read at time of \EditorialBoard usage.

The filename is called \jobname.edo.

\documentclass{article}

\usepackage{booktabs}
\usepackage{xparse}
\usepackage{xkeyval}

\makeatletter
\let\latex@@section\section
\let\latex@@subsection\subsection

% Define two keys

\define@key{editorial}{helper}{%
  \def\kveditorial@helper{#1}%
}

\define@key{editorial}{responsible}{%
  \def\kveditorial@responsible{#1}
}

\newcommand{\editorialboardname}{Editorial Board}

\ExplSyntaxOn

\seq_new:N \g_vallentin_editorial_seq % Holding the content

\iow_new:N \g_vallentin_editorial_outfile
\ior_new:N \g_vallentin_editorial_infile


\cs_new:Nn \vallentin_store_editorial_content:n {%
  \iow_open:Nn \g_vallentin_editorial_outfile {#1}
  \seq_map_inline:Nn \g_vallentin_editorial_seq {%
    \iow_now:Nn \g_vallentin_editorial_outfile {##1}
  }
  \iow_close:N \g_vallentin_editorial_outfile % Close the file
}

\NewDocumentCommand{\StoreEditorialContent}{m}{%
  \vallentin_store_editorial_content:n{#1}
}



\cs_new:Nn \read_from_external_file:n{%
  % Only add the content if it's not already there!
  \seq_if_in:NnF \g_vallentin_editorial_seq {#1}{%
    \seq_gput_right:Nn \g_vallentin_editorial_seq {#1}
  }
}

\cs_new:Nn \grab_old_editorial_file:n{%
  \seq_gclear:N \g_vallentin_editorial_seq
  \ior_open:Nn \g_vallentin_editorial_infile {#1}
  \ior_map_inline:Nn \g_vallentin_editorial_infile {\read_from_external_file:n{##1}}%
  \ior_close:N \g_vallentin_editorial_infile
}

\NewDocumentCommand{\ReadEditorialContent}{m}{%
  \IfFileExists{#1}{%
    \section*{\editorialboardname}
    \grab_old_editorial_file:n {#1}
  }{}
}

\NewDocumentCommand{\displayeditorialline}{}{%
  \seq_use:Nn \g_vallentin_editorial_seq {\tabularnewline\midrule} % Display all in a row!
}


\NewDocumentCommand{\AddSectionEditorialLine}{m}{%
  \seq_gput_right:Nx \g_vallentin_editorial_seq {#1}
}


\ExplSyntaxOff

% Redefine the section commands -- does not work for memoir.cls!
\RenewDocumentCommand{\section}{somo}{%
  \IfBooleanTF{#1}{%
    \latex@@section*{#3}%
  }{%
    \IfValueTF{#2}{%
      \latex@@section[#2]{#3}%
    }{%
      \latex@@section{#3}%
    }%
    \IfValueTF{#4}{%
      \setkeys{editorial}{#4}%
      \AddSectionEditorialLine{#3 \thesection & & \kveditorial@responsible  & \kveditorial@helper}%
    }{%
      \AddSectionEditorialLine{#3}
    }
  }%
}

\RenewDocumentCommand{\subsection}{somo}{%
  \IfBooleanTF{#1}{%
    \latex@@subsection*{#3}%
  }{%
    \IfValueTF{#2}{%
      \latex@@subsection[#2]{#3}%
    }{%
      \latex@@subsection{#3}%
    }%
    \IfValueTF{#4}{%
      \setkeys{editorial}{#4}%
      \AddSectionEditorialLine{& #3 \thesubsection & \kveditorial@responsible  & \kveditorial@helper}%
    }{%
      \AddSectionEditorialLine{& #3}%
    }%
  }%
}



\makeatother


\AtEndDocument{%
  \StoreEditorialContent{\jobname.edo}%
}

\NewDocumentCommand{\EditorialBoard}{O{\jobname.edo}}{%
  \clearpage
  \ReadEditorialContent{#1}%
  \begin{tabular}{*{4}{p{3cm}}}
    \bfseries Section & \bfseries Subsection & \bfseries Responsible & \bfseries Helper \tabularnewline
    \toprule
    \displayeditorialline%
  \end{tabular}
}




\begin{document}
\tableofcontents

\EditorialBoard


\section{Foo}[helper=Harpo,responsible=Chico]

\section{Foo bar}[helper=Gummo,responsible=Groucho]

\section{Other foo bar}

\subsection{Some subsection}[helper={some blokes from TeX.SX},responsible=You!]

\subsection{Other stuff}[helper={Ann Elk},responsible={Arthur Gumby}]

\section{A new section}[responsible={Gandalf},helper={Frodo}]



\end{document}

enter image description here

13
  • I can't get neither of those to work. The second (update) won't even compile. The first compiles, but only shows sections which doesn't have the [helper=...] stuff after. It also only shows stuff in the "Section" part, but nothing more than that.
    – vallentin
    May 26, 2016 at 19:29
  • @Vallentin: You seem to have a faulty or outdated TeX installation then -- as you can see from the screen shot, it works. I am using Linux, TL 2015
    – user31729
    May 26, 2016 at 19:31
  • I'm using sharelatex.com, and honestly don't know that much of the inner workings of LaTeX! :)
    – vallentin
    May 26, 2016 at 19:32
  • @Vallentin: Sharelatex, oh my ... well, I know why I don't like this kind of stuff.
    – user31729
    May 26, 2016 at 19:34
  • I'm using it, as we're multiple people working on the same document.
    – vallentin
    May 26, 2016 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .