When I'm fine-tuning the design of my documents in LaTeX/XeLaTeX, it's sometimes helpful to use color to highlight the location and size of my fixed spacing. For example, I sometimes temporarily replace code like \hspace{2pt} with the code \textcolor{red}{\rule{2pt}{2pt}}} so I can very clearly see the 2pt space and, for example, make sure there are not any unintended spaces or extra spaces appearing on the left or right of my definite 2pt space.
But I have not been able to find a similar way in LaTeX/XeLaTeX of colorfully highlighting the stretchable glue that I use in my documents.
For example, \textcolor{red}{\hspace{6pt plus 2pt minus 1pt}} doesn't work.
Also, \textcolor{red}{\rule{6pt plus 2pt minus 1pt}{2pt}} doesn't work.
How can I apply color to stretchable glue using TeX/LaTeX/XeLaTeX so it is easy to see it when I am fine-tuning my documents?
Is there maybe a way to color the background (i.e., the paper) so that stretchable glue will appear to be colored compared to the text before and after it?
Is there maybe a programmatic way of detecting the value of the stretchable glue as the document is being compiled and automatically replacing the stretchable glue with a \rule set to the same width as the stretchable glue?






\vspacewhich is easy to implement (using TikZ), but would need at least 2 runs to get it right. – Skillmon Sep 14 '18 at 08:38