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.

Possible Duplicate:
Extract all emphasized words from latex document

I'm writing a report which involves a comparative analysis of some standards. Throughout the body of my report, I have a detailed comparison of minor and major issues. However, at the end of the document, I want a separate section which will only highlight the major differences, for someone who doesn't have time to go through the detailed report.

For this, I basically want to extract specific lines from the rest of the document and insert them in my final section. But I want this insertion to be automatic, such that when I mark a particular line of text in my document, it will automatically get added to this final section, i.e. something that works like automatic Table of Content generation based on the section names.

I don't know how else to phrase this question. Any help would be much appreciated.

share|improve this question
1  
This question is very similar to Extract all emphasized words from latex document. Please take a look at it as the information there might help you. If so, that's great, and we'll probably close this question as a duplicate just to keep the place tidy and to help people find answers quickly. If not, please edit your question here to explain why so that people can better focus their attention to help you. –  Werner Nov 7 '12 at 18:23
    
Adding to @Werner's comment: Another such similar question is tex.stackexchange.com/questions/14393/… –  doncherry Nov 7 '12 at 18:32
add comment

marked as duplicate by Werner, Kurt, Martin Schröder, lockstep, percusse Nov 8 '12 at 0:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

up vote 6 down vote accepted

You might start with this:

\documentclass{article}
\newtoks\majortoks

\newcommand{\majorissue}[1]{%
  \global\majortoks=\expandafter{\the\majortoks\issue{#1}}%
  #1}

\newcommand{\printmajorissues}{%
  \section*{Summary of major issues}
  \begin{itemize}
  \the\majortoks
  \end{itemize}
}

\newcommand{\issue}[1]{\item #1}

\begin{document}

\section{First}

This is a prolog. Next we describe the first major issue, that is about
walking \majorissue{barefoot in the park}. A minor issue is not having an
elevator.

\section{Second}

A meaningless text. The second major issue is that \majorissue{some like it hot}.
A minor issue is that nobody's perfect.

\printmajorissues

\end{document}

enter image description here

We collect all we want to typeset at the end in a container (formally, the token register \majortoks). When \majorissue{some text} is found, the macro adds to the container the tokens

\issue{some text}

and also prints "some text" at the point.

TeXnically, in that case we'd execute

\global\majortoks=\expandafter{\the\majortoks\issue{some text}}

so the register is incremented globally, independent of the grouping structure. With \the\majortoks the previous contents of the register is delivered before assigning the new value, thus really doing an incremental update.

Finally, the macro \printmajorissues delivers the contents so accumulated. In my example the contents is delivered in a itemize environment and \issue is defined to give, for instance

\item some text

but you are free to do what you want with it.

Plan carefully what you need and well designed macros will help better.

share|improve this answer
    
This is fantastic! Thanks a lot @egreg –  Chatterjee Nov 7 '12 at 18:46
    
@Chatterjee Please, don't be shy in asking for other features. –  egreg Nov 7 '12 at 19:01
add comment

One approach to this would be to use the aux file method that LaTeX provides. Below is a simple example that simply collects all desired text in a new aux files with extension .sum and reads that back in. Advantage is that the data is not kept in memory and you can have the summary anywhere in the document, but the disadvantage then is (of course) that you need two runs to get it formatted even if the summry is at the very end.

I've thrown in an itemizeenvironment to format the entries, but effectively any other approach could be used.

\documentclass{article}

\makeatletter
\newcommand\mysummary{%
    \section*{some heading if heading wanted}%
    \begin{itemize}%
    \@starttoc{sum}%
    \@newlistfalse           %we don't want list errors if there are no items
    \end{itemize}%
    }

\newcommand\summarytext[1]{%
  \leavevmode
  \addtocontents{sum}%
     {%     
      \protect\item % standard formatting for each entry could go here
      #1%
      \par             % final formatting for each entry could go here     
     }%
  #1%               % process the text in mid document
}
\makeatother

\begin{document}

some text \summarytext{first text} some more text

\summarytext{second text with a \par paragraph break} and some more text

\mysummary

\end{document}

As a result you get

enter image description here

As slightly more elaborate solution would be to use \addcontentline in which case you would be able to format the data with page numbers referring back to the source.

share|improve this answer
add comment

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