我怎样才能在目录中为每个部分添加阿拉伯语翻译

我怎样才能在目录中为每个部分添加阿拉伯语翻译

我正在用 LaTeX 排版《古兰经》,左边是英文,右边是阿拉伯文。我使用 XeLaTeX 和 arabxetex 来做这件事。我使用托克洛夫特包来定制目录和标题安全包来定制标题页。我想要做的是将阿拉伯语 Surah 名称放在标题页和目录的右侧,将英语 Surah 名称放在左侧。在某人的帮助下,我设法完成了标题页部分我在这里发布的另一个问题

我遇到问题的部分是目录。我希望在文本宽度中间之前显示英文章节编号和英文章节名称,并在右侧显示英文页码,在右侧显示阿拉伯数字章节编号(textarab{1}例如,您可以使用命令获取阿拉伯数字),并在其旁边显示章节名称。这是我目前拥有的代码:

\documentclass{book}

\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}

\usepackage[paperwidth = 6 in,paperheight = 9 in,margin = 0.75 in,bindingoffset = 0.125 in]{geometry}

% Use the Quran version of the Amiri font
\newfontfamily\arabicfont[Script=Arabic]{Amiri Quran}

% Use "Surah" instead of "Chapter"
\renewcommand\chaptername{Surah}

% English on the left, Arabic on the right
\usepackage[explicit]{titlesec}
\usepackage[fullvoc]{arabxetex}
\titleformat{\chapter}[display]
   {\normalfont\huge\bfseries}
   {\chaptertitlename\ \thechapter \hfill \textarab{سورة \surahnum}}
   {0pt}
   {\Huge  #1\hfill\textarab{\archapter}}
\titlespacing*{\chapter}{0pt}{-20pt}{40pt}

\newcommand\archapter{\textarab{فهرس}}

\usepackage[titles]{tocloft}
\renewcommand{\cftchapleader}{\hfill} % Content between chaptertion title and page number
\renewcommand{\cftchapafterpnum}{\bfseries\hspace{1em}\textarab{\thepage}\hfill\textarab{\archapter}} % Content after chaptertion page number

\title{}
\author{}
\date{}

\begin{document}
\maketitle

\tableofcontents

\newcommand\surahnum{1}
\renewcommand\archapter{الفاتحة}
\chapter{Al-Faatiha}

\end{document}

它看起来是这样的:

结果存在一些问题:

  1. 阿拉伯页码不是该部分的实际页码:它应该是 5,而不是 3。屏幕截图中显示的阿拉伯数字是 3,因为这是目录开始的页面,但它应该是该章节的页面。
  2. 阿拉伯语章节名称不是 Surah(章节)的名称,而是阿拉伯语中“目录”或“索引”的意思。这是因为它不是从该行的章节中获取阿拉伯语章节名称,而是从当前所在的章节(目录)中获取。
  3. 页码稍微靠右了一点。它们应该位于正中央。

答案1

你也可以将定义放入目录中。但感觉有点太手工了,可能应该避免像这样存储页码,但需要更多时间更仔细地检查 titletoc 的代码。

\documentclass{book}

\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}

\usepackage[paperwidth = 6 in,paperheight = 9 in,margin = 0.75 in,bindingoffset = 0.125 in]{geometry}

% Use the Quran version of the Amiri font
\newfontfamily\arabicfont[Script=Arabic]{Amiri Quran}

% Use "Surah" instead of "Chapter"
\renewcommand\chaptername{Surah}

