20

I'm currently writing a report in org-mode. I have a couple of sections which have the same names, with the section names appearing both as a subsection of the background section, and as a section in themselves. The following example should show the issue that I'm coming across. In the document below, I want to refer to the two sections with duplicate names in the introduction. To refer to a section the [[Section Name]] syntax is used. A brief description of the usage is found in the org manual.

#+TITLE: Musings about Sections #+AUTHOR: R. Chapter #+OPTIONS: H:3 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t #+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc #+INFOJS_OPT: view:nil toc:t ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js #+LATEX_CLASS: article #+LATEX_CLASS_OPTIONS: [a4paper,11pt] * Introduction In section [[The Use of Sections]], we speak about how sections are used. In section [[How Sections Work]] we briefly introduce the implementation of sections. In section [[How Sections Work]] we go into more detail about the inner workings of sections. * Background ** The Use of Sections ** How Sections Work * How Sections Work 

Exporting this file to latex results in the first section with the duplicate name being referenced twice, where in fact the first section reference to "How Sections Work" should be to sec-2-2, and the second to sec-3.

\title{Musings about Sections} \author{R. Chapter} \date{\today} \begin{document} \maketitle \section{Introduction} \label{sec-1} In section \ref{sec-2-1}, we speak about how sections are used. In section \ref{sec-2-2} we briefly introduce the implementation of sections. In section \ref{sec-2-2} we go into more detail about the inner workings of sections. \section{Background} \label{sec-2} \subsection{The Use of Sections} \label{sec-2-1} \subsection{How Sections Work} \label{sec-2-2} \section{How Sections Work} \label{sec-3} 

Is there any way that I can refer to a specific section from within org-mode, given that I don't know what section reference it will be given when I export it?

2
  • This is not possible in orgmode at present - the labels for sections and subsections are hard-coded into the exporter function. I suggest you submit a feature-request to the orgmode list. Commented May 3, 2013 at 18:17
  • 1
    This is really a question about org-mode, not about LaTeX. Why was it migrated? Commented May 18, 2013 at 9:59

3 Answers 3

14

You can get what you want with the CUSTOM_ID property

#+TITLE: Musings about Sections #+AUTHOR: R. Chapter #+OPTIONS: H:3 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t #+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc #+INFOJS_OPT: view:nil toc:t ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js #+LATEX_CLASS: article #+LATEX_CLASS_OPTIONS: [a4paper,11pt] * Introduction In section [[The Use of Sections]], we speak about how sections are used. In section [[#background-how]] we briefly introduce the implementation of sections. In section [[#detail-how]] we go into more detail about the inner workings of sections. * Background ** The Use of Sections ** How Sections Work :PROPERTIES: :CUSTOM_ID: background-how :END: * How Sections Work :PROPERTIES: :CUSTOM_ID: detail-how :END: 

Exporting this to latex creates a second label for each section

\documentclass[a4paper,11pt]{article} \usepackage{hyperref} \title{Musings about Sections} \author{R. Chapter} \date{\today} \hypersetup{ pdfkeywords={}, pdfsubject={}, pdfcreator={Emacs Org-mode version 7.8.11}} \begin{document} \maketitle \section{Introduction} \label{sec-1} In section \hyperref[sec-2-1]{The Use of Sections}, we speak about how sections are used. In section \ref{background-how} we briefly introduce the implementation of sections. In section \ref{detail-how} we go into more detail about the inner workings of sections. \section{Background} \label{sec-2} \subsection{The Use of Sections} \label{sec-2-1} \subsection{How Sections Work} \label{sec-2-2} \label{background-how} \section{How Sections Work} \label{sec-3} \label{detail-how} \end{document} 

Other folks reading this might need to

(setq org-export-latex-hyperref-format "\\ref{%s}")

4

It's also possible to use \label and \ref directly in org-mode code:

* Introduction \label{sec:intro} * Main See section \ref{sec:intro}. 

or with @@latex:@@ to does not export it in other formats:

* Introduction @@latex:\label{sec:intro}@@ * Main See section @@latex:\ref{sec:intro}@@. 

And with macro to manage other formats:

#+MACRO: label @@latex:\label{$1}@@@@html:<a name="$1"></a>@@ #+MACRO: ref @@latex:\vref{$1}@@@@html:<a href="#$1">$1</a>@@ * Introduction {{{label(sec:intro)}}} * Main See section {{{ref(sec:intro)}}}. 
0

Use package org-ref.
Use internal links to label sections like <<sec:section-name>>
Use name for images, tables and source-codes, like #+name: fig:my-fig
Use command M-x org-ref-insert-ref-link to insert an internal link, which in turn manifests like ref:sec:section-name or ref:fig:my-fig in the org buffer.

Refer to this answer for more details: https://stackoverflow.com/a/74890075/4366367

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.