2
$\begingroup$

Is there a way of using Export[] method to take a text with colors (using Style) and then export to file, such that when I open that file the text shows with the correct color?

I'm trying to export a list of strings with some styles to be read in a text processor such as Microsoft Word.

$\endgroup$
3
  • 1
    $\begingroup$ For starters you need so specify a file type that supports colors. pdf , html ? depends of what you are trying to do. $\endgroup$
    – george2079
    May 6, 2015 at 18:36
  • 2
    $\begingroup$ RTF format might be a good choice for opening in Word $\endgroup$ May 6, 2015 at 18:54
  • $\begingroup$ Yeah, I think the same, but it is not woking, could you put some example, please. $\endgroup$ May 6, 2015 at 18:55

2 Answers 2

1
$\begingroup$

This seems to work:

list = Style @@@ ColorData["Crayola", "ColorRules"];

Export["test.rtf", Cell[BoxData @ ToBoxes @ #, "Output"] & /@ list]
$\endgroup$
2
  • $\begingroup$ thanks, but it doesn't work too. Do you run it on OSX? I'm guessing that it could be a bug or something weird. $\endgroup$ May 6, 2015 at 21:15
  • $\begingroup$ @d555, no I'm using Windows. Looks like you have a Mac specific bug... $\endgroup$ May 6, 2015 at 21:17
1
$\begingroup$

The challenge for me was concatenating styled strings. To concatenated the styled text for output, just put a space between them. With that the styles export successfully:

    Export["test.rtf", 
        Style["Arff", Red] Style["Meow", Blue]
    ]

That made the text is colored correctly when opened with Word on Windows. You can also try:

    Export["test.html", 
      Style["Arff", Red] Style["Meow", Blue]
    ]

Which might work cross platform - this file loaded okay in the IE, but not Word.

$\endgroup$
3
  • $\begingroup$ Actually, your example it doesn't work too. I'm using Mathematica 10.1 on OS X 10.10 $\endgroup$ May 6, 2015 at 19:22
  • $\begingroup$ I am using 10.1, but on Windows. I will try using an HTML file as the export... $\endgroup$
    – xsk8rat
    May 6, 2015 at 19:28
  • 1
    $\begingroup$ the syntax here cant be right. $\endgroup$
    – george2079
    May 27, 2015 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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