MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Expressions as images

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117392] Re: Expressions as images
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Thu, 17 Mar 2011 06:31:13 -0500 (EST)
  • References: <ilnh36$o56$1@smc.vnet.net>

On 15/03/2011 11:04, =8Aer=FDch Jakub wrote:
> Dear Mathgroup,
>
> I would like to create .png images from some expressions using Mathematica. It works, but it has two problems:
>
> 1) How to hold exactly the form in which I have entered the expression? For example this expression:
>
> ((3 a b)/(25 x^2 y^2))^-3/((4 a)/(5 x y^2))^-3
>
> (entered in 2D form using for example Palettes)
>
> is always simplified by Mathematica to:
>
> 1/(((3 a b)/(25 x^2 y^2))^3/((4 a)/(5 x y^2))^3)
>
> I tried to use Hold and Defer but it is always simplified.
>
>
> 2) Export is "optimising" images so that long expression is divided into more lines. How to keep it in one line? I tried the AspectRatio and ImageSize options, but without any success.
>
> Example (in original also entered in 2D form):
>
> Export["filename.png",
>   Defer[(1/m^2 - (3 m)/n + 2/(m n)) (m^3 + Sqrt[16 m^4 n^6] + 5 n^5)],
>   ImageResolution ->  300]
>
> Thanks for any info
>
> Jakub
>
You really need to get hold of the BoxForm for the original expression,
as typed in. So suppose we consider a slightly simpler expression with
the same problem:

y^-1 x^3
-----------
x^4

If you type that into a cell, even Hold will not prevent partial
'evaluation'. The solution, is to access the BoxForm of the original
expression. This can be achieved clumsily by selecting the cell
containing the expression, and pressing Ctrl-Shift-E, giving you
something like:

Cell[BoxData[
  FractionBox[
   RowBox[{
    SuperscriptBox["y",
     RowBox[{"-", "1"}]],
    SuperscriptBox["x", "3"]}],
   SuperscriptBox["x", "4"]]], "Code"
  ]

This expression is a faithful representation of what you typed in, and
you should export DisplayForm[f], where f is the FractionBox expression
embedded in the above (more generally, the first argument of the Boxform
function).

This is fine for one or two such expressions, but could get tedious if
used on a larger scale! A better approach would be to use notebook
manipulation to obtain all the relevant boxform expressions from a
notebook, and export them as above.

Regarding the second question, this seems to be yet another example of
the hopeless documentation for Import/Export. Somehow all the subtle
information gets lost between the vague general documentation of the two
functions themselves, and the per-format documentation. This is really
crazy, because it is clear that WRI have put enormous effort into these
two functions, and much of that work is simply wasted because nobody
knows what is there!

The answer seems to be to combine both the options you mentioned:

Export["c:\\crap\\fes.png",
  Defer[(1/m2 - (3 m)/n + 2/(m n)) (m3 + Sqrt[16 m4 n6] + 5 n5)],
  ImageResolution -> 100,ImageSize->600]

On its own, it would seem that either option just sets the scale of the
image, but used together, it is possible to force the image to appear as is!

David Bailey
http://www.dbaileyconsultancy.co.uk



  • Prev by Date: Re: mathematica fit data to inverse gamma distribution
  • Next by Date: Re: A bug in Partition?
  • Previous by thread: Re: Expressions as images
  • Next by thread: eigenvector computations