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


Groups > comp.soft-sys.math.mathematica > #9201

Re: Different Color in ToString

From Bill Rowe <readnews@sbcglobal.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Different Color in ToString
Date 2012-03-22 10:54 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jkf0d8$8lk$1@smc.vnet.net> (permalink)

Show all headers | View raw


On 3/21/12 at 5:44 AM, scolwell@uoguelph.ca (Scott Colwell) wrote:

>Does anyone know how to change the color of the font in a ToString
>command.

>For example, in the following, the text should be blue, but the
>number 3 should be red.

>n = 3;
>Text[Style["There is "<> ToString[Style[n, Red]] <> " numbers here", Blue]]

This cannot do what you want for two reasons. First, the command
ToString outputs black strings and undoes the effect of
Style[n,Red]. And even if this did what you wanted you compose a
string by string joining all the pieces then set the style of
this new string to blue. So the result will be a blue string.

Look at the output of this which I think does what you want

Grid[{{Style["There are ", Blue], Style[n, Red],
    Style[" numbers here", Blue]}}, Spacings -> 0]

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Different Color in ToString Bill Rowe <readnews@sbcglobal.net> - 2012-03-22 10:54 +0000

csiph-web