TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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.

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
up vote 6 down vote accepted

You might start with this:



  \section*{Summary of major issues}

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



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


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



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

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.


    \section*{some heading if heading wanted}%
    \@newlistfalse           %we don't want list errors if there are no items

      \protect\item % standard formatting for each entry could go here
      \par             % final formatting for each entry could go here     
  #1%               % process the text in mid document


some text \summarytext{first text} some more text

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



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

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