Mac – emacs ORG-mode “headless” export-as commands


When I use org-export-as-latex or org-export-as-html orgmode turns my buffer into a .tex file or .html file. But I don't want all the extra junk that it adds to the file: I want to handle the documentclass and everything myself and just \input the org mode generated file. (Or the analogous things for html with php).

So if my org file just has:

* Section
- Stuff
- Things

I want the org mode command to output just

\item Stuff
\item Things

Without any of the extra \tableofcontents junk that ORG adds to it. I know I could define my own kind of #+LaTeX_CLASS that could add the packages I want and so on, but I don't want to do things that way (and that wouldn't remove the \maketitle or the spurious \vspace* that ORG insists on inserting.

Is there a command to do this "headless" parsing and converting? I had a look but it's not obvious from the documentation. Presumably some low level ORG command is doing the parsing and converting I want, but I couldn't find what it was called from looking at the docs and C-h pages…

This is not a question about HTML or LaTeX but about emacs ORG mode. So don't kick it off to some other site…

Best Answer

For LaTeX output, here are some options for getting cleaner output:

The function org-export-as-latex actually takes several parameters, one of which is a flag called BODY-ONLY.

The prototype for this function is (org-export-as-latex ARG &optional HIDDEN EXT-PLIST TO-BUFFER BODY-ONLY PUB-DIR) for OrgMode 7.5.

You can try the output by evaluating the LISP call explicitly:

M-: (org-export-as-latex nil nil nil nil t) RET

where the t symbol indicates the body-only option. This will create a new buffer with the LaTeX output. (RET means pressing the return key)

A shortcut for the above is to call org-export-region-as-latex. This is an interactive function which you can call with M-x. Its only argument is the body-only flag.

For example, you can select the whole buffer (via C-x h), then call this function with a prefix argument (to give a non-nil value to body-only):

C-u M-x org-export-region-to-latex RET

Now you'll have a new buffer selected with the LaTeX output and no header / footer / titles / TOC added.

This idea works also with org-export-region-as-html.

There is also a contributed package org-export-generic that lets you define an exporter completely:

P.S. I'm using the latest development version of OrgMode 7.5