Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Org Mode include heading

Tags:

emacs

org-mode

I use org-mode to write both papers and slides. The code to generate tables and figures is placed in source blocks. Most of the time I use the same tables in my slides as in my papers, but a lot of preprocessing code is needed to generate the tables. I'd like to put the generation of these tables in its own org-mode file and just be able to include certain headings in the paper or slide document. For example, I would have an org-mode document called mytables.org:

* Heading 1
** Regressions
#+BEGIN_SRC R
cat("hello world")
#+END_SRC R
* Heading 2

And another document mypaper.org:

* Section 1
#+INCLUDE: "mytables.org" :heading "Heading 1/Regressions"
* Section 2

The content from below the ** Regression headline in mytables.org would be included on export in mypaper.org. It would also be great to be able to follow the INCLUDE to the file with C-c '. Org provides some facilities for these includes, but does not allow for headings ( http://orgmode.org/manual/Include-files.html ). Obviously org does not have the :heading parameter, but any suggestions for a solution to make this work are greatly appreciated.

Thanks.

like image 986
Rob Richmond Avatar asked Sep 17 '14 16:09

Rob Richmond


People also ask

How do I add tags in Org mode?

Org-mode supports arbitrary tags on headlines. If you are using Org to track tasks, then you might tag items “work” or “phone”. Tags go at the end of the line, surrounded by colons. You can use C-c C-C to enter a tag in the minibuffer, but most of the time I type the tag, surrounded by colons.

What is the point of Org mode?

Org mode is routinely used to build and manage complex workflows. It does this using an elegantly simple syntax that scales from basic markup to full LaTeX typesetting and from plain text notes to literate programs. Everything you need to get started is demonstrated in the example.

How do I set up Org mode?

To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document. Those are minuses, not underscores. MY PROJECT is the title of the document, this can be anything. This will enable Org mode for this document, no matter what the file-ending is.

How do I convert Org mode to PDF?

To export your org file to a web page, type C-c C-e to start the exporter and then press h to select html and o to select open. A new web page should now open in your browser. Similarly, typing l and o in the exporter will convert the org file to latex and then compile it to produce a pdf and display that.


2 Answers

Org mode 8.3 supports this (I'm using 8.3beta).

For example:

#+INCLUDE: "./paper.org::*conclusion" :lines 1-20

will include the first 20 lines of the headline named conclusion.

Also, to include a heading by its CUSTOM_ID property (suppose it is Sec: Introduction):

#+INCLUDE: "./paper.org::#Sec: Introduction"

I found :only-contents t works well for my application (I'm including a subtree from another org file for a beamer presentation):

#+INCLUDE: "./paper.org::*conclusion" :only-contents t
like image 124
joon Avatar answered Sep 20 '22 03:09

joon


Why doesn't this do what you want?

** Heading 1/Regressions
#+INCLUDE: my-table.org :minlevel 2

This will nest your file under the heading. If you need selective exports, then tag the sections with :paper: or :presentation:, and use EXPORT_EXCLUDE_TAGS to indicate which one to export.

like image 42
John Kitchin Avatar answered Sep 21 '22 03:09

John Kitchin