Seems that the ButtonBox is visually (not functionally) treating the String as an Expression.
(* 1 *) DisplayForm[ButtonBox["2%"]]
(* 2 *) Button["2%"]
(* 3 *) DisplayForm["2%"]
(* 4 *) "2%"
(* 5 *) 2%
The text in 1 and 5 appear the same (2x%). The rest appear as the string (2%).
Is there some option or function that allows the ButtonBox to visually treat the string as a string?
edit:
I was going down this road, rather than simply using Buttons, just to see if there were ways to speed up a dynamic display. The suggestion by @CarlWoll was almost three times as fast as using the HoldForm way.
If you have a list of strings that have "%" in them, such as
strings = {"this", "that", "2%", "(330%)"}
then something like this
StringReplace[strings, {StringExpression[d : (DigitCharacter ...),
"%"] :> StringExpression["\"", d, "%", "\""]}]
would fix them so that they can be displayed properly.
"\"2%\""instead of"2%"DisplayForm uses heuristics to decide whether a string should be considered as "boxes" or it should be considered as "expression". RawBoxes does not use any heuristics, all strings are interpreted as "boxes". – Carl Woll Feb 22 '22 at 17:56