Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorizing #5

Closed
ercancem opened this issue Jan 3, 2021 · 4 comments
Closed

Colorizing #5

ercancem opened this issue Jan 3, 2021 · 4 comments
Labels

Comments

@ercancem
Copy link

ercancem commented Jan 3, 2021

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
Copy link

seloumi commented Jan 3, 2021

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

@ercancem
Copy link
Author

ercancem commented Jan 3, 2021

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

@seloumi
Copy link

seloumi commented Jan 3, 2021

\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 javadr added the question label Jan 4, 2021
@javadr
Copy link
Owner

javadr commented Jan 4, 2021

@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

@javadr javadr closed this as completed Jan 4, 2021
@javadr javadr mentioned this issue Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants