0
  • For a specific selected diacritical mark within the word, how can you apply either all or one of the text formatting options below:

    • highlighting
    • coloring
    • Underlining
    • Changing to Bold
    • Changing to Italic
    • framing: Making a frame around the diacritical marks where such frame can be:
      • Dashed line
      • Dotted line
      • Dashed/Dotted line
      • Continuous line
      • Control the color of the frame

In addition, how to consider applying the above options to each selected diacritical mark with different settings, how to apply such settings separately to each of the selected diacritical marks?

The lines of code below can be used as a starting point, I couldn't modify them to be used in a similar manner with diacritical mark.

Coloring diacritical marks

Letter Formatting

Letter Formatting


\documentclass{article}
\usepackage[bidi=basic]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}{Amiri}
\usepackage{luacolor,lua-ul}
\usepackage{xstring} 
\usepackage{xparse} 
\usepackage{tikz}
\usepackage[normalem]{ulem}
\useunder{\uline}{\ulined}{} 

\newcommand{\ulinei}[1]{\uline{#1}}
\newcommand{\ulinel}[1]{^^^^200d\uline{^^^^200d#1}}
\newcommand{\uliner}[1]{\uline{#1^^^^200d}^^^^200d}
\newcommand{\ulineb}[1]{^^^^200d\uline{^^^^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]{%
  ^^^^200d\tikz[baseline=(x.base)]\node(x)[boxstyle]{^^^^200d#1};%
}
\newcommand{\arbboxr}[1]{%
  \tikz[baseline=(x.base)]\node(x)[boxstyle]{#1^^^^200d};^^^^200d%
}
\newcommand{\arbboxb}[1]{%
  ^^^^200d\tikz[baseline=(x.base)]\node(x)[boxstyle]{^^^^200d#1^^^^200d};^^^^200d%
}



\begin{document}

\Huge

\highLight[red]{ج}\underLine{نو}\highLight[yellow]{ب} \quad
\textcolor{red}{ج}\underLine{نو}\textcolor{blue}{ب} \quad
\underLine{\textcolor{red}{ج}نو}\highLight[green]{\textcolor{red}{ب}} \quad
% Coloring diacritical marks
ج%
\textcolor{blue}{َ}% fatha
نوب%
\textcolor{red}{ٌ}% tanween

\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}


Code output

5
  • The question is not clear. By "diacritical mark", do you mean the dots? They are part of the glyph, and not separate from the glyph like marks would be.
    – Cicada
    Nov 25, 2021 at 16:17
  • @Cicada diacritical marks are Fatha dama and kasra َُِ they are placed on letters to modify there sounds
    – Salim Bou
    Nov 25, 2021 at 16:56
  • @SalimBou Thanks. They colour OK in lualatex for me (also shown at end of the first line). I do not understand what the error is that the question is describing.
    – Cicada
    Nov 26, 2021 at 3:37
  • @Cicada, I need to "Highlight" the diacritical marks rather than "changing their color". "Highlight" in the same manner where the letters have yellow and green boxes around them with dashed or dotted border in addition to having the ability to just highlight them with no border. In other words: make a "bounding box" around the "diacritical mark", color this box and add the functionality to show or hide the border of the box a well as make it dotted, dashed, solid line...., also the box should not affect the spacings, size.... and other font properties and settings related to the used language.
    – Silva
    Nov 27, 2021 at 3:49
  • @Silva Consider the bounding box for the diacritical mark to be zero width: the box can be coloured with highlight and underlined, but zero width makes it invisible. Meanwhile, the diacritical mark prints on top of the following letter, and the only thing the mark has that can be seen is text-colour (and size, boldness), but no visible box. Instead of a font-based solution (assuming there are no fonts with "gaps" for teaching purposes), do a picture-based one (e.g., tikz) but this means manual placement of items to make the illustration.
    – Cicada
    Nov 27, 2021 at 6:22

1 Answer 1

2

Amended answer, based on the comment.

Using the \color command manually

Diacritics and letters can be coloured OK using lualatex using normal colour commands.

colours

Typing a mixture of RTL/LTR is too confusing (at least for me), so I made non-LTR commands instead, based on technique in unisugar package.

MWE

\documentclass{article}
\usepackage{xcolor}
\usepackage[bidi=basic]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}[Scale=2]{Amiri}
\usepackage{luacolor,lua-ul}

%inspired via unisugar:
\catcode`¶=11
\edef\¶{¶}
\catcode`¶=0 


\newcommand{¶اللون}[1]{\color{#1}}% allawn colour
\newcommand{¶أسود}{black}% 'aswad black
\newcommand{¶أحمر}{red}% 'ahmar red
\newcommand{¶أخضر}{green!95!blue!40}% (lawn) 'akhdar green
\newcommand{¶أزرق}{blue}% 'azraq blue


\begin{document}
\Huge

ب¶اللون{¶أحمر}َ¶اللون{¶أخضر}ب¶اللون{¶أزرق}ب

\end{document}

Using regex

With expl3's regex capability, a range of glyphs can be specified as a group, such as the diacritical marks.

regex

The uppercase and lowercase Latin letters as a group look like([a-zA-Z]). Diacritical marks in Arabic, direct input, look like ([ؐ-ًؚ-ٟ]), which is a bit hard to read (depending on how your editor/browser displays fonts) and needed to be typed in in sequence.

In lualatex, setting the colour does not interfere with the glyph-flow of the font, so ligatures etc form naturally. Setting boxes and tikz nodes directly does affect the font, so using an overlay method after the text has been typeset could be a possible solution; alternatively, luacode (somewhat like in Defining different scripts with fontspec) could be used to inspect each glyph and create an attribute list (probably not a five-minute task, though).

MWE

\documentclass{article}
\usepackage{xcolor}
\usepackage[bidi=basic]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}[Scale=2]{Amiri}
\usepackage{luacolor,lua-ul}



%inspired via unisugar:
\catcode`¶=11
\edef\¶{¶}
\catcode`¶=0 


\newcommand{¶اللون}[1]{\color{#1}}% allawn colour
\newcommand{¶أسود}{black}% 'aswad black
\newcommand{¶أحمر}{red}% 'ahmar red
\newcommand{¶أخضر}{green!95!blue!40}% (lawn) 'akhdar green
\newcommand{¶أزرق}{blue}% 'azraq blue

%================


\ExplSyntaxOn
%-----
\NewDocumentCommand \marktext { +m } { \l_texthighlight:n { #1 } }
\cs_new_protected:Npn \l_texthighlight:n #1
 {
     \tl_set:Nn \l_tmpa_tl { #1 }
     \regex_replace_all:nnN 
          { ([ؐ-ًؚ-ٟ]) }
          { \c{textcolor}\cB\{ red \cE\}\cB\{\1\cE\} }    
          \l_tmpa_tl
  \tl_use:N \l_tmpa_tl
 }
 
 

\ExplSyntaxOff

\begin{document}
\Huge

ب¶اللون{¶أحمر}َ¶اللون{¶أخضر}ب¶اللون{¶أزرق}ب

{\normalsize using regex }

\fbox{\marktext{بَبَب}}
\color{black}

\fbox{\marktext{بًتٌثٍبَتُثِفّقْكٓشٔصٕضٖطٗ}}
\end{document}

(Expl3 code borrowed and adapted from another page on this site.)

In terms of boxes, a bit of exploration shows that boxes may not be useful: diacritical marks are outside their box, or have no box, or become part of the combined box with the base letter. Different ways of saying the same thing. So a solution that by-passes fonts (e.g., picture overlay) could be the way to go.

boxes

MWE

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Amiri}[Scale=5]

\newcommand{\mfb}[1]{\makebox[2cm]{\fbox{#1}}}

\begin{document}

\setlength{\fboxsep}{-\fboxrule}

\mfb{e}\mfb{^^^^0628}

\mfb{^^^^0302}\mfb{^^^^064e}

\mfb{e^^^^0302}\mfb{^^^^064e^^^^0628}

\end{document}

The low-level glyph-components can be accessed individually with the \symbol command (or equivalents, like ^^^^ notation), and the (visible) bounding box for ordinary characters can be highlighted and underlined, but the bounding box for diacritical marks appears to be zero-width (which makes sense, since the mark is designed to go with another character, not to be on its own).

boxes and elements

MWE

\documentclass{article}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{luacolor,lua-ul}

\newfontface\myfont{Amiri-Regular.ttf}[Script=Arabic,Scale=5]
\begin{document}
\myfont
\symbol{983073}\symbol{983076}\symbol{983074} = \symbol{983073} + \symbol{983076} + \symbol{983074}

x\color{red}\highLight[yellow]{\symbol{983283}}\normalcolor x

x\color{red}\fbox{\symbol{983283}}\normalcolor x


x\highLight[blue!20]{\underLine{\symbol{983052}}}\underLine{\color{red}\symbol{983283}}\normalcolor x

x\highLight[blue!20]{\underLine{\symbol{983052}}}\fbox{\color{red}\symbol{983283}}\normalcolor x


\end{document}

Highlighting diacritical marks using overlapping colorboxes

It appears that glyphs of mark class have anchor points, rather than bounding boxes as such. They use the anchor points to position themselves on the base character.

Which suggests that using the method of overlapping boxes is possible, with the box "underneath" (nearest the background) begin fully coloured, and the box "on top" (nearest the reader) being page-coloured and also missing the diacritic, so leaving a "gap" for the box behind to show through that part (sort of like clipping). Requires very careful coding (and thinking), though.

overlaps

MWE

\documentclass{article}
\usepackage{xcolor}
\usepackage{luacolor,lua-ul}
\usepackage[bidi=basic]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}[Scale=5]{Amiri}

\setlength{\fboxsep}{-\fboxrule}

\newcommand\cola{green!24}
\newcommand\colb{brown!30}
\newcommand\colc{red}
\newcommand\cold{white}

\newcommand{\hldm}[2]{%
\colorbox{\cola}{#1}\llap{\colorbox{\cold}{#2}}
}

\begin{document}

\bigskip{\tiny (a)} \begin{tabular}{|c|c|c|}
\hline
\tiny 3 & \tiny 2 & \tiny 1 \\
\hline
\mbox{\colorbox{\cola}{\symbol{1576}\color{\colc}\symbol{1611}}\llap{\colorbox{\cold}{\symbol{1576}}}}
&
\mbox{\colorbox{\cola}{\symbol{1576}\color{\colc}\symbol{1611}}\llap{\colorbox{\colb}{\symbol{1576}}}}
&
\mbox{\colorbox{\cola}{\symbol{1576}\color{\colc}\symbol{1611}}\colorbox{\colb}{\symbol{1576}}}
\\
\hline
\end{tabular}


\normalcolor %x

\bigskip{\tiny (b)} \hldm{\symbol{1576}\color{\colc}\symbol{1611}}{\colorbox{\cold}{\symbol{1576}}}

\bigskip{\tiny (c)} \hldm{\symbol{1576}\symbol{1614}\symbol{1576}\symbol{1615}\symbol{1576}\symbol{1616}}{\symbol{1576}\symbol{1576}\symbol{1576}}

\bigskip{\tiny (d)} {\colorbox{\cola}{\symbol{1576}\symbol{1614}^^^^200d}^^^^200d\symbol{1576}\symbol{1615}\symbol{1576}\symbol{1616}}\llap{\colorbox{\cold}{\symbol{1576}^^^^200d}^^^^200d\symbol{1576}\symbol{1615}\symbol{1576}\symbol{1616}} 

\end{document}

Original answer

Assuming the question is about highlighting the dots, the \clip function can be used, but, because the dot is part of the glyph, positioning the clip rectangle will have to be hand-crafted for each case. It is like making a part of the glyph A a different colour.

The method is: draw the text, position the clip area, draw the text again in a different colour, and so only the text inside the clip area is drawn.

clip

MWE

\documentclass{article}
\usepackage[bidi=basic]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}{Amiri}
\usepackage{luacolor,lua-ul}
\usepackage{tikz}
\newcommand{\Atwo}[3][A]{%
  \begin{tikzpicture}
    %place the underlying word
    \node[inner sep=0pt,outer sep=0pt,text=#2] (a) {#1};
    %define the clip rectangle
    \clip  (a.south east) [xshift=-1ex] rectangle (a.north);
    % place the clipped word above
    \node[inner sep=0pt,outer sep=0pt,text=#3]  {#1};
  \end{tikzpicture}
}

\newcommand{\Athree}[3][A]{%
  \begin{tikzpicture}
    %place the underlying word
    \node[inner sep=0pt,outer sep=0pt,text=#2] (a) {#1};
    %define the clip rectangle
    \clip  (a.south east) [xshift=-1ex] rectangle (a.north west);
    % place the clipped word above
    \node[inner sep=0pt,outer sep=0pt,text=#3]  {#1};
  \end{tikzpicture}
}

\newcommand{\Afour}[3][A]{%
  \begin{tikzpicture}
    %place the underlying word
    \node[inner sep=0pt,outer sep=0pt,text=#2] (a) {#1};
    %define the clip rectangle
    \clip[draw]  (a.south east) [xshift=-0.5ex] rectangle ++(-7pt,6pt);
    % place the clipped word above
    \node[inner sep=0pt,outer sep=0pt,text=#3]  {#1};
  \end{tikzpicture}
}

\begin{document}

\Huge
ببب
\Atwo[ببب]{blue}{red}

\Atwo{blue}{red}

\Athree[ببب]{blue}{red}

\Athree{blue}{red}

\Afour[ببب]{blue}{red}

\end{document}

An alternative is a font designer has produced two font files of exactly the same glyphs and metrics, one file does not have the dots (it has gaps), and the other file does (but no strokes, just the dots), and one font is printed on top of the other.

4
  • thanks for the reply, however, does this code allows you to highlight the "diacritical mark" as well? The code allows you to change their color, but what about highlighting them in the same manner the "Green" and "Yellow" boxes appear in the example shown in the original question?
    – Silva
    Nov 27, 2021 at 3:44
  • @Silva "in the same manner" - no, because of font shape-formation rules; glyphs can be highlighted, diacritical marks ("X") become a combined glyph with the base letter ("Y") according to the font ligature tables ("X"+"Y"="Z"), and are no longer "separate" items (only "Z" is there), so an overlay-type method after the ligature has been formed will be needed, or maybe lua code to use either font attribute mechanism (to keep font shaping undisturbed), or to draw each part separately "by hand".
    – Cicada
    Nov 27, 2021 at 4:23
  • @Silva Look at the font in FontForge or similar, to examine the ligature tables. That will give an idea how font-shaping works. (Perhaps: "Z" - "Y" = "X", to reconstruct the diacritical mark as a separate item; but then its position will need to be calculated, too. Not something I can do quickly.)
    – Cicada
    Nov 27, 2021 at 4:26
  • @Silva I added a bit about font boxes. Bounding boxes appear to be impractical for highlighting accents (but someone may have a solution); an "overlay" solution seems more feasible.
    – Cicada
    Nov 27, 2021 at 4:40

You must log in to answer this question.

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