我可以索引正文詞\索引{正文詞}而不必寫「正文詞」2x嗎?

我可以索引正文詞\索引{正文詞}而不必寫「正文詞」2x嗎?

我正在製作我的第一個索引。下面的 MWE 將單字「once」寫入索引,但不寫入正文。因此,once\index{once}如果我想要正文和索引中的文本,我需要編寫。我可以編寫一個巨集來為我執行此操作,因此可以編寫 `\myindex{once} 並將其出現在正文和索引中。有沒有內建的 LaTeX 方法可以做到這一點?

\documentclass[12pt]{memoir}
\usepackage[makeindex]{imakeidx}

\makeindex

\begin{document}

1. This is how you use the index command\index{command}.\\
2. Instead of typing "command" twice above, I'd rather
type it \index{once}.\\

\printindex

\end{document}

相關內容