解释我想要什么的最简单方法是显示所需的输出 ,我希望通过编写类似以下内容来获得此输出:
\begin{document}
Draw point B \STEP{drawb}. Connect A and B \STEP{connectab}. Draw point A \STEP{drawa}.
The correct order is \REF{drawa} then \REF{drawb} and finally
\REF{connectab}.
\end{document}
参考文献应该是链接,所以我可以通过单击它跳转到那里。
\STEP
又该如何\REF
定义?
这个例子过于简单了。文本中引用的部分不能放入枚举环境或诸如此类的东西中,它们位于某些段落内,必须保留在那里。我使用的是 latex 和 hyperref 包。
请随意编辑标题,我不知道如何以简洁的方式表述它。
答案1
链接自\STEP
至\REF
\documentclass{article}
\usepackage{hyperref}
\newcounter{step}
\renewcommand*{\thestep}{Step~\arabic{step}}
\newcommand*{\REF}[1]{%
\begingroup
\refstepcounter{step}%
\label{#1}%
\thestep
\endgroup
}
\newcommand*{\STEP}[1]{%
(\ref{#1})%
}
\begin{document}
Draw point B \STEP{drawb}. Connect A and B \STEP{connectab}. Draw point A
\STEP{drawa}.
The correct order is \REF{drawa} then \REF{drawb} and finally
\REF{connectab}.
\end{document}
链接自\REF
至\STEP
\REF
您可能想要从到 的链接\STEP
。此解决方案在两种情况下都放置了锚点。因此,如果需要,可以轻松扩展它以在两个方向上建立链接。
\documentclass{article}
\usepackage[verbose]{hyperref}
\newcounter{step}
\renewcommand*{\thestep}{Step~\arabic{step}}
\newcommand*{\REF}[1]{%
\begingroup
\refstepcounter{step}%
\label{ref:#1}%
\hyperref[{step:#1}]{\thestep}%
\endgroup
}
\newcommand*{\STEP}[1]{%
\begingroup
\phantomsection
\label{step:#1}%
(\ref*{ref:#1})%
\endgroup
}
\makeatother
\begin{document}
Draw point B \STEP{drawb}. Connect A and B \STEP{connectab}. Draw point A
\STEP{drawa}.
The correct order is \REF{drawa} then \REF{drawb} and finally
\REF{connectab}.
\end{document}
链接自\STEP
至\REF
带有\ref
\documentclass{article}
\usepackage[verbose]{hyperref}
\usepackage{refcount}[2010/12/01]
\makeatletter
\newcounter{step}
\renewcommand*{\thestep}{Step~\arabic{step}}
\newcommand*{\REF}[1]{%
\begingroup
\refstepcounter{step}%
\IfRefUndefinedBabel{step:#1}{%
}{%
\edef\@currentHref{%
\getrefbykeydefault{step:#1}{anchor}{}%
}%
}%
\label{#1}%
\hyperref[{step:#1}]{\thestep}%
\endgroup
}
\newcommand*{\STEP}[1]{%
\begingroup
\phantomsection
\label{step:#1}%
(\ref*{#1})%
\endgroup
}
\makeatother
\begin{document}
Draw point B \STEP{drawb}. Connect A and B \STEP{connectab}. Draw point A
\STEP{drawa}.
Additional reference: \ref{connectab}.
The correct order is \REF{drawa} then \REF{drawb} and finally
\REF{connectab}.
Additional references: \ref{drawa} and \ref{drawb}.
\end{document}
答案2
编辑:根据新信息调整的示例。
\documentclass{article}
\newcounter{steps}
\newcommand*\refstep[1]{%
\refstepcounter{steps}\label{#1}\hyperlink{step:#1}{step~\arabic{steps}}}
\newcommand*\step[1]{\hypertarget{step:#1}{step~\ref*{#1}}}
\usepackage{hyperref}
\begin{document}
Draw point B (\step{drawb}). Connect A and B (\step{connectab}).
Draw point A (\step{drawa}).
\newpage% to see that the links work
The correct order is \refstep{drawa} then \refstep{drawb} and finally
\refstep{connectab}.
\end{document}
原文:如果是这样的话:
\documentclass{article}
\newcounter{steps}
\newcommand*\step[1]{step~\ref{step:#1}}
\newcommand*\refstep[1]{step~\refstepcounter{steps}\thesteps\label{step:#1}}
\begin{document}
Draw point B (\step{drawb}). Connect A and B (\step{connectab}).
Draw point A (\step{drawa}).
The correct order is \refstep{drawa} then \refstep{drawb} and finally
\refstep{connectab}.
\end{document}