# How to put Theorem Numbers in Boxes?

I'm using amsthm and amsbook. I was wondering how to put theorem numbers in rectangular boxes, both when they first appear as well as when citing them. Here is a picture of what it looks like now: and what it should look like: Here is a MWE of what I mean:

%% LyX 2.2.0dev created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[oneside,english,reqno]{amsbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{luainputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=1cm,bmargin=1cm,lmargin=1cm,rmargin=1cm}
\setcounter{secnumdepth}{5}
\usepackage{amsthm}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\swapnumbers
\theoremstyle{plain}
\newtheorem{thm}{\protect\theoremname}[section]
\theoremstyle{plain}
\newtheorem{claim}[thm]{\protect\claimname}
\theoremstyle{definition}
\newtheorem{defn}[thm]{\protect\definitionname}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
citecolor=blue, urlcolor=blue]{hyperref}
\usepackage{braket}
\usepackage{mathtools}
\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\DeclarePairedDelimiter\norm{\lVert}{\rVert}%
\let\oldnorm\norm
\def\norm{\@ifstar{\oldnorm}{\oldnorm*}}
\makeatother
\usepackage{amsfonts}
\usepackage{dsfont}
\renewcommand{\vec}[1]{\mathbf{#1}}
\usepackage[scaled=0.88]{beraserif}
\usepackage[scaled=0.85]{berasans}
\usepackage[scaled=0.84]{beramono}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage[T1,small,euler-digits]{eulervm}
\numberwithin{section}{chapter}
% remove theorem indentation
% -------------
\makeatletter
\let\sv@thm\@thm
\def\@thm{\let\indent\relax\sv@thm}
\makeatother
% -------------
\usepackage{etoolbox}
\expandafter\patchcmd\csname\string\proof\endcsname
{\normalparindent}{0pt }{}{}

\AtBeginDocument{
\def\labelitemii{$$\circ$$}
\def\labelitemiv{$$\star$$}
}

\makeatother

\usepackage{babel}
\providecommand{\claimname}{Claim}
\providecommand{\definitionname}{Definition}
\providecommand{\theoremname}{Theorem}

\begin{document}

\title{Title}
\maketitle

\chapter{First Chapter}

\section{First Section}

Here is some text. As it begins a paragraph, it starts indented. Bla
bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla
bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla.
Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla
bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla
bla. Bla bla bla. Bla bla bla. Bla bla bla. Bla bla bla.
\begin{claim}
\label{claim:Cool_Claim}Some Claim {[}some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words{]}
\begin{proof}
this is a proof
\end{proof}
\end{claim}
\begin{defn}
Some Definition
\end{defn}
This is now normal text again. As we learnt in \ref{claim:Cool_Claim}.
\end{document}

• I updated my answer with a simplification of the code using thmtools that might be of interest for you. – Gonzalo Medina Feb 26 '15 at 23:56

Below I show two possibilities: one using some customized theorem styles and the other one redefining the counters.

1. Using some customized theorem styles plainboxed and definitionboxed which basically place the number inside a \fbox; a new command \thref was also defined so the cross-references are also boxed (\swapnumbers shouldn't be used anymore):

\documentclass[oneside,english,reqno]{amsbook}
\usepackage{etoolbox}

\makeatletter
\newtheoremstyle{plainboxed}
{\thm@preskip}
{\thm@postskip}
{\itshape}
{0pt}
{\scshape}
{.}
{.5em}
{\smash{\fbox{\thmnumber{#2.}}}~\thmname{#1}\thmnote{~{\normalfont(#3)}}}
\newtheoremstyle{definitionboxed}
{\thm@preskip}
{\thm@postskip}
{\normalfont}
{0pt}
{\scshape}
{.}
{.5em}
{\smash{\fbox{\thmnumber{#2.}}}~\thmname{#1}\thmnote{~{\normalfont(#3)}}}%

\theoremstyle{plainboxed}
\newtheorem{thm}{\protect\theoremname}[section]
\newtheorem{claim}[thm]{\protect\claimname}

\theoremstyle{definitionboxed}
\newtheorem{defn}[thm]{\protect\definitionname}

\numberwithin{section}{chapter}

\makeatletter
\let\sv@thm\@thm
\def\@thm{\let\indent\relax\sv@thm}

\let\oldref\ref
\newcommand\thref[1]{\textup{\fbox{\ref{#1}}}}

\makeatother

\expandafter\patchcmd\csname\string\proof\endcsname
{\normalparindent}{0pt }{}{}
\makeatother

\providecommand{\claimname}{Claim}
\providecommand{\definitionname}{Definition}
\providecommand{\theoremname}{Theorem}

\begin{document}

\chapter{First Chapter}

\section{First Section}

\begin{claim}
\label{claim:Cool_Claim}Some Claim some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words
\begin{proof}
this is a proof
\end{proof}
\end{claim}
\begin{defn}
Some Definition
\end{defn}
This is now normal text again. As we learnt in \thref{claim:Cool_Claim}.
\end{document}


1. Redefining the counters; the code is shorter, but now the formatting of the numbers is not exactly the desired one (the final dot is outside the box):

\documentclass[oneside,english,reqno]{amsbook}
\usepackage{etoolbox}

\makeatletter
\swapnumbers
\theoremstyle{plain}
\newtheorem{thm}{\protect\theoremname}[section]
\newtheorem{claim}[thm]{\protect\claimname}

\theoremstyle{definition}
\newtheorem{defn}[thm]{\protect\definitionname}

\numberwithin{section}{chapter}

\let\theoldthm\thethm
\let\theoldclaim\theclaim
\let\theolddefn\thedefn
\renewcommand\thethm{\fbox{\theoldthm}}
\renewcommand\theclaim{\fbox{\theoldclaim}}
\renewcommand\thedefn{\fbox{\theolddefn}}

\makeatletter
\let\sv@thm\@thm
\def\@thm{\let\indent\relax\sv@thm}
\makeatother

\expandafter\patchcmd\csname\string\proof\endcsname
{\normalparindent}{0pt }{}{}
\makeatother

\providecommand{\claimname}{Claim}
\providecommand{\definitionname}{Definition}
\providecommand{\theoremname}{Theorem}

\begin{document}

\chapter{First Chapter}

\section{First Section}

\begin{claim}
\label{claim:Cool_Claim}Some Claim some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words
\begin{proof}
this is a proof
\end{proof}
\end{claim}
\begin{defn}
Some Definition
\end{defn}
This is now normal text again. As we learnt in \ref{claim:Cool_Claim}.
\end{document}


## Update

Using the thmtools package as front-end for amsthm, the code for the first approach simplifies:

\documentclass[oneside,english,reqno]{amsbook}
\usepackage{etoolbox}
\usepackage{thmtools}

\makeatletter
\providecommand{\claimname}{Claim}
\providecommand{\definitionname}{Definition}
\providecommand{\theoremname}{Theorem}

\declaretheoremstyle[
spaceabove=\thm@preskip,
spacebelow=\thm@postskip,
notefont=\mdseries,
notebraces={(}{)},
numberwithin=section,
bodyfont=\BodyFont,
]{boxed}
\def\BodyFont{\normalfont\itshape}
\declaretheorem[style=boxed,name=\theoremname]{thm}
\declaretheorem[style=boxed,name=\claimname]{claim}
\def\BodyFont{\normalfont}
\declaretheorem[style=boxed,name=\definitionname]{defn}

\numberwithin{section}{chapter}

\makeatletter
\let\sv@thm\@thm
\def\@thm{\let\indent\relax\sv@thm}

\let\oldref\ref
\newcommand\thref[1]{\textup{\fbox{\ref{#1}}}}

\expandafter\patchcmd\csname\string\proof\endcsname
{\normalparindent}{0pt }{}{}
\makeatother

\begin{document}

\chapter{First Chapter}

\section{First Section}

\begin{claim}
\label{claim:Cool_Claim}Some Claim some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words some words some words some
words some words some words some words
\begin{proof}
this is a proof
\end{proof}
\end{claim}
\begin{defn}
Some Definition
\end{defn}
This is now normal text again. As we learnt in \thref{claim:Cool_Claim}.
\end{document}


## Remark

As barbara beeton mentions in her comment, if the numbers are boxed, they don't really need to be ended with a period. Replacing \thmnumber{#2.} with \thmnumber{#2} in the first approach will supress the final period; therequired change in the thmtools approach would be to replace headformat=\smash{\fbox{\NUMBER.}}~\NAME\NOTE, with headformat=\smash{\fbox{\NUMBER}}~\NAME\NOTE

• seems to me that if the numbers are boxed, they don't need to be ended with a period. so \thmnumber{#2.} would reduce to \thmnumber{#2} in the first approach. – barbara beeton Feb 27 '15 at 14:51
• @barbarabeeton I agree with you, However, the OP's image shows the box and the final period so I decided to keep them. I've however added a remark to my answer about your comment. – Gonzalo Medina Feb 27 '15 at 17:44