2

I used to use markdown all the time. Now I use emacs org-mode for everything ("this koolaid tastes good"). One piece that kept driving me nuts was the ability to use backticks for inline code in emacs. Everything I read wanted me to use easy templates for source code like this:

#+BEGIN_SRC 
Just add: " < " + one of the letters below
s   #+BEGIN_SRC ... #+END_SRC
e   #+BEGIN_EXAMPLE ... #+END_EXAMPLE
q   #+BEGIN_QUOTE ... #+END_QUOTE
v   #+BEGIN_VERSE ... #+END_VERSE
c   #+BEGIN_CENTER ... #+END_CENTER
l   #+BEGIN_LaTeX ... #+END_LaTeX
L   #+LaTeX:
h   #+BEGIN_HTML ... #+END_HTML
H   #+HTML:
a   #+BEGIN_ASCII ... #+END_ASCII
A   #+ASCII:
i   #+INDEX: line
I   #+INCLUDE: line 
#+END_SRC

Then I stumbled onto the post by Mr. Abrams: Exporting inline code to html in org-mode. I just need to use =code= instead of 'code' for emacs inline quotes? OK. Why isn't this noted somewhere simple in the months worth of docs I've been perusing!? (It probably is!)

Now of course, I want to know how to customize the color, font, and size of these inline code snippets in emacs. The default size is too small and there is no subtle background color like with markdown.

see how small and unhighlighted "sshd" is?

Thank you

2 Answers 2

1

I believe Org Mode exports your current color theme. To verify that, you can change the colour scheme of your emacs and re-export your buffer to see if things change.

As for myself, I set org-html-htmlize-output-type to css and org-html-head to the following:

<link rel="stylesheet" type="text/css" href="path/to/my.css" />

This way, I can tune the css as I want regardless the colour theme of my emacs.

Below please see the help of org-html-htmlize-output-type:

org-html-htmlize-output-type is a variable defined in ‘ox-html.el’. Its value is ‘css’ Original value was inline-css

Documentation: Output type to be used by htmlize when formatting code snippets. Choices are ‘css’ to export the CSS selectors only,‘inline-css’ to export the CSS attribute values inline in the HTML or ‘nil’ to export plain text. We use as default ‘inline-css’, in order to make the resulting HTML self-containing.

To get a start for your css file, start Emacs session and make sure that all the faces you are interested in are defined, for example by loading files in all modes you want. Then, use the command ‘M-x org-html-htmlize-generate-css’ to extract class definitions.

You can customize this variable.

EDIT Please put the following to your init.el, restart emacs and retry to see if it works:

(setq       org-html-htmlize-output-type 'css)
(setq-default org-html-head "<link rel=\"stylesheet\" .../>")
Sign up to request clarification or add additional context in comments.

6 Comments

Ok. I'm not sure how to really check my color "scheme". I use solarized theme so my buffer looks very different than the HTML output. I will need to dig into using custom css to format the code snippets. When I run M-x org-html-htmlize-generate-css on a snippet in the buffer, I get the error Cannot open load file: No such file or directory, htmlize. This must be a package in Melpa?
Ok, awesome. So yes, htmlize was a package in Melpa. I installed it then ran M-x org-html-htmlize-generate-css and it generated all(?) of the css attributes in a nice long list! Since I use =code= to define my inline snippets, I imagine i'll need to edit the following css: .org-org-verbatim { /* org-verbatim */ color: #586e75; }
Hm. Please advise: I set org-html-htmlize-output-type to css and org-html-head to the following: <link rel="stylesheet" type="text/css" href="~/.emacs.d/html_output.css" /> Restarted emacs. Then changed the verbatim selector to a wildly different color. No change in html output.
When I view source of the html output, it looks like the css is inline rather than referencing the html_output.css file I created. Do I need to add something to my emacs init file to point it? I thought thats what I did when setting org-html-head as above.
I've got: ~/.emacs.d/stylesheet.css created with the .org-org-code { /* org-code */ color: #3A8EDB; background-color: #073642; Also have: (setq org-html-htmlize-output-type 'css) (setq-default org-html-head "<link rel="stylesheet" type="text/css" href="~/.emacs.d/stylesheet.css" /> set in my emacs init file. Still cannot get '=code=' to render any differently when exported to HTML.
|
1

I just need to use =code= instead of 'code' for emacs inline quotes?

I think this is because you didn't go through the manual carefully. Monospace is described in 11.2 Emphasis and Monospace

You can make words ‘bold’, ‘/italic/’, ‘underlined’, ‘=verbatim=’ and ‘~code~

If you want to represent a code block, you can use #+BEGIN_SRC and #+END_SRC pair.

#+BEGIN_SRC emacs-lisp
  (defun org-xor (a b)
    "Exclusive or."
    (if a (not b) b))
 #+END_SRC

As you have mentioned in your question description, you can type <s and TAB for auto completion.


I want to know how to customize the color, font, and size of these inline code snippets in emacs.

There are two levels to set font in org.

  1. Change the font on a document-wide level

Add below #+HTML_HEAD_EXTRA: to the begin of your org file.

#+HTML_HEAD_EXTRA: <style>*{font-family:Arial,'Times New Roman','Microsoft YaHei',SimHei; font-size: 20px; font-style: italic; !important}</style>

@Lungang Fang gives you another way to place CSS.

  1. Change the font size locally
#+BEGIN_EXPORT html
<p style="font-family:Monospace; font-size: 30px; font-style: italic;">
This is a customized line.
</p>
#+END_EXPORT

To customize the style of a block mentioned in your quetion description, you can see my other answer.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.