虽然\cref
对我来说效果很好,但在框架中使用时它似乎无法识别部分标签emulateapj.cls
。以下是一个例子:
\documentclass[iop,apj,tighten,numberedappendix,twocolappendix,revtex4]{emulateapj}
% PACKAGES
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{bm}
\usepackage[pdfa]{hyperref}
\usepackage[capitalize,noabbrev]{cleveref}
\usepackage{filecontents}
\usepackage{natbib}
\bibliographystyle{apj}
\usepackage{paralist}
\usepackage{color}
\hypersetup{colorlinks,
linkcolor=blue,
citecolor=blue,
filecolor=blue,
urlcolor=blue}
\begin{document}
\title{Towards Unifying Time Domain Astronomy}
\shorttitle{Towards Unifying Time Domain Astronomy}
\author{G.\ B\'elanger}
\affil{European Space Astronomy Centre (ESA/ESAC), Science Operations Department, \\
Villanueva de la Ca\~nada (Madrid), Spain; \\
\href{mailto:[email protected]}{[email protected]}}
\begin{abstract}
Time domain astronomy concerns itself with the study of astrophysical systems
by characterising the properties of the light they emit in order to deduce and
infer something about the physical mechanisms that could be responsible for
giving rise to this emission.
\end{abstract}
\keywords{methods: data analysis -- methods: statistical}
\section{Introduction}
The task is divided in three the categories mentioned earlier, which relate to
the characterisation of constance, which also includes searching for new or
transient sources (\cref{s:constancy}); periodicity at any scale and whatever
the nature (\cref{s:periodicity}); and stochastic variability, including the
tracing and detection of state changes (Section \ref{s:variability}).
\section{Characterising Constancy}
\label{s:constancy}
\section{Characterising Periodicity}
\label{s:periodicity}
\section{Characterising Stochastic Variability}
\label{s:variability}
\end{document}
输出如下所示:
TeXBlog 的 Tom 建议
\newcommand\sref[1]{Section \ref{#1}}
有效。如果能找到问题的原因并为cleveref
或中的每个人修复它,那就太好了emulateapj
,但这远远超出了我作为用户而非 latex 开发人员的能力范围。
答案1
花了半天时间挖掘资料后,我想我可能已经发现了这个问题的原因。
所有 LaTeX\section
命令都包含宏\refstepcounter
,它负责更新节计数器。它被重新定义为 ,用于cleveref
在 中存储有关当前节的附加信息。此信息稍后由重新定义的命令\cref@currentlabel
写入文件。如果我们现在查看 中 的重新定义(被 重命名为),我们会发现现在被一对和包围,因此退出该组时对 的所有更改都会丢失。一个解决办法是将组内的分配设为全局的。\label
.aux
\@sect
\H@old@sect
hyperref
emulateapj.cls
\refstepcounter
\begingroup
\endgroup
\cref@currentlabel
我们通过以下例子来说明:
\documentclass{emulateapj}
\usepackage{hyperref,cleveref}
% patch
\makeatletter
\usepackage{etoolbox}
\patchcmd\H@refstepcounter{\protected@edef}{\protected@xdef}{}{}
\makeatother
\begin{document}
\section{This}\label{this}\cref{that}
\section{That}\label{that}\cref{this}
\end{document}
如果我们在不使用补丁的情况下排版该文档,我们会在文件中找到以下几行.aux
:
\newlabel{this}{{1}{2}{This}{section.1}{}}
\newlabel{this@cref}{{}{2}}
...
\newlabel{that}{{2}{3}{That}{section.2}{}}
\newlabel{that@cref}{{}{3}}
这是 写出的节信息\label
;显然第二行和第四行的空括号之间缺少了一些东西。使用补丁后,我们得到的是:
\newlabel{this}{{1}{2}{This}{section.1}{}}
\newlabel{this@cref}{{[section][1][]1}{2}}
...
\newlabel{that}{{2}{3}{That}{section.2}{}}
\newlabel{that@cref}{{[section][2][]2}{3}}
信息现已显示,并且章节引用也有效。