TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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).

share|improve this question

migrated from stackoverflow.com Jul 8 '11 at 8:16

This question came from our site for professional and enthusiast programmers.

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 8 '11 at 8:38
up vote 12 down vote accepted

With XeLaTeX it's possible via the xesearch package.



This is text that shows a keyword,\\
which is something special.

The result is shown below


share|improve this answer
Does this also work if a macro expands to keyword or something? – Aditya Jul 8 '11 at 15:53
@Aditya: I just tested that and yes it works. It also works if e.g. key is expanded by one macro and word by some other as long the result is keyword. – Martin Scharrer Jul 8 '11 at 17:01

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}\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.

share|improve this answer
With XeLaTeX one could try and use xesearch. – egreg Jul 8 '11 at 8:44

Use soul:

\hl{this text is highlighted}



share|improve this answer
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 8 '11 at 8:46
@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 8 '11 at 9:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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