I have an article document using indexes like the following:

    This is a text, and it contains the index entry text.\index{text}

However, I would like to not type the index entry (here: "text") twice in the source code every time it appears. (As "text" in \index{text} does not get printed.)

I would like to use something like ...contains the index entry \some_command{text} which would both print the text "contains the index entry text" and adds "text" to the index.

  • 1
    It is best to make your own macro for this. say \newcommand\mindex[1]{#1\index{#1}}. But remember that indices are not always as simple as just index this term, sometimes you need to separate sorting and display for the index (say \index{latex@\LaTeX} to have \LaTeX sorted under l (the handling of \.. macros depends on the index program being used).
    – daleif
    Dec 13, 2019 at 9:23
  • 1
    I agree, best use a macro that also deals with subentries and possibly index formatting commands, which requires several optional arguments. My macro is therefore using \NewDocumentCommand from xparse.
    – ebcontrol
    Dec 13, 2019 at 10:09
  • 1
    Why not go for the glossaries-extra package that already includes commands that offer the desired feature?
    – leandriis
    Dec 13, 2019 at 11:33


You must log in to answer this question.

Browse other questions tagged .