如何自定义emacs内联代码的颜色、大小和字体

How to customize color, size, and font of emacs inline code

我以前一直用markdown。现在我对所有东西都使用 emacs org-mode(“这个 koolaid 味道不错”)。让我抓狂的一件事情是在 emacs 中对内联代码使用反引号的能力。 我阅读的所有内容都希望我使用简单的源代码模板,如下所示:

#+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

然后我偶然发现了 Abrams 先生的 post:Exporting inline code to html in org-mode。我只需要对 emacs 内联引号使用 =code= 而不是 'code' 吗?好的。为什么在我一直在仔细阅读的几个月的文档中没有简单地指出这一点!? (可能是!)

当然,我想知道如何在 emacs 中自定义这些内联代码片段的颜色、字体和大小。默认尺寸太小,没有像 markdown 那样微妙的背景颜色。

谢谢

我相信 Org 模式会导出您当前的颜色主题。要验证这一点,您可以更改 emacs 的配色方案并重新导出缓冲区以查看情况是否发生变化。

至于我自己,我将 org-html-htmlize-output-type 设置为 css 并将 org-html-head 设置为以下内容:

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

这样,无论我的 emacs 的颜色主题如何,我都可以根据需要调整 css。

下面请看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.

编辑 请将以下内容放入您的 init.el,重新启动 emacs 并重试以查看它是否有效:

(setq       org-html-htmlize-output-type 'css)
(setq-default org-html-head "<link rel=\"stylesheet\" .../>")

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

我认为这是因为你没有仔细阅读手册。在 11.2 Emphasis and Monospace

中描述了 Monospace

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

如果要表示一个代码块,可以使用#+BEGIN_SRC#+END_SRC对。

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

正如您在问题描述中提到的,您可以键入 <sTAB 来自动完成。


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

org中有两个级别设置字体。

  1. 在文档范围内更改字体

将下面 #+HTML_HEAD_EXTRA: 添加到您的组织文件的开头。

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

@Lungang Fang 给你另一种方式放置CSS.

  1. 在本地更改字体大小
#+BEGIN_EXPORT html
<p style="font-family:Monospace; font-size: 30px; font-style: italic;">
This is a customized line.
</p>
#+END_EXPORT

自定义你问题描述中提到的block的样式,可以看我的other answer.