9

I have an article with many keywords mixed throughout. I also have a list of those keywords and their definitions (this list needn't appear in the document, and I can put it in a CSV or any format as necessary). Is there any way to have LaTeX search for these keywords in the document and highlight them?

Two possible options:

  1. Place any keywords found in the document in italics.

  2. (preferred) Create a \footnote wherever the keywords appears in the document, with the definition or use some other form of automated cross-reference (for instance, against a glossary).

Martin Scharrer
  • 262,582
Village
  • 13,603
  • 23
  • 116
  • 219
  • Welcome to TeX.sx! Your question got migrated here from a different stackexchange site. Please also register yourself here and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. – Martin Scharrer Jul 08 '11 at 08:38

3 Answers3

13

With XeLaTeX it's possible via the xesearch package.

\documentclass[border=1]{standalone}
\usepackage{fontspec}
\usepackage{xesearch}

\SearchList{list1}{\textit{#1}}{keyword,something}

\begin{document}\Huge
This is text that shows a keyword,\\
which is something special.
\end{document}

The result is shown below

here

David Carlisle
  • 757,742
egreg
  • 1,121,712
3

No, LaTeX can't search through the whole document for you to highlight specific words. You need to format them by yourself. You might want to define a custom macro for this which you can change later:

\newcommand*{\kw}[1]{\emph{#1}}
%\newcommand*{\kw}[1]{\emph{#1}\footnote{#1: ...}

You could use the Search&Replace feature of your Text/LaTeX editor to add this macro around keywords. Using tools like sed or Perl you could do this for all words in your CSV file at once.

For showing the definition of the keyword you can use the glossaries or acronym packages.

Martin Scharrer
  • 262,582
1

Use soul:

\usepackage{soul}
...
\hl{this text is highlighted}

documentation

via

gulbrandr
  • 111
  • Since microtype might be thought of as a replacement for soul I wonder if there is a way to do this with microtype? – N.N. Jul 08 '11 at 08:46
  • 1
    @N.N.: I wouldn't call microtype "a replacement for soul", it does heck more than it. AFAIK both allow for letterspacing and microtype does it better. Also the benefit of soul is the formatting of longer text while still allowing line breaks, which is kind of not required for single keywords (OK, you loose hyphenation, but I think soul doesn't support that either). Anyway, besides the question title, the main issue seems not which actual highlighting macro to use but how to apply it automatically to all keywords in a text. – Martin Scharrer Jul 08 '11 at 09:00