上下文相关的交叉引用格式

上下文相关的交叉引用格式

我想格式化我的方程式,以便在任何章节中,生成的标签是

(\thesection.\theequation)1+1=2

(无章节编号)。

给定章节内的交叉引用仅包含这两个数字,但对不同章节中相同等式的引用将产生:

(章节.部分.方程式)

我见过这种做法(Hairer、Wanner 等人的书),但找不到正确的信息。

我打算从这个开始

\documentclass[chapterprefix=on,leqno,10pt,notitlepage,abstracton]{scrreprt}
\usepackage{amsmath}
\usepackage{amsthm}
\numberwithin{equation}{section}
\begin{document}
\chapter{first}
    \label{cha:first}

\section{FA}
\label{sec:fa}
\begin{equation}
  x + x = 2x
\end{equation}

\section{FB}
\label{sec:fa}
\begin{equation}
  \label{eq:1}
  x + b = a
\end{equation}

\chapter{Second}
\label{cha:second}

\section{SA}
\label{sec:sa}

See Eqn.~\eqref{eq:1}
\begin{equation}
  \label{eq:2}
  e^{i\beta}
\end{equation}

Eqn.~\eqref{eq:2} is Euler's favorite: it has all the important constants
in it. 
\section{b}
\label{sec:b}
From Eqn.~\eqref{eq:1}, we cannot derive Eqn.~\eqref{eq:2}. 
\end{document}

答案1

以下是开始使用zref的“财产清单”:

在此处输入图片描述

\documentclass{report}

\usepackage{zref}

\makeatletter
\zref@newlist{relrefprops}
\zref@newprop{chapter}{\arabic{chapter}}
\zref@newprop{chapeqnum}{\thesection.\arabic{equation}}
\zref@newprop{eqnum}{\arabic{section}.\arabic{equation}}
\zref@addprops{relrefprops}{chapter,chapeqnum,eqnum}

% Mark a possible "relative label"
\newcommand{\releqlabel}[1]{%
  \zref@labelbylist{#1}{relrefprops}%
}
% Use a "relative label" in a reference
\newcommand{\releqref}[1]{%
  \mbox{(%
  \ifnum\value{chapter}=\zref@extractdefault{#1}{chapter}{0}
    \zref@extract{#1}{eqnum}% In same chapter
  \else
    \zref@extract{#1}{chapeqnum}% In different chapter
  \fi
  )}%
  \zref@refused{#1}% Reference has been used
}
\makeatother

\renewcommand{\theequation}{\thesection.\arabic{equation}}

\begin{document}

\setcounter{chapter}{4}% Just for this example
\chapter{A chapter}
\setcounter{section}{8}% Just for this example
\setcounter{equation}{3}% Just for this example
\section{A section}
See \releqref{eq:f} and \releqref{eq:g}.
\begin{equation}
  f(x) = ax^2 + bx + c \releqlabel{eq:f}
\end{equation}

{\let\clearpage\relax% Just for this example
\setcounter{chapter}{7}% Just for this example
\chapter{Another chapter}
}\setcounter{section}{5}% Just for this example
\setcounter{equation}{9}% Just for this example
\section{Another section}
See \releqref{eq:f} and \releqref{eq:g}.
\begin{equation}
  g(x) = \alpha x^2 + \beta x + \delta \releqlabel{eq:g}
\end{equation}

\end{document}

\releqlabellabel为稍后eq可能需要参考的评估设置。类似地,用于为当前章节可能需要参考的评估设置。rel\releqrefrefeqrel

zref兼容hyperref,因此这种方法可以扩展到包括这一点。

答案2

经过一些小调整,现在就这样了。

\documentclass[chapterprefix=on,leqno,10pt,notitlepage,abstracton]{scrreprt}
\usepackage{amsmath}
\usepackage{zref}


\usepackage{chngcntr}
\counterwithin{equation}{section}


\makeatletter
\zref@newlist{relrefprops}
\zref@newprop{chapter}{\arabic{chapter}}
\zref@newprop{section}{\arabic{section}}
\zref@newprop{chapeqnum}{\thechapter.\thesection.\arabic{equation}}
\zref@newprop{eqnum}{\arabic{section}.\arabic{equation}}
\zref@addprops{relrefprops}{chapter,chapeqnum,eqnum,section}

% Mark a possible "relative label"
\newcommand{\releqlabel}[1]{%
  \zref@labelbylist{#1}{relrefprops}%
}
% Use a "relative label" in a reference
\newcommand{\releqref}[1]{%
  \mbox{(%
  \ifnum\value{chapter}=\zref@extractdefault{#1}{chapter}{0}
    \zref@extract{#1}{eqnum}% In same chapter
  \else
    \zref@extract{#1}{chapeqnum}% In different chapter
  \fi
  )}%
  \zref@refused{#1}% Reference has been used
}
\makeatother

\renewcommand\thesection{\arabic{section}} 
\renewcommand{\theequation}{\thesection.\arabic{equation}}

\begin{document}

\setcounter{chapter}{4}% Just for this example
\chapter{A chapter}
\setcounter{section}{8}% Just for this example
\setcounter{equation}{3}% Just for this example
\section{A section}
See \releqref{eq:f} and \releqref{eq:g}.
\begin{equation}
  f(x) = ax^2 + bx + c \releqlabel{eq:f}
\end{equation}

{\let\clearpage\relax% Just for this example
\setcounter{chapter}{7}% Just for this example
\chapter{Another chapter}
}\setcounter{section}{5}% Just for this example
\setcounter{equation}{9}% Just for this example
\section{Another section}
See \releqref{eq:f} and \releqref{eq:g}.
\begin{equation}
  g(x) = \alpha x^2 + \beta x + \delta \releqlabel{eq:g}
\end{equation}

\end{document}

相关内容