6

I'd like to roll my own commands that achieve something similar, in principle, to how \index places the indexed term in a later section, or how footnotes place text in a footer.

\summaryandextended{
    I'm just a summary of a result, and should appear in main text.
}
{
    I'm a long, complicated derivation of the result above. 

    I belong in the back portion of the book, read only by the nerdiest of nerds.
}

\gatheredappendix % I collect all of the #2 arguments and display them.

I don't want to duplicate either indexing or footnotes per se; I'm curious how one could make commands that build arbitrary collections of content within a specified section of a document.

4
  • You will use \summaryandextended multiple times, I assume?
    – user31729
    Nov 4, 2015 at 15:20
  • @ChristianHupfer Yes, precisely. Nov 4, 2015 at 15:21
  • You could use tcolorbox and it's savelowerto feature as well
    – user31729
    Nov 4, 2015 at 15:35
  • @ChristianHupfer Interesting, thanks! In my immediate application that's likely the more expedient solution, though the expl3 approach you gave was exactly the general approach I was looking for. Nov 4, 2015 at 15:55

4 Answers 4

4

This is a expl3 syntax way: Store the second argument for later use on seq variable and display it later on with \gatheredappendix.

This way no external file is necessary (as would be for \index)

\documentclass{article}

\usepackage{xparse}



\ExplSyntaxOn
\seq_new:N \l_gather_stuff_seq
\NewDocumentCommand{\storesecondarg}{+m}{%
  \seq_put_right:Nn \l_gather_stuff_seq {#1}
}
\NewDocumentCommand{\gatheredappendix}{}{%
  \seq_use:Nn \l_gather_stuff_seq {\par}
}
\ExplSyntaxOff

\NewDocumentCommand{\summaryandextended}{+m+m}{%
  #1%
  \storesecondarg{#2}%
 }


\begin{document}

\summaryandextended{
    I'm just a summary of a result, and should appear in main text.
}
{
    I'm a long, complicated derivation of the result above. 

    I belong in the back portion of the book, read only by the nerdiest of nerds.
}

\summaryandextended{
  Other stuff
}
{
  Other useless stuff

  Even more useless text
}

\vskip\baselineskip
\hrule

\vskip\baselineskip

\gatheredappendix % I collect all of the #2 arguments and display them.


\end{document}

enter image description here

2
  • Thanks Christian, your response got me pointed in a fruitful direction. I didn't want to ask an elaborate follow-up question in comments, so I asked another here. Nov 4, 2015 at 17:10
  • The assignments should be global, in my opinion.
    – egreg
    Nov 4, 2015 at 23:29
5

This task is simply solvable by TeX primitives. You needn't any special package.

\long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\def\gatheredappendix{}
\long\def\summaryandextended#1#2{#1\global\addto\gatheredappendix{#2\par}}

Really, you need only these three lines (independent of used format). On the other hand, when \usepackage{xparse} is used then TeX needs to read 21711 lines of code.

4

Nothing really complicated: it's a matter of augmenting the definition of a macro:

\makeatletter
\newcommand{\summaryandextended}[2]{%
  #1% typeset the first argument
  \g@addto@macro\sean@extensions{\sean@extension{#2}}%
}
\gdef\sean@extensions{}% initialize

\newcommand{\gatheredappendix}{\sean@extensions}
\newcommand{\sean@extension}[1]{#1\par}% or whatever formatting you'd like
\makeatother

Note that, instead of just pushing the second argument in the replacement text of \sean@extensions, I add some structure making it the argument to \sean@extension that can then be used to specially format the texts. For instance, you may want to use an itemized list. In this case, change the definitions for \gatheredappendix and \sean@extension like

\newcommand{\gatheredappendix}{%
  \begin{itemize}
  \sean@extensions
  \end{itemize}
}
\newcommand{\sean@extension}[1]{\item #1}
3

You could do the following:

  1. In your preamble, set \gatheredappendix to the empty string:

    \newcommand{\gatheredappendix}{}
    
  2. Then define a command \summaryandextended with two arguments that does the following:

    a) Redefine \gatheredappendix by adding the second argument #2 (see Appending to Variables or other places at tex.stackexchange)

    b) Output the first argument #1.

Of course, \summaryandextended could do additional things, like adding a new subsection title or so whenever content is added to \gatheredappendix.

You must log in to answer this question.

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