<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Dear all,</p>
    <p>My original problem is to substitute any subformula with a rule of a specific color. The problem I am facing is that techniques such as creating a box as
</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">\setbox\mybox=\hbox{$\m@th #1{#2}$}</p>
    <p><style type="text/css">
p, li { white-space: pre-wrap; }</style></p>
    <p>and getting its dimensions do not work for cramped subformulas. I know about \cramped in mathtools, but I do not know in advance when a cramped subformula will be cramped since equations are arbitrary.</p>
    <p>As a solution I thought in using a fake font which is equivalent to the current one but with the full box filled with ink. It would be something like transforming a character into a rule. I do not know how to do that.</p>
    <p>Ideas?</p>
    <p>Best regards,</p>
    <p>Daniel</p>
    <p>PS: This is what I coded until know, which works well except for cramped subformulas (and the fact that subformulas are still printed over the color box)
</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">\def\mycolorphant#1#2{</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">  \mathpalette\myauxcol@rphant{{#1}{#2}}</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">}</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">\def\myauxcol@rphant#1#2{</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">  \mycol@rphant#1#2</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">}</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">\def\mycol@rphant#1#2#3{</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">  \setbox\mycpbox=\hbox{$\m@th #1{#3}$}</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">  \begingroup</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">  \color{#2}</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">  \color@block{\wd\mycpbox}{\ht\mycpbox}{\dp\mycpbox}</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">  \endgroup</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">  \box\mycpbox</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">}</p>
    <p><style type="text/css">
p, li { white-space: pre-wrap; }</style>

</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">
</p>
    <p><style type="text/css">
p, li { white-space: pre-wrap; }</style></p>
  </body>
</html>