Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5988949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:01:52+00:00 2026-05-22T23:01:52+00:00

I often wish to see the internal representation of Mathematica ‘s graphical objects not

  • 0

I often wish to see the internal representation of Mathematica‘s graphical objects not in the FullForm but in much more readable InputForm having the ability to select parts of the code by double-clicking on it and easily copy this code to a new input Cell. But the default InputForm does not allow this since InputForm is displayed by default as a String, not as Mathematica‘s code. Is there a way to have InputForm displayed as Mathematica‘s code?

I also often wish to see a shortened version of such InputForm where all long lists of coordinates are displayed as the first coordinate followed by number of skipped coordinate values wrapped with Skeleton, all empty Lists removed and all numbers are also shortened for displaying no more than 6 digits. It would be even better to use 6 digits only for coordinates but for color directives such as Hue display only 2 significant digits. For example,

Plot[{Sin[x], .5 Sin[2 x]}, {x, 0, 2 \[Pi]}, 
  Filling -> {1 -> {2}}] // ShortInputForm

should give:

Graphics[GraphicsComplex[{{1.28228`*^-7, 1.28228*^-7}, <<1133>>}, 
    {{{EdgeForm[], Directive[{Opacity[0.2], Hue[0.67, 0.6, 0.6]}], 
          GraphicsGroup[{Polygon[{{1133, <<578>>}}]}]}, 
        {EdgeForm[], Directive[{Opacity[0.2], Hue[0.67, 0.6, 0.6]}],              
     GraphicsGroup[{Polygon[{{432, <<556>>}}]}]}}, {{Hue[0.67, 0.6, 
      0.6], Line[{1, <<431>>}]}, {Hue[0.91, 0.6, 0.6], 
          Line[{432, <<701>>}]}}}], {AspectRatio -> GoldenRatio^(-1), 
  Axes -> True, AxesOrigin -> {0, 0}, 
    Method -> {"AxesInFront" -> True}, 
  PlotRange -> {{0, 2*Pi}, {-1., 1}}, 
    PlotRangeClipping -> True, 
  PlotRangePadding -> {Scaled[0.02], Scaled[0.02]}}]

(note that -0.9999998592131705 is converted to -1., 1.2822827157509358*^-7 is converted to 1.28228*^-7 and Hue[0.9060679774997897, 0.6, 0.6] is converted to Hue[0.91, 0.6, 0.6]).

In this way, I wish to have the output of InputForm as Mathematica‘s code and also have a ShortInputForm function which will give the shortened version of this code. Can anybody help me?


As to the first part of the question, I have found one way to achieve what I want:

Plot[{Sin[x], .5 Sin[2 x]}, {x, 0, 2 \[Pi]}, Filling -> {1 -> {2}}] //
   InputForm // StandardForm
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:01:52+00:00Added an answer on May 22, 2026 at 11:01 pm

    UPDATE

    The most recent version of the shortInputForm function can be found here.


    Original post

    Here is another, even better solution (compatible with Mathematica 5):

    myInputForm[expr_] := 
     Block[{oldContexts, output, interpretation, skeleton},
      output = ToString[expr, InputForm];
      oldContexts = {$Context, $ContextPath};
      $Context = "myTemp`"; $ContextPath = {$Context};
      output = DisplayForm@ToBoxes[ToExpression[output] /.
          {myTemp`interpretation -> If[$VersionNumber >= 6,
             System`Interpretation, System`First@{#} &],
           myTemp`Row -> System`Row,
           myTemp`skeleton -> System`Skeleton,
           myTemp`sequence :> (System`Sequence @@ # &)}, StandardForm];
      {$Context, $ContextPath} = oldContexts; output]
    shortInputForm[expr_] := myInputForm[expr /. {{} -> Sequence[],
        lst : {x_ /; VectorQ[x, NumberQ], y__} /;
          (MatrixQ[lst, NumberQ] && Length[lst] > 3) :>
         {x /. v : {a_, b__} /; Length[v] > 3 :>
            {a, interpretation[skeleton[Length[{b}]], sequence@{b}]},
          interpretation[skeleton[Length[{y}]], sequence@{y}]},
        lst : {x_, y__} /; VectorQ[lst, NumberQ] && Length[lst] > 3 :>
         {x, interpretation[skeleton[Length[{y}]], sequence@{y}]}}]
    

    How it works

    This solution is based on simple idea: we need to block conversion of such things as Graphics, Point and others to typeset expressions in order to get them displayed in the internal form (as expressions suitable for input). Happily, if we do this, the resulting StandardForm output is found to be just formatted (two-dimensional) InputForm of the original expression. This is just what is needed!

    But how to do this?
    First of all, this conversion is made by FormatValues defined for Symbols like Graphics, Point etc. One can get full list of such Symbols by evaluating the following:

    list = Symbol /@ 
      Select[DeleteCases[Names["*"], "I" | "Infinity"], 
       ToExpression[#, InputForm, 
         Function[symbol, Length[FormatValues@symbol] > 0, HoldAll]] &]
    

    My first idea was just Block all these Symbols (and it works!):

    myInputForm[expr_] := 
     With[{list = list}, Block[list, RawBoxes@MakeBoxes@expr]]
    

    But this method leads to the evaluation of all these Symbols and also evaluates all FormatValues for all Symbols in the $ContextPath. I think it should be avoided.

    Other way to block these FormatValues is just to remove context "System`" from the $ContextPath. But it works only if these Symbols are not resolved yet to the "System`" context. So we need first to convert our expression to String, then remove "System`" context from the $ContextPath and finally convert the string backward to the original expression. Then all new Symbols will be associated with the current $Context (and Graphics, Point etc. – too, since they are not in the $ContextPath). For preventing context shadowing conflicts and littering the "Global`" context I switch $Context to "myTemp`" which can be easily cleared if necessary.

    This is how myInputForm works.

    Now about shortInputForm. The idea is not just to display a shortened version of myInputForm but also preserve the ability to select and copy parts of the shortened code into new input cell and use this code as it would be the full code without abbreviations. In version 6 and higher it is possible to achieve the latter with Interpretation. For compatibility with pre-6 versions of Mathematica I have added a piece of code that removes this ability if $VersionNumber is less than 6.

    The only problem that I faced when working with Interpretation is that it has no SequenceHold attribute and so we cannot simply specify Sequence as the second argument for Interpretation. But this problem can easily be avoided by wrapping sequence in List and then Applying Sequence to it:

    System`Sequence @@ # &
    

    Note that I need to specify the exact context for all built-in Symbols I use because at the moment of calling them the "System`" context is not in the $ContextPath.

    This ends the non-standard decisions taken me in the development of these functions. Suggestions and comments are welcome!

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Often times I see something like this: <body> <div class=container> </div> </body> Why not
Often, we can use p foo or foo.inspect to see the instance variables, but
Often I find myself interacting with files in some way but after writing the
I understand that DML technically encompasses SQL verbs which merely query but do not
UPDATE: I've solved this now - see my own comment. Amazing how often writing
Often in code I see a line of code, I have an idea it
I often see source code using types like uint32, uint64 and I wonder if
Often while editing config files, I'll open one with vi and then when I
Often, I find myself wanting to write a unit test for a portion of
Often we need to add a non-nullable column to a table, and it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.