TransWikia.com

Arabic and symbol of multiplication

TeX - LaTeX Asked by Netchaiev on June 8, 2021

I have in an article the following structure, since I need french, Arabic and math symbols :

documentclass[12pt]{article}
usepackage[utf8]{inputenc}
usepackage{arabtex}
usepackage{amsmath}
usepackage{tikz}
usepackage[arabic,french]{babel}
usepackage{utf8}
usepackage[T1]{fontenc}  % pour l'utilisation de 'french'


title{Zéro}

begin{document}

maketitle
setcode{utf8} 
zéro : 
<صفر  >
fg{} (d{s}u{i}fr) 

[ 0 times 0 ]


end{document}

Which is working fine except for the fact that the multiplication symbol times is not produced in the final output :
result of the code

2 Answers

I have used the answer of the user @egreg

DeclareRobustCommand{timesr}{fontfamily{artimes}selectfont}
lettimesrelax
DeclareMathSymbol{times}{mathbin}{symbols}{"02}

(see the link Problem with inserting the symbols times and omega when using arabi package)

documentclass[12pt]{article}
usepackage[utf8]{inputenc}
usepackage{arabtex}
usepackage{amsmath}
usepackage{tikz}
usepackage[arabic,french]{babel}
usepackage{utf8}
usepackage[T1]{fontenc}  % pour l'utilisation de 'french'
DeclareRobustCommand{timesr}{fontfamily{artimes}selectfont}
lettimesrelax
DeclareMathSymbol{times}{mathbin}{symbols}{"02}

title{Zéro}

begin{document}

maketitle
setcode{utf8} 
zéro : 
<صفر  >
fg{} (d{s}u{i}fr) 

[ 0 times 0 ]


end{document}

enter image description here

Correct answer by Sebastiano on June 8, 2021

I would recommend you use Unicode fonts in LuaTeX when you can, and legacy 8-bit fonts when you have to. Here is a solution that works in LuaLaTeX from 2020 or later, and might also work with luahbtex from earlier distributions. It could be modified to work with XeLaTeX.

It detects which language you are typing in and changes the font and the hyphenation patterns accordingly. The output PDF will support search and copy for both languages as well as math symbols.

documentclass[12pt]{article}
tracinglostchars=2 % Warn if the current font does not have a character!
usepackage{tikz}
usepackage[french, bidi=basic, layout=tabular]{babel}
usepackage{unicode-math}
usepackage{microtype} % Font expansion and protrusion.

usetikzlibrary{babel} % Turn off Babel shorthands inside TikZ nodes.
babelprovide[import=ar, onchar=ids fonts]{arabic} % Or import=ar-DZ, etc.

defaultfontfeatures{ Scale=MatchLowercase, Ligatures=TeX, Renderer=HarfBuzz }

% You can substitute your fonts of choice here.  Any OpenType or TrueType
% font should work.
babelfont{rm}
          [Ligatures=Common, Scale=1.0]{Libertinus Serif}
babelfont[arabic]{rm}
          [Ligatures=Common]{Amiri}
babelfont{sf}
          [Ligatures=Common]{Libertinus Sans}
% Specify babelfont[arabic]{sf} here, if needed.
babelfont{tt}
          {Libertinus Mono}
babelfont[arabic]{tt}
          {ALM Fixed}
setmathfont{Libertinus Math}

title{Zéro}

begin{document}

maketitle

zéro :
«صفر»
(d{s}u{i}fr) 

[ 0 times 0 ]


end{document}

Libertinus/Amiri sample

For this example, I used the Libertinus and Amiri fonts by Khaled Hosny, which are attractive, compatible, comprehensive and free, but you can substitute any fonts that you could use in your word processor.

I added a few other best practices, such as layout=tabular to make Arabic tables display right-to-left, usetikzpackage(babel) so TikZ drawing commands still work, and so on.

This assumes you are using words or short phrases in Arabic within a document primarily in French. If you need to alternate between entire paragraphs in French and Arabic, or switch between two languages that use the same script, the onchar= auto-detection will not suffice. You will need to use language tags such as begin{otherlanguage}{arabic} or foreignlanguage{arabic}.

Warnings about the language French not being defined for the script Latin in a font are harmless, but you can suppress them by adding the Language=Default option, e.g.

babelfont{sf}
          [Ligatures=Common, Language=Default]{Libertinus Sans}

Answered by Davislor on June 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP