TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I try to used \index{} inside of \newcommand, the entry is made in the index, however, the text no longer appears in the body. How can I achieve a macro for the \index command?

\documentclass[12pt]{article}
\usepackage{fontspec}


\newcommand{\myentry}[1]{This is an #1}

\begin{document}
\myentry{Apple}

\end{document}

typesets:

enter image description here

\documentclass[12pt]{article}
\usepackage{fontspec}

\usepackage{makeidx}
\makeindex
\newcommand{\myentry}[1]{This is an \index{#1}}

\begin{document}
\myentry{Apple}
\printindex
\end{document}

typesets:

enter image description here

share|improve this question
up vote 9 down vote accepted

Since \index merely passes information to be indexed and actually does not print anything, use

\newcommand{\md}[1]{This is an \index{#1}#1}

which prints the command after passing it to \index.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.