Open mbertucci47 opened 10 months ago
Using name=
as the default value of optional argument of \thmt@splitrestateargs
seems to work. Need more tests.
\documentclass{article}
\usepackage{amsthm,thmtools,kantlipsum}
\declaretheorem{theorem}
\makeatletter
\renewcommand\thmt@splitrestateargs[1][name=]{%
\g@addto@macro\thmt@storedoptargs{,#1}%
\def\tmp@a##1\@{\def\thmt@storename{##1}}%
\tmp@a
}
\makeatother
\begin{document}
% \begin{theorem}[restate={[name=]foo}]
\begin{theorem}[restate={foo}]
\kant[1][2]
\end{theorem}
\foo*
\begin{theorem}[restate=foobar,name=Heading]
\kant[2][1]
\end{theorem}
\foobar*
\end{document}
I think the restate={[name=]foo}
is a testing holdover, it should just say restate=foo
, right?
Good catch, again! Example now corrected.
Actually I think the comma in \thmt@storedoptargs{,#1}
is unnecessary. Trying \ShowCommand{\thmt@storedoptargs}
in a few places like
\documentclass{article}
\usepackage{amsthm,thmtools,kantlipsum}
\declaretheorem{theorem}
\makeatletter
\begin{document}
\begin{theorem}[restate=foo]
\kant[1][2]
\end{theorem}
\ShowCommand{\thmt@storedoptargs}
\foo*
\begin{theorem}[restate=foobar,name=Heading]
\kant[2][1]
\end{theorem}
\ShowCommand{\thmt@storedoptargs}
\foobar*
\begin{theorem}[restate=foobaraa,name=aaa,label=abc]
\ShowCommand{\thmt@storedoptargs}
\kant[2][1]
\end{theorem}
\end{document}
shows in the log things like
> \thmt@storedoptargs=macro:
->,.
<argument> \thmt@storedoptargs
and
> \thmt@storedoptargs=macro:
->,,name=Heading.
<argument> \thmt@storedoptargs
and
> \thmt@storedoptargs=macro:
->,,name=aaa,label=abc.
<argument> \thmt@storedoptargs
So it's putting an extra comma, which with no other keys is interpreted as a title. Just deleting the comma in the definition seems to fix it.
By the way, I noticed this syntax in only one other place, the definition of \thmt@define@thmuse@key
in thm-kv.sty
. Not sure if it matters there.
Partial findings: After
\begin{theorem}[restate={foo}]
\kant[1][2]
\end{theorem}
\foo*
will finally call \begin{theorem}[{,}] ... \end{theorem}
. And it's this intermediate form that caused the problem, see simplified example below.
To support old usage \begin{theorem}[<name>]
as well as the extended \begin{theorem}[name=<name>]
, thmtools
tries to distinguish valid key-value (like name=<name>
) list between invalid (like New name
). The latter is then treated as <name>
as a whole. See \thmt@garbleoptarg
. The problem here is that valid but meaningless key-value lists like ,
and ,
(or any combination of comma and space) are wrongly treated as invalid, hence used as theorem name.
\documentclass{article}
\usepackage{amsthm,thmtools,kantlipsum}
\declaretheorem{theorem}
\begin{document}
\begin{theorem}[{,}]
content
\end{theorem}
\begin{theorem}[{, }]
content
\end{theorem}
\begin{theorem}[{name=New name}]
content
\end{theorem}
\begin{theorem}[{,name=New name,name=New name 2,,,,}]
content
\end{theorem}
\end{document}
Not sure if kvsetkeys
, the underneath key-value parser package has such a user interface. If not, then adding two guarding key-value pairs like \begin{theorem}[@kv=on,<normal kv-list>,@kv=off]
can be a guaranteed, though slow solution.
Yes I suppose this is a broader issue than the one I reported. However, in this specific case, doesn't removing the comma in \g@addto@macro\thmt@storedoptargs{,#1}%
fix the issue without causing any harm?
Just not general enough. (We still have to add words to inform users why the innocent \begin{theorem}[,]
will give unexpected output.) If possible I would avoid doing so. But as my previous comment started with "partial findings", right now I don't have enough info to answer the question "if it's possible to solve the general form, lightly?".
If
restate
is given to a theorem with noname
key, then the restated theorem has(,)
in the title. If aname
is given, then there is no issue.