Re: DisplayForm Problem
- To: mathgroup at smc.vnet.net
- Subject: [mg81092] Re: DisplayForm Problem
- From: "Chris Chiasson" <chris at chiasson.name>
- Date: Wed, 12 Sep 2007 03:45:21 -0400 (EDT)
- References: <200709111630.l8BGU2QB001895@localhost.localdomain>
On Tue, 11 Sep 2007 16:30:02 UT, Tom Zeller <support at wolfram.com> wrote: > Chris, > > Well, this time no MathGroup responders get me off the hook. :-] > > First it is not clear that there is anything wrong, a least not with > DisplayForm. > > In[18]:= DisplayForm@"5" > Out[18]//DisplayForm= \!\(\* > TagBox["\<\"5\"\>", > DisplayForm]\) > > In[19]:= ExpressionCell[DisplayForm@"5", "Text"] > Out[19]= (ExpressionCell[DisplayForm["5"], "Text"]) > > Both of these show up as 5 (no quotes) so it does not seem as if > DisplayForm is adding the quotes in the visual output. I tried to pre-empt this response in my initial email, but I wasn't clear (or convincing?) enough: >> Note that if you try to test this with regular input and output, you >> will probably be confounded by the "ShowStringCharacters"->False >> option setting of the "Output" cell style. The reason DisplayForm@"5" shows up as 5 in output is because of the option "ShowStringCharacters"->False present in the definition of the "Output" style. "Input" and "Text" styles do not have this option. So, if you were to attempt to edit the output of DisplayForm@"5" by placing your cursor in the cell and typing, you would then see the string quotation marks. "ShowStringCharacters"->False is evil and confusing (was it Maxim that said that?). The extra string quotes may also be seen in the output you pasted. This explanation also applies to ExpressionCell[DisplayForm@"5", "Text"], because ExpressionCell doesn't actually generate its own cell when called like this. In other words, there is no implied CellPrint going on. As a result, the boxes created for the ExpressionCell construct still appear inside an "Output" style cell, and the "ShowStringCharacters"->False option prevents the showing of the string quotations. Things are different when ExpressionCell is wrapped inside of CellPrint, because CellPrint prints a cell and returns a result of Null (for which the front end does not generate a cell). To test this, you could execute CellPrint[ExpressionCell[DisplayForm@"5","Text"]]+1 , which will return "5" Out[1]= 1+Null Moving along, > > As you note: > > In[20]:= CellPrint@ExpressionCell[DisplayForm@"5", "Text"] > > "5" > > However the documentation on ExpressionCell seems to indicate that this is > expected. From the Properties & RelationsSection: > > TextCell and ExpressionCell format contents differently: > > In[1]:= CellPrint[{TextCell["abcde", "Text"], ExpressionCell["abcde", "Text"]}] > > abcde > > "abcde" > > Now ... throwing DisplayForm back into the mix, gives quotes again in the TextCell: > > CellPrint[{TextCell[DisplayForm["abcde"], "Text"], > ExpressionCell["abcde", "Text"]}] > > "abcde" > > "abcde" > > but > > In[33]:= TextCell[DisplayForm["abcde"], "Text"] > Out[33]= abcde > > It seems CellPrint is adding the quotes rather than DisplayForm. Actually, it seems that TextCell exhibits the same behavior as ExpressionCell, with some special logic to parse a base Row object into TextData and expressions therein to sub-cells. It suffers from the same confusing behavior of the "Output" cell style unless it is CellPrint ed. CellPrint@TextCell[Row[{"blah blah eqn: ", DisplayForm["abcde"]}], "Text"] TextCell[Row[{"blah blah eqn: ", DisplayForm["abcde"]}], "Text"] gives blah blah eqn: "abcde" blah blah eqn: abcde > Some of this may be that DisplayForm as documented "prints with low- > level boxes inside expr ..." Perhaps its just that DisplayForm does not > know what to do with the boxless "5" and is designed not to respond with > the inelegant, unevaluated DisplayForm["5"]. As you have shown, as soon > as boxes are introduced into DisplayForm's argument the quotes disappear > from the visible output. If DisplayForm puts out an invalid box structure, that's easy to catch because the front end will go berserk. When DisplayForm puts out an extra set of quotation marks that are not shown in a plain "Output" cell, then hardly anyone is going to notice. I would wager that the reason DisplayForm is broken is that it is **hard to figure out** that it is broken. > I am not sure that there is anything to report here. So, are you convinced? -- http://chris.chiasson.name/