\ref 自动完成功能对我的计数器不起作用

\ref 自动完成功能对我的计数器不起作用

我定义了一个计数器和一个命令,用于定义示例并标记它们。不幸的是,当我使用这些定义时,\reftexmaker 或 sharelatex 不会自动完成。

我应该在定义中添加什么内容才能让编辑器知道现有的标签?

梅威瑟:

\documentclass{article}
\newcounter{examples}[section]
\renewcommand\theexamples{\arabic{section}.\arabic{examples}}

\newcommand{\xampl}[2]{\refstepcounter{examples}\par\medskip\noindent%
\begin{tabular}{@{}p{14mm}@{}l@{}}%
(\theexamples) & #1\\
\end{tabular}\label{#2}}

\begin{document}
\section{Introduction}

\xampl{The sentence is the first example}{l1}
\xampl{The sentence is the 2nd example}{l2}

\ref{l1}, \ref{l2}
\end{document}

答案1

大多数编辑器(包括 sharelatex)通过解析显式源代码来提供标签的自动完成功能\label{...},因此当您隐藏\label在宏中时,解析器不再拾取该标签。

最好的解决方案可能是不包含\label在宏定义中,而是使用类似的

\xampl{The sentence is the first example}
\label{l1}

这也使得源代码更容易阅读。

\label编辑器在通过键值接口设置接口时也会遇到类似的问题。例如listings包提供的接口。

相关内容