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)
\usepackage{xcolor}
\usepackage{stringstrings}
\let\svcomma,\let\svperiod.\let\svsemicolon;
\catcode`,=\active\catcode`.=\active \catcode`;=\active %
\newcommand\colorpuncton[1][red]{%
% \catcode`,=\active\def,{\colorbox{#1}{\svcomma}}%
\catcode`.=\active\def.{\colorbox{blue!30}{\svperiod}}%
\catcode`;=\active\def;{\colorbox{green!30}{\svsemicolon}}%
}
\def\colorpunctoff{%
\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
{\colorpunctoff\oldfigure[#1]}
{\endoldfigure\colorpuncton}
\let\oldtable\table%
\let\endoldtable\endtable%
\renewenvironment{table}[1][htbp]%
{\colorpunctoff\oldtable[#1]}
{\endoldtable\colorpuncton}
\let\oldSI\SI
\renewcommand{\SI}[2]{\colorpunctoff\oldSI{#1}{#2}\colorpuncton}


figureenvironment to disable upon entry and reenable upon exit. – Steven B. Segletes Aug 05 '16 at 13:52But 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 06 '16 at 17:27\Xcitetakes no arguments directly, only indirectly. – Steven B. Segletes Aug 09 '16 at 12:24