简体   繁体   中英

How to use different fonts within the same (org-mode) buffer?

Since I use Emacs' org-mode for academic writing, in the beginning of my .org files, I always have a long list of latex export settings of the form:

#+LATEX_HEADER: lorem ipsum dolor
#+LATEX_HEADER: lorem ipsum dolor
...

Or code snippets scattered around the document of the form:

#+BEGIN_SRC emacs-lips
lorem ipsum dolor
#+END_SRC

All these lines (both the lorem ipsum part and the #+BLAHBLAH part), I would like to have displayed in a mono spaced font, say Liberation Mono , that respects the custom colors and custom sizes I have defined elsewhere.

I searched, and I came to the conclusion that, as suggested here , using font-lock would be the way to go. Unfortunately, by looking at examples, I couldn't figure out on my own how to set it up properly. I tried the following, but either the regexp is wrong or the syntax is wrong:

(add-hook 'org-mode-hook
          (lambda ()
           (font-lock-add-keywords nil
            '(("^\#\+.*$" 1
               font-lock-comment-face t)))))

So, the question is: has anybody been able to work this out? Or, would anyone suggest a different way?

I was trying to get something similar going for me. I came up with the following code, after poking around other answers here and in the Emacs Stack Exchange.

(add-hook 'org-mode-hook
            '(lambda ()
               (variable-pitch-mode 1) ;; All fonts with variable pitch.
               (mapc
                (lambda (face) ;; Other fonts with fixed-pitch.
                  (set-face-attribute face nil :inherit 'fixed-pitch))
                (list 'org-code 
                      'org-link 
                      'org-block
                      'org-table
                      'org-block-begin-line
                      'org-block-end-line
                      'org-meta-line
                      'org-document-info-keyword))))

I tried it with Emacs 25.1 and Org-mode 9.0.3.

You can always create a heading * Configuration :ARCHIVE: with the ARCHIVE tag at the top of your file. That keeps the heading from being expanded, hiding it from normal view. The ARCHIVE tag

  • [...] does not open when you attempt to do so with a visibility cycling command (see Visibility cycling). You can force cycling archived subtrees with C-TAB, or by setting the option org-cycle-open-archived-trees. Also normal outline commands like show-all will open archived subtrees.
  • During sparse tree construction (see Sparse trees), matches in archived subtrees are not exposed, unless you configure the option org-sparse-tree-open-archived-trees.
  • During agenda view construction (see Agenda views), the content of archived trees is ignored unless you configure the option org-agenda-skip-archived-trees, in which case these trees will always be included. In the agenda you can press va to get archives temporarily included.
  • Archived trees are not exported (see Exporting), only the headline is. Configure the details using the variable org-export-with-archived-trees.
  • Archived trees are excluded from column view unless the variable org-columns-skip-archived-trees is configured to nil.

LaTeX-exporting works if you set '(org-export-with-archived-trees nil) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM