2

I am currently using Document > Settings > Modules > Theorems (Numbered by Type within Sections) in Lyx.

However, I need my theorems/definitions to be numbered according to subsection instead. i.e.

2 Introduction

2.1 Subsection ...

Definition 2.1.1

Theorem 2.1.2

2.2 Subsection 2

Theorem 2.2.1

Additionally, I also want the text after the labels to be in a new line (instead of continuing after the bold text), i.e.

Definition 2.2.2

The definition of formula is...

I would also like to state that I am rather new to lyx so I am not familiar with editing TeX code (if required) in the editor so detailed steps would really be appreciated.

Thank you!

Edit 1: MWE (I removed mostly font related code)

% Preview source code

#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 508
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\begin_modules
theorems-ams-bytype
theorems-sec-bytype
\end_modules
\maintain_unincluded_children false
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\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
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\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 Standard
\noindent
\begin_inset CommandInset toc
LatexCommand tableofcontents

\end_inset


\end_layout

\begin_layout Standard
\paragraph_spacing onehalf
\noindent
\begin_inset Newpage newpage
\end_inset


\end_layout

\begin_layout Section
\paragraph_spacing onehalf
\noindent
Title
\series bold
 1
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
numberwithin{equation}{section}
\end_layout

\end_inset


\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
setlength{
\backslash
parindent}{1.5pt}
\end_layout

\end_inset


\end_layout

\begin_layout Section
\paragraph_spacing onehalf
\noindent
Title 2
\end_layout

\begin_layout Subsection
\paragraph_spacing onehalf
\noindent
Sub 1
\end_layout

\begin_layout Subsection
\paragraph_spacing onehalf
\noindent
Sub 2
\end_layout

\begin_layout Definition
\noindent
My first definition
\end_layout

\end_body
\end_document
1

I do not know whether it's possible from within LyX, but here is what you have to add to you preamble to obtain it:

\newtheoremstyle{break}%
{5pt}{4pt}% spaces added before and after the environment
{\itshape}{}%
{\bfseries}{}% % Note that final punctuation is omitted.
{\newline}{}
\theoremstyle{break}
\newtheorem{theorem}{Theorem}[subsection]

\newtheoremstyle{defbreak}%
{5pt}{4pt}% spaces added before and after the environment
{\upshape}{}%
{\bfseries}{}% % Note that final punctuation is omitted.
{\newline}{}
\theoremstyle{defbreak}
\newtheorem{defn}{Definition}[subsection]

enter image description here

Here is the full code (slightly modified):

\documentclass{article}
\usepackage{amsthm}
\usepackage{lipsum}

\newtheoremstyle{break}%
{5pt}{4pt}% spaces added before and after the environment
{\itshape}{}%
{\bfseries}{}% % Note that final punctuation is omitted.
{\newline}{}
\theoremstyle{break}
\newtheorem{thm}{Theorem}[subsection]

\newtheoremstyle{defbreak}%
{5pt}{4pt}% spaces added before and after the environment
{\upshape}{}%
{\bfseries}{}% % Note that final punctuation is omitted.
{\newline}{}
\theoremstyle{defbreak}
\newtheorem{Def}{Definition}[subsection]

\begin{document}

\section{Introduction}
\subsection{A first subsection}
\lipsum[3]

\begin{thm}
  A silly test theorem. A silly test theorem. A silly test theorem. A silly test theorem. A silly test theorem.
\end{thm}

\lipsum[4]
\begin{Def}
 This is a \texttt{defbreak} style example. Some text. Some more text. Some more text. Some more text.
\end{Def}
\lipsum[5]

\end{document}
  • Received two errors: 1) Latex Error: Command \defn already defined 2) Latex Error: Missing \begin {Document} – Kasit Mar 7 '17 at 10:52
  • 1) Maybe internally, LyX has a \defncommand (or a defn environment). Change it to something else that isn't defined,You may try Def. 2) I posted only what has to be added to the preamble, not a full compilable code. If you want, I can post the full code of my test file. – Bernard Mar 7 '17 at 11:01
  • I added the code you posted to my latex preamble and got those errors. Does the source code I posted above in the original comment help in identifying what should be added to the preamble instead? I have a feeling the AMS modules defines a definition format and I cannot just add a preamble to overwrite it. – Kasit Mar 7 '17 at 11:04
  • As I said, I do not know Lyx. What I can say is is works as a pure LaTeX code. From what you posted (which sems to be specific to LyX=, I'm not sure Lyx loads the amsthm package. Try adding this package. – Bernard Mar 7 '17 at 11:13
1

A good solution would require make your own module, but a poor's man solution could be:

1) Not load any module.

2) Insert this in Document > Stetings... > LaTeX Preamble

\usepackage{amsthm}
\newtheoremstyle{xxx}{}{}{\itshape}{}{\scshape\bfseries}{:}%
{\newline}{\thmname{#1}\thmnumber{ #2}\thmnote{(#3)}\smallskip}%
\theoremstyle{xxx}
\newtheorem{xxx}{\protect\theoremname}[subsection]
\providecommand{\theoremname}{Smart theorem}

3) Make your your theorem with \begin{xxx} ... \end{xxx} in a ERT box (Ctrl+L) or alternatively make two ERT boxes for \begin{xxx} and \end{xxx} respectively and left the theorem text as a normal paragraph.

The result must be equivalent to this LaTeX source code:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{amsthm}
\newtheoremstyle{xxx}{}{}{\itshape}{}{\scshape\bfseries}{:}%
{\newline}{\thmname{#1}\thmnumber{ #2}\thmnote{(#3)}\smallskip}
\theoremstyle{xxx}
\newtheorem{xxx}{\protect\theoremname}[subsection]
\providecommand{\theoremname}{Smart theorem}
\begin{document}
\section{xxx}
Bla bla bla ...
\subsection{adasd}
\begin{xxx}
Bla bla bla ...
\end{xxx}
Bla bla bla ...
\end{document}

Obviously, you can change the style xxx to some name more meaningful, as well as the arguments of \newtheoremstyle to fit more to your desired layout. Run texdoc amsmath for information about the arguments.

  • Opps, I do not see that Bernard already showed the same solution. I left because is more LyX-new use oriented, though. – Fran Mar 7 '17 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.