LaTeX forum ⇒ MakeIndex, Nomenclature, Glossaries and AcronymsThe contents of a macro in an index

Information and discussion about MakeIndex - the tool to generate subject indices for LaTeX documents.
finou314159
Posts: 4
Joined: Sat Jul 13, 2024 10:19 am

The contents of a macro in an index

Postby finou314159 » Sat Jul 13, 2024 10:25 am

I need to write the contents of a macro \number in an index.
I use multiple indexes with the index package. When I consult the adx file, \number is not interpreted and remains \number. Is it possible to have the contents of the macro \number in the index rather than its name ?

THANKS

Fabrice

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
User avatar
Stefan Kottwitz
Site Admin
Posts: 10224
Joined: Mon Mar 10, 2008 9:44 pm

The contents of a macro in an index

Postby Stefan Kottwitz » Mon Jul 15, 2024 1:38 pm

Hi Fabrice,

welcome to the forum!

When I use a macro within an \index command, it is interpreted and its contents are printed in the index. What are you doing, exactly? Perhaps post a Infominimal working example that shows the issue.

Stefan
LaTeX.org admin

finou314159
Posts: 4
Joined: Sat Jul 13, 2024 10:19 am

The contents of a macro in an index

Postby finou314159 » Mon Jul 15, 2024 3:03 pm

Yes, this is definitely a misuse on my part. I want to use the idx file to retrieve the page number in a python script. However in the idx file, the macro newcommand \foo is coded \foo and not its content. I understand that it is not possible for the idx file to include the content of my macro rather than its name.
THANKS

finou314159
Posts: 4
Joined: Sat Jul 13, 2024 10:19 am

The contents of a macro in an index

Postby finou314159 » Mon Jul 15, 2024 3:06 pm

An example :

\newcommand{\foo}{bar}

\index{\foo}

In my idx file :

\indexentry{\foo}{56}

I would have liked to read \indexentry{bar}{56}

finou314159
Posts: 4
Joined: Sat Jul 13, 2024 10:19 am

The contents of a macro in an index

Postby finou314159 » Mon Jul 15, 2024 7:01 pm

I found a way to do this :

\newcommand{\foo}[1]
{
\newcommand{\fooo}{\index{#1}}

\fooo
}

\foo{YES}

This way I force the expansion of the command. This allows me to use a variable #1 in my index and retrieve its value in the idx file


Return to “MakeIndex, Nomenclature, Glossaries and Acronyms”

Who is online

Users browsing this forum: No registered users and 2 guests