1
$\begingroup$

I would like to reset an expression in a Standar Output inside a Cell.

For example,

c + Style[a+b, Red] (*I want the a+b part in red *)

Style[%, Blue]  (*Now I would like all the expression in Blue or Black*)

The last output will give c+( ) in blue but the inside parenthesis a +b will remain red, because this is equivalent to

Style[c + Style[a + b, Red], Red]

But I want my last Output as

Style[c + a + b, Red]

This would be simple if there would be a way to clear all the % style.

$\endgroup$
2
  • $\begingroup$ maybe Style[ToExpression@StripBoxes@ToBoxes@%, Blue]? $\endgroup$
    – kglr
    Sep 15 '20 at 23:32
  • $\begingroup$ ... or Style[% /. Style -> (# &), Blue]? $\endgroup$
    – kglr
    Sep 15 '20 at 23:50
2
$\begingroup$
c + Style[a + b, Red]
Style[% /. Style -> (# &), Blue, 24]

enter image description here

c + Style[a + b, Red]

Style[% /. Style -> (HoldForm@# &), Blue, 24]

ReleaseHold @ %

enter image description here

$\endgroup$
2
$\begingroup$

After many hours trying to solve this, I found out that with simply

c + Style[a + b, Red]
%/. Style[x__, y__] -> x

clear the Style. Thanks all!!

$\endgroup$

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.