1

This is a follow-up to this question and this one. Basically, I would like to avoid the sequence ([...]) in theorem's optional arguments, as shown below:

To obtain this result, as suggested by this answer, I used the \patchcmd macro of the etoolbox package. However, I have to switch from \patchcmd{\thmhead}{(#3)}{#3}{}{} to \patchcmd{\thmhead}{#3}{(#3)}{}{} on every change, which is not very convenient for a large book with many theorems. Thus I was wondering whether a single command would be possible. Note that I am using the two forms \cite{} and \cite[]{}, which makes things a bit more complex.

\documentclass[10pt]{article}

\usepackage[]{amsmath, amssymb, amsthm}
\newtheorem{theorem}{Theorem}[section] \usepackage{etoolbox}% http://ctan.org/pkg/etoolbox

\begin{document}

\section{Pythagoras' theorem}

\noindent Correct versions:

\begin{theorem}[Pythagoras] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[Pythagoras, \cite{Pythagoras}] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[Pythagoras, {\cite[p.\ 345]{Pythagoras}}] $a^2 + b^2 = c^2$. \end{theorem}

\patchcmd{\thmhead}{(#3)}{#3}{}{}

\begin{theorem}[\cite{Pythagoras}] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[{\cite[p.\ 21]{Pythagoras}}] $a^2 + b^2 = c^2$. \end{theorem}

\noindent To be avoided:

\patchcmd{\thmhead}{#3}{(#3)}{}{}

\begin{theorem}[\cite{Pythagoras}] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[{\cite[p.\ 21]{Pythagoras}}] $a^2 + b^2 = c^2$. \end{theorem}

\begin{thebibliography}{HD}

\bibitem[1]{Pythagoras} Pythagoras' theorem.

\end{thebibliography}

\end{document}

J.-E. Pin
  • 619
  • 2
    Why not just have the citation as the first thing within the theorem? This also has the added benefit of not having a strange bold full stop after non-bold text. – oliversm Sep 09 '20 at 10:39
  • 1
    @oliversm one reason to use the optional argument is that it is printed in the List of Theorems (\listoftheorems). – Marijn Sep 09 '20 at 14:49
  • And why not a \footcite? – Bernard Sep 09 '20 at 15:15
  • @Marijn, Having something like a named theorem in the list of theorems is useful, but having a naked numeric citation I can't imagine being desirable in the list of theorems. – oliversm Sep 09 '20 at 15:17
  • @oliversm Isn't the bold full stop the default behaviour of the optional argument (See Theorem 1.1) ? Anyway, your comment is not relevant to my question. – J.-E. Pin Sep 09 '20 at 15:56

2 Answers2

1

You can match the argument against a regular expression that represents \cite followed by zero or one occurrence of [...] and by {...}.

\documentclass[10pt]{article}

\usepackage[]{amsmath, amssymb, amsthm}

% see https://tex.stackexchange.com/a/17555/4427 for the parameters \newtheoremstyle{jepinplain} {\topsep} % ABOVESPACE {\topsep} % BELOWSPACE {\itshape} % BODYFONT {0pt} % INDENT (empty value is the same as 0pt) {\bfseries} % HEADFONT {.} % HEADPUNCT {5pt plus 1pt minus 1pt} % HEADSPACE {\thmname{#1}\thmnumber{ #2}\thmnote{{\normalfont\ \checkcite{#3}}}} % CUSTOM-HEAD-SPEC

\ExplSyntaxOn \NewDocumentCommand{\checkcite}{m} { \regex_match:nnTF {\A \c{cite}(?:[[^]]])?{.} \Z} { #1 } {% only \cite #1 } { (#1) } } \ExplSyntaxOff

\theoremstyle{jepinplain} \newtheorem{theorem}{Theorem}[section]

\begin{document}

\section{Pythagoras' theorem}

\noindent Correct versions:

\begin{theorem} $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[Pythagoras] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[Pythagoras, \cite{Pythagoras}] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[Pythagoras, {\cite[p.\ 345]{Pythagoras}}] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[\cite{Pythagoras}] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[{\cite[p.\ 21]{Pythagoras}}] $a^2 + b^2 = c^2$. \end{theorem}

\begin{thebibliography}{1}

\bibitem[1]{Pythagoras} Pythagoras' theorem.

\end{thebibliography}

\end{document}

A new theorem style is better, unless you want to modify the standard \thmhead command.

enter image description here

egreg
  • 1,121,712
0

This question is a little old now, but I was addressing the same issue so thought I'd post how I did it. It would be nice to somehow be able to just flag whether parentheses should be added or not, but I worked around it manually.

Solution 0:

Leave the amendment in place permanently, and add your own parentheses.

\patchcmd{\thmhead}{(#3)}{#3}{}{}

\begin{theorem}[(Pythagoras)] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[(Pythagoras, \cite{Pythagoras})] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[\cite{Pythagoras}] $a^2 + b^2 = c^2$. \end{theorem}

Of course, this loses part of the benefit of LaTeX macros, that you can redefine an appearance in one place and have it apply everywhere -- if you suddenly decide to bracket the theorem notes some other way, you'd have to go through and manually change them all. So a tiny improvement is:

Solution 1:

Define a macro.

\patchcmd{\thmhead}{(#3)}{#3}{}{}
\newcommand{\notewrap}[1]{(#1)}

\begin{theorem}[\notewrap{Pythagoras}] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[\notewrap{Pythagoras, \cite{Pythagoras}}] $a^2 + b^2 = c^2$. \end{theorem}

\begin{theorem}[\cite{Pythagoras}] $a^2 + b^2 = c^2$. \end{theorem}