Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: How Can I Make A String Variable With Styled Text?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128787] Re: How Can I Make A String Variable With Styled Text?
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Sun, 25 Nov 2012 23:24:57 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <k8psvt$is4$1@smc.vnet.net> <k8sqm5$ooe$1@smc.vnet.net>

On 25/11/2012 10:08, Nasser M. Abbasi wrote:
> On 11/24/2012 1:29 AM, Gregory Lypny wrote:
>> Hello everyone,
>>
>> I have a string variable
>>
>> myString = "This is boldface.  The rest is not."
>>
>> When I execute myString, I want the first sentence to appear in bold type.
>> Selecting the sentence and formatting it as bold when I create the string does not work.
>> StringForm will do the trick, as in
>>
>> 	myString = StringForm["`` The rest is not.", Style["This is boldface", Bold]]
>>
>> but, of course, the Head of myString will no longer be String.  Is there any other way to do this?
>>
>
> Colors and Bold or not and other attributes are part of the display processes,
> not the data itself.
>
> Why not simply do:
>
> -----------------------------
> boldString    = "This is boldface.";
> notBoldString = "  The rest is not.";
>
> Row[{Style[boldString, Bold], notBoldString}]
> -------------------------------
>
> --Nasser
>
>
Although in practice, that is probably good advice, it isn't quite the 
whole story! To see this consider:

"ABCDEFGHI"

Colour the letters DEF red, and then evaluate it. The result is still 
coloured - which means that the string that was processed by the kernel 
must contain the colour information! To discover what that is, take the 
same partially coloured string, but apply FullForm:

"ABCDEFGHI"//FullForm


"\!\(\*\nStyleBox[\(abc\*\n StyleBox[\"def\",\nFontColor->RGBColor[1, 0, 
0]]ghi\)]\)"

In practice, I am not sure this observation is particularly useful, 
because the encoding of colour information in strings, is so messy, but 
strings can contain colour and also box structures (try using Ctrl+_ to 
insert a subscript into a string).

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





  • Prev by Date: Re: Function Libraries and 'LibraryFunction'
  • Next by Date: Re: non optimized inner for loops
  • Previous by thread: Re: How Can I Make A String Variable With Styled Text?
  • Next by thread: Re: How Can I Make A String Variable With Styled Text?