For example, if I use amsbook document class and have the section Problems, how to include problem environments created like:

\documentclass[a4paper,12pt, reqno, oneside]{amsbook}
\usepackage{hyperref}

\begin{document}
\frontmatter
\setcounter{tocdepth}{4}
\tableofcontents
\mainmatter
\section{Problems}
\begin{problem}
\end{problem}
\end{document}


The chapters and sections appear in ToC and are clickable too. I want it for other environments, too.

How can I do that?

Thanks :)

-
what do you mean by "this part" the whole problem? or do you intend there to be a title of some sort cf the sectionheads that normally go in the tabke of contents? –  David Carlisle Dec 21 '12 at 13:18
Not the whole problem of course, I want it like Problem 1...123 (page number) –  Vahid Dec 21 '12 at 13:23

Define the problem environment using an inner theorem-like environment and adding the entry to the TOC.

\documentclass{amsbook}
\usepackage{hyperref}

\newtheorem{problemx}{Problem}[section]
\newenvironment{problem}[1][]
{\expandafter\problemx\if\relax\detokenize{#1}\relax\else[#1]\fi
{\protect\tocsubsection{}{\theproblemx}{Problem\if\relax\detokenize{#1}\relax\else\ (#1)\fi}}%
}
{\endproblemx}

\setcounter{tocdepth}{2}% subsections in toc

\begin{document}

\frontmatter
\tableofcontents
\mainmatter
\chapter{Title}
\section{A}
\subsection{B}
text

\section{Problems}
\begin{problem}
What is $1+1$?
\end{problem}

\begin{problem}[Easy]
Show that every even number greater than $2$ is the sum of two prime numbers, not necessarily distinct.
\end{problem}

\end{document}


-

\documentclass[a4paper,12pt, reqno, oneside]{amsbook}
\usepackage{hyperref}

\makeatletter
\newtheorem{problem}{Problem}

\let\saved@begintheorem\@begintheorem
\def\@begintheorem #1#2[#3]{%
\saved@begintheorem{#1}{#2}[{#3}]%
\makeatother

\begin{document}
\frontmatter
\setcounter{tocdepth}{4}
\tableofcontents
\mainmatter
\section{Problems}

\begin{problem}[fermats last theorem]
$x^n+y^n=z^n$
\end{problem}
\end{document}

-
With this all theorem-like environments will be listed as problems in the TOC. –  egreg Dec 21 '12 at 14:30
@egreg, yes I know:-), I actually started to code it as in your answer with an inner environment but thought I'd keep it simpler to highlight the addcontentsline bit. It may be there are no other theorem environments, or you do want all such environments in the toc, in which case this is simpler, if you need individual control then your version is the way to go... –  David Carlisle Dec 21 '12 at 15:10