TeX - LaTeX Asked on June 18, 2021
I am looking for an extension to the solved question in Avoid parentheses around optional header material in theorem environment for ams style?.
I would like to have optional header text for a theorem environment on some but not on all slides. Here is what I tried:
documentclass{beamer}
setbeamertemplate{theorems}[ams style]
newtheorem*{thm*}{Theorem}
begin{document}
begin{frame}
begin{thm*}[only<beamer:2->{additional information}]
My Theorem
end{thm*}
end{frame}
end{document}
In the above example, slide 2 looks as expected, but slide 1 prints Theorem ().
Is there a way to adapt the solution here to take the overlay into account?
EDIT
I have also tried
documentclass{beamer}
setbeamertemplate{theorems}[ams style]
newtheorem*{thm*}{Theorem}
begin{document}
begin{frame}
begin{thm*}only<beamer:2->{[additional information]}
My Theorem
end{thm*}
end{frame}
end{document}
which is worse; LaTeX does not see additional information
as optional header text, but as content of the environment itself.
EDIT 2
Like suggested below, I had considered deleting the parentheses from the command, then hard-coding them in each instance of an optional header of an environment. I would like to avoid doing that, since I may have many instances of such optional headers.
Workaround: remove the parenthesis with the solution from the other question, then add them manually in the theorem (together with a space).
documentclass{beamer}
setbeamertemplate{theorems}[ams style]
makeatletter
setbeamertemplate{theorem begin}
{%
begin{inserttheoremblockenv}
{%
inserttheoremheadfont%
inserttheoremname%
inserttheoremnumber%
ifxinserttheoremaddition@emptyelseinserttheoremadditionfi%
inserttheorempunctuation%
}%
}
makeatother
newtheorem*{thm*}{Theorem}
begin{document}
begin{frame}
begin{thm*}[only<beamer:2->{ (additional information)}]
My Theorem
end{thm*}
end{frame}
end{document}
Edit: you can also apply the parentheses automatically using some string manipulation with the xstring
package. However, this is probably less robust, so I would advise to use the manual solution above. But in case you want to try here a version using the following steps:
only
. If yes:inserttheoremaddition
. The text of the optional argument is the last syntax unit (here: {additional information}
)xstring
look inside syntax units{}
.MWE:
documentclass{beamer}
usepackage{xstring}
setbeamertemplate{theorems}[ams style]
makeatletter
setbeamertemplate{theorem begin}
{%
begin{inserttheoremblockenv}
{%
inserttheoremheadfont%
inserttheoremname%
inserttheoremnumber%
ifxinserttheoremaddition@emptyelse%
IfBeginWith{inserttheoremaddition}{only}{%
StrLen{inserttheoremaddition}[grouplen]%
StrChar{inserttheoremaddition}{grouplen}[myarg]%
exploregroups%
StrLen{myarg}[arglen]%
StrLeft{myarg}{arglen}[newarg]%
noexploregroups%
StrSubstitute{inserttheoremaddition}{myarg}{{ (newarg)}}%
}%
{ (inserttheoremaddition)}fi%
inserttheorempunctuation%
}%
}
makeatother
newtheorem*{thm*}{Theorem}
begin{document}
begin{frame}
begin{thm*}[only<beamer:2->{additional information}]
My Theorem
end{thm*}
begin{thm*}[Header]
My Theorem
end{thm*}
end{frame}
end{document}
Result:
Correct answer by Marijn on June 18, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP