I want to convert the $10^i$ tick labels generated by LogTicks
of the CustomTicks
package to regular numbers. The first tick label is in element [[1,2]]
of the object generated by LogTicks
. FullForm
tells me the format is as follows:
LogTicks[0, 2][[1, 2]] // FullForm
\!\( TagBox[ StyleBox[ RowBox[{"DisplayForm", "[", RowBox[{"SuperscriptBox", "[", RowBox[{"10", ",", "0"}], "]"}], "]"}], ShowSpecialCharacters->False, ShowStringCharacters->True, NumberMarks->True], FullForm]\)
Actually, in the notebook it looks different:
Subsequently, I can use ToExpression
to obtain the regular number 1:
ToExpression[%]
(* 1 *)
But it doesn't work in one step:
ToExpression[LogTicks[0, 2][[1, 2]]]
ToExpression::notstrbox: 10^0 is not a string or a box. ToExpression can only interpret strings or boxes as Wolfram Language input.
What would be the command to get
command[LogTicks[0, 2][[1, 2]]]
(* 1 *)
and what is the reason why my approach failed?
command[expr_] := First@Cases[expr, SuperscriptBox[x_, y_] :> x^y]
$\endgroup$expr
if it can't be converted that way (e.g., some elements ofLogTicks[0, 2][[All, 2]]
are just empty strings "" $\endgroup$If
statement to check the structure ofexpr
first, and returnexpr
if it's an empty string or something. Otherwise, why doesn'tToExpression@FullForm@expr
work? $\endgroup$ToExpression@ToBoxes@FullForm@expr
? Or maybe justToExpression@ToBoxes@expr
? $\endgroup$