4

I have a list of words that I'd like to include in an index, listed in a separate text file. But I'm not sure how to add this list into LaTeX to produce an index.

For example, let's say my document is a simple one-paragraph text:

\documentclass{book}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Nulla convallis quis nunc a aliquam. Pellentesque habitant 
morbi tristique senectus et netus et malesuada fames ac 
turpis egestas. Nulla porttitor dolor nec imperdiet elementum. 

\end{document}

And my list of words is in a separate file that looks like this:

amet
dolor
ipsum
lorem
nulla

Is there any way I can use this wordfile to create an index? Or am I limited to using things like makidx and using commands like \index{amet} within the main file?

  • 4
    Welcome to TeX.se. I'm a bit confused about your question. How will you connect your list of words with the pages they appear on? That's the point of using \index{} in the text. And a good index is thematic, in that it doesn't just index occurrences of words, but indexes relevant places where particular concepts are discussed. – Alan Munn Jun 8 '19 at 1:20
  • I was hoping that there would be an automated way to locate the words in the wordlist to the pages they appear on. – Paasha Jun 8 '19 at 1:21
  • 4
    See my edited comment. That's not really how an index works. Good indexes are created by people who know the subject matter, not by concordances. – Alan Munn Jun 8 '19 at 1:22
  • I see, and thank you for your help. But is there any way to do the index using a separate file? Even if it is suboptimal from an indexing standpoint? – Paasha Jun 8 '19 at 1:25
  • 1
    You can use ConTeXt with the translate module or XeLaTeX with the xeindex package. – Henri Menke Jun 8 '19 at 1:26
2

If I understood your needs, you could use csvsimple to elaborate you word list file as you like (even if, as Alan said in his comment, it's not possible to create the link to where the word is cited in the text).

\documentclass{book}

\usepackage{csvsimple}
\usepackage{multicol}

% The following code is here only to create the file mylist.txt
% you don't need it in your actual document,
% since you already have your word list file
\usepackage{filecontents}
\begin{filecontents*}{mylist.txt}
amet
dolor
ipsum
lorem
nulla
\end{filecontents*} 

\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Nulla convallis quis nunc a aliquam. Pellentesque habitant 
morbi tristique senectus et netus et malesuada fames ac 
turpis egestas. Nulla porttitor dolor nec imperdiet elementum.

\chapter{My index}
\begin{multicols}{3}
\csvreader[no head]{mylist.txt}{1=\name}{\noindent\name\par}
\end{multicols}
\end{document}

enter image description here

Edit: in case you manage to create a file with term and pages where the term is referred (the problem is it's very hard to create it manually if you have a lot of terms, and even harder to create it automatically), you can do something like this:

\documentclass{book}

\usepackage{csvsimple}
\usepackage{multicol}

% The following code is here only to create the file mylist.txt
% you don't need it in your actual document,
% since you already have your word list file
\usepackage{filecontents}
\begin{filecontents*}{mylist.txt}
amet, 1
dolor, {30, 50}
ipsum, 4
lorem, {7, 9}
nulla, {10, 11, 12}
\end{filecontents*} 

\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Nulla convallis quis nunc a aliquam. Pellentesque habitant 
morbi tristique senectus et netus et malesuada fames ac 
turpis egestas. Nulla porttitor dolor nec imperdiet elementum.

\chapter{My index}
\begin{multicols}{3}
\csvreader[no head]{mylist.txt}{1=\name,2=\whereis}{\noindent\name\dotfill\whereis\par}
\end{multicols}
\end{document}

enter image description here

| improve this answer | |
  • I am afraid that it is also expected that the index will show the number of pages in which each word appears. – Fran Jun 8 '19 at 7:27
  • @Fran I'm afraid it's impossibile unless the number is in the .txt. – CarLaTeX Jun 8 '19 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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