4
$\begingroup$

I've made my research in how to change the color of comments inside an input cell. I've tried it all and nothing seems to work as it should.

First, I am using a Stylesheet, not the default looking Notebook (where I can, indeed, change the color). Here, the default settings don't work. This is expected.

Now, to change the color I first tried to do it within the notebook itself by selecting a color in Format>TextColor with a comment selected. It does not work.

I then went to the StyleSheet editor to forcedly change the color via code. My input cell style looks like this:

Cell[StyleData["Input"],CellDingbat->"\[Wolf]",
Background->RGBColor[0.12156862745098039`, 0.12156862745098039`,0.12156862745098039`],
AutoStyleOptions>{"CommentStyle" -> {FontWeight -> Bold,FontColor -> RGBColor[0.75,0.73,0]}}]

(That RGB is a yellow-like color)

This should totally do it, but it doesn't. It only changes the color of comment's "braces" (* *).

The color of the text inside the comment remains unchanged, only the "(* *)" changed to the yellow-like color I wanted.

As the image below shows: (you can ignore the actual code, just pay attention to the comments)

enter image description here

What should I do?

$\endgroup$
2
  • 1
    $\begingroup$ Did you try the preferences menu for syntax coloring? It will allow you to change the comment color and font size. $\endgroup$ Jun 6, 2022 at 21:27
  • $\begingroup$ That only affects the Style of a default stylesheet; when using a different or customized one, those preferences do not hold $\endgroup$ Jun 6, 2022 at 22:06

1 Answer 1

5
$\begingroup$

This works for me:

Cell[StyleData["Input"],
 CellDingbat->"\[Wolf]",
 AutoStyleOptions->{
 "CommentStyle"->{
  FontColor -> RGBColor[0.75, 0.73, 0.], FontWeight -> Bold, 
   ShowSyntaxStyles -> False}},
 Background->RGBColor[
  0.12156862745098039`, 0.12156862745098039`, 0.12156862745098039`]]

Comments seem to be treated as commented-out input code. If you turn off syntax styles, it won't be colored. Try putting Plot or some other keyword in the setup in the OP and it will be colored differently than the undefined symbols.

Here are the default settings. You may wish to consider other suboptions:

"AutoStyleOptionsCommentStyle" /. 
 CurrentValue[{StyleDefinitions, "Input", AutoStyleOptions}]
(*
{FontColor -> RGBColor[0.27, 0.58, 0.68],
 FontWeight -> Plain, 
 ShowAutoStyles -> False,
 ShowSyntaxStyles -> False, 
 AutoNumberFormatting -> False, 
 TranslationOptions -> {"Enabled" -> False}}
*)
$\endgroup$
0

Your Answer

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

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