emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Charles Berry <ccberry@ucsd.edu>
To: emacs-orgmode@gnu.org
Subject: Re: Generate a table of contents without exporting
Date: Tue, 1 Apr 2014 21:03:04 +0000 (UTC)	[thread overview]
Message-ID: <loom.20140401T225510-655@post.gmane.org> (raw)
In-Reply-To: loom.20140331T233337-501@post.gmane.org

RG Williams <rgwills <at> gmail.com> writes:

> 
> Hi,
> I know you can generate a table of contents when exporting, but can you do
> it just within org? For context, I'm uploading an .org file to github and I
> don't need to export it to another format because github recognizes and
> displays it just fine. It's long so a ToC would be nice. Do I just have to
> write it myself?
> 
> 

AFAIK, you do have to write it yourself, but org-mode provides decent tools
for doing it. Here is an example. Run the src-block and a table of contents
will appear near the top. Change the content and rerun the src-block and
the t-o-c will change accordingly.

It doesn't deal with rules for omitting headlines like
COMMENT, :noexport:, etc, but if you are simply copying the .org file,
maybe it is good enough.


--8<---------------cut here---------------start------------->8---
#+RESULTS: Table_of_Contents

* h
lower H
* i
lower I
* j
lower J
** 1
one
** 2
two

#+NAME: Table_of_Contents
#+BEGIN_SRC emacs-lisp :wrap example
  (mapconcat 'identity
   (org-element-map 
       (org-element-parse-buffer 'headline) 'headline 
     (lambda (hl) (let
                      ((lev
                        (org-element-property :level hl)) 
                       (htitle (org-element-property :title hl)))
                    (concat (make-string  lev ? ) "- " htitle )))) "\n")
#+END_SRC
--8<---------------cut here---------------end--------------->8---


HTH,

Chuck

  parent reply	other threads:[~2014-04-01 21:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-31 21:38 Generate a table of contents without exporting RG Williams
2014-03-31 22:32 ` Thorsten Jolitz
2014-04-01  0:33   ` RG Williams
2014-04-01 21:03 ` Charles Berry [this message]
2014-04-01 21:52   ` Nick Dokos
2014-04-02 15:05     ` RG Williams
2014-04-02 15:03   ` RG Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20140401T225510-655@post.gmane.org \
    --to=ccberry@ucsd.edu \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).