I cannot use \example
from any of the Theorems
modules because LaTeX says "Command \example already defined"
to the line \newtheorem{example}[thm]{\protect\examplename}
generated by Lyx. I am using Lyx 2.2.2 on Mac. Any ideas how to fix it?
[Tex/LaTex] Command \example already defined
amsthmlyxtheorems
Related Solutions
Add to the document preamble (Document --> Settings --> LaTeX preamble)
\newref{claim}{name=claim~}
and it will probably work. As mentioned by egreg in the comments, the refstyle
package is used, and you have to tell it what it should insert for labels starting with claim:
.
refstyle
also provides commands for start-of-sentence references (capital letter) and plural forms, and the words to insert in these cases can also be specified, e.g.
\newref{claim}{name=claim~,Name=Claim~,names=claims~,Names=Claims~}
I don't know, however, how to make LyX use these, other than through using an ERT, with e.g. \Claimref{claim:1}
. See the refstyle
documentation for details.
Example
Copy the following code to an empty file and save as a .lyx
file, e.g. example.lyx
. Open in LyX and compile. Screenshots of LyX view and PDF below.
#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass article
\begin_preamble
\newref{claim}{name=claim~}
\end_preamble
\use_default_options true
\begin_modules
theorems-bytype
theorems-sec-bytype
\end_modules
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\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
\papersize default
\use_geometry false
\use_amsmath 1
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\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 Section
Something
\end_layout
\begin_layout Claim
\begin_inset CommandInset label
LatexCommand label
name "claim:claim1"
\end_inset
I hereby claim that I don't use LyX.
\end_layout
\begin_layout Theorem
\begin_inset CommandInset label
LatexCommand label
name "thm:1"
\end_inset
LyX makes some things harder.
\end_layout
\begin_layout Standard
Inserting references:
\begin_inset CommandInset ref
LatexCommand formatted
reference "thm:1"
\end_inset
and
\begin_inset CommandInset ref
LatexCommand formatted
reference "claim:claim1"
\end_inset
.
\end_layout
\end_body
\end_document
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]
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}
Best Answer
If you're using the Paper (Standard Class) document class together with Theorems (AMS) module, the latter defines the
example
environment which conflicts with the document class (since it's already defined).Unfortunately it does not help placing any corrections in the Document > Settings... > LaTeX Preamble since the User specified LaTeX commands section (this contains whatever you place in the preamble) is only inserted after
To fix this, you have to address the module-specific definition via a Local Layout:
The only addition to this local layout (fix) is the insertion of
which removes any existing
example
environment definitions. This allows\newtheorem{example}
to function as expected, without having to change environments or mess with menu items.