# How to style all instances of a certain word?

In my document I want to change the colour of every instance of the * character to red.

How can I style every instance of a single word or character without interfering with the document's other styles?

If you stick to the * example, you can do the following:

\documentclass{article}
\usepackage{luacode}
\begin{document}

\begin{luacode}
dofile("star.lua")
\end{luacode}

Hello * cruel * world

\end{document}


and star.lua is the following:

local GLYF = node.id("glyph")
local HLIST = node.id("hlist")
local VLIST = node.id("vlist")

local colstackstart, colstackstop
colstackstart = node.new("whatsit","pdf_colorstack")
colstackstop  = node.new("whatsit","pdf_colorstack")

colstackstart.data = "1 0 0 rg "
colstackstart.stack = 0
colstackstop.data = ""
colstackstop.stack = 0

-- one could look for the availability of the field 'cmd' instead
if status.luatex_version < 79 then
colstackstart.cmd = 1
colstackstop.cmd = 2
else
colstackstart.command = 1
colstackstop.command = 2
end

-- recurse into the hbox or vbox, if there are any
-- the * is ascii 42, I hope
end

• Will this leave e.g. \section*[]{} untouched? (I am not curious enough to run code I don't understand at all ;).) – cfr Mar 17 '15 at 0:25