Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using LyX and want to have an end mark for examples, definitions and theorems within chapters like this:

Theorem 1.1   Statement...... 
Definition 1.1   Statement...... 
Example 1.1   Statement...... 
Example 1.2   Statement...... 
Definition 1.2   Statement...... 

My LaTex preamble in LyX is:

\documentclass[12pt,oneside,english]{book}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{geometry}
\geometry{verbose,tmargin=4cm,bmargin=4cm,lmargin=4cm,rmargin=2cm}
\pagestyle{plain}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parindent}{40bp}
\usepackage{color}
\usepackage{babel}
\usepackage{array}
\usepackage{bm}
\usepackage{multirow}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{setspace}
\usepackage[authoryear]{natbib}
\doublespacing
\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=true]
 {hyperref}
\hypersetup{
 linkcolor=black,citecolor=black,urlcolor=blue,filecolor=blue,pdfpagelayout=OneColumn,pdfnewwindow=true,pdfstartview=XYZ,plainpages=false,pdfpagelabels,citecolor=blue,linkcolor=blue}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
  \theoremstyle{definition}
  \ifx\thechapter\undefined
    \newtheorem{example}{\protect\examplename}
  \else
    \newtheorem{example}{\protect\examplename}[chapter]
  \fi
  \theoremstyle{plain}
  \ifx\thechapter\undefined
    \newtheorem{fact}{\protect\factname}
  \else
    \newtheorem{fact}{\protect\factname}[chapter]
  \fi
  \theoremstyle{definition}
  \ifx\thechapter\undefined
    \newtheorem{defn}{\protect\definitionname}
  \else
    \newtheorem{defn}{\protect\definitionname}[chapter]
  \fi
  \theoremstyle{plain}
  \ifx\thechapter\undefined
    \newtheorem{thm}{\protect\theoremname}
  \else
    \newtheorem{thm}{\protect\theoremname}[chapter]
  \fi

\@ifundefined{date}{}{\date{}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=3cm,rmargin=3cm}
\usepackage{babel}

\usepackage{hyperref}
\hypersetup{colorlinks=true,citecolor=blue, linkcolor=blue}
\usepackage{graphicx,epstopdf}
\usepackage{amsmath}
\usepackage[toc,page]{appendix}
\usepackage{bm}

\usepackage{tocloft,calc}
\renewcommand{\cftchappresnum}{Chapter } \AtBeginDocument{\addtolength\cftchapnumwidth{\widthof{\bfseries Chapter }}} 


\setlength{\cftafterloftitleskip}{12pt}  % list of figures
\setlength{\cftafterlottitleskip}{12pt}  % list of tables
\setlength{\cftaftertoctitleskip}{12pt}  % table of contents

\usepackage{titlesec}
\titlespacing*{\chapter}{0pt}{-50pt}{20pt}
\titleformat{\chapter}[display]{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}


\usepackage{tikz}
 \usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning}

\usepackage{enumerate}

\usepackage[format=plain,labelfont=bf,up,textfont=it,up]{caption}

\usepackage{amssymb}
\usepackage{thmtools}
\declaretheorem[style=definition,qed=$\blacksquare$,numberwithin=chapter]{definition}

\makeatother

  \providecommand{\definitionname}{Definition}
  \providecommand{\examplename}{Example}
  \providecommand{\factname}{Fact}
\providecommand{\theoremname}{Theorem}

\begin{document}
Text

\end{document}

I would highly appreciate your help to figure out this problem. Thanks

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Taking some guidance from Denoting the end of example/remark, use the following definitions for your theorem-like environments:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
  \theoremstyle{definition}
  \ifx\thechapter\undefined
    \newtheorem{examplex}{\protect\examplename}
  \else
    \newtheorem{examplex}{\protect\examplename}[chapter]
  \fi
  \newenvironment{example}
    {\pushQED{\qed}\renewcommand{\qedsymbol}{$\triangle$}\examplex}
    {\popQED\endexamplex}
  \theoremstyle{plain}
  \ifx\thechapter\undefined
    \newtheorem{factx}{\protect\factname}
  \else
    \newtheorem{factx}{\protect\factname}[chapter]
  \fi
  \newenvironment{fact}
    {\pushQED{\qed}\renewcommand{\qedsymbol}{$\blacksquare$}\factx}
    {\popQED\endfactx}
  \theoremstyle{definition}
  \ifx\thechapter\undefined
    \newtheorem{defnx}{\protect\definitionname}
  \else
    \newtheorem{defnx}{\protect\definitionname}[chapter]
  \fi
  \newenvironment{defn}
    {\pushQED{\qed}\renewcommand{\qedsymbol}{$\Box$}\defnx}
    {\popQED\enddefnx}
  \theoremstyle{plain}
  \ifx\thechapter\undefined
    \newtheorem{thmx}{\protect\theoremname}
  \else
    \newtheorem{thmx}{\protect\theoremname}[chapter]
  \fi
  \newenvironment{thm}
    {\pushQED{\qed}\renewcommand{\qedsymbol}{$\circ$}\thmx}
    {\popQED\endthmx}

Each theorem-like environment is defines using \newtheorem{<env>x} which defines the auxiliary environment <env>x, together with the main environment <env> which calls <env>x with appropriate QED-symbol (or end mark).

Using the above definitions, your end marks look like this:

enter image description here

\documentclass{book}
\usepackage{amsthm}% http://ctan.org/pkg/amsthm
\usepackage{amssymb}% http://ctan.org/pkg/amssymb

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\theoremstyle{definition}
\ifx\thechapter\undefined
  \newtheorem{examplex}{\protect\examplename}
\else
  \newtheorem{examplex}{\protect\examplename}[chapter]
\fi
\newenvironment{example}
  {\pushQED{\qed}\renewcommand{\qedsymbol}{$\triangle$}\examplex}
  {\popQED\endexamplex}
\theoremstyle{plain}
\ifx\thechapter\undefined
  \newtheorem{factx}{\protect\factname}
\else
  \newtheorem{factx}{\protect\factname}[chapter]
\fi
\newenvironment{fact}
  {\pushQED{\qed}\renewcommand{\qedsymbol}{$\blacksquare$}\factx}
  {\popQED\endfactx}
\theoremstyle{definition}
\ifx\thechapter\undefined
  \newtheorem{defnx}{\protect\definitionname}
\else
  \newtheorem{defnx}{\protect\definitionname}[chapter]
\fi
\newenvironment{defn}
  {\pushQED{\qed}\renewcommand{\qedsymbol}{$\Box$}\defnx}
  {\popQED\enddefnx}
\theoremstyle{plain}
\ifx\thechapter\undefined
  \newtheorem{thmx}{\protect\theoremname}
\else
  \newtheorem{thmx}{\protect\theoremname}[chapter]
\fi
\newenvironment{thm}
  {\pushQED{\qed}\renewcommand{\qedsymbol}{$\circ$}\thmx}
  {\popQED\endthmx}

\providecommand{\definitionname}{Definition}
\providecommand{\examplename}{Example}
\providecommand{\factname}{Fact}
\providecommand{\theoremname}{Theorem}

\begin{document}

\begin{example}Here is an example.\popQED\end{example}
\begin{fact}Here is a fact.\end{fact}
\begin{defn}Here is a definition.\end{defn}
\begin{thm}Here is a theorem.\end{thm}

\end{document}

Specific to LyX (2.0.4), set the document class to book:

enter image description here

followed by the inclusion of everything before \begin{document} in the LaTeX preamble:

enter image description here

Then, your LyX document:

enter image description here


On a completely different note: You need to clean up your LaTeX preamble... You're loading a number of packages more than once: fontenc, geometry, hyperref, ... This is just not necessary.

share|improve this answer
    
Thanks a lot for your helpful answer. Much appreciated. Thanks again. –  MYaseen208 Jun 26 '12 at 5:42
    
Your given code works fine in LaTex but when I try this LyX I got error. Would you mind to elaborate your code for LyX too. Thanks –  MYaseen208 Aug 9 '12 at 4:40
    
It gives me this error '\defn already defined latex error' in LyX –  MYaseen208 Aug 9 '12 at 4:52
    
@MYaseen208: I've added some LyX images showing the input. If you have \defn already defined as an error, it must be from some other package that you're using. Perhaps just change the environment defn I defined to something like defntn so it is unique. –  Werner Aug 9 '12 at 5:15
    
Thanks @Werner for your help. Much appreciated. Thanks again. –  MYaseen208 Aug 9 '12 at 5:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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