4

I am making a document containing only definitions, to do this I am using this code

\documentclass[12pt, a4paper, fleqn]{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Definition
\newcounter{defns}[section] \setcounter{defns}{0}
\renewcommand{\thedefns}{\arabic{section}.\arabic{defns}}
\newenvironment{defns}[2][]{%
\refstepcounter{defns}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Definition~\thedefns};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Definition~\thedefns:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=green!20,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
\label{#2}}{\qed\end{mdframed}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\tableofcontents
\newpage
\section{Definitions}
\begin{defns}[Ring]{defns:ring01}
Let $R$ be an Abelian group under addition in witch multiplication is...            
\end{defns}
 This is a reference to definition \ref{defns:ring01}

\end{document}

Everything is okay but instead of contents I need a clickable list of all the definitions.

Please help me how to do this?

1
  • Welcome to TeX.SX! The \setcounter{defns}{0} at the beginning is not necessary since \newcounter{defns} will set it to zero
    – user31729
    Commented Nov 27, 2015 at 16:01

1 Answer 1

4

\listof... commands can be defined with tocloft package and the \newlistof command in conjunction with \addcontentsline (which is the usual suspect ;-))

Explanation: Since the counter is named defns the \newlistof command is used to define this counter (with resetting counter section), a file extension, say .dfn and the heading name of the \list of definitions.

This defines a command \listofdefns (i.e. \listof.... with the suffix being the same like the counter name.

Add entries within the definitions environment with \addcontentsline{dfn}{section}{\protect\numberline{\thedefns}~#1}.

\newcommand{\listofdefinitionsname}{List of definitions}
\newlistof[section]{defns}{dfn}{\listofdefinitionsname}

Please note that the counter mustn't be defined before -- this is a design flaw of tocloft. It does not allow something like use counter from etc, unfortunately.

Here is the code:

\documentclass[12pt, a4paper, fleqn]{article}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tocloft}
\usepackage{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 % Definition
\newcommand{\listofdefinitionsname}{List of definitions}
\newlistof[section]{defns}{dfn}{\listofdefinitionsname}

\setcounter{defns}{0}
\renewcommand{\thedefns}{\arabic{section}.\arabic{defns}}
\newenvironment{defns}[2][]{%
 \refstepcounter{defns}%
 \addcontentsline{dfn}{section}{\protect\numberline{\thedefns}~#1} % Add it to the dfn file
 \ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Definition~\thedefns};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=green!20]
{\strut Definition~\thedefns:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=green!20,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
\label{#2}}{\qed\end{mdframed}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\tableofcontents
\clearpage
\listofdefns
\newpage
\section{Definitions}
\begin{defns}[Ring]{defns:ring01}
Let $R$ be an Abelian group under addition in witch multiplication is...            
\end{defns}
 This is a reference to definition \ref{defns:ring01}

\end{document}

Please note that the tcolorbox package provides similar features like mdframed and an automatic listof...

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .