# Color-highlight selected letters in LaTeX

I intentionally produced my latex leaflet to promote myself as an actor with reduced coloration, but I had an idea to have some letters throughout the text coloured, just to amuse.   My first attempt was to replace all occurances of “et” (French for “and”…) in the text with \textcolor{Red}{et}.  This was fairly quick to do with the power of gVim, and I quite liked the pdf output result, but not the visual mess in the tex file.  I looked for a way to semi-automate it in LaTeX, and found Sh3ljohn’s helpful StackExchange question, which got me thinking that I could colour-highlight these letters throughout my leaflet: J H T j h t.

### First attempt, following Segletes’ answer

First I reduced his revised code to highlight just two capitals, M and T:

 \documentclass{article} \usepackage{xcolor} \usepackage{stringstrings}   \let\svmc M \let\svtc T %o-\let\svol o \catcodeM=\active \catcodeT=\active %o-\catcodeo=\active \newcommand\colorcapon[1][red]{% \catcodeM=\active\def M{\textcolor{#1}{\svmc}}% \catcodeT=\active\def T{\textcolor{#1}{\svtc}}% %o- \catcodeo=\active\def o{\textcolor{#1}{\svol}}% } \def\colorcapoff{% \catcodeM=11\let M\svmc% \catcodeT=11\let T\svtc% %o- \catcodeo=11\let o\svhl% } \catcodeM=11 \catcodeT=11 %o-\catcodeo=11   \parskip 1em   \begin{document}   \colorcapon[cyan] \verb|\colorcapon[color]| will change all caps to the specified color\\ Mostly to Tom (\verb|Even in \Verbatim|)   \colorcapoff \verb|\colorcapoff| will restore all things to the original LaTeX setting\\ Mostly to Tom   \end{document}

– which makes this:

The next step was to try lower-case highlighting,  for the letter o I thought (just remove those %o- comment marks from my tex code).  Nope, it doesn’t work: the line \catcode`o=\active breaks all further use of o in the tex file – for example the following line’s \newcommand is interpreted as \newc !  I now realised why he was pointing out that it’s a dangerous method.  It only happens to work for capitals because they’re not being used in subsequent LaTeX commands…