I would like to automatically highlight all punctuation in my document, ideally with a different background color, or by changing the color of the punctuation mark.

The aim is mostly for me to cross check my sentence length aand general style, so I'm not worried about dots in equations and/or headlines.

Is there an easy way for me to 'redefine' a dot as \color{red}{.} to turns all dots red?

Solution using the accepted answer below (because I can't make code work in the comments)


\catcode`,=\active\catcode`.=\active \catcode`;=\active %
% \catcode`,=\active\def,{\colorbox{#1}{\svcomma}}%

\catcode`,=12\let ,\svcomma%
\catcode`.=12\let .\svperiod%
\catcode`;=12\let ;\svperiod%

\catcode`,=12 \catcode`.=12 \catcode`;=12 %

\parskip 1em

\let\oldfigure\figure% Store old figure environment start
\let\endoldfigure\endfigure% Store old figure environment end
\renewenvironment{figure}[1][htbp]% Redefine figure


Based on my answer at Change the color of capital letters. The ability to turn it off might allow things like the period to be used in the normal way when needed.

EDITED to allow simple suspend/renew of the method, if one must call on some other macro requiring punctuation, such as \cite. RE-EDITED to allow this suspend/renew in a single macro call, \Xcite{}.


\catcode`,=\active \catcode`.=\active \catcode`;=\active %
  \catcode`,=\active %
  \catcode`.=\active %
  \catcode`;=\active %
  \catcode`,=12 %
  \catcode`.=12 %
  \catcode`;=12 %
  \expandafter\let\expandafter#1\csname sv\thestring\endcsname%
\catcode`,=12 \catcode`.=12 \catcode`;=12 %

\parskip 1em


\verb|\colorpunctinit[color]| will change all punctuation to the specified color,\\
here cyan, and should be done to initialize this process.\\
(\verb|But not commas; for some reason, in \verbatim.|)

\verb|\colorpunctoff| will, indeed, suspend the procedure.

\verb|\coloron{<punctuation>}{color}| will turn an inactive symbol active with the
specified color, done here  with red, to ",", blue!30 to the ``.'' and green!30 to the

\verb|\coloroff{<punctuation>}|, done here to the comma,
will restore that letter to the original LaTeX
setting; the others remain active.

To change the color an already active symbol, one must first turn the color off;
then set the color anew, as done here to the comma ``,''.

To use \verb|\cite|, one must employ \verb|\Xcite{A, B}|
as in \Xcite{A, B}. The punctuation, it is still colored; yes it is.

enter image description here

  • Thanks for the suggestion. Unfortunately, as you predicted, I need to disable the code for almost every graphic that's been included in the document (of about 100 pages). Would there be an easy way to escape that or do I need to disable it befoer each figure individually? – myrtille Aug 5 '16 at 13:44
  • @myrtille You could perhaps revise the figure environment to disable upon entry and reenable upon exit. – Steven B. Segletes Aug 5 '16 at 13:52
  • I managed to get most of it fixed. I tried to post the code, but it looked horrible. But I can't make the cite command work (it breaks if you use 2 or more citations in a single cite \cite{herrmann:1984, arnold:2005}. I'm using the cite package. if anyone could give me a tip on how to achieve that? So far I'm just not higlhighting the , which works as well. – myrtille Aug 6 '16 at 17:27
  • @myrtille See my edit. I have redefined all the macros a bit to accommodate it. – Steven B. Segletes Aug 8 '16 at 10:25
  • The challenge is in redefining the cite command to automatically disables & reeneables coloroff. It is not as easy as for the SI command unfortunately. – myrtille Aug 9 '16 at 12:12

You can make the period active and give it a definition. But you should be aware that periods are quite often part of the syntax e.g. of numbers, and that you can get quite horrible errors if the period is not what the syntax expects. So you will have to change the catcode again in such cases.


a horse. a horse. a horse.

\catcode`\.=12 %disable the colored period

a kingdom.


enter image description here

  • Thanks for the solution. Unfortunately I have the same issue here, as I have with the second solution offered: Is there a work around to not manually disable & reenable this for every figure in the text, as I usually give the size of the fiugre relative to the textwidth, the sizes all contain something similar to" 0.7\textwidth" which breaks. – myrtille Aug 5 '16 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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