Basic implementation
After working on this answer, I realized that the undocumented FrontEnd`ExportPacket
with "InputForm"
as second argument may be considered as an alternative to FullGraphics
. First, a basic definition:
fullGraphicsBasic[expr_, dist_ : 1.2] := Block[{e = dist}, ToExpression[
First@FrontEndExecute[
FrontEnd`ExportPacket[Cell[BoxData@ToBoxes[expr]], "InputForm"]]]]
Here is a demonstration of how fullGraphicsBasic
works (Mathematica 13.1.0):
Plot[Sin[x], {x, 0, 6 Pi}]
fullGraphicsBasic[%]
ResourceFunction["ShortInputForm"][%]
The axes and ticks look lighter than they are on the original figure due to the default Antialiasing -> True
applied to the graphics primitives (by default Axes
and Frame
are rendered with Antialiasing -> False
). We can fix this, for example, as follows:
fullGraphicsBasic[Plot[Sin[x], {x, 0, 6 Pi}]] /.
AbsoluteThickness[0.2`] :> Sequence[AbsoluteThickness[0.2`], Antialiasing -> False]
Discussion and better implementation
I was forced to wrap the main code of fullGraphicsBasic
with Block
, because for some reason it returns an expression with undefined variable e
, which determines the distance between the minus sign and the number. The minus signs are separately drawn as Style["-", FontFamily -> "MathematicaSans"]
, while the numbers are drawn with FontFamily -> "Arial"
. Surprisingly, the "Hyphen-Minus" characters "-"
look the same (at least on Windows 10 x64) in these fonts, so this complication is completely redundant. But it makes a trouble, because the correct value for this variable seemingly depends on where the number is placed on the plot. The same problem applies to some other mathematical characters, for example: ~
, ±
, =
etc. Applying PrivateFontOptions -> {"OperatorSubstitution" -> False}
doesn't change this behavior.
This feature/bug is present in all versions I checked: 8.0.4, 12.3.1 and 13.1.0, excepting version 5.2 where the method itself doesn't quite work. It is interesting, that if I specify "Output"
as a style for the Cell
in the definition above, this undefined variable e
disappears and the result looks as if it is replaced with 1.8
(as a consequence, the minus sign runs over the number). These observations indicate that this functionality of FrontEnd`ExportPacket
is still incomplete.
As a workaround to this horrible feature, one can replace the "Hyphen-Minus" character with zero before applying FrontEnd`ExportPacket
, and then replace it back after it. Since we are most interested in reproducing the Ticks
and FrameTicks
, we can proceed as follows:
Clear[fullGraphics]
fullGraphics[expr_] := Module[{e},
e = expr /.
g_Graphics :>
Show[g, AbsoluteOptions[g, {Ticks, FrameTicks}] /.
s_String :>
StringReplace[
s, {StartOfString ~~ "-." -> "00.", StartOfString ~~ "-" -> "0"}]];
ToExpression[
First@FrontEndExecute[
FrontEnd`ExportPacket[Cell[BoxData@ToBoxes[e]], "InputForm"]]] /.
Text[Style[s_String, opts__], c__] :>
Text[Style[Row[{Invisible["0"],
StringReplace[
s, {StartOfString ~~ "0" ~~ d : DigitCharacter :> "\[Minus]" <> d}]}], opts],
c]];
Plot[Sin[x], {x, 0, 10}] /. {HoldPattern[Frame -> _] -> Frame -> False} // FullGraphics
$\endgroup$