Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to make a document that has a large amount of sections which describe tasks. I would like to mark several of the sections as "high priority" with some kind of label, and then build up a table of contents which lists only the sections marked with this label. What is the best way to go about doing this in LaTeX?

share|improve this question
1  
Are you interested in having a "standard ToC" with your "high priority ToC", or is it just the latter? –  Werner Oct 18 '11 at 23:31
add comment

1 Answer

up vote 5 down vote accepted

The following is a mockup of what you might be after.

It provides a new "List of High Priority Sections" (as defined in \highpriorityname) by using \listofhpsection that prints all the starred sections in your document. New "List of"'s are possible by means of the tocloft package. Each of the starred sections are also included, with number, in the regular \tableofcontents. This is done by a redefinition of the regular \section command using xparse. Additionally, as an in-line marking mechanism, each section of "high priority" will have an asterisk in the form of \star added to the end.

So, in short, \section* commands will be typeset using the traditional section counter/number with an appended \star, but it will also be included in the new list of "high priority" sections. Sections issued using \section will be typeset in the traditional way.

enter image description here

\documentclass{article}
\usepackage[titles]{tocloft}% http://ctan.org/pkg/tocloft
\usepackage{xparse}% http://ctan.org/pkg/xparse
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{letltxmacro}% http://ctan.org/pkg/letltxmacro
\newcommand{\highpriorityname}{List of High Priority Sections}
\newlistof{hpsection}{hps}{\highpriorityname}

\begin{document}
% ================ FRONTMATTER ================
\tableofcontents
\listofhpsection

% ================ REDEFINTION ================
\LetLtxMacro{\oldsection}{\section}% Store old \section macro
\RenewDocumentCommand{\section}{s o m}{%
  \setcounter{hpsection}{\value{section}}% Copy section counter
  \IfBooleanTF{#1}
    {\refstepcounter{hpsection}%
     \IfNoValueTF{#2}%
       {\oldsection[#3]{#3$^\star$}\addcontentsline{hps}{section}{\numberline{\thehpsection} #3}}% starred section \section*{<title>}
       {\oldsection[#2]{#3$^\star$}\addcontentsline{hps}{section}{\numberline{\thehpsection} #2}}% starred section \section*[<ToC>]{<title>}
    }%
    {\IfNoValueTF{#2}%
       {\oldsection{#3}}% unstarred section \section{<title>}
       {\oldsection[#2]{#3}}% unstarred section \section[<ToC>]{<title>}
    }%
}

% ================ MAINMATTER ================
\section{First section} \lipsum[1-2]
\section*{Second section} \lipsum[3-4]
\section{Third section} \lipsum[5-6]
\section*{Fourth section} \lipsum[7-8]
\section*{Fifth section} \lipsum[9-10]
\section{Final section} \lipsum[11-12]
\end{document}

The document structure is such that the sectional redefinition happens between FRONTMATTER and MAINMATTER. Otherwise Contents and List of High Priority Sections would also be numbered sections.

Saving of the original \section command is done using the letltxmacro package, while lipsum provides dummy text.

share|improve this answer
    
Wow this is excellent. Thank you for the help! –  stevejb Oct 19 '11 at 1:40
    
One remark for the example: when you replace lipsum with blindtext you could use \blinddocument (or \Blinddocument for a large version) to get dummy text including section headings. Disadvantage: you need also babel. –  knut Oct 19 '11 at 7:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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