rlatexquarto

How to render text in Pashto in a Quarto pdf?


I am attempting to render text in Pashto in a Quarto pdf in r. Below my code:

---
title: "Pashto text"
format: 
  pdf:
    toc: true
    number-sections: false
    colorlinks: true
    pdf-engine: lualatex
include-in-header:
  text: |
    \usepackage{fontspec}
    \usepackage[bidi=basic]{babel}
    \babelprovide[import=ps,mapdigits]{pashto}
    \babelfont[pashto]{rm}[Renderer=HarfBuzz]{Amiri}
---

```{r setup, echo=FALSE, include=FALSE}
cat("\\selectlanguage{pashto} دا پښتو متن دی")
cat("\\n")
```

I get the following error:

installing hyphen-pashto (1 of 1)
ERROR: [non-error-thrown] tlmgr returned a non zero status code
tlmgr install: package hyphen-pashto not present in repository.
tlmgr: action install returned an error; continuing.
tlmgr: An error has occurred. See above messages. Exiting.

In my understanding, there is no hyphen-pashto package. Is there a workaround?


Solution

  • You can use fontspec and then create a new fontfamily pashtofont with Script=Arabic. Amiri seems to be not available, which is why I took Arial. The cat-output can be parsed as LaTeX if you put results = 'asis'. We then also have to use \\textdir TRT, otherwise cat will flip the arabic and this will change the meaning!

    Option 1 (easy)

    ---
    title: "Pashto text"
    format: 
      pdf:
        toc: true
        number-sections: false
        colorlinks: true
        pdf-engine: lualatex
    include-in-header:
      text: |
        \usepackage{fontspec}
        \newfontfamily\pashtofont[Script=Arabic]{Arial}
        
    ---
    ```{r test, echo=FALSE, include=TRUE, results='asis'}
    cat("\\pashtofont \\textdir TRT دا پښتو متن دی")
    ```
    

    giving

    out

    Option 2 with custom 'Amiri' font

    You can download Amiri-Regular.ttf and put it in the same directory as your quarto file. Then use the following as outlined here

    ---
    title: "Pashto text"
    format: 
      pdf:
        toc: true
        number-sections: false
        colorlinks: true
        pdf-engine: lualatex
    include-in-header:
      text: |
        \usepackage[bidi=default, nil]{babel}
        \usepackage{fontspec}
        \newfontfamily\psfnt[Renderer={Harfbuzz}]{Amiri-Regular.ttf}
        \DeclareTextFontCommand\pstxt{\psfnt}
        
    ---
    ```{r test, echo=FALSE, include=TRUE, results='asis'}
    cat("\\textdir TRT \\pstxt{دا پښتو متن دی}")
    ```
    

    out Note: