Mathematica Asked on January 26, 2021
I want to highlight the coefficient of the polynomial is not ±1, I have tried
Factor[x^105 - 1] /. k_ x_^n_ /; Abs[k] > 1 -> Style[k x^n, Red]
HoldForm @@ {Factor[x^105 - 1]} /. k_ x_^n_ /; Abs[k] > 1 -> Style[k , Red] x^n
These are not the results I want, I hope to get results like this
It would be better if it could be displayed in traditional format in programmatically
HoldForm @@ {Factor[x^105 - 1]} /. k_ x_^n_ :>
RuleCondition[With[{b = Style[Abs[k], Red]},
If[Internal`SyntacticNegativeQ[k], -1, 1] HoldForm[b x^n]], Abs[k] > 1]
Use Highlighted[Abs[k]]
instead of Style[Abs[k], Red]
to get
See also: Replacement inside held expression
Update: Displaying in TraditionalForm
:
HoldForm @@ (TraditionalForm /@ {Factor[x^105 - 1]}) /. k_ x_^n_ :>
RuleCondition[With[{b = Style[Abs[k], 14, Red]},
If[Internal`SyntacticNegativeQ[k], -1, 1] HoldForm[b x^n]], Abs[k] > 1]
We can get Highlighted
looks using
HoldForm @@ (TraditionalForm /@ {Factor[x^105 - 1]}) /. k_ x_^n_ :>
RuleCondition[With[{b = Framed[Style[Abs[k], 14], Background -> Yellow,
FrameStyle -> None]},
If[Internal`SyntacticNegativeQ[k], -1, 1] HoldForm[b x^n]], Abs[k] > 1]
Correct answer by kglr on January 26, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP