Re: StyleForm
- To: mathgroup at smc.vnet.net
- Subject: [mg14258] Re: StyleForm
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Mon, 12 Oct 1998 13:51:40 -0400
- References: <6vf692$dja@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
David Epstein wrote in message <6vf692$dja at smc.vnet.net>...
>When working with the kernel (no front-end), I give the following
>commands:
>
>text = StyleForm[Text["a",{2,4}]]
>text
>Show[Graphics[%]]
>
>I get a reasonable result.
>
>When I give the subsequent command
>Show[Graphics[text]]
>
>I get an error message
>
>Graphics::gprim: Unknown Graphics primitive Text[c, {2, 4}] encountered.
>
>I thought Text[c,{2,4}] WAS a graphics primitive---very strange.
>
>Can someone explain to me how I should be handling the second case. The
>reason I want to use StyleForm is in order to increase the font size of
>the text in my picture.
>
>David Epstein
>
David:
In the following
(A) contains suggestions for doing what you want;
(B) is an explanation of what you found.
Allan
----------------------
Alllan Hayes
Mathematica Training and Consulting
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
(A) suggestions for doing what you want
I shall deal only with text size, but other options and lists of options
can be used similarly.
The following techniques are of increasing generality. Local rules
overide more general ones. However Show , the last technique, has its
own rules.
1) take StyleForm inside and wrap it round "a"
text = Text[StyleForm["a", FontSize->24] ,{3,4}]; Show[Graphics[text]];
2) option in Text
Show[Graphics[Text["a",{3,4}, TextStyle->{FontSize->24}]] ];
3) option in Plot
Plot[x,{x,0,1}, TextStyle-> {FontSize->24}];
4) change default Plot option
SetOptions[Plot,TextStyle:>{FontSize->36}]; Plot[x,{x,0,1}]
5) option in a Graphics object
Show[
phics[
{Text["a",{3,4}]},
TextStyle->{FontSize->24}]
];
6) change default Graphics option
SetOptions[Graphics,TextStyle:>{FontSize->36}];
Show[Graphics[ {Text["a",{3,4}]}]];
7) Change default TextStyle option value (affects all graphics)
$TextStyle = {FontSize -> 24};
ContourPlot[x,{x,0,1},{y,0,1}];
8) Option in Show (supercedes options in Graphics, Graphics3D...but not
options with StyleForm and Text)
Show[
phics[
{Text["a",{2,4}], text},
TextStyle->{FontSize->24}],
TextStyle -> {FontSize -> 10}
];
(B) an explanation of what you found.
Your results arise from the way that $OutputForms evaluate. These forms
are used to alter the way in which expressions are displayed. In
principal they should not affect value and output but in fact they can
do so. A complet list of them is.
$OutputForms
{InputForm,OutputForm,TextForm,CForm,Short,Shallow,MatrixForm,TableForm,
TreeForm,FullForm,NumberForm,EngineeringForm,ScientificForm,PaddedForm,
AccountingForm,BaseForm,DisplayForm,StyleForm,FortranForm,TeXForm,
StandardForm,TraditionalForm}
Let's look at MatrixForm, since its effects are evident in ASCII (to
help with this I set the Default Output Format Type to OutputForm (see
the Cell menu)) mt = {{1,2},{3,4}};
MatrixForm[mt]
1 2
3 4
This displays as a 2D matrix structure. But the output is actually the
same as for mt
%
{{1,2},{3,4}}
MatrixForm has been stripped off at the final stage, when the value of
Output[..] was assigned(the //MatrixForm in the output label indicates
this)
Check the full form
FullForm[%%]
List[List[1,2],List[3,4]]
**** However the stripping off occurs only when MatrixForm is the head
of the expression entered.
A[ MatrixForm[mt]];
%
A[1 2]
3 4
Check the full form
FullForm[%%]
A[MatrixForm[List[List[1,2],List[3,4]]]]
This retention of interior output formats often gives a surprise:
compare the following two inputs
3+ MatrixForm[mt] (*the retained MatrixForm prevents 3 being taken
inside the matrix*)
3 + 1 2
3 4
MatrixForm[3+ mt]
4 5
6 7
In your example
text = StyleForm[Text["a",{3,4}]];
assigns StyleForm[Text["a",{3,4}]] to text in the process of evaluation,
before any ouput is generated; so StyleForm has not been stripped.
Check this:
?text
"Glob
al`text"
text = StyleForm[Text["a", {3, 4}]]
But the output from evaluating text has StyleFrom stripped off
text
Text["a",{3,4}]
So with Show[Graphics[%]] you are getting
Show[Graphics[Text["a",{3,4}]]];
Which is fine, since Text is a good Graphics primitive.
However, with Show[Graphics[text]] the evaluation steps are
Show[Graphics[text]] ;
Show[Graphics[StyleForm[Text["a",{3,4}]]]];
And StyleForm[Text["a",{3,4}]] is not a graphics primitive. So you
would expect a message to tell you this. But instead you get one
telling you that Text[a, {3, 4}] is not a Graphics primitive - which
is false. Thus:
Show[Graphics[StyleForm[Text["a",{3,4}]]]];
Graphics::gprim:
Unknown Graphics primitive Text[a, {3, 4}]
encountered.
The reason for this that the displayed form of
StyleForm[Text["a",{3,4}]] seen in the message is Text["a",{3,4}]
We can hint at this with
Show[Graphics[StyleForm[Text["a",{3,4}],FontSize->24]]];
which displays Text[...] in 24 point font.