2

enter image description here Dear all I have a problem when \label and \ref as it is in this minimal example please help me

    \documentclass[12pt,a4paper,openany]{book}
%-------------------------------------------------------
\usepackage{hyperref}

\hypersetup{% bookmarks=true,
    unicode=true,
    colorlinks=true,
    citecolor=green, %black,
    filecolor=black,
    linkcolor=blue, 
    urlcolor=cyan, 
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{titlesec}
\usepackage{titletoc}

%%%%%%%%%%%%%%%%%%%



\newtheorem{theorem}{مبرهنة}[section]

\usepackage{tcolorbox}

\tcbuselibrary{theorems}
\newtcbtheorem
  [number within= section]% init options
  {definition}% name
  {تعريف}
  % title
  {%
    colback=green!5,
    colframe=green!35!black,
    fonttitle=\bfseries,
  }% options
{def}% prefix



%-------------------------------------------------------
\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.1,AutoFakeSlant=-0.03]{Amiri}
\setsansfont[Script=Arabic,Scale=1.1]{Amiri}
%-------------------------------------------------------


\begin{document}
\section{1}
\begin{definition}{}{}\label{1}
نسمي
\end{definition}

من
\ref{1}
\section{2}
\begin{theorem}\label{2}
ليكن 
\end{theorem}

\ref{2}
\end{document}
1

Theorems and similar environment in tcolorbox have two parameters, the first one is the theorem title and the second is the label suffix which will be added to the label prefix declares as fourth mandatory parameter in tcbtheorem declaration.

In \newtcbtheorem[number within=section]{theorem}{Theorem}{}{theo}

theo is the preffix so, when you declare

\begin{theorem}{theorem name}{2}
...
\end{theorem}

label theo-2 is created and you can use \ref{theo-2} to make a reference to this theorem. Similar behaviour with definition. You don't need an external \label command.

\documentclass[12pt,a4paper,openany]{book}
%-------------------------------------------------------
\usepackage{hyperref}

\hypersetup{% bookmarks=true,
    unicode=true,
    colorlinks=true,
    citecolor=green, %black,
    filecolor=black,
    linkcolor=blue, 
    urlcolor=cyan, 
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{titlesec}
\usepackage{titletoc}

%%%%%%%%%%%%%%%%%%%



%\newtheorem{theorem}{مبرهنة}[section]

\usepackage[most]{tcolorbox}

\tcbuselibrary{theorems}

\newtcbtheorem[number within=section]{theorem}{Theorem}{}{theo}

\newtcbtheorem
  [number within= section]% init options
  {definition}% name
  {Name}
  % title
  {%
    colback=green!5,
    colframe=green!35!black,
    fonttitle=\bfseries,
  }% options
{def}% prefix



%-------------------------------------------------------
%\usepackage{polyglossia}
%\setmainlanguage[numerals=maghrib]{arabic}
%\setotherlanguage{english}
%\newfontfamily\arabicfont[Script=Arabic,Scale=1.1,AutoFakeSlant=-0.03]{Amiri}
%\setsansfont[Script=Arabic,Scale=1.1]{Amiri}
%-------------------------------------------------------


\begin{document}
\section{1}
\begin{definition}{Definition name}{1}
نسمي
\end{definition}

من
\ref{def:1}
\section{2}
\begin{theorem}{theorem name}{2}
ليكن 
\end{theorem}

\ref{theo:2}
\end{document}

enter image description here

1
  • thank you very much – Nora Nour Feb 22 at 12: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.