# Theorem default names

I am trying to produce the following effect:

\begin{theorem}
\end{theorem}


creates

1.2 Theorem.

and

\begin{theorem}[Uniform Boundedness Principle]
\end{theorem}


creates

1.2 Uniform Boundedness Principle.

I have tried using a \IfValueTF but it does not produce the desired result:

\usepackage{amsthm}
\usepackage{xstring}

% Theorem styles
\newtheoremstyle{testtheorem}
{}
{}
{\itshape}
{}
{\bfseries}
{.}
{ }
{\thmnumber{#2}\IfValueTF{#3}{\thmname{ #1}}{\thmnote{ (#3)}}}

\theoremstyle{testtheorem}
\newtheorem{ttheorem}{Theorem}[section]

\begin{document}

\begin{ttheorem}
\end{ttheorem}
\begin{ttheorem}[Test]
\end{ttheorem}

\end{document}


Your approach is fine but the problem is that the amsthm package does not use the syntax from xparse. If no optional argument is given to a theorem environment then #3 is set to \relax rather than -NoValue-, so rather than using \IfValueTF you need to test for \relax.

Changing your MWE to do this it becomes:

\documentclass{article}
\usepackage{amsthm}
\usepackage{xparse}

% Theorem styles
\newtheoremstyle{testtheorem}
{}
{}
{\itshape}
{}
{\bfseries}
{.}
{ }
{\thmnumber{#2}\ifx#3\relax\relax\thmname{ #1}\else\thmnote{ #3}\fi}

\theoremstyle{testtheorem}
\newtheorem{ttheorem}{Theorem}[section]

\begin{document}

\begin{ttheorem}
\end{ttheorem}
\begin{ttheorem}[Test]
\end{ttheorem}

\end{document}


and you obtain the desired output:

The amsthm package uses \@ifempty for this purpose:

\documentclass{article}
\usepackage{amsthm}

% Theorem styles
\makeatletter
\newtheoremstyle{testtheorem}
{}
{}
{\itshape}
{}
{\bfseries}
{.}
{ }
{\thmnumber{#2}\@ifempty{#3}{\thmname{ #1}}{\thmnote{ (#3)}}}
\makeatother

\theoremstyle{testtheorem}
\newtheorem{ttheorem}{Theorem}[section]

\begin{document}

\begin{ttheorem}
\end{ttheorem}
\begin{ttheorem}[Test]
\end{ttheorem}

\end{document}