Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #12447 > unrolled thread

How Can I Make A String Variable With Styled Text?

Started byGregory Lypny <gregory.lypny@videotron.ca>
First post2012-11-24 07:29 +0000
Last post2012-11-26 04:27 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  How Can I Make A String Variable With Styled Text? Gregory Lypny <gregory.lypny@videotron.ca> - 2012-11-24 07:29 +0000
    Re: How Can I Make A String Variable With Styled Text? "Nasser M. Abbasi" <nma@12000.org> - 2012-11-25 10:08 +0000
      Re: How Can I Make A String Variable With Styled Text? David Bailey <dave@removedbailey.co.uk> - 2012-11-26 04:38 +0000
    Re: How Can I Make A String Variable With Styled Text? David Reiss <dbreiss@gmail.com> - 2012-11-26 04:27 +0000

#12447 — How Can I Make A String Variable With Styled Text?

FromGregory Lypny <gregory.lypny@videotron.ca>
Date2012-11-24 07:29 +0000
SubjectHow Can I Make A String Variable With Styled Text?
Message-ID<k8psvt$is4$1@smc.vnet.net>
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?

Gregory

[toc] | [next] | [standalone]


#12464

From"Nasser M. Abbasi" <nma@12000.org>
Date2012-11-25 10:08 +0000
Message-ID<k8sqm5$ooe$1@smc.vnet.net>
In reply to#12447
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

[toc] | [prev] | [next] | [standalone]


#12471

FromDavid Bailey <dave@removedbailey.co.uk>
Date2012-11-26 04:38 +0000
Message-ID<k8urn8$ssu$1@smc.vnet.net>
In reply to#12464
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


[toc] | [prev] | [next] | [standalone]


#12467

FromDavid Reiss <dbreiss@gmail.com>
Date2012-11-26 04:27 +0000
Message-ID<k8ur30$sp4$1@smc.vnet.net>
In reply to#12447
One should be able to do this with the function Interpretation;
however, Interpretation does not seem to work properly with strings.
I "interpret" that as a bug...

Thus, I believe that one should be able to define

temp = Interpretation[
  Row[{Style["This is boldface.", Bold], "  The rest is not."}],
  "This is boldface.  The rest is not."]

and then be able to execute some thing like,

Characters[temp]

and get the list of characters in the string.  This, however, does not
work.

--David


On Nov 24, 2:31 am, Gregory Lypny <gregory.ly...@videotron.ca> 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?
>
> Gregory

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web