TeX - LaTeX Asked on August 23, 2020
Regarding the “Arabic Language”, words in such language are written such that the letters are connected, unlike English where words are written such that each letter is written separately. However, upon trying to emphasize any letter in Arabic text through the use of any of the options below:
In such cases, the text letters become separated and are no longer connected. Is there a way to emphasize letters through the use of various options while maintaining the word structure where the letters remain attached and are not disconnected??
Here is a MWE where I use Lualatex, notice I used the command described in How to highlight text with an arbitrary color so as to allow custom color regarding highlight command.
documentclass[a4paper,12pt,twoside]{book}
usepackage[a4paper,top=2.5cm,bottom=2.5cm,margin=2.5cm,bindingoffset=0.5cm]{geometry}
usepackage[bidi=basic,layout=lists.tabular]{babel}
babelprovide[import=ar,mapdigits,main]{arabic}
babelprovide[import=en,language=Default]{english}
babelfont{rm}{Latin Modern Roman}
babelfont[arabic]{rm}{amiri}
babelfont[english]{rm}{Times New Roman}
usepackage{xcolor}
usepackage{color}
usepackage{soul}
definecolor{mygrey}{gray}{0.9}
sethlcolor{mygrey}
newcommand{hlc}[2][yellow]{{%
colorlet{foo}{#1}%
sethlcolor{foo}hl{#2}}%
}
usepackage[normalem]{ulem}
begin{document}
foreignlanguage{english}{This is the word under study}
جنوب
foreignlanguage{english}{Bold}
جن
textbf{و}
ب
foreignlanguage{english}{underline}
جن
ul{و}
ب
foreignlanguage{english}{italic}
جن
textit{و}
ب
foreignlanguage{english}{highlight}
جن
hlc[gray!25]{و}
ب
end{document}
Robert's answer with babel, added arbboxi
, arbboxr
, arbboxl
and arbboxb
for isolated, beginning, end, middle form of letters. boxes are drawn with TikZ you can customize them with boxstyle
as you like using tikzset{boxstyle/.append style={...}}
documentclass[a4paper,12pt,twoside]{book}
usepackage [bidi=basic,layout=lists.tabular]{babel}
babelprovide[import=ar,mapdigits,main]{arabic}
babelfont{rm}{Amiri}
usepackage{tikz}
usepackage{ulem}
newcommand{ulinei}[1]{uline{#1}}
newcommand{ulinel}[1]{^^^^200duline{^^^^200d#1}}
newcommand{uliner}[1]{uline{#1^^^^200d}^^^^200d}
newcommand{ulineb}[1]{^^^^200duline{^^^^200d#1^^^^200d}^^^^200d}
tikzset{boxstyle/.style={draw=red,inner sep=0pt,fill=yellow}}
newcommand{arbboxi}[1]{%
tikz[baseline=(x.base)]node(x)[boxstyle]{#1};%
}
newcommand{arbboxl}[1]{%
^^^^200dtikz[baseline=(x.base)]node(x)[boxstyle]{^^^^200d#1};%
}
newcommand{arbboxr}[1]{%
tikz[baseline=(x.base)]node(x)[boxstyle]{#1^^^^200d};^^^^200d%
}
newcommand{arbboxb}[1]{%
^^^^200dtikz[baseline=(x.base)]node(x)[boxstyle]{^^^^200d#1^^^^200d};^^^^200d%
}
begin{document}
Large
جنوب
hrulefill
uliner{ج}نوب
جulineb{ن}وب
جنulinel{و}ب
جنوulinei{ب}
hrulefill
arbboxr{ج}نوب
جarbboxb{ن}وب
جنarbboxl{و}ب
جنوarbboxi{ب}
tikzset{boxstyle/.append style={dashed,draw=blue,font=bfseries,fill=green}}
hrulefill
arbboxr{ج}نوب
جarbboxb{ن}وب
جنarbboxl{و}ب
جنوarbboxi{ب}
end{document}
I have created a command FormatChar
(thanks to @David Carlisle https://tex.stackexchange.com/a/529439/54817)
you can apply any commands for a character in Arabic word, the command can also be used with xelatex
.
documentclass[a4paper,12pt,twoside]{book}
usepackage [bidi=basic,layout=lists.tabular]{babel}
babelprovide[import=ar,mapdigits,main]{arabic}
babelfont{rm}{Amiri}
usepackage{tikz}
usepackage{ulem}
defconnecti{i}
defconnectr{r}
defconnectl{l}
defconnectb{b}
makeatletter
defFormatChar#1#2#3#4{%
letjoineri@firstofone%
letjoinerii@firstofone%
defformatcs{#1}%
deftemp{#3}%
iftempconnectb%
else
iftempconnectr%
letjoinerii@gobble%
else
iftempconnectl%
letjoineri@gobble%
else
iftempconnecti%
letjoineri@gobbleletjoinerii@gobble%
else
@latex@error
{temp is not available for contextual forms}
fi%
fi%
fi%
fi%
xFormatChar{#2}#4}%
defxFormatChar#1#2{ifnum#1=1joineri{^^^^200d}%
formatcs{joineri{^^^^200d}#2joinerii{^^^^200d}}%
joinerii{^^^^200d}expandafter@gobbletwo%
else#2fixFormatChar{numexpr#1-1relax}}
makeatother
tikzset{charboxstyle/.style={draw=red,inner sep=0pt,fill=yellow}}
newcommand{charbox}[1]{%
tikz[baseline=(x.base)]node(x)[charboxstyle]{#1};%
}
begin{document}
%FormatChar{#1}{#2}{#3}{#4}
% #1: Command
% #2: Position of char (number)
% #3: Contextual forms r , l , b , i
% #4: Word
Huge
FormatChar{uline}{1}{l}
{جنوب}
%
FormatChar{textcolor{blue}}{2}{b}
{جنوب}
%
FormatChar{textcolor{red}}{3}{r}
{جنوب}
%
FormatChar{charbox}{4}{i}
{جنوب}
%
tikzset{charboxstyle/.append style={dashed,draw=blue,fill=green,text=orange}}
%
FormatChar{charbox}{1}{l}
{جنوب}
end{document}
For multiple letters macro FormatChars
can be used (thanks to @egreg https://tex.stackexchange.com/a/529602/54817 )
documentclass{article}
usepackage{tikz}
usepackage{xparse}
usepackage{ulem}
usepackage [bidi=basic]{babel}
babelprovide[import=ar,main]{arabic}
babelfont{rm}{Amiri}
tikzset{charboxstyle/.style={draw=red,inner sep=0pt,fill=yellow}}
newcommand{charbox}[1]{%
tikz[baseline=(x.base)]node(x)[charboxstyle]{#1};%
}
ExplSyntaxOn
NewDocumentCommand{FormatChars}{m >{SplitArgument{1}{-}}m O{i} m}
{
cs_set_nopar:Npn inputcs { #1 }
cs_set_nopar:Npn joinb {^^^^200d}
cs_set_nopar:Npn joine {^^^^200d}
str_case:nnF { #3 }
{
{ i } { letjoinbrelaxletjoinerelax }
{ r } { letjoinerelax }
{ l } { letjoinbrelax }
{ b } { }
}
{
msg_error:nn {}{#2~is~not~available~for~contextual~forms,~try~with~r,~l,~or~b}
}
% #2 is passed as two braced arguments
_FormatChars:nnn #2 { #4 }
}
cs_new_protected:Nn _FormatChars:nnn
{
% let's analyze the first two args
tl_if_novalue:nTF { #2 }
{% no hyphen in the argument
___FormatChars:nnn { #1 } { #1 } { #3 }
}
{
bool_lazy_or:nnTF { tl_if_blank_p:n { #1 } } { tl_if_blank_p:n { #2 } }
{% argument is -n or m- or -
tl_if_blank:nTF { #1 }
{
tl_if_blank:nTF { #2 }
{% argument is -
joinbinputcs{joinb #3joine}joine
}
{% argument is -n
___FormatChars:nnn { 1 } { #2 } { #3 }
}
}
{% argument is m-
___FormatChars:nnn { #1 } { -1 } { #3 }
}
}
{% argument is m-n
___FormatChars:nnn { #1 } { #2 } { #3 }
}
}
}
cs_new_protected:Nn ___FormatChars:nnn
{
int_compare:nTF { #1 > #2 > 0 }
{
#3
}
{
tl_range:nnn { #3 } { 1 } { #1 - 1 }
joinbinputcs{joinb tl_range:nnn { #3 } { #1 } { #2 }joine }joine
tl_range:nnn { #3 } { #2 + 1 } { -1 }
}
}
ExplSyntaxOff
begin{document}
%FormatChars{#1}{#2}[#3]{#4}
% #1 : command to apply on range ex : uline
% #2 : range of letters ex : 2-6
% #3 : type of connection : i , r , l , b (default i)
% #4 : word
Huge
FormatChars{uline}{1-3}
{جنوب}
%
FormatChars{textcolor{blue}}{2-3}[r]
{جنوب}
%
FormatChars{textcolor{red}}{2-}[r]
{جنوب}
%
FormatChars{charbox}{4}
{جنوب}
%
tikzset{charboxstyle/.append style={draw=blue,fill=black,text=white}}
%
FormatChars{charbox}{-2}[l]
{جنوب}
end{document}
Correct answer by Salim Bou on August 23, 2020
The following can be improved in various ways (e.g. using tikz is probably a bit overkill and also doesn't work well in RTL mode; there should be a way to select the glyphs which gets a frame and to change the colors; glue and other nodes are currently ignored, so it works only for single words) but it shows that it is basically possible to inspect the words, get the dimensions and draw something which doesn't interfere with the font shaping:
documentclass[a4paper,12pt,twoside]{book}
usepackage [bidi=basic,layout=lists.tabular]{babel}
babelprovide[import=ar,mapdigits,main]{arabic}
babelprovide[import=en,language=Default]{english}
babelfont{rm}{Latin Modern Roman}
babelfont[arabic]{rm}[Renderer=HarfBuzz]{amiri}
babelfont[english]{rm}{Times New Roman}
usepackage{tikz}
newsaveboxmyword
usepackage{luacode}
begin{luacode}
function frameword (boxnum)
local head = tex.box[boxnum].head
local colortable={"yellow","red","blue","green"}
local GLYPH = node.id("glyph")
local widthtable={}
local heighttable={}
local depthtable={}
for n in node.traverse(head) do
local id = n.id
if id == GLYPH then
table.insert(widthtable,n.width);
table.insert(heighttable,n.height);
table.insert(depthtable,n.depth);
texio.write_nl (" WIDTH ".. n.width .. " CHAR " .. n.char)
else
texio.write_nl ("????")
end
end
for i = table.getn(widthtable), 1, -1 do
color = colortable[math.fmod(i,4)+1]
tex.sprint("printrectangle{"..color.."}{".. widthtable[i] .."}{" .. heighttable[i].."}{" .. depthtable[i] .."}")
end
end
end{luacode}
begin{document}
جنوب
newcommandprintrectangle[4]{tikz[overlay]draw[#1,opacity=0.5](0,-#4sp)rectangle(#2sp,#3sp);hspace{#2sp}}
saveboxmyword{textdir TRT جنوب}
leavevmodeforeignlanguage{english}{directlua{frameword(themyword)}llap{useboxmyword}}
end{document}
Answered by Ulrike Fischer on August 23, 2020
EDIT: I added below a rather primitive approach for drawing frames. Then, in the document itself, I added the invisible ^^^^200d mark at the appropriate places.
Not an answer, but only a suggestion. In my opinion, coloring the glyphs is the way to go in Arabic typographically speaking. Underlining may also be considered.
documentclass[12pt]{article}
usepackage[novoc]{arabluatex}
newcommand{ulinel}[1]{^^^^200duline{^^^^200d#1}}
newcommand{uliner}[1]{uline{#1^^^^200d}^^^^200d}
newcommand{ulineb}[1]{^^^^200duline{^^^^200d#1^^^^200d}^^^^200d}
NewDocumentCommand{arbbox}{O{white} O{white} m}{%
fboxsep=0pt%
fcolorbox{#1}{#2}{#3}%
}
begin{document}
begin{arab}
^ganUb
^ganarbcolor[blue]{U}b
^ganulinel{U}b
^gaulineb{n}Ub
^ganarbbox[red][yellow]{U}b
end{arab}
end{document}
Answered by Robert Alessi on August 23, 2020
With luacolor you can color the glyphs too
documentclass[a4paper,12pt,twoside]{book}
usepackage[a4paper,top=2.5cm,bottom=2.5cm,margin=2.5cm,bindingoffset=0.5cm]{geometry}
usepackage[bidi=basic,layout=lists.tabular]{babel}
babelprovide[import=ar,mapdigits,main]{arabic}
babelprovide[import=en,language=Default]{english}
babelfont{rm}{Latin Modern Roman}
babelfont[arabic]{rm}{amiri}
babelfont[english]{rm}{Times New Roman}
usepackage{xcolor}
usepackage{luacolor}
begin{document}
foreignlanguage{english}{This is the word under study}
جنوب
color{yellow}جcolor{red}نcolor{blue}وcolor{green}ب
end{document}
Answered by Ulrike Fischer on August 23, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP