TransWikia.com

List of invisible things

TeX - LaTeX Asked by Morzen on February 27, 2021

I need to create a list of invisible things.
For instance, in the following MWE, there is a list of examples, but it should not appear in the text.

MWE:

documentclass{article}
usepackage{tocloft}
newcommand{listexamplename}{example}
newlistof{example}{exp}{listexamplename}
newcommand{example}[1]{
refstepcounter{example}
parnoindenttextbf{Example theexample. #1}
addcontentsline{exp}{example}
{protectnumberline{}#1}par}
begin{document}
example{An example}
example{Another example}
listofexample
end{document}

enter image description here
The red rectangle should be removed completely from the body of text. Preferably without leaving extra space.

I have tried using listings package invisible caption, but if the environment is empty the caption does not show.

(This is a workaround to a more complicated issue I have – creating a manuscript with 2 TOC’s in 2 languages. Therefore, the solution of addcontentsline{toc}{}{} will not work)

One Answer

An extended, but revised, version of your MWE.

% loeprob.tex  SE 578105

documentclass{article}
usepackage{lipsum}
usepackage{tocloft}
newcommand{listexamplename}{example}
newlistof{example}{exp}{listexamplename}
newcommand{example}[1]{
refstepcounter{example}
%parnoindenttextbf{Example theexample. #1}
addcontentsline{exp}{example}
{protectnumberline{}#1}par}
begin{document}
lipsum[1-2]
example{An example}
lipsum[3-8]
example{Another example}
lipsum[5-6]
listofexample
end{document}

Within your definition of example do not output any text except to your list of examples.

You say your real life problem is more complex as your ToC(s) is/are in two languages. You have not shown how you have done that but I assume that you can apply the same ideas to list(s) of examples.

Correct answer by Peter Wilson on February 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP