3

If I do

Format[$hello, StandardForm] := "world"

then

Put[HoldComplete[Format[$hello, StandardForm]], "file.m"]

or

Export["file.m", HoldComplete[Format[$hello, StandardForm]]]

file.m will contain

HoldComplete["\"world\""]

How do I get literally

HoldComplete[Format[$hello, StandardForm]]

in the exported file?

masterxilo
  • 5,739
  • 17
  • 39

2 Answers2

6
Block[{Format},
   Put[
      HoldComplete[Format[$hello, StandardForm]],
      "file.m"
   ]
]

FilePrint @ "file.m"
test = Get @ "file.m"
FullForm[test]

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740
0
Export["file.m", FullForm@HoldComplete[Format[$hello, StandardForm]], "String"]

works, but all operators will be eliminated because of FullForm:

FullForm@HoldComplete[Format[$hello, StandardForm]*2]

HoldComplete[Times[Format[$hello, StandardForm], 2]]

masterxilo
  • 5,739
  • 17
  • 39
  • This is related: http://mathematica.stackexchange.com/q/124677/12 Not that you can set a Format for FullForm too! It is unlikely that anyone would do so, but it is possible. – Szabolcs Sep 01 '16 at 12:09