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

Is there a way to color keywords into a document?

For instance, I want all the occurrences of a given word to appear in red in the whole document.

something like :

share|improve this question
You could (mis)use the spelling package and put your keywords in \jobname.spb. Then set \spellinghighlightcolor to red. This only works with LuaLaTeX, though. – Martin Heller Feb 7 '13 at 21:35

Just to elaborate a little on my comment. You could use spelling with LuaLaTeX like this:




Keyword foo in text.

Keyword bar in text.


This will highlight foo and bar. You'll need two compilations.

share|improve this answer

AFAIK there is no such way, the easiest would be to use search & replace. Using LuaTeX however it should be possible. I have seen a presentation about the chickenize package once which showed similar features. LuaTeX is able to hook into the text output before it is written to the PDF.

Here's a link to the German presentation PDF: http://www.dante.de/events/mv45/Programm/atrautmann/folien-trautmann.pdf

share|improve this answer
You could automate and vary @UweZeigenhagen 's search & replace strategy with an awk (or python or ...) script that processed your TeX source prior to compilation. – Ethan Bolker Feb 7 '13 at 19:38
It would be nice if you made your answer more complete, and included a simple example that does not rely on external sources. It is prefered on this site ;) – yo' Feb 7 '13 at 20:04
"Give the hungry a fish and he's fed for a while. Show him how to catch fish and he'll tell you he has better things to do than putting sticks in the water..." :-) I have no experience with either the package or LuaTeX itself, so I can't provide an example. I just remembered the talk. – Uwe Ziegenhagen Feb 7 '13 at 20:43

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.