2

I'm currently working on a book, and I want to create a list of examples. I tried lots of solutions available online, but none suited me well - see for example: https://texblog.org/2008/07/13/define-your-own-list-of/#comments My book is written in Arabic. Here is my MWE.

\documentclass[12pt,a4paper,openany]{book} ‎\usepackage{polyglossia}‎‎ ‎\usepackage[top=2cm,bottom=2cm‎, ‎left=3cm,right=2cm,headheight=17pt,includehead‎, ‎includefoot,heightrounded]{geometry}‎ ‎\usepackage{fancyhdr}‎ ‎\pagestyle{fancy}‎ ‎\fancyhf{}‎ ‎\fancyhead[RE,LO]{\thepage}‎ ‎\fancyhead[LE]{\small\leftmark}‎ ‎\fancyhead[RO]{\small\rightmark}‎‎ ‎\usepackage{natbib}‎ ‎\RequirePackage[linkcolor=black,bookmarksnumbered,pagebackref=true]{hyperref}‎‎ ‎\hypersetup{colorlinks,citecolor=purple,linkcolor=blue}‎ ‎\usepackage[titles]{tocloft}‎‎‎‎ ‎\usepackage{amsthm}‎‎ ‎\usepackage{dingbat}% for typing pencil with‎: ‎\smallpencil‎ ‎\theoremstyle{definition} ‎\newtheorem{definition}{تعریف}[chapter]‎ ‎\newtheorem{example}[definition]{\smallpencil‎ مثال} ‎‎ ‎\setmainlanguage{arabic}‎‎ ‎\setotherlanguage{english}‎‎ ‎\setmainfont[Scale=1.2]{Arial}%{Amiri}%{Traditional Arabic}‎‎ ‎\begin{document}‎‎ جميع حقوق النشر والنسخ، التصوير الليزري، الترجمة، الاقتباس و ... من هذا الكتاب محفوظة‏. إن نقل واقتباس الموضوعات مع الإرجاع لهذا الكتاب مسموح وبلا مانع.‎ ‎\tableofcontents\addtocontents{toc}{\linespread{1.25}\selectfont}%to change line spacing in table of contents‎ ‎\chapter{‏الفصل الأول}‎‎‎ \section{‎‏الاختبار الأول} ‎‏نص‎‎ ما أول \section{‎‏الاختبار الثاني} ‎‏نص‎‎ ما ثاني ‎\chapter{‏الفصل الثاني}‎‎‎ \section{‎‏الاختبار الأول} ‎‏نص‎‎ ما أول \section{‎‏الاختبار الثاني} ‏ ‎ما ثاني‎ نص‎‎ \begin{example} ‏ن‏ إنجاز الاختبار‎ ‎‎$‎H_0:\beta_1=0‎$‎‏‎ مقابل ‎$‎H_1:\beta_1\neq0‎$‎‏ عند المستوى ‎$‎‎\alpha‎=0.05‎$‎‏‎‏ باعتماد الإحصاء ‎‎‎‎يتم كما يلي ‎\end‎{example}‎ ‎\end{document} 

As I was advised by @mbert comments I edited the question a little bit. The final code I tried is this:

\documentclass[12pt,a4paper,openany]{book} ‎\usepackage{polyglossia}‎‎ ‎\usepackage[top=2cm,bottom=2cm‎, ‎left=3cm,right=2cm,headheight=17pt,includehead‎, ‎includefoot,heightrounded]{geometry}‎ ‎\usepackage{fancyhdr}‎ ‎\pagestyle{fancy}‎ ‎\fancyhf{}‎ ‎\fancyhead[RE,LO]{\thepage}‎ ‎\fancyhead[LE]{\small\leftmark}‎ ‎\fancyhead[RO]{\small\rightmark}‎‎ ‎\usepackage{natbib}‎ ‎\RequirePackage[linkcolor=black,bookmarksnumbered,pagebackref=true]{hyperref}‎‎ ‎\hypersetup{colorlinks,citecolor=purple,linkcolor=blue}‎ ‎\usepackage[titles]{tocloft}‎‎‎‎ ‎\usepackage{amsthm}‎‎ ‎\usepackage{dingbat}% for typing pencil with‎: ‎\smallpencil‎ ‎\theoremstyle{definition} ‎\newtheorem{definition}{تعریف}[chapter]‎ \newtheorem{example}[definition]{\smallpencil‎ مثال} ‎‎ \usepackage{thmtools} \declaretheorem[name=مثال]{example} \renewcommand{\listoftheoremname}{‏قائمة الأمثلة}%the Arabic of List of ‎examples‎ ‎\setmainlanguage{arabic}‎‎ ‎\setotherlanguage{english}‎‎ ‎\setmainfont[Scale=1.2]{Arial}%{Amiri}%{Traditional Arabic}‎‎ ‎\begin{document}‎‎ جميع حقوق النشر والنسخ، التصوير الليزري، الترجمة، الاقتباس و ... من هذا الكتاب محفوظة‏. إن نقل واقتباس الموضوعات مع الإرجاع لهذا الكتاب مسموح وبلا مانع.‎ ‎\tableofcontents\addtocontents{toc}{\linespread{1.25}\selectfont}%to change line spacing in table of contents‎ \begingroup \let\footnotemark\relax \listoftheorems[ignoreall,show={example}] \endgroup ‎\chapter{‏الفصل الأول}‎‎‎ \section{‎‏الاختبار الأول} ‎‏نص‎‎ ما أول \section{‎‏الاختبار الثاني} ‎‏نص‎‎ ما ثاني ‎\chapter{‏الفصل الثاني}‎‎‎ \section{‎‏الاختبار الأول} ‎‏نص‎‎ ما أول \section{‎‏الاختبار الثاني} ‏ ‎ما ثاني‎ نص‎‎ \begin{example} ‏ن‏ إنجاز الاختبار‎ ‎‎$‎H_0:\beta_1=0‎$‎‏‎ مقابل ‎$‎H_1:\beta_1\neq0‎$‎‏ عند المستوى ‎$‎‎\alpha‎=0.05‎$‎‏‎‏ باعتماد الإحصاء ‎‎‎‎يتم كما يلي ‎\end‎{example}‎ ‎\end{document} 

