# Write eastern language Persian/Farsi/Arabic

**URL:** <https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209>\
**Category:** Q&A\
**Created:** [January 14, 2021, 7:52pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209 "2021-01-14T19:52:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![saeedsltm](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/saeedsltm/32/835_2.png) [@saeedsltm](https://forum.generic-mapping-tools.org/u/saeedsltm)\
**Post date:** [January 14, 2021, 7:52pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/1 "2021-01-14T19:52:34Z")

</div>

Hi,

Does anyone know how we can write eastern language like Persian/Farsi/Arabic in GMT pstext? It seems there is a problem around encoding/decoding strings.

Regards

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [January 14, 2021, 8:12pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/2 "2021-01-14T20:12:27Z")

</div>

Others may provide more help if you could provide your example script and the image (although they don’t work as expected).

---

<div class="post-metadata">

**Author:** ![saeedsltm](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/saeedsltm/32/835_2.png) [@saeedsltm](https://forum.generic-mapping-tools.org/u/saeedsltm)\
**Post date:** [January 14, 2021, 8:17pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/3 "2021-01-14T20:17:48Z")

</div>

Ok, here is a very quick sample:

echo “10 10 15 10 0 2 سعید” | pstext -R-30/30/-10/20 -Jm0.1i -P -B5 -S0.5p \> plot.ps

the text i want to be shown in the output figure is a Persian name (سعید) but there is problem with it.  
[plot.ps](https://forum.generic-mapping-tools.org/uploads/short-url/roAnGdHSHvxVfSSFqWLp5SURU6X.ps) (23.2 KB)

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [January 14, 2021, 8:21pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/4 "2021-01-14T20:21:32Z")

</div>

I think you need to find some fonts for Persian languages and then tell GMT to use it.

This example may be helpful:

> **[(31) Using non-default fonts in PostScript — GMT 6.1.1 documentation](https://docs.generic-mapping-tools.org/latest/gallery/ex31.html)**

---

<div class="post-metadata">

**Author:** ![saeedsltm](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/saeedsltm/32/835_2.png) [@saeedsltm](https://forum.generic-mapping-tools.org/u/saeedsltm)\
**Post date:** [January 14, 2021, 8:43pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/5 "2021-01-14T20:43:07Z")

</div>

Thanks, i will try it 🙂

---

<div class="post-metadata">

**Author:** ![saeedsltm](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/saeedsltm/32/835_2.png) [@saeedsltm](https://forum.generic-mapping-tools.org/u/saeedsltm)\
**Post date:** [January 15, 2021, 8:20am UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/6 "2021-01-15T08:20:55Z")

</div>

Well, i’ve tried something like example 31 and it works only for border labels and not for string text inside the map! Strange!

i zipped the script, fonts and pdf output here.  
[test.zip](https://forum.generic-mapping-tools.org/uploads/short-url/vLkREsDcjjmw6Jcw76etrp0FUa7.zip) (78.1 KB)

---

<div class="post-metadata">

**Author:** ![CraneBoba](https://avatars.discourse-cdn.com/v4/letter/c/977dab/32.png) [@CraneBoba](https://forum.generic-mapping-tools.org/u/CraneBoba)\
**Post date:** [January 15, 2021, 5:27pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/7 "2021-01-15T17:27:36Z")

</div>

I tried same mathod, I used for Russian  
letters\< but could not cheack it in russsian windows gmt version  
gmt begin GMT\_tut\_1

gmt set PS\_CHAR\_ENCODING ISO-8859-6  
gmt basemap -R10/70/-3/8 -JX4i/3i -B -B+t"\621\622\623\624\625\626"  
gmt end show

---

<div class="post-metadata">

**Author:** ![uleysky](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/uleysky/32/574_2.png) [@uleysky](https://forum.generic-mapping-tools.org/u/uleysky)\
**Post date:** [January 16, 2021, 6:33am UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/8 "2021-01-16T06:33:25Z")

</div>

@saeedsltm, this problem is complex and not the fact that it has a solution at all.  
First, PS\_CHAR\_ENCODING ISO-8859-1 is not work at all, because ISO-8859-1 doesn’t contain Arabic characters. You must use PS\_CHAR\_ENCODING ISO-8859-6, but it is not functional in the GMT. Without going into details, you should create your encoding vector for the font you are using and insert it into the eps file before gmt end. It is tricky, but possible. I can show you how.  
Second, in your example, the Persian name is given in unicode, this is guaranteed not to work. You must use a single-byte encoding, such as cp1256 or the ISO-8859-6. I cannot recode your example, iconv reported “illegal input sequence at position 8” for you file data.csv. Perhaps I was mistaken with the encoding, unfortunately I am not familiar with the Persian language.

In any case, it is necessary that the input text is in single-byte encoding. Then I can try to help solve your problem. However, I am almost sure that it will not be possible to solve the problem with writing from right to left.

P.S. The numbers in your example are correct because in the font you used the usual 0-9 are replaced with Persian. This will not happen with another font.

---

<div class="post-metadata">

**Author:** ![saeedsltm](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/saeedsltm/32/835_2.png) [@saeedsltm](https://forum.generic-mapping-tools.org/u/saeedsltm)\
**Post date:** [January 16, 2021, 7:58am UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/9 "2021-01-16T07:58:21Z")

</div>

@uleysky, many thanks for your very detailed information.  
I’d tried iso8859-6 which contains Arabic encoding and it was failed with my example as you’ve already mentioned.  
So, steps i have to do are like the followings (?)  
1- creating an encoding vector for the Persian font (can you give me a hint how to do it? Is it something like ISO-\*.ps files located in …gmt/share/pslib directory?)  
2- finding the right encoding for my data.csv file which contains characters both in English and Persian (using command `file -i data.csv` it says utf-8).  
3- I’ve tried to convert mt data.csv file from utf-8 encoding to cp1256 or ISO-8859-6 using the command `"iconv -f utf-8 -t iso8859-6 data.csv > data_iso.csv"` but it didn’t work `iconv: data.csv:1:7: cannot convert`  
4- Regarding R-to-L, we can ignore it at the moment.

Just for your info, the Persian font style and characters are somehow like Arabic.

---

<div class="post-metadata">

**Author:** ![uleysky](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/uleysky/32/574_2.png) [@uleysky](https://forum.generic-mapping-tools.org/u/uleysky)\
**Post date:** [January 16, 2021, 9:13am UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/10 "2021-01-16T09:13:23Z")

</div>

> [@saeedsltm](#):
>
> 1- creating an encoding vector for the Persian font (can you give me a hint how to do it? Is it something like ISO-\*.ps files located in …gmt/share/pslib directory?)

Yes, a like. A description of the generation of an encoding vector and scripts for this are in this bug report: [Fonts in GMT · Issue #4565 · GenericMappingTools/gmt · GitHub](https://github.com/GenericMappingTools/gmt/issues/4565).

> [@saeedsltm](#):
>
> 3- I’ve tried to convert mt data.csv file from utf-8 encoding to cp1256 or ISO-8859-6 using the command `"iconv -f utf-8 -t iso8859-6 data.csv > data_iso.csv"` but it didn’t work `iconv: data.csv:1:7: cannot convert`

Yes, I figured it out, the problem is with the symbol [Unicode Character 'ARABIC LETTER FARSI YEH' (U+06CC)](https://www.fileformat.info/info/unicode/char/06cc/index.htm), for some reason it is missing in the encodings CP1256 and ISO-8859-6. Anyway, your font doesn’t have this character, I replaced it with [Unicode Character 'ARABIC LETTER YEH' (U+064A)](https://www.fileformat.info/info/unicode/char/064a/index.htm)

> [@saeedsltm](#):
>
> 4- Regarding R-to-L, we can ignore it at the moment.

This simplifies the task.

You modified script, data.csv and resulting pdf:  
[mod.zip](https://forum.generic-mapping-tools.org/uploads/short-url/yh7M9zepADsXXLiecw9czlRo7Bo.zip) (26.3 KB)

Since the font BZar does not contain the Latin alphabet, instead of the symbol ‘N’ on the figure there are squares.

---

<div class="post-metadata">

**Author:** ![saeedsltm](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/saeedsltm/32/835_2.png) [@saeedsltm](https://forum.generic-mapping-tools.org/u/saeedsltm)\
**Post date:** [January 16, 2021, 11:02am UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/11 "2021-01-16T11:02:23Z")

</div>

Your changes are great and thank you very much for that 🙂 .  
Regarding your reported bug, i found that making vectors is very complicated!  
There are two points now, one is that in Persian, characters have a double behavior and sometimes they have to be stuck together. For example, the word `"سلام"` (which means “hello”) contains the letters of the alphabet `س ل ا م`, but in writing, these characters are in the stacked form which makes “سلام” .  
The second point is the direction of each word itself. I thought you meant miss-direction of all words together in a paragraph, but now I realize that the miss-direction exists even inside the words themselves (e.g. `سلام` will be written as `ملاس` and of course not in stacked form). Therefore, with the current approach, words are written in reverse. 🙄  
So there are two important objects:

1. Words must be written in stacked form, unless the white-space character separates them.
2. Each word must be written from right to left.

I’m not sure if by changing the font itself we can solve any above mentioned issues, (sometime it works, even in Microsoft Word we have something like that) but at least i can try it with different fonts.

---

<div class="post-metadata">

**Author:** ![uleysky](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/uleysky/32/574_2.png) [@uleysky](https://forum.generic-mapping-tools.org/u/uleysky)\
**Post date:** [January 16, 2021, 11:56am UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/12 "2021-01-16T11:56:46Z")

</div>

Please, check this variant with “hello”: [ex31.pdf](https://forum.generic-mapping-tools.org/uploads/short-url/hBOxrAIUY4KM7y8g8Dlc57eSdIh.pdf) (43.9 KB)  
If it suits you, I will explain how you can achieve this. But this will require quite a lot of work, which I cannot do due to my ignorance of the language.

---

<div class="post-metadata">

**Author:** ![saeedsltm](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/saeedsltm/32/835_2.png) [@saeedsltm](https://forum.generic-mapping-tools.org/u/saeedsltm)\
**Post date:** [January 16, 2021, 12:10pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/13 "2021-01-16T12:10:42Z")

</div>

Well everything is OK except the first character which is typed in isolated mode (`س`) instead of stacked (`سـ`). (actually `سـ` here is composed of two character, but in real is the stacked form of `س`). Other characters are in their correct form and the direction also is correct for the whole word.

---

<div class="post-metadata">

**Author:** ![uleysky](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/uleysky/32/574_2.png) [@uleysky](https://forum.generic-mapping-tools.org/u/uleysky)\
**Post date:** [January 16, 2021, 12:39pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/14 "2021-01-16T12:39:08Z")

</div>

Okay, maybe not everything is as hopeless as it seemed at first. So what i did:

1. I revert word “سلام” manually (just rewrite it in reverse direction).
2. I find that “لا” is a lam-alef ligature, and I replace two symbols on one [https://www.compart.com/en/unicode/U+FEFC](https://www.compart.com/en/unicode/U+FEFC)
3. Codepoint U+FEFC missing in encoding ISO-8859-6, so I added this code point in the encoding to an empty space (F3) and generated a new encoding vector.
4. Since the iconv can no longer recode text from utf8 to our new encoding, I used direct access to characters, as the @CraneBoba demonstrated above. String “سلام” became “\345\363\323”.
5. The font of the string is different here, I took the NotoSansArabic-Regular for the test, but it does’nt matter.

As I undestand from there [https://stackoverflow.com/questions/33718144/do-arabic-characters-have-different-unicode-code-points-based-on-position-in-str](https://stackoverflow.com/questions/33718144/do-arabic-characters-have-different-unicode-code-points-based-on-position-in-str), the Arabic letter has a different drawning (and unicode code point!) depending on where in the word it appears. Thus, we have a difficult but solvable problem of translating a sequence of Arabic letters into a sequence of unicode code points. This is something that only you can do. I can help with creating an encoding vector for this sequence and embedding it in the EPS file. If you are interested in this, let’s try it. I think that the instructions for using Arabic characters in the GMT will be useful to many because now there is no adequate way to do this.

---

<div class="post-metadata">

**Author:** ![saeedsltm](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/saeedsltm/32/835_2.png) [@saeedsltm](https://forum.generic-mapping-tools.org/u/saeedsltm)\
**Post date:** [January 16, 2021, 12:55pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/15 "2021-01-16T12:55:58Z")

</div>

That is a great news, and I AM IN 🙂 As you rightly pointed out, many users need to use Persian or Arabic writing. let start it 🙂 I don’t know if this is helpful, but there is possibility to write Persian in Latex, but i don’t know how it works. BTW, please tell me what should i do next, and i will do it asap.

---

<div class="post-metadata">

**Author:** ![uleysky](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/uleysky/32/574_2.png) [@uleysky](https://forum.generic-mapping-tools.org/u/uleysky)\
**Post date:** [January 16, 2021, 1:25pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/16 "2021-01-16T13:25:57Z")

</div>

As I said, the first step is to transform the Arabic text into a sequence of unicode code points. In other words, an algorithm is needed by which an Arabic text typed from the keyboard turns into an image on the screen. Formal description can be found here [http://www.unicode.org/versions/Unicode8.0.0/ch09.pdf](http://www.unicode.org/versions/Unicode8.0.0/ch09.pdf)  
I think that there are ready-made solutions for this task, it will be easier for you to find them than for me. Maybe this [https://mpcabd.xyz/python-arabic-text-reshaper/](https://mpcabd.xyz/python-arabic-text-reshaper/) is what we need.

---

<div class="post-metadata">

**Author:** ![saeedsltm](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/saeedsltm/32/835_2.png) [@saeedsltm](https://forum.generic-mapping-tools.org/u/saeedsltm)\
**Post date:** [January 16, 2021, 1:56pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/17 "2021-01-16T13:56:58Z")

</div>

Yes using arabic\_reshaper we now have access to all unicode points of Persian alphabet based on their position [isolated, initial, medial,final]. The next is using this unicode to make an encoding vector, right?  
We could also use two simple function to get RTL and corrected form of any Persian word.

---

<div class="post-metadata">

**Author:** ![uleysky](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/uleysky/32/574_2.png) [@uleysky](https://forum.generic-mapping-tools.org/u/uleysky)\
**Post date:** [January 16, 2021, 3:05pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/18 "2021-01-16T15:05:54Z")

</div>

Seems to work [ex31.rs.pdf](https://forum.generic-mapping-tools.org/uploads/short-url/8gaa97QqtAFKH466RQB94XrC9c0.pdf) (43.8 KB)  
Please check.

Now another problem arose. I counted the number of code points used by the arabic\_reshaper, and it turned out to be 372, which is significantly more than the maximum length of the encoding vector (256, but in fact even less, since it is necessary to leave room for numbers and punctuation). I suspect that in practice not all code points are needed, and only those that are actually used should be left. I will try to prepare a rendered list of these code points in the near future so that you can select the practically used ones.

---

<div class="post-metadata">

**Author:** ![saeedsltm](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/saeedsltm/32/835_2.png) [@saeedsltm](https://forum.generic-mapping-tools.org/u/saeedsltm)\
**Post date:** [January 16, 2021, 3:20pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/19 "2021-01-16T15:20:42Z")

</div>

Perfect 😃 , Yes you are right, we may not necessarily to use all of them. I’v checked [https://github.com/mpcabd/python-arabic-reshaper/blob/master/arabic\_reshaper/letters.py](https://github.com/mpcabd/python-arabic-reshaper/blob/master/arabic_reshaper/letters.py) and count only LETTERS\_ARABIC. it includes 77 character, so adding numbers and some special characters, i think the total number would be less than 256 (hopefully).

---

<div class="post-metadata">

**Author:** ![uleysky](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/uleysky/32/574_2.png) [@uleysky](https://forum.generic-mapping-tools.org/u/uleysky)\
**Post date:** [January 16, 2021, 3:34pm UTC](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209/20 "2021-01-16T15:34:57Z")

</div>

Also check ligatures.py, most of the code points are there. If you can figure it out and make a list of the code points you need, it will be good. If not, then, as I said, I’ll make a graphical list later for convenience.

And let’s make some more complicated examples for the proof of concept. Write a few test lines, and I will try to display them in the program. But tomorrow, I have a time zone further east than yours )

[Next page](https://forum.generic-mapping-tools.org/t/write-eastern-language-persian-farsi-arabic/1209.md?page=2)
