如何重新定义标签以使其识别其环境

如何重新定义标签以使其识别其环境

如何重新定义label命令,使得如果它在环境(例如定理)内则\label{thm:2}变成\label[Theorem]{thm:2}

\documentclass{article}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[colorlinks,linkcolor=blue,citecolor=green]{hyperref}
\usepackage[nameinlink]{cleveref}

\newtheorem{thm}{Theorem}[section]
\newtheorem{lemma}[thm]{Lemma}

\crefname{lemma}{lemma}{lemmas}
\Crefname{lemma}{Lemma}{Lemmas}
\crefname{thm}{theorem}{theorems}
\Crefname{thm}{Theorem}{Theorems}


\begin{document}
\section{Bla Bla}

\begin{lemma}\label{noname}% This becomes \label[Lemma]{noname} automaticaly  
  A lemma that has no name.
\end{lemma}

\begin{lemma}[My Lemma]\label{lem:a}% This becomes \label[Lemma]{lem:a}  automaticaly
  This is some statement.
\end{lemma}

\begin{thm}[My Theorem]\label{thm:b}% This becomes \label[Theorem]{thm:b} automaticaly
  This is a theorem.
\end{thm}

\end{document}

相关内容