# Is it possible to create index from an external file?

I just have started to write my master thesis dissertation and I want to have an index section. I know about makeidx package and \index{An important word!} command. However, I was wondering if it's possible to create an external file containing all the words that I want to appear in the index section without using \index command in the .tex source file.

The point is if I'm going to use \index command, eventually I will forgot to do so in some points.

If it is possible to use an external file, is it also possible to limit the depth of such indexing mechanism? What I mean by limiting is that [as an example] it only index the words if they appear in the subsections (and not in the subsubsection) or index only the first three occurrence in each section.

Obviously I can do this with some simple find-and-replace mechanism in a text editor or a script but I was wondering if there is some LaTeX magic for this purpose.

• Use the \input{file}? that file can have your section, or other indexes. – selwyndd21 Sep 23 '13 at 9:29
• It is possible to scan runs of text looking for words in latex but it's immensely fragile and likely to break in conjunction with code to actually produce your document. As you say, it is trivial to write a script (in any text editing tool rather than latex) that searches for your list of to-be-indexed words and makes sure they are all wrapped in \index and that is likely to be a far more robust approach. – David Carlisle Sep 23 '13 at 10:17
• Indexing is marking the relevant places where a term appears; as such, it's quite difficult to make it automatic: a term can appear both in technical or non technical sense and one would index only the former case. Say you want to index "function": you don't want to index the verb, but only the name. – egreg Sep 23 '13 at 12:43
• The better way is to be clever with the \index command: Index-worthy terms that are used often should be given a macro that prints the word in text and in the index (and, ideally, an optional argument that will allow for you to give further sub-category differentiation); and an indexing command like \Index{<term>} that will print in the text and in the index. Then using external tools for search-and-replace will become even easier to use. But as @egreg says: context is everything! You need to think at a higher level about the intended meaning of your document in order to index properly. – jon Sep 23 '13 at 13:35