1

I'm creating a Table of Content for an art journal. The Table of Contents should group the works by their genre (Poetry, Non Fiction, Fiction, Visual Art) but the material will be mixed throughout the journal (poetry pages:1,5,8,12 non fiction pages: 2,7,13 etc.) It will be published electronically, and I still want people to be able to click the work and be directed to the page.

1 Answers1

1

Here's one way to do it using four copies of \section:

  • \poesection for poems.
  • \nofisection for non fiction works.
  • \fisection for fiction works.
  • \vasection for visual art works.

Each of those commands behaves exactly as the standard memoir's \section (in particular, you can use the three arguments for each one of them), except that each writes the ToC information to a designated file. The command \TableOfContents produces the grouped table of contents.

The code:

\documentclass{memoir}
\usepackage{xparse}
\usepackage{letltxmacro}
\usepackage[colorlinks=true]{hyperref}

\makeatletter
\LetLtxMacro\poesection\section
\LetLtxMacro\nofisection\section
\LetLtxMacro\fisection\section
\LetLtxMacro\vasection\section

\RenewDocumentCommand\fisection{oom}{
  \IfNoValueTF{#1}
    {\section{#3}\addcontentsline{lfi}{section}{\numberline{\thesection}#3}}
    {
      \IfNoValueTF{#2}
        {\section[#1]{#3}\addcontentsline{lfi}{section}{\numberline{\thesection}#1}}
        {\section[#1][#2]{#3}\addcontentsline{lfi}{section}{\numberline{\thesection}#1}}
    }
}
\RenewDocumentCommand\nofisection{oom}{
  \IfNoValueTF{#1}
    {\section{#3}\addcontentsline{lnf}{section}{\numberline{\thesection}#3}}
    {
      \IfNoValueTF{#2}
        {\section[#1]{#3}\addcontentsline{lnf}{section}{\numberline{\thesection}#1}}
        {\section[#1][#2]{#3}\addcontentsline{lnf}{section}{\numberline{\thesection}#1}}
    }
}
\RenewDocumentCommand\vasection{oom}{
  \IfNoValueTF{#1}
    {\section{#3}\addcontentsline{lva}{section}{\numberline{\thesection}#3}}
    {
      \IfNoValueTF{#2}
        {\section[#1]{#3}\addcontentsline{lva}{section}{\numberline{\thesection}#1}}
        {\section[#1][#2]{#3}\addcontentsline{lva}{section}{\numberline{\thesection}#1}}
    }
}
\RenewDocumentCommand\poesection{oom}{
  \IfNoValueTF{#1}
    {\section{#3}\addcontentsline{lpo}{section}{\numberline{\thesection}#3}}
    {
      \IfNoValueTF{#2}
        {\section[#1]{#3}\addcontentsline{lpo}{section}{\numberline{\thesection}#1}}
        {\section[#1][#2]{#3}\addcontentsline{lpo}{section}{\numberline{\thesection}#1}}
    }
}

\newcommand\vacontentsname{Visual Art}
\newcommand\tableofvacontents{%
  \section*{\vacontentsname}
  \@starttoc{lva}%
}
\newcommand\noficontentsname{Non Fiction}
\newcommand\tableofnoficontents{%
  \section*{\noficontentsname}
  \@starttoc{lnf}%
}
\newcommand\ficontentsname{Fiction}
\newcommand\tableofficontents{%
  \section*{\ficontentsname}
  \@starttoc{lfi}%
}
\newcommand\poemcontentsname{Poetry}
\newcommand\tableofpoemcontents{%
  \section*{\poemcontentsname}
  \@starttoc{lpo}%
}

\newcommand\generalcontentsname{General Contents}
\newcommand\TableOfContents{
  \begingroup
  \pagestyle{plain}
  \section*{\generalcontentsname}
  \tableofficontents
  \tableofnoficontents
  \tableofvacontents
  \tableofpoemcontents
  \endgroup  
}
\makeatother

\begin{document}

\TableOfContents
\clearpage

\fisection{Another fiction work}
\nofisection{A first non-fiction work}
\vasection{Yet another visual art work}
\clearpage
\setcounter{page}{13}
\poesection{A first test poem}
\clearpage
\vasection{Another visual work}
\poesection{Yet another test poem}
\fisection{A first fiction work}
\clearpage
\setcounter{page}{25}
\nofisection{Yet another non-fiction work}
\fisection{Yet another fiction work}
\clearpage
\vasection{A first visual work}
\nofisection{Another non-fiction work}
\poesection{Another test poem}

\end{document}

The resulting ToC:

enter image description here

Gonzalo Medina
  • 505,128