0

I am trying to create two commands:

  1. A command \collect that stores a string/text.
  2. A command \callcollection that call all these stored texts placed before the command (without any configuration, just to print the text content).

I tried to mimic the parnote package strategy, but I have trouble in adapt it. (Also I did not understand the mechanism of "collect notes" and after call them.)

Basically, all my attempts was frustrated and I do not know what is going on...

Here a dummy MWE:

\documentclass{article}
    
    \newcommand{\collect}[1]{#1}
    \newcommand{\callcollection}{-- Call all previous texts in "collect" --}
    \begin{document}
    
    
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
    quam\collect{Vitae mauris tempus!} consequat. In nec neque vitae magna
    pulvinar pretium.\collect{Nunc purus augue, egestas vitae lobortis at,
    eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
    et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
    \collect{Porta} et elementum diam sagittis.
    
    \callcollection
    % Here I want the \callcollection command place all the texts in previous paragraph

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
    quam\collect{Vitae mauris tempus!} consequat. In nec neque vitae magna
    pulvinar pretium.\collect{Nunc purus augue, egestas vitae lobortis at,
    eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
    et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
    \collect{Porta} et elementum diam sagittis.
    
    \callcollection
    % Here I want the \callcollection command place all the texts in previous paragraph

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
    quam\collect{Vitae mauris tempus!} consequat. In nec neque vitae magna
    pulvinar pretium.\collect{Nunc purus augue, egestas vitae lobortis at,
    eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
    et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
    \collect{Porta} et elementum diam sagittis.
    
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
    quam\collect{Vitae mauris tempus!} consequat. In nec neque vitae magna
    pulvinar pretium.\collect{Nunc purus augue, egestas vitae lobortis at,
    eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
    et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
    \collect{Porta} et elementum diam sagittis.
    
    \callcollection
% Here I want the \callcollection command place all the texts in the 2 previous paragraphs    

    \end{document}

2 Answers 2

1

Here is a Lua-based approach:

\documentclass{article}
\directlua{buffer = {}}
\newcommand{\collect}[1]{#1\directlua{table.insert(buffer, [[#1]])}}
\newcommand{\callcollection}{\directlua{
    tex.sprint(table.concat(buffer, " "))
    buffer = {}
}}
\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\collect{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\collect{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\collect{Porta} et elementum diam sagittis.

\callcollection
% Here I want the \callcollection command place all the texts in previous paragraph

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\collect{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\collect{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\collect{Porta} et elementum diam sagittis.

\callcollection
% Here I want the \callcollection command place all the texts in previous paragraph

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\collect{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\collect{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\collect{Porta} et elementum diam sagittis.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer aliquet
quam\collect{Vitae mauris tempus!} consequat. In nec neque vitae magna
pulvinar pretium.\collect{Nunc purus augue, egestas vitae lobortis at,
eleifend quis erat.  Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae.} In aliquet tortor sed tellus
\collect{Porta} et elementum diam sagittis.

\callcollection
% Here I want the \callcollection command place all the texts in the 2 previous paragraphs    

\end{document}

enter image description here

EDIT: \collect now also prints its argument (bugfix)

1
  • 1
    Thank you very much! After this very simple answer, I have been convinced that it is time to learn Lua! Apr 25, 2022 at 17:03
2

The scontents package provides such a store / recall mechanism. Enclose the part that you want to be able to store inside a scontents environment, and then recall it with \getstored.

\begin{scontents}[store-env=a_name]
text that you want to store
\end{scontents}

\getstored{a_name}

a_name is a name of your choice.

2
  • The other answer suited better for my porpoises, but thank you for this package suggestion! I did not know its existence, it will be very useful for me in other situations! Apr 25, 2022 at 17:02
  • @TheEndofTheWorld I think the command version \Scontents and \foreachsc fits better (starred version if you are going to use Verbatim)...see doc. Apr 27, 2022 at 4:05

You must log in to answer this question.

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