2

I have this problem in right to left colored text.

\documentclass[12pt]{article}
\usepackage{color}
\usepackage[utf8]{inputenc}
\usepackage[LAE]{fontenc}
\usepackage[arabic]{babel}
\begin{document}
$normal$ \textcolor{blue}{$blue$} $more$
\end{document}

This is an old bug, and a workaround is already known

\documentclass[12pt]{article}
\usepackage{color}
\usepackage[utf8]{inputenc}
\usepackage[LAE]{fontenc}
\usepackage[arabic]{babel}
\newcommand{\Artextcolor}[2]{\textLR{\textcolor{#1}{\AR{#2}}}}
\begin{document}
$normal$ \Artextcolor{blue}{$blue$} $more$
\end{document}

But this dosen't help if the colored text reaches a linebreak

\documentclass[12pt]{article}
\usepackage{color}
\usepackage[width=6cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[LAE]{fontenc}
\usepackage[arabic]{babel}
\newcommand{\Artextcolor}[2]{\textLR{\textcolor{#1}{\AR{#2}}}}
\begin{document}
$normal$ %this should be black
\Artextcolor{blue}{$blue$  $just$ $a$ $long$ $text$ $to$ $show$ $the$ $problem$}
$more$ %this should be black
\end{document}

For xelatex with package xecolor the problemis seem to be partially solved. Is there any solution for pdflatex?

1 Answer 1

3

pdftex is trying to helpfully have a stack of color that is pushed then popped to restore the original color

the color package is trying to helpfully insert a color pop at the end of a group

tex--xet re-arranges the node list and means neither of these processes is at all helpful.

A real fix would require deep changes to pdftex so a simpler fix is to first simplify the \color command so that it simply sets a global color at that point and does not use the pdftex color stack or insert a revert at the end of the group.

Then you "just" have to insert color changes at points that end up in the right place after tex--xet re-arranges the order of nodes on each line.

enter image description here

\documentclass[12pt]{article}
\usepackage{color}
\makeatletter
\def\set@color{%
  \pdfliteral{\current@color}%
  }
\usepackage[width=6cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[LAE]{fontenc}
\usepackage[arabic]{babel}
\newcommand{\Artextcolor}[2]{\AR{#2\color{#1}}}
\begin{document}
\color{blue}$normal$ \color{black}%this should be black
\Artextcolor{blue}{$blue$  $just$ $a$ $long$ $text$ $to$ $show$ $the$ $problem$}
$more$ %this should be black
\end{document}
1
  • good, very good, i will try this. Commented Oct 20, 2023 at 22:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .