Given the following code:
test[p_] :=
With[{str = If[p > 0, "+", "-", "+"]},
DisplayForm@
RowBox[{DisplayForm[SuperscriptBox["J", "P"]], "=",
ToString[DisplayForm[SuperscriptBox["3/2", str]]]}]]
I expect an output like
$$J^P=3/2^\pm$$
depending on the sign of $p$.
However, I get the following output:
RowBox[List[DisplayForm[SuperscriptBox["J","P"]],"="," +\n3/2"]]
Why is the output so mangled? Note the "3/2" appearing last and behind whitespaces and specifically a linebreak \n
. How can I fix this?
Version 13.1.0.0 Student Edition (64-bit on Ubuntu 22.04)