javadr / quran

Simplifying The Holy Quran Typesetting in XeLaTeX.
22 stars 5 forks source link

Colorizing #5

Closed ercancem closed 3 years ago

ercancem commented 3 years ago

Is it possible to colorize parts of an ayah (a word (words), a letter (letters), or perhaps haraka). I often need to highlight a certain word, etc., and that would be highly useful feature.

seloumi commented 3 years ago

I think this is doable with lualatex rather then xelatex with unicode.utf8.gsub function

ercancem commented 3 years ago

I am working in LuaLaTeX. Can you please supply a concrete example?

seloumi commented 3 years ago
\documentclass{article}
\usepackage{fontspec}
\usepackage{luacode,luacolor}
\setmainfont[Script=Arabic,Scale=3.5]{Amiri}

\newcommand\colr[2]{%
  \protect\leavevmode
  \begingroup
    \color{#1}%
    #2%
  \endgroup
}

\begin{luacode}
function colored ( s )
 s = unicode.utf8.gsub(s, "[ًٌٍَُِْ]","\\colr{red}{%1}")
  return  s 
end
\end{luacode}

\def\FormatOn{%
\directlua{luatexbase.add_to_callback("process_input_buffer", colored, "colored")}}
\def\FormatOff{%
\directlua{luatexbase.remove_from_callback("process_input_buffer","colored")}}

\pagestyle{empty}

\begin{document}

\centering

\pardir TRT \textdir TRT

\FormatOn

تَجرِيبْ بسمِ اللهِ الرحمَانِ الرَحِيمْ

\FormatOff

\begin{luacode}
function colored ( s )
 s = unicode.utf8.gsub(s, "[بم]","\\colr{blue}{%1}")
  return  s 
end
\end{luacode}

\FormatOn

تَجرِيبْ بسمِ اللهِ الرحمَانِ الرَحِيمْ

\FormatOff

تَجرِيبْ بسمِ اللهِ الرحمَانِ الرَحِيمْ

\end{document}

image

javadr commented 3 years ago

@ercancem

Actually, I don't know any obvious way to colorize symbols (haraka or letter) in xelatex, but as @seloumi mentioned you can simply use lualatex to do that. Although this way is applicable in normal text, you can't apply it in the text typeset by the quran package because the output of the all macros are not expandable.

There is a nice way to colorize the haraka with the aid of Amiri Quran Colored font.

\documentclass{article}

\usepackage{quran}
\usepackage{fontspec}
\setmainfont{Amiri Quran Colored}[RawFeature=colr,Script=Arabic]

\begin{document}
\pardir TRT \textdir TRT

\quransurah

\end{document}

Screenshot from 2021-01-04 11-26-32

If you want to colorize a word or part of an ayah, I strongly suggest you to use wordwise option--this solution also works with xelatex :D.

\documentclass{article}
\usepackage{xcolor}
\usepackage[wordwise]{quran}
\usepackage{fontspec}
\setmainfont{Amiri}[Script=Arabic]

\begin{document}
\pardir TRT \textdir TRT

\quranayah[2][286][1-30] 
{\color{red} \quranayah[2][286][31-38]}
\quranayah[2][286][39-49]

\end{document}

Screenshot from 2021-01-04 11-36-54