Org-mode source code display control

org-mode let’s me do source code like this:

#+begin_src elisp
;; use ansi-term with zsh
(defun zterm ()
  "term to use zsh"
  (ansi-term "zsh"))

here is what it looks like:

if you strain your eyes, you might be able to see the first line which is a comment.

how can i change the background or comment color so it is visible?

i know i can put in a css page or manually change the background with a sed script, but making any changes in my .emacs file doesn’t seem to translate over via hugo. the closest i’ve come to finding an answer is this post:
Strange org mode source code block effect

so what’s the best way to deal with this?

You can either (a) specify a different highlighting style in your site configuration, or (b) create a style sheet from an existing built-in style and then modify the comment color.

To specify a different style in your site configuration:

style = 'rrt' # default is monokai

rrt example:


Let me know if you would prefer to create a style sheet from an existing built-in style.

hey thx jm! that’s excellent! i just tried it!

now i’d like to learn how to do it the second way, please:
“create a style sheet from an existing built-in style”

In your site configuration:

noClasses = false  # default is true

When noClasses is false, the rendered HTML includes class attributes instead of inline style attributes, so you need a style sheet.

From the root of your project:

mkdir -p assets/css
hugo gen chromastyles --style rrt > assets/css/chroma-rrt.css

Now edit assets/css/chroma-rrt.css as needed.

To include the style sheet, do something like this within the head element of your base template:

{{ with resources.Get "css/chroma-rrt.css" | minify }}
  <link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}

that is very nice too! and i can customize the style sheet too once i figure out what is what!
i just found the docs for it too:
Syntax highlighting

so 2 more questions:

  1. if i wish to add more css elements for my site, should i add a new css page into assetts/css and then put in a second
    {{ with resources.Get “css/myown.css” | minify }}
{{ end }} or just add to the chroma one?

it seems to me that doing a new one is more sensible because if i go to something other than rrt, i’d have to regen and that would wipe out my alterations.

  1. how did you display my code in your first post here using rrt? does discourse have some mechanism for it? i don’t see how it could be done in markup.
(print "i can do this much")

but how can i add something like rrt to my post?

I created content/ in a test project, set the site configuration as shown, then posted a screen capture.

That depends on how you handle style sheets for your site. I prefer to bundle everything, but you can certainly add them one at a time.

ah ok! i thought there may be some cryptic markdown command that existed! i certainly appreciate your extra effort on that count!

thx for all this jm! i’m all set now!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.