Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reference a section by number in org-mode export?

Tags:

emacs

org-mode

I'm working in org-mode and trying to generate a link to reference a section by its number, not its title.

* Section One
:PROPERTIES:
:CUSTOM_ID: sec:one
:END:

* Section Two
#+label: sec:two

I can reference Section One with  [[#sec:one]] and [[#sec:one][Section One]],
but I can't get the actual section number (1) to resolve.

I want to see

As you can see in Section 1

By writing something like

As you can see in Section [[sec:one]],

Any ideas?

like image 574
Sam Ritchie Avatar asked May 02 '13 19:05

Sam Ritchie


3 Answers

I use dedicated targets for this:

* Section One
  <<sec:one>>

* Section Two
  <<sec:two>>

I can reference Section One with  [[sec:one]] and [[sec:one][Section One]],
but I can get the actual section number (1) to resolve.

This works as expected; see the orgmode documentation on internal links for reference.

like image 93
Tom Regner Avatar answered Oct 28 '22 12:10

Tom Regner


Tom Regner's approach works, however, you don't have to use dedicated target, you can still use custom_id link, but without a description. Like this:

* Section One
:PROPERTIES:
:CUSTOM_ID: sec:one
:END:

* Section Two
You can reference Section One with [[#sec:one]] but NOT
[[#sec:one][Section One]], i.e., the link without description
will get you the actual section number (1).
like image 33
York Avatar answered Oct 28 '22 10:10

York


You can refer to sections by name:

* Section One

* Section Two

* Links
  This is a number link: [[Section One]]
  This is a textual link: [[Section One][Some text for the link]]

Here's the LaTeX output:

\section{Section One}
\label{sec:orgheadline1}

\section{Section Two}
\label{sec:orgheadline2}

\section{Links}
\label{sec:orgheadline3}
This is a number link: \ref{sec:orgheadline1}
This is a textual link: \hyperref[sec:orgheadline1]{Some text for the link}
like image 8
Clément Avatar answered Oct 28 '22 11:10

Clément