[Date Index]
[Thread Index]
[Author Index]
a biased rant about exporting expressions
*To*: mathgroup at smc.vnet.net
*Subject*: [mg69078] a biased rant about exporting expressions
*From*: "Chris Chiasson" <chris at chiasson.name>
*Date*: Tue, 29 Aug 2006 04:47:40 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
Let me count the ways.
I created a small set of Mathematica picture commands to illustrate my
points. The commands are at the end of the email & are prepared for
copy/paste. They also print labels and bytecounts, so it's easy to
follow along with the email.
Point #1 I noticed that the documentation for Export says it can
handle Notebook and Cell expressions. It should also say that if you
want to Export any (general) expressions other than graphics and you
also want any meaningful control over the appearance or layout of such
expressions, that you must supply a complete Cell or Notebook
expression [1]. Otherwise, you're up a creek without a paddle [2] [3].
Pics 1 - 3 illustrate this point.
(these references are not pictures, the pictures are generated from
the code at the end of this email)
[citation number] what's important - Author(s)
link
[1] cell & notebook export - WRI's Horton
http://forums.wolfram.com/mathgroup/archive/2001/Oct/msg00284.html
[2] border problem explanation / lack of good workaround confirmation
- Chiasson / Kuska
http://forums.wolfram.com/mathgroup/archive/2006/Mar/msg00007.html
[3] no workaround yet available for border problem - WRI's Vertloo
http://forums.wolfram.com/mathgroup/archive/2006/Mar/msg00357.html
Point #2 The kernel relies on the Front End for exporting general
expressions [1] [4]. The front end insists that Mathematica always run
at 72 dpi [5] [6]. Below is the result of using imagemagick to
identify the dpi of a picture Export(ed) from Mathematica with
ImageResolution->300 and no other options (and also no Box, Cell, or
Notebook functions in the expression). Yes, that's right. Mathematica
doesn't set the dpi to 300x300, which is why I have the problems
detailed in the recent post "high dpi expressions aren't allowed to be
exported correctly - got a workaround?". This point is supported by
picture 4.
identify -verbose x1ay2bz3c.png | grep Resolution
Resolution: 72x72
[4] kernel relies on front end for graphical representation of general
expressions - Hinton
http://forums.wolfram.com/mathgroup/archive/1999/May/msg00115.html
[5] the front end always running at 72 dpi workaround - Chiasson / WRI's Zeller
http://forums.wolfram.com/mathgroup/archive/2006/Apr/msg00575.html
[6] tech support confirms no present solution, only [5]'s workaround
- Chiasson / WRI's Zeller
emails available upon request
#3 The Magnification option for Notebook expressions makes Export go
haywire. If Magnification isn't an option for Notebook, I ask you how
I'm supposed to know that in light of the fact that it isn't an option
for Cell either (see my other post from today, "if Magnification is an
Option for Cell, why is it ... not?"). Why did I even try using it?
See #2, where ImageResolution doesn't work properly. This point is
supported by pictures 3, 5, and 6. Try the code with different
magnifications for even more fun.
#4 Because it is so "broken", I need to know much more about Export
than the documentation shows. WRI, please either "fix" Export or put
more information about the exact steps a general Mathematica
expression passes through before it becomes a graphic file. Ideally,
you should also include a direct way to inspect the options that
Mathematica sets in the graphics file, such as the DPI (aka PPI, aka
image density, aka ImageResolution).
#5 WRI, if you're going to require notebook and cell wrappers for
exporting general expressions, please expand the color model to
include transparency and make the default Background Option of
Notebook and Cell transparent. If you've already done that, then I
thank you.
The picture code:
(Format[#[i:__Integer|__Symbol]]=Subscript[#,i])&/@{X,Y,h};
Print["An unusual expression that makes the border painfully apparent... "<>
"at least on my computer."];
Print[xpr[1]=h[i]==0==
Piecewise[
{{4-X[O][1]^2/4-X[O][2]^2,i==1},
{4-X[O][3]^2/4-X[O][4]^2,i==2},
{4-X[O][5]^2/4-X[O][6]^2,i==3},
{4-X[O][7]^2/4-X[O][8]^2,i==4},
{(X[O][1]-X[O][3])*(-X[O][1]+X[O][7])-
(-X[O][2]+X[O][4])*(-X[O][2]+X[O][8]),i==5
},
{X[O][1]-X[O][3]+X[O][5]-X[O][7],i==6},
{X[O][2]-X[O][4]+X[O][6]-X[O][8],i==7}}
]
];
theWringer[id_String,comment_String,expr_,opts___]:=
Function[
Print[
id<>" ByteCount: ",
ByteCount@#,
"\nExport Options: ",
{opts},
"\nComment: ",
comment
];
Show@#
][ImportString[ExportString[expr,"PNG",opts],"PNG"]];
theWringer[
"pic_1",
"Horrible! Note the white border. (Click on the picture.)",
StyleForm[
xpr[1],
Background->Red
]
];
theWringer[
"pic_2",
"Notice the border is gone. "<>
"Also notice this doesn't fit on a printed page with regular margins.",
Notebook[
{Cell[
BoxData[
ToBoxes[
xpr[1]
]
],
Background->Red
]}
]
];
Print[
];
theWringer[
"pic_3",
"Excuse me while I curse being forced to specify column "<>
"widths in em while specifying \"page\" width in points...\n"<>
"There. Done. No sweat! Blindingly obvious! etc.",
nb[1]=
Notebook[
{Cell[
BoxData[
ToBoxes[
xpr[1]]/.
{grd:GridBox[___]:>
Insert[grd,ColumnWidths->{20,4},2]
}
],
Background->Red,
PageWidth->450,
CellMargins->{{0,0},{0,0}},
CellFrameMargins->{{0,0},{0,0}}
]},
WindowWidth->Infinity
]
];
theWringer[
"pic_4",
"Here we graphically see Export's inability to set the DPI of a PNG to "<>
"anything other than 72. When it re-imports the file, the pixels "<>
"go toward increasing the physical size of the picture rather than "<>
"making a clearer picture of the same size. If I wanted to change "<>
"ImageSize, I would have.",
Function[Print["just for pic_4: ",#];#]@HoldForm[(X[C]/2)^2+Y[C]^2==4],
ImageResolution->120
];
nb[2]=Insert[nb[1],Magnification->1,-1];
theWringer[
"pic_5",
"This is the same as pic_3, but with ImageResolution increased. "<>
"It should not appear larger, but it does. "<>
"No Magnification has been set. Notice the significant ByteCount "<>
"increase for a small increase in DPI, as should be expected.",
nb[1],
ImageResolution->120
];
theWringer[
"pic_6",
"This is the same as pic_5, but with Magnification->1. "<>
"Notice the picture is different from pic_5, which has the same "<>
"ImageResolution and that the ByteCount is the same as pic_3, which "<>
"has a lower ImageResolution. Also, general expressions don't obey "<>
"ImageSize, even as an upper limit. So much for trying to increase "<>
"pixel density instead of picture size.",
nb[2],
ImageResolution->120
];
--
http://chris.chiasson.name/
Prev by Date:
**Re: General--Exponential simplifications by default**
Next by Date:
**Re: restart?**
Previous by thread:
**Re: high dpi expressions aren't allowed to be exported correctly - got a workaround?**
Next by thread:
**scaled complementary error function in Mathematica?**
| |