2

When I write YAML code in the Quarto config file to include latex commands that render Arabic nicely into pdf it works fine. The same YAML code does not work in Quarto.

This is the code that works in plain markdown, but not in the Quarto config file (_quarto.yml):

header-includes:
  - |
    ```{=latex}
    \usepackage{babel}
    \babelfont[arabic]{rm}[Scale=1.2]{Amiri}

I use Quarto with VSCodium, and as far as I know, it uses the same pdf engine (xelatex) as when I render plain .md files. I get the following error message in the terminal when I try to render:

In file _quarto.yml
(line 34, column 7) Array entry 1 is empty but it must instead be a string.
33:     header-includes:
34:     - |
         ~
35:       ```{=latex}

If I delete the header-includes lines my .qmd documents render nicely into pdf, except that there are just blanks where the Arabic script should have been.

shafee
  • 15,566
  • 3
  • 19
  • 47
jacobhoi
  • 35
  • 5

2 Answers2

2

You do not need to use the latex block to include raw contents. Use include-in-header and the text subkey instead. From the documentation,

To include raw content in the YAML header, use the text subkey. When using text:, add the | character after text: to indicate that the value is a multi-line string.

So try as the following,

include-in-header:
   text: |
    \usepackage{babel}
    \babelfont[arabic]{rm}[Scale=1.2]{Amiri}
shafee
  • 15,566
  • 3
  • 19
  • 47
  • Many thanks! It still does not work perfectly, but at least there are some Arabic characters in the pdf files now. The rest is probably just to tweak the latex instructions according to the fonts and engine I have on my computer. – jacobhoi Jun 23 '23 at 15:10
  • If using the latex command does not work perfectly, then I think @tarleb suggestion in his answer is worth trying. – shafee Jun 23 '23 at 17:06
1

Instead of using raw LaTeX commands, try to set the document language to Arabic and experiment with different LaTeX engines. As far as I know, LuaLaTeX has the best support for Arabic:

---
lang: ar
pdf-engine: lualatex
---
tarleb
  • 19,863
  • 4
  • 51
  • 80
  • Thanks for the suggestion. Unfortunately it doesn't work. Most of the document is in Latin script (Norwegian language), and that gets garbled when setting lang to "ar". So I think I will have to find some kind of LaTeX solution. – jacobhoi Jul 19 '23 at 19:43