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.
Post Reply
finou314159
Posts: 4
Joined: Sat Jul 13, 2024 10:19 am

The contents of a macro in an index

Post by finou314159 »

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 TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

The contents of a macro in an index

Post by Stefan Kottwitz »

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

Post by finou314159 »

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

Post by finou314159 »

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

Post by finou314159 »

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
Post Reply