Search code examples
emacsorg-mode

Is it possible to have nested "includes" in emacs org mode?


I'm writing documentation and one of my documents has started getting really bulky. I decided to break it up into sections and include them all in a main section, but I realized that it's not possible for me to correctly export an html file when I do that.

Example:

I have a main org file:

#+TITLE: SO Example
#+LaTeX_CLASS: memoir
#+OPTIONS: ^:nil LaTeX:nil TeX:nil

* 1st Level
This is the first level.
#+INCLUDE: "nested_includes.org"

nested_includes.org looks like:

** 2nd Level
This is the second level
#+INCLUDE: "single_include.org"

single_include.org looks like:

*** 3rd Level
This is the third level

I build my HTML file using the following command:

C:\...\emacs\bin\emacs.exe parent.org --batch -q --no-site-file --load C:\...\site-lisp\org-html-so.el -f org-export-as-html --kill

This is what my org-html-so.el looks like:

(setq org-export-author-info nil)
(setq org-export-creator-info nil)
(setq org-export-time-stamp-file nil)
(setq org-export-with-timestamps nil)

When I build, I end up getting something like this:

result

Meanwhile, I'm expecting something like this:

expected

Is this a known issue/limitation with emacs org mode? Is there a way for me to increase include depth?

Thank you!


Solution

  • I suspect from the function you are using for export that you have an older version of org-mode. In version 8 of org-mode the export functionality was rewritten. I've had a quick look at how I can get this working with the version of org I have installed with my emacs. So for me:

    M-x org-version

    gives:

    Org-mode version 8.2.10 (release_8.2.10 @ c:/dev/emacs/share/emacs/24.5/lisp/org/)

    Which is shipped with my version of emacs 24.5. Given the same files you created. I changed org-html-so.el to read:

    (require 'org)
    (require 'ox) 
    (require 'ox-html)
    (setq org-export-author-info nil)
    (setq org-export-creator-info nil)
    (setq org-export-time-stamp-file nil)
    (setq org-export-with-timestamps nil)
    

    Then the emacs invocation was:

    emacs.exe parent.org --batch -q --no-site-file --load org-html-so.el -f org-html-export-to-html --kill

    Include Depth

    This version of include does not seem to limit depth, it does though remember files previously included regions to ensure includes are not recursive.

    Upgrading

    If you have an earlier version of emacs: you can either upgrade your version of emacs, or you can install a newer version of org, into your existing installation.

    To install the newer version through the package manager or install it locally from github. See the page in installation in the Org Manual.

    It's worth upgrading, in the least because the later versions are more actively you can take advantage of the latest features. For example you might like the support for html themes org-html-themes.