Custom directives

| categories: org-mode, emacs | tags: | View Comments

You can define custom special blocks in org-mode. Here is an example of creating attention and note directives. Note you need to specify the styles and environments in the header like this:

#+HTML_HEAD_EXTRA:  <style>.attention {font-size: 30px; text-indent: 50px; color: red; background-color:HotPink;}</style>
#+HTML_HEAD_EXTRA:  <style>.note {font-size: 30px; text-indent: 50px; background-color:LightSkyBlue;}</style>

#+LATEX_HEADER: \usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
#+LATEX_HEADER: \newenvironment{attention}{\color{red}}{\ignorespacesafterend}
#+LATEX_HEADER: \newenvironment{note}{\itshape}{\ignorespacesafterend}

That allows you to define different looks for exporting to html and LaTeX. For the blog post, I put the style in the body of the html.

Here is the markup for an attention block.

#+BEGIN_ATTENTION
Pay attention to this text!
#+END_ATTENTION

Renders like this:

Pay attention to this text!

A note is defined as:

#+begin_note
this is a note
#+end_note

and it renders like this:

this is a note.

I am not sure if it is possible to add arguments, e.g. via attributes. Anyway, this may enable some flexibility in adding content that may be rendered in html and LaTeX in org-mode. There is a function (org-html-special-block and org-latex-special-block) that does the rendering, and it has an info plist that probably has the information. It does not appear you can pass arguments in though. That would require a filter that redefines the rendering.

Copyright (C) 2013 by John Kitchin. See the License for information about copying.

org-mode source

blog comments powered by Disqus