Take the 2-minute tour ×
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.

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

1 Answer 1

up vote 8 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.