目标是拥有一个可以根据触发器创建以下内容的环境:
假设1答案越好,分数越高。
或者那个
假设2a分数越高,与鞋码越呈正相关。
假设 2b较低的分数与鞋码呈负相关。
我尝试了在Google 群组,并且它有效。但是它会产生一些我不明白的错误消息。请参见下面的最小示例:
\documentclass{article}
\usepackage{ntheorem}
\newtheorem{hyp}{Hypothesis}
\newcounter{subhyp}
\newcommand{\subhyp}{
\setcounter{subhyp}{0}
\renewcommand\thehyp{\protect\stepcounter{subhyp}%
\arabic{hyp}\alph{subhyp}\protect\addtocounter{hyp}{-1}}
}
\newcommand{\normhyp}{
\renewcommand\thehyp{\arabic{hyp}}
\stepcounter{hyp}
}
\begin{document}
\normhyp
\begin{hyp}
The better the answer, the higher the score.
\end{hyp}
\subhyp
\begin{hyp}
Higher score is positive correlated with shoesize.
\end{hyp}
\begin{hyp}
Lower score is negative correlated with shoesize.
\end{hyp}
\end{document}
答案1
我会避免滥用\thehyp
:例如,如果你想获得一系列假设,你就会遇到麻烦。
hyp
我认为,最好的方法是将“子假设”封闭在一个可以改变计数器和一些相关事物的含义的环境中。
\documentclass{article}
\usepackage{ntheorem}
\newtheorem{hyp}{Hypothesis}
\makeatletter
\newcounter{subhyp}
\let\savedc@hyp\c@hyp
\newenvironment{subhyp}
{%
\setcounter{subhyp}{0}%
\stepcounter{hyp}%
\edef\saved@hyp{\thehyp}% Save the current value of hyp
\let\c@hyp\c@subhyp % Now hyp is subhyp
\renewcommand{\thehyp}{\saved@hyp\alph{hyp}}%
}
{}
\newcommand{\normhyp}{%
\let\c@hyp\savedc@hyp % revert to the old one
\renewcommand\thehyp{\arabic{hyp}}%
}
\makeatother
\begin{document}
\begin{hyp}
The better the answer, the higher the score.
\end{hyp}
\begin{subhyp}
\begin{hyp}
Higher score is positive correlated with shoesize.
\end{hyp}
\begin{hyp}
Lower score is negative correlated with shoesize.
\end{hyp}
\end{subhyp}
\begin{hyp}
Something
\end{hyp}
\begin{subhyp}
\begin{hyp}
Again
\end{hyp}
\begin{hyp}
And again
\end{hyp}
\end{subhyp}
\begin{hyp}
Will it work?
\end{hyp}
\end{document}
如果愿意,您仍然可以使用\subhyp
和\normhyp
,但最好利用 LaTeX 的群组结构。
答案2
如果你使用解决方案,你的代码就可以工作
\protect\addtocounter{subhyp}{1} instead of \stepcounter{subhyp}
另一方面,你可以利用\newtheorem
具有有趣的可选参数的命令的优势。基于 Mico 的示例使用:
\newtheorem{hyp}{Hypothesis}
\newtheorem{subhyp}{Hypothesis}[hyp]
完整代码如下:
\documentclass{article}
\usepackage{ntheorem}
\newtheorem{hyp}{Hypothesis}
\newtheorem{subhyp}{Hypothesis}[hyp]
\renewcommand\thesubhyp{\thehyp.\alph{subhyp}}
\begin{document}
\begin{hyp}
The better the answer, the higher the score.
\end{hyp}
%\stepcounter{hyp}
%\setcounter{subhyp}{0}
\begin{subhyp}
A higher score is positively correlated with shoesize.
\end{subhyp}
\begin{subhyp}
A lower score is negatively correlated with shoesize.
\end{subhyp}
\begin{hyp}
Pythagoras had something to say.
\end{hyp}
%\setcounter{subhyp}{0} % Don't execute \stepcounter{hyp} in this case.
\begin{subhyp}
Pythagoras contributed something to geometry.
\end{subhyp}
\begin{subhyp}
\emph{Pythagoras} wasn't a single person but a group of like-minded philophers and mathematicians.
\end{subhyp}
\end{document}
答案3
与您的代码相比,下面的 MWE 执行以下操作:
它定义了一个明确调用的环境
subhyp
。无需一直输入
\normhyp
和\subhyp
。相反,在开始一组子假设时,您需要输入\stepcounter{hyp}\setcounter{subhyp}{0}
如果子假设与前面的(主要)假设没有联系,或者
\setcounter{subhyp}{0}
子假设是否应该与前面的(主要)假设共享其主要反对意见。
\documentclass{article}
\usepackage{ntheorem}
\newtheorem{hyp}{Hypothesis}
\newtheorem{subhyp}{Hypothesis}
\renewcommand\thesubhyp{\thehyp\alph{subhyp}}
\begin{document}
\begin{hyp}
The better the answer, the higher the score.
\end{hyp}
\stepcounter{hyp}
\setcounter{subhyp}{0}
\begin{subhyp}
A higher score is positively correlated with shoesize.
\end{subhyp}
\begin{subhyp}
A lower score is negatively correlated with shoesize.
\end{subhyp}
\begin{hyp}
Pythagoras had something to say.
\end{hyp}
\setcounter{subhyp}{0} % Don't execute \stepcounter{hyp} in this case.
\begin{subhyp}
Pythagoras contributed something to geometry.
\end{subhyp}
\begin{subhyp}
\emph{Pythagoras} wasn't a single person but a group of like-minded philophers and mathematicians.
\end{subhyp}
\end{document}