引用 org-mode latex 中的特定部分

引用 org-mode latex 中的特定部分

我目前正在用 Org-mode 写一份报告。我有几个部分具有相同的名称,这些部分的名称既作为背景部分的子部分出现,又作为其自身的部分出现。以下示例应显示我遇到的问题。在下面的文档中,我想引用引言中名称重复的两个部分。要引用某个部分,请[[Section Name]]使用以下语法。用法的简要说明位于组织手册

#+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

将此文件导出至 latex 会导致重复名称的第一个部分被引用两次,而实际上,第一个部分对“部分工作原理”的引用应为sec-2-2,第二个部分对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}

由于我不知道导出时会给出哪个部分引用,有没有什么方法可以让我在 org-mode 中引用特定部分?

答案1

你可以得到你想要的CUSTOM_ID财产

#+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:

将其导出到 latex 为每个部分创建第二个标签

\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}

阅读本文的其他人可能需要

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

答案2

也可以在 org-mode 代码中直接使用 \label 和 \ref:

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

或者使用 @@latex:@@ 不会以其他格式导出:

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

并使用宏来管理其他格式:

#+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)}}}.

答案3

使用包org-ref
使用内部链接标记部分,如<<sec:section-name>>
使用名称标记图像、表格和源代码,如#+name: fig:my-fig
使用命令M-x org-ref-insert-ref-link插入内部链接,进而在组织缓冲区中显示为ref:sec:section-name或。ref:fig:my-fig

请参阅此答案以了解更多详细信息: https://stackoverflow.com/a/74890075/4366367

相关内容