幫助索引的命令

幫助索引的命令

我希望有更簡單的方法來索引大型文本,例如論文、報告、書籍。我在這裡發現了很多帖子,要求使用一些神奇的工具來自動執行此操作。據我從評論中了解到,沒有人相信機器可以做到這樣的事情重要的給我們任務。

因此,我認為促進索引工作的最佳解決方案是創建適當的個人命令(到目前為止我不擅長...)。我想做至少以下幾點:

  1. 有辦法列印文本中的索引詞,即避免輸入兩次

    (some text) word \index{word} ...
    

    \self透過以下方式的命令定義我得到了我想要的。

    \DeclareRobustCommand{\self}[1]{{#1}\index{#1}} %solves 1 
    
  2. 為重複多次的索引詞內的條目定義指令。例如:避免重複“單字”

    \index{word! entry1}, \index{word! entry1}, \index{word! entry1}...
    

下面的命令\sub就可以了。

    \DeclareRobustCommand{\sub}[1]{\texttt{#1}\index{Set subordinate!#1}} %solves2
  1. 與 2 相同,但現在命令必須在文字部分使用變數定義(以替換前面的固定“單字”)。那可能嗎?請參閱下面範例中“特殊”部分的嘗試

  2. \splex將索引 ( ) 條目(n變數)分割為多個的命令\index{}?例如,為了避免makeindex在同一行中列印所有條目\index{Cramer, determinant, matrices}。我不知道如何開始編寫命令,特別是因為我假設條目數量變化的一般情況。我的想法是使用\splex{Cramer, determinant, matrices}以便\index{Cramer} \index{determinant} \index{matrices}在文本中生成..

我在網路上的其他範例中發現了一些類似的命令,我正在根據自己的興趣進行調整,但有些我仍然無法弄清楚。下面範例中的命令是否可以,或者可以改進/替換嗎?那麼第3點和第4點如何解決呢?

\documentclass{article}
\usepackage{makeidx}
\makeindex
%\DeclareRobustCommand{\self}[1]{\texttt{#1}\index{#1}} %solves 1 but changes text style
\DeclareRobustCommand{\self}[1]{{#1}\index{#1}} %solves 1 
\DeclareRobustCommand{\sub}[1]{\texttt{#1}\index{Set subordinate!#1}} %solves2
\newcommand{\subdef}[2]{\index{\subd!#1}} %attempt to 3
\begin{document}
  Usefull \self{commands}.

   (some text) \sub{entry1}. 
   (some text)  \sub{entry2}. 

    \newpage
    \section{Especial *NOT WORKING*}
    \def\subd{especial}
     Something1  \subdef{entry1}. 
     Something2  \subdef{entry2}. 
\printindex
\end{document}

附錄

如果您有一個很好的教程來指示學習創建個人命令(從基本到複雜的命令),請在評論中發布連結。

答案1

我不完全確定我理解第三點的意思。您的命令指定了 2 個參數,但您在定義中只使用了一個參數,並且沒有任何程式碼可以將參數放入文字中,我認為在本例中這是需要的。然而,據我所知 3,我認為這可以解決問題。

4 就您的需求而言更容易理解。然而,我的解決方案有點複雜,因為它依賴於etoolbox.

\documentclass{article}
\usepackage{makeidx,etoolbox}
\makeindex
\DeclareRobustCommand{\self}[1]{{#1}\index{#1}}% solves 1
\DeclareRobustCommand{\sub}[1]{\texttt{#1}\index{Set subordinate!#1}}% solves2
\DeclareRobustCommand{\subdef}[1]{\texttt{#1}\index{\subd!#1}}% solves 3? (not sure I've understood the aim of 3)
% etoolbox manual p. 24
\newcommand\splex[1]{% solves 4
  \forcsvlist{\listadd\mylist}{#1}%
  \forlistloop{\index}{\mylist}}
\begin{document}
  Useful \self{commands}.

  (some text) \sub{entry1}.
  (some text)  \sub{entry2}.

  \section{Especial *WORKING*}
  \def\subd{especial}
  Something1  \subdef{entry1}.
  Something2  \subdef{entry2}.

  \section{Another test}
  \def\subd{another test}
  Something 3  \subdef{entry3}.
  Something 4 \subdef{entry4}.

  \section{Split commands}
  Nothing much to say.\splex{Cramer, determinant, matrices}

  \printindex
\end{document}

文字和列表

相關內容