# \swapnumbers drops chapter

I'm trying to use \swapnumbers to get the numbering of theorems etc first in amsbook, as detailed here: \swapnumbers in lyx

However, when I add \swapnumbers, it seems like the numbering scheme changes from "Theorem chapter.section.number" to "section.number Theorem". How can I make "chapter.section.number Theorem"?

Here's a MWE: In LyX code:


#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 479
\begin_document
\begin_header
\textclass amsbook
\begin_preamble
\usepackage[breaklinks,colorlinks=true,linkcolor=blue,
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}
\end_preamble
\options reqno
\use_default_options true
\begin_modules
theorems-ams
eqs-within-sections
figs-within-sections
theorems-sec
\end_modules
\maintain_unincluded_children false
\begin_local_layout
Preamble
\swapnumbers
EndPreamble
\end_local_layout
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_math auto
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder false
\pdf_colorlinks true
\pdf_backref false
\pdf_pdfusetitle true
\papersize a4paper
\use_geometry true
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 0
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 1cm
\topmargin 1cm
\rightmargin 1cm
\bottommargin 1cm
\secnumdepth 5
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\bullet 1 0 9 -1
\bullet 3 0 7 -1
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Title
Title
\end_layout

\begin_layout Chapter
First Chapter
\end_layout

\begin_layout Section
First Section
\end_layout

\begin_layout Standard
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.
\end_layout

\begin_layout 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]
\end_layout

\begin_layout Definition
Some Definition
\end_layout

\end_body
\end_document
%% 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{remark}
\newtheorem{claim}[thm]{\protect\claimname}
\theoremstyle{definition}
\newtheorem{defn}[thm]{\protect\definitionname}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage[breaklinks,colorlinks=true,linkcolor=blue,
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}

\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}
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{]}
\end{claim}
\begin{defn}
Some Definition
\end{defn}

\end{document}



and in generated LaTeX:


%% 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{remark}
\newtheorem{claim}[thm]{\protect\claimname}
\theoremstyle{definition}
\newtheorem{defn}[thm]{\protect\definitionname}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage[breaklinks,colorlinks=true,linkcolor=blue,
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}

\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}
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{]}
\end{claim}
\begin{defn}
Some Definition
\end{defn}

\end{document}


• Replace [section] by [chapter] on thm definition. – Sigur Feb 20 '15 at 22:53
• You mean \newtheorem{thm}{\protect\theoremname}[chapter]? It doesn't seem to work... – PPR Feb 20 '15 at 23:02
• you are right. Now I noticed you are using amsbook and it is not working. – Sigur Feb 20 '15 at 23:04
• since amsthm is built into amsbook, the former shouldn't be loaded explicitly, although that shouldn't make any difference here. i would expect to see \numberwithin{section}{chapter} to have the chapter number as part of a theorem number, and i don't see that. i'll test this out as soon as i get to somewhere with the facilities to do so. there are also some other really peculiar things here that appear to have been inserted by lyx. i don't use lyx, so can test only the latex code, but i'll check what i can. – barbara beeton Feb 21 '15 at 2:49

## 1 Answer

the "omission" of the chapter in the theorem numbering has nothing to do with \swapnumbers. the fact is, there is nothing in your code that says to include the chapter number in the theorem number.

how you add it depends on how you want your sections numbered.

if you want your sections to have a two-part number, then add the command

\numberwithin{section}{chapter}


in your preamble, and the three-part numbering of the theorems will follow automatically. if you want the section numbers to remain single-part, then modify the theorem numbers directly, after all the \newtheorem commands have been specified:

\let\theoldthm\thethm
\renewcommand{\thethm}{\thechapter.\theoldthm}


(again, this is in the preamble.)

i'm not a lyx user, so i don't know whether there is any special protocol for inserting latex definitions directly. however, the two approaches described above are the recommended ways to make this modification using amsthm; if this code is unacceptable for lyx, then you will have to ask the lyx maintainers how to do it.

• Dear Barbara, I tried your first suggestion and it works perfectly, in LyX (there's a way to add commands to the preamble). – PPR Feb 23 '15 at 21:19