有没有办法根据上下文使用快捷方式定义 \label 和 \pageref。
在 mwe 中两者都不起作用。
\documentclass[a4paper]{article}
\newcommand\phasevie[2]{\section{#1-#2}\def\cod{#2}}
\newcommand\reffs[1]{\fctcod-#1}
\newcommand\reffc[1]{\fctcod-#1~page~\pageref{fct:\fctcod{}-#1}}
\newenvironment{FC}[2]{\def\fctcod{\cod{}FC#2}}{}
\newenvironment{FIC}[3]
{%
\def\fctcod{\cod{}FC#2-#3}
\subsection{\fctcod{} --- #1}\label{fct:\fctcod{}}
}{}
\begin{document}
\phasevie{phase1}{PHS}
\begin{FC}{This is a function}{1}
criteria number one explained inline: \reffs{1}
criteria number two explained after: \reffc{2}
criteria number two explained after: \reffs{2}~page~\pageref{fct:PHSFC1-2}
\end{FC}
\begin{FIC}{Criteria}{1}{2}
% \label{fct:PHSFC1-2}
Description of function criteria \fctcod{}.
\end{FIC}
\end{document}
答案1
不要到处都使用括号。在标签和引用中,它们可能很重要:
\documentclass[a4paper]{article}
\newcommand\cod{}
\newcommand\fctcod{}
\newcommand\phasevie[2]{\section{#1-#2}\def\cod{#2}}
\newcommand\reffs[1]{\fctcod-#1}
\newcommand\reffc[1]{\fctcod-#1~page~\pageref{fct:\fctcod-#1}}
\newenvironment{FC}[2]{\def\fctcod{\cod FC#2}}{}
\newenvironment{FIC}[3]
{%
\def\fctcod{\cod FC#2-#3}
\subsection{\fctcod{} --- #1}\label{fct:\fctcod}
}{}
\begin{document}
\phasevie{phase1}{PHS}
\begin{FC}{This is a function}{1}
criteria number one explained inline: \reffs{1}
criteria number two explained after: \reffc{2}
criteria number two explained after: \reffs{2}~page~\pageref{fct:PHSFC1-2}
\end{FC}
\begin{FIC}{Criteria}{1}{2}
% \label{fct:PHSFC1-2}
Description of function criteria \fctcod{}.
\end{FIC}
\end{document}