\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[arabic,main=english]{babel}
\begin{document}
\chapter{Introduction}
\label{ch:intro}
We talked about the second chapter \ref{ch:poly}.
\section{start}
\section{end}
\chapter{Polyglot}
\label{ch:poly}
We talked about the first chapter \ref{ch:intro}.
\section{first}
\section{second}
\end{document}
通过 babel 添加阿拉伯语支持将导致以下结果:
答案1
\@chapter
对done by的重新定义有一个错误arabicore.sty
;对 的重新定义也存在同样的错误\@part
。
\def\@part[#1]#2{%
\addtocontents{toc}{\xstring\select@language{\main@Arabi@language}}%
\if@rl{\SAV@@part[\textRL{#1}]{\textRL{#2}}}%
\else{\SAV@@part[\textLR{#1}]{\textLR{#2}}}%
\fi}
\def\@chapter[#1]#2{%
\addtocontents{toc}{\xstring\select@language{\main@Arabi@language}}%
\if@rl{\SAV@@chapter[\textRL{#1}]{\textRL{#2}}}%
\else{\SAV@@chapter[\textLR{#1}]{\textLR{#2}}}%
\fi}
实际情况是,\SAV@@chapter
(原始\@chapter
命令)在一个组中执行,因此退出该组时,\@currentlabel
set by的值\refstepcounter{chapter}
将丢失。实际上,\ref{ch:poly}
您得到的是 1.2,这是最后由 分配的数字\section
。
使固定:
\def\@part[#1]#2{%
\addtocontents{toc}{\xstring\select@language{\main@Arabi@language}}%
\if@rl\SAV@@part[\textRL{#1}]{\textRL{#2}}%
\else\SAV@@part[\textLR{#1}]{\textLR{#2}}%
\fi}
\def\@spart#1{%
\addtocontents{toc}{\xstring\select@language{\main@Arabi@language}}%
\if@rl\SAV@spart{\textRL{#1}}%
\else\SAV@spart{\textLR{#1}}%
\fi}
\def\@chapter[#1]#2{%
\addtocontents{toc}{\xstring\select@language{\main@Arabi@language}}%
\if@rl\SAV@@chapter[\textRL{#1}]{\textRL{#2}}%
\else\SAV@@chapter[\textLR{#1}]{\textLR{#2}}%
\fi}
\def\@schapter#1{%
\addtocontents{toc}{\xstring\select@language{\main@Arabi@language}}%
\if@rl\SAV@schapter{\textRL{#1}}%
\else\SAV@schapter{\textLR{#1}}%
\fi}
\@spart
我还更改了和的重新定义\@schapter
,尽管它们实际上并没有涉及。 的其他用法\if@rl
似乎并不像我修复的那样危险。
完整示例
\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[arabic,main=english]{babel}
\makeatletter
\def\@part[#1]#2{%
\addtocontents{toc}{\xstring\select@language{\main@Arabi@language}}%
\if@rl\SAV@@part[\textRL{#1}]{\textRL{#2}}%
\else\SAV@@part[\textLR{#1}]{\textLR{#2}}%
\fi}
\def\@spart#1{%
\addtocontents{toc}{\xstring\select@language{\main@Arabi@language}}%
\if@rl\SAV@spart{\textRL{#1}}%
\else\SAV@spart{\textLR{#1}}%
\fi}
\def\@chapter[#1]#2{%
\addtocontents{toc}{\xstring\select@language{\main@Arabi@language}}%
\if@rl\SAV@@chapter[\textRL{#1}]{\textRL{#2}}%
\else\SAV@@chapter[\textLR{#1}]{\textLR{#2}}%
\fi}
\def\@schapter#1{%
\addtocontents{toc}{\xstring\select@language{\main@Arabi@language}}%
\if@rl\SAV@schapter{\textRL{#1}}%
\else\SAV@schapter{\textLR{#1}}%
\fi}
\makeatother
\begin{document}
\chapter{Introduction}
\label{ch:intro}
We talked about the second chapter \ref{ch:poly}.
\section{start}
\section{end}
\chapter{Polyglot}
\label{ch:poly}
We talked about the first chapter \ref{ch:intro}.
\section{first}
\section{second}
\end{document}
答案2
这似乎解决了问题。
\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[arabic,english]{babel}
\begin{document}
\chapter{Introduction \label{ch:intro}}
We talked about the second chapter \ref{ch:poly}.
\section{start}
\section{end}
\chapter{Polyglot \label{ch:poly}}
We talked about the first chapter \ref{ch:intro}.
\section{first}
\section{second}
\end{document}