2
$\begingroup$

I want to write a line of letters one by one, each with a different font colour and background. WriteString with stdout lets me write all the letters in the same line, but it can only be used with plain text. Is there any way to do the same but with coloured text? My best guess was to create a list with the coloured text and then join it with StringJoin, but it does not work. Yes, I am quite new to Mathematica.

So, I want to start with something like {A,B,C} and get ABC, with each letter with different color and background. Any ideas?

$\endgroup$
  • 1
    $\begingroup$ With lst = {Style["A", Red], Style["B", Blue], Style["C", Green]}; you can use Row[lst] or StringJoin[ToString[#, StandardForm] & /@ lst]? $\endgroup$ – kglr May 9 '18 at 17:32
  • $\begingroup$ @kglr yes, that solves it, thank you!! $\endgroup$ – John May 9 '18 at 17:49
  • $\begingroup$ John, posted the comment as an answer. Welcome to mma.se. $\endgroup$ – kglr May 9 '18 at 18:06
2
$\begingroup$
lst = {Style["A", 72, Red, Bold, Background -> Yellow], 
   Style["B", 72, Blue, Bold, Background -> Pink], 
   Style["C", 72, Black, Bold, Background -> Cyan]};

You can use

Row[lst] (* or *)
StringJoin[ToString[#, StandardForm] & /@ lst]

to get

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.