
Estou usando o amsthm
pacote e thmtools
o pacote para formatar meu manuscrito.
Estou numerando observações dentro de teoremas, isto é, tendoObservação 2.1.,Observação 2.2.e assim por diante depoisTeorema 2. No entanto, quando apenas uma observação é feita depois, digamos,Teorema 1, espero que possa ser numerado comoObservação 1.em vez deObservação 1.1.
Utilizando a opção numbered=unless unique
em thmtools
, a numeração pode ser eliminada completamente, ficandoObservação. Isto não é o que eu realmente desejo, porque espero poder referir-me à observação mais tarde de forma conveniente pela sua numeração, em vez de dizer algo como "a observação feita após o Teorema 1".
Abaixo está um MWE, onde estou preso e me perguntando se existe alguma adaptação rápida para concretizar meu propósito. Agradecemos antecipadamente por possíveis soluções.
\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\newtheorem{thm}{Theorem}
\theoremstyle{remark}
\declaretheorem[numberwithin=thm, name=Remark, numbered=unless unique]{rmk}
\begin{document}
\begin{thm}
This is a theorem.
\end{thm}
\begin{rmk} % only one remark made
This is the only remark, so number it the same as the previous theorem.
What I want is Remark 1., instead of Remark. or Remark 1.1.
\end{rmk}
\begin{thm}
This is the second theorem.
\end{thm}
\begin{rmk} % Multiple remarks
Multiple remarks follow, and this is the first.
\end{rmk}
\begin{rmk}
Since there are multiple remarks made, all of them are numbered.
\end{rmk}
\begin{rmk}
The style is Remark 2.1., 2.2., and 2.3., etc.
\end{rmk}
\end{document}
Responder1
Você pode definir o comportamento desejado "manualmente" usando o unique
pacote. O seguinte apenas emula o thmtools
que acontece com numbered=unless unique
, mas em vez de tornar a observação sem número, se for única, ela é definida \thermk
como \thethm
.
\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[unq]{unique}
\newtheorem{thm}{Theorem}
\theoremstyle{remark}
\declaretheorem[numberwithin=thm, name=Remark]{rmk}
\addtotheorempreheadhook[rmk]{%
\setuniqmark{rmk.\thethm}%
\ifuniq{rmk.\thethm}
{\def\thermk{\thethm}}
{}%
}
\begin{document}
\begin{thm}
This is a theorem.
\end{thm}
\begin{rmk} % only one remark made
This is the only remark, so number it the same as the previous theorem.
What I want is Remark 1., instead of Remark. or Remark 1.1.
\end{rmk}
\begin{thm}
This is the second theorem.
\end{thm}
\begin{rmk} % Multiple remarks
Multiple remarks follow, and this is the first.
\end{rmk}
\begin{rmk}
Since there are multiple remarks made, all of them are numbered.
\end{rmk}
\begin{rmk}
The style is Remark 2.1., 2.2., and 2.3., etc.
\end{rmk}
\begin{thm}
bla
\end{thm}
\begin{rmk}
more bla
\end{rmk}
\end{document}
Não é muito difícil definir uma chave que tenha o mesmo efeito.
\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\makeatletter
\define@key{thmdef}{uniquewithparent}{%
\setkeys{thmdef}{parent=#1}
\RequirePackage[unq]{unique}
\addtotheorempreheadhook[\thmt@envname]{%
\setuniqmark{\thmt@envname.\csname the#1\endcsname}%
\ifuniq{\thmt@envname.\csname the#1\endcsname}
{\@xa\def\csname the\thmt@envname\endcsname{\csname the#1\endcsname}}
{}%
}
}
\makeatother
\newtheorem{thm}{Theorem}
\declaretheorem[uniquewithparent=section]{lemma}
\theoremstyle{remark}
\declaretheorem[name=Remark,uniquewithparent=thm]{rmk}
\begin{document}
\section{A section}
\begin{lemma}
Some text.
\end{lemma}
\begin{thm}
This is a theorem.
\end{thm}
\begin{rmk} % only one remark made
This is the only remark, so number it the same as the previous theorem.
What I want is Remark 1., instead of Remark. or Remark 1.1.
\end{rmk}
\begin{thm}
This is the second theorem.
\end{thm}
\begin{rmk} % Multiple remarks
Multiple remarks follow, and this is the first.
\end{rmk}
\begin{rmk}
Since there are multiple remarks made, all of them are numbered.
\end{rmk}
\section{Another section}
\begin{lemma}
More text.
\end{lemma}
\begin{lemma}
Even more text.
\end{lemma}
\end{document}
Responder2
Com expl3
podemos armazenar o número de observações seguindo um teorema em uma lista de propriedades (valores adicionais serão sobrescritos, obtendo assim o máximo).
Ao final da execução, esses valores são gravados no arquivo aux no formato
\rmklist{1=1,2=3,1=1,}
(valores do exemplo), para que no início da próxima execução possamos preencher outra lista de propriedades que será usada para a verificação. Se o número armazenado for maior que 1, .\arabic{rmk}
será usado.
\documentclass{article}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\theoremstyle{remark}
\newtheorem{rmk}{Remark}[thm]
\renewcommand{\thermk}{\thethm\checkrmk}
\ExplSyntaxOn
% populate the property list for the checks
\NewDocumentCommand{\rmklist}{m}
{
\prop_gset_from_keyval:Nn \g_dustrain_rmk_in_prop { #1 }
}
% check whether the number of remarks is > 1
\NewExpandableDocumentCommand{\checkrmk}{}
{
\__dustrain_rmk_check:e { \arabic{thm} }
}
% at end of rmk, store the last value of rmk
\AddToHook{env/rmk/after}
{
\prop_gput:Nee \g_dustrain_rmk_out_prop { \arabic{thm} } { \arabic{rmk} }
}
% at end document, write down the values in the aux file
\AtEndDocument
{
\iow_now:ce { @auxout }
{
\rmklist { \prop_map_function:NN \g_dustrain_rmk_out_prop \__dustrain_rmk_write:nn }
}
}
% variables
\prop_new:N \g_dustrain_rmk_out_prop
\prop_new:N \g_dustrain_rmk_in_prop
% internal functions
\cs_new:Nn \__dustrain_rmk_write:nn { #1=#2, }
\cs_new:Nn \__dustrain_rmk_check:n
{
\int_compare:nT { 0\prop_item:Nn \g_dustrain_rmk_in_prop { #1 } > 1 } { .\arabic{rmk} }
}
\cs_generate_variant:Nn \__dustrain_rmk_check:n { e }
\ExplSyntaxOff
\begin{document}
\begin{thm}
This is a theorem.
\end{thm}
\begin{rmk} % only one remark made
This is the only remark, so number it the same as the previous theorem.
What I want is Remark 1., instead of Remark. or Remark 1.1.
\end{rmk}
\begin{thm}
This is the second theorem.
\end{thm}
\begin{rmk} % Multiple remarks
Multiple remarks follow, and this is the first.
\end{rmk}
\begin{rmk}
Since there are multiple remarks made, all of them are numbered.
\end{rmk}
\begin{rmk}
The style is Remark 2.1., 2.2., and 2.3., etc.
\end{rmk}
\begin{thm}
bla
\end{thm}
\begin{rmk}
more bla
\end{rmk}
\end{document}