这是我的简单文档
\textbf{Theorem 3. }
\it{Let $M_R$ be a $C3$-module. If $M=X\s Y$ and $f:X\to Y$ is a homomorphism with
$\ker f \ds X$, then $\im f \ds Y$.}\label{theorem3}
An immediate consequence of Theorem \ref{theorem3} is the following.
我尝试引用该定理,但是当我\ref
第一次插入并编译时出现两个问号,而当我第二次编译时两个问号消失并且没有出现数字。
错误在哪里?有没有合适的方法来引用这样的文本?
答案1
您可以使用定理的标准界面,而不必为每个定理进行容易出错的手动格式化。
我定义mthm
(米年度日核心米) 环境,即一个类似于标准定理的环境(称为mthminner
),它设置了一个计数器,我们可以通过重新定义相关表示\themthminner
来使用它。可选参数可用于将标题(默认“定理”)设置为“推论”、“引理”或其他。
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\newtheorem{mthminner}{\mthminnername}
\newcommand{\mthminnername}{}
\newenvironment{mthm}[2][Theorem]
{%
\renewcommand\themthminner{#2}%
\renewcommand{\mthminnername}{#1}%
\begin{mthminner}%
}
{\end{mthminner}}
\newcommand{\s}{\oplus}
\newcommand{\ds}{\leq^{\oplus}}
\DeclareMathOperator{\im}{im}
\begin{document}
\begin{mthm}{3}\label{theorem3}
Let $M_R$ be a $C3$-module. If $M=X\s Y$ and $f:X\to Y$ is a homomorphism with
$\ker f \ds X$, then $\im f \ds Y$.
\end{mthm}
An immediate consequence of Theorem \ref{theorem3} is the following corollary.
\begin{mthm}[Corollary]{3.1}\label{corollary3.1}
Corollaries are easy.
\end{mthm}
\end{document}
针对多种语句类型的不同方法。
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\newcounter{mthm}
\newtheorem{mthmitalic}[mthm]{\mthmname}
\theoremstyle{definition}
\newtheorem{mthmroman}[mthm]{\mthmname}
\newcommand{\mthmname}{}
\newcommand{\varnewtheorem}[3]{%
\newenvironment{#1}[1]{%
\renewcommand{\mthmname}{#2}%
\renewcommand{\themthm}{##1}%
\csname mthm#3\endcsname
}{\csname endmthm#3\endcsname}%
}
\varnewtheorem{theorem}{Theorem}{italic}
\varnewtheorem{corollary}{Corollary}{italic}
\varnewtheorem{definition}{Definition}{roman}
\varnewtheorem{example}{Example}{roman}
\newcommand{\s}{\oplus}
\newcommand{\ds}{\leq^{\oplus}}
\DeclareMathOperator{\im}{im}
\begin{document}
\begin{definition}{A}
This is a definition of $X\ds Y$.
\end{definition}
\begin{theorem}{3}\label{theorem3}
Let $M_R$ be a $C3$-module. If $M=X\s Y$ and $f:X\to Y$ is a homomorphism with
$\ker f \ds X$, then $\im f \ds Y$.
\end{theorem}
An immediate consequence of Theorem \ref{theorem3} is the following corollary.
\begin{corollary}{3.1}\label{corollary3.1}
Corollaries are easy.
\end{corollary}
And we can even give examples.
\begin{example}{42}
This is an example related to Corollary~\ref{corollary3.1}
\end{example}
\end{document}
答案2
\@currentlabel
需要更新才能使您的方法发挥作用。以下示例定义了arbitrarytheorem
采用单个参数(数字)的环境,并进行了相应更新。这允许您按预期\@currentlabel
使用\label
- 。\ref
\documentclass{article}
\makeatletter
\newenvironment{arbitrarytheorem}[1]{%
\par
\addvspace{.25\baselineskip}% Space above (arbitrary) theorem
\noindent\textbf{Theorem~#1.}% Theorem heading
\edef\@currentlabel{#1}% Store current label
\itshape% Default shape used within theorem
\ignorespaces
}{%
\par
\addvspace{.25\baselineskip}% Space below (arbitrary) theorem
}
\begin{document}
\begin{arbitrarytheorem}{3}
Let $M_R$ be a $C3$-module. If $M = X \setminus Y$ and $f : X \to Y$ is a homomorphism with $\int f \mathrm{d}s X$, then $\int f \mathrm{d}s Y$.
\label{theorem3}
\end{arbitrarytheorem}
An immediate consequence of Theorem~\ref{theorem3} is the following.
\end{document}