从右到左的文本颜色奇怪

从右到左的文本颜色奇怪

我有这个例子

\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{bidi}

\setmainfont{Amiri}

\parindent=0pt

\begin{document}

{\color{red} text from  left to right  text from  left to right   \par
text from  left to right  text from  left to right }

\hrulefill

\setRTL

\color{red} text from  right to left  text from  right to left
\par  text from  right to left text from  right to left \normalcolor

\hrulefill

{\color{red} text from  right to left  text from  right to left \par
 text from  right to left  text from  right to left}

\hrulefill

{before \color{red} text from  right to left  text from  right to left \par
 text from  right to left  text from  right to left}

\end{document}

有了这个结果 在此处输入图片描述

ltr(从左到右)的文本颜色很好,但 rtl 效果\color令人困惑,而且之前的文本也是\color彩色的!看起来命令是从段落的开头应用到结尾的,而不考虑命令的位置。

\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{bidi}

\setmainfont{Amiri}

\parindent=0pt

\begin{document}

\setRTL

{\leavevmode\color{red} text from  right to left  text from  right to left \par
text from  right to left}  text from  right to left  \par 
text from  right to left  text from  right to left 

\end{document}

在此处输入图片描述

更新 2018/06/29

使用\addfontfeature{Color=red}(来自包的命令fontspec)可以这样解决问题

\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{bidi}

\setmainfont{Amiri}

\parindent=0pt

\begin{document}

\setRTL

before {\addfontfeature{Color=red} text from  right to left  text from  right to left \par
text from  right to left}  text from  right to left  \par 
text from  right to left  text from  right to left 

\end{document}

在此处输入图片描述

我的目的是找到一种直接使用xcolor(或color)包而不依赖于包的方法fontspec

答案1

有解决方案,但是除了您自己建议使用的一个解决方案之外,没有一个是好的fontspec

% !TeX TS-program = xelatex
\documentclass[12pt]{article}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{bidi}

\setmainfont{Amiri}

\parindent=0pt

\newcommand{\parnew}[1][red]{\par\color{#1}}

\begin{document}

{\color{red} text from  left to right  text from  left to right   \par
text from  left to right  text from  left to right }

\hrulefill

\setRTL

{\color{red} text from  right to left  text from  right to left
{\parnew  text from  right to left text from  right to left} \normalcolor

}
\hrulefill

\newcommand{\mycolour}{blue}

{\color{\mycolour}{ text from  right to left  text from  right to left \parnew[\mycolour]
 text from  right to left  text from  right to left}

}
\hrulefill

before {\color{red} text from  right to left  text from  right to left} {\parnew
 text from  right to left  text from  right to left

}
\hrulefill

before \textcolor{red}{ text from  right to left  text from  right to left }\par
\textcolor{red}{text from  right to left  text from  right to left}

\hrulefill

\textcolor{black}{before}   {\color{red}text from  right to left  text from  right to left 

text from  right to left \textcolor{black}{text from  right to left}

}
\hrulefill

before {\addfontfeature{Color=red} text from  right to left  text from  right to left \par
    text from  right to left}  text from  right to left  \par 
text from  right to left  text from  right to left

\hrulefill


\end{document}

在此处输入图片描述

相关内容