I got two errors and one problem. The first error says "LaTeX Error: Command \example already defined", but I need this " \newtheorem{example}[definition]{\smallpencil‎ مثال} ‎‎" to get section and chapter with small pencil‎ shape. The second error says " LaTeX Error: \listoftheoremname undefined." Now, concerning the resulted problem, the result is good as it prints chapter and section of examples, but the title is in English "List of theorems", instead of Arabic.

So, I re-frame my question. I need three things: 1- using \begin{example} ... \end{example}, which is also in the referenced link given by by @mbert. 2- I need to print the small pencil shape, and to print the Arabic title instead of "List of ‎Theorems" . enter image description here enter image description here

11
  • I'd like to keep using: \begin{example} ... \end{example} Commented Jun 15, 2024 at 20:30
  • Welcome! Does tex.stackexchange.com/a/388535 help? Off-topic: you are loading hyperref too late. Can you use a font everyone has? Arial is proprietary. A font from TeX Live is generally ideal. Commented Jun 15, 2024 at 20:58
  • See thmtools' \listoftheorems command. You can give it the options ignoreall,show=example to list only examples Commented Jun 15, 2024 at 21:20
  • @cfr Thanks for editing my question. Unfortunately, in the referenced link you posted they use \mycustomfiction{Your first example} to define new example. I really would like to keep using \begin{example} ... \end{example} environment. Also, I like to use \smallpencil‎ command. Concerning the Arabic font, could you use Amiri font or other Arabic font? Thanks for your contribution. Commented Jun 16, 2024 at 14:07
  • @mbert Thank you. In fact, I used that solution before, and it is not what I'm looking for. Commented Jun 16, 2024 at 14:13

1 Answer 1

2

Perhaps using \@starttoc command, and the titletoc and titlesec packages to assist with formatting.

screenshot of output

screenshot of output

the code

\documentclass{article} \usepackage{lipsum} \usepackage{titlesec} \usepackage{titletoc} \usepackage{hyperref} \hypersetup{ colorlinks=true, linkcolor=blue, } \contentsuse{shatitle}{new} % toc settings \titleclass{\shatitle}{straight}[\section] \titleformat{\shatitle}{}{}{}{} \titlecontents{shatitle}% <paragraph> [1cm]% <left> {\small\itshape}% <above-code> {}% <numbered-entry-format>; you could also use {\thecontentslabel. } to show the numbers {}% <numberless-entry-format> {\titlerule*[0.5em]{$\cdot$}\contentspage} \newcounter{example} \newenvironment{example}[1][]{% \refstepcounter{example}% \addcontentsline{new}{shatitle}{example \theexample: #1}% \textbf{Example \theexample~#1 }}{} \makeatletter \newcommand{\mylistofexamples}{\section*{my list of examples}\setcounter{tocdepth}{4}\@starttoc{new}} \begin{document} \mylistofexamples \begin{example}[optional title] \lipsum[1] \end{example} \begin{example}[another arg] \lipsum[2] \end{example} \end{document} 

example numbers within chapters

following the comment, you can use

\renewcommand{\theexample}{\arabic{chapter}.\arabic{example}} 

as in the following

\documentclass{book} \usepackage{lipsum} \usepackage{titlesec} \usepackage{titletoc} \usepackage{hyperref} \hypersetup{ colorlinks=true, linkcolor=blue, } \contentsuse{shatitle}{new} % toc settings \titleclass{\shatitle}{straight}[\section] \titleformat{\shatitle}{}{}{}{} \titlecontents{shatitle}% <paragraph> [1cm]% <left> {\small\itshape}% <above-code> {}% <numbered-entry-format>; you could also use {\thecontentslabel. } to show the numbers {}% <numberless-entry-format> {\titlerule*[0.5em]{$\cdot$}\contentspage} \newcounter{example} \renewcommand{\theexample}{\arabic{chapter}.\arabic{example}} \newenvironment{example}[1][]{% \refstepcounter{example}% \addcontentsline{new}{shatitle}{example \theexample: #1}% \textbf{Example \theexample~#1 }}{} \makeatletter \newcommand{\mylistofexamples}{\section*{my list of examples}\setcounter{tocdepth}{4}\@starttoc{new}} \begin{document} \mylistofexamples \chapter{my first chapter} \begin{example}[optional title] \lipsum[1] \end{example} \begin{example}[another arg] \lipsum[2] \end{example} \end{document} 
3
  • Thank you so much. Since I'm writing a book, I need to make the examples counter like this: example 23.2, means it is the item number 23 in chapter two. What changes should I make in your code, sir? Commented Jun 19, 2024 at 8:13
  • @shahroor see the update Commented Jun 22, 2024 at 5:20
  • So much appreciated. Your code works very well without any errors. I just needed to remove "\itshape" command from {\small\itshape}, because the Arabic font doesn't work properly with an italic shape. One last thing, in your code you used \section*{my list of examples}. Could we use something that helps making "my list of examples" appears in the page header? Thank you so much. I wouldn't have gotten this far without your help and time. Commented Jun 22, 2024 at 12:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.