% English on the left, Arabic on the right
\usepackage[explicit]{titlesec}
\usepackage[fullvoc]{arabxetex}
\titleformat{\chapter}[display]
   {\normalfont\huge\bfseries}
   {\chaptertitlename\ \thechapter \hfill \textarab{سورة \surahnum}}
   {0pt}
   {\Huge  #1\hfill\textarab{\archapter}}
\titlespacing*{\chapter}{0pt}{-20pt}{40pt}

\newcommand\archapter{\textarab{فهرس}}

\usepackage[titles]{tocloft}
\renewcommand{\cftchapleader}{\hfill} % Content between chaptertion title and page number
\renewcommand{\cftchapafterpnum}{\bfseries\hspace{1em}\textarab{\arpage}\hfill\textarab{\archapter}} % Content after chaptertion page number

\title{}
\author{}
\date{}
\newcommand\arpage{1}
\begin{document}
\maketitle

\tableofcontents


\cleardoublepage% important
\newcommand\surahnum{1}
\renewcommand\archapter{الفاتحة}
\addtocontents{toc}{% 
 \protect\renewcommand\protect\arpage{\thepage}%
 \protect\renewcommand\protect\archapter{الفاتحة}}
\chapter{Al-Faatiha}

\end{document}

答案2

基于帖子后,我想到了一个可行的解决方案:

\documentclass{book}

\usepackage{etoolbox}
\usepackage{parcolumns}
\usepackage{calc}

\makeatletter

\patchcmd{\pc@placeboxes}{\vrule}{{\VRULE}}{}{}
\newcommand\VRULE{\color{SOME_COLOR}\vrule width 0.2mm}

\newcounter{storetocdepth}

\let\latex@@chapter\chapter
\RenewDocumentCommand{\chapter}{somos}{%
  \IfBooleanTF{#1}{%
    \latex@@chapter*{#3}%
  }{%
    \IfBooleanTF{#5}{%
      \setcounter{storetocdepth}{\value{tocdepth}}
      \addtocontents{toc}{\protect\setcounter{tocdepth}{-4}}
      % The #2 is of no use here, except of page headings /chapter mark
      \IfValueTF{#2}{%
        \latex@@chapter[#2]{#3}%
      }{%
        \latex@@chapter{#3}%
      }%
      \addtocontents{toc}{\protect\setcounter{tocdepth}{\number\value{storetocdepth}}}
      \addtocontents{toc}{\protect\contentsline{chapter}{\protect\phantom{#3}}{}}% Provide an empty fake entry
    }{%
      \IfValueTF{#2}{%
        \latex@@chapter[#2]{#3}%
      }{%
        \latex@@chapter{#3}%
      }%
    }%
    \IfValueTF{#4}{%
      \addcontentsline{ftoc}{chapter}{\protect\numberline{\csname thechapter\endcsname}#4}
    }{%
      \addtocontents{ftoc}{\protect\contentsline{chapter}{\protect\phantom{#2}}{}}% Provide an empty fake entry
    }%
  }%
}

\renewcommand\tableofcontents[1][toc]{%
  \@starttoc{#1}%
}

\makeatother

\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}

\usepackage[paperwidth = 6 in,paperheight = 9 in,margin = 0.75 in,bindingoffset = 0.125 in]{geometry}

% Use the Quran version of the Amiri font
\newfontfamily\arabicfont[Script=Arabic]{Amiri Quran}

% Use "Surah" instead of "Chapter"
\renewcommand\chaptername{Surah}

% English on the left, Arabic on the right
\usepackage[explicit]{titlesec}
\usepackage[fullvoc]{arabxetex}
\titleformat{\chapter}[display]
   {\normalfont\huge\bfseries}
   {\chaptertitlename\ \thechapter \hfill \textarab{سورة \surahnum}}
   {0pt}
   {\Huge  #1\hfill\textarab{\archapter}}
\titlespacing*{\chapter}{0pt}{-20pt}{40pt}

\newcommand\archapter{\textarab{فهرس}}

\title{}
\author{}
\date{}

\begin{document}
\maketitle

\chapter*{Contents}

\newlength\distance
\addtolength\distance{\columnsep * 2}

\begin{parcolumns}[distance = \distance]{2}
    \colchunk{

            \tableofcontents
    }
    \colchunk{

        \tableofcontents[ftoc]
    }
\end{parcolumns}

\newcommand\surahnum{1}
\renewcommand\archapter{الفاتحة}
\chapter{Al-Faatiha}[Arabic test]

\end{document}

相关内容