2

I have one reference in Arabic that shows blank squares instead of the Arabic characters.

This is my YAML

---
title: "A fancy project"
author: "A reliable human being"
output:
  bookdown::pdf_document2:
    latex_engine: lualatex           
    keep_tex: yes                   #keep the latex format
header-includes:
  - \usepackage[arabic, english]{babel}
  - \usepackage{fontspec}
  - \setmainfont{Garamond}
date: "2022-09-16"
bibliography: references.bib
csl: apa.csl
---

My reference is this one:

@article{al2020الخصائص,
  title={الخصائص السيكو مترية للصورة العربية للإصدار الثاني من قائمة الخمسة الكبار},
  author={Al-Ansari, Bader M and Alali, Talal B},
  journal={BAU Journal-Society, Culture and Human Behavior},
  volume={1},
  number={2},
  pages={3},
  year={2020}
}

This is my session info:

R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22622)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] kableExtra_1.3.4 dplyr_1.0.10    

loaded via a namespace (and not attached):
 [1] pillar_1.8.1      compiler_4.2.1    tools_4.2.1       digest_0.6.29    
 [5] viridisLite_0.4.1 evaluate_0.16     lifecycle_1.0.2   tibble_3.1.8     
 [9] pkgconfig_2.0.3   rlang_1.0.6       cli_3.4.1         DBI_1.1.3        
[13] rstudioapi_0.14   yaml_2.3.5        xfun_0.33         fastmap_1.1.0    
[17] stringr_1.4.1     httr_1.4.4        knitr_1.40        xml2_1.3.3       
[21] systemfonts_1.0.4 generics_0.1.3    vctrs_0.4.1       webshot_0.5.3    
[25] tidyselect_1.1.2  svglite_2.1.0     glue_1.6.2        R6_2.5.1         
[29] fansi_1.0.3       rmarkdown_2.16    bookdown_0.29     purrr_0.3.4      
[33] magrittr_2.0.3    scales_1.2.1      htmltools_0.5.3   assertthat_0.2.1 
[37] rvest_1.0.3       colorspace_2.0-3  utf8_1.2.2        stringi_1.7.8    
[41] munsell_0.5.0 

I have tried the solutions proposed here and here, but to no avail. They apply if Arabic characters are wanted within the text, so solutions like marking the text that you want in Arabic are not an option.

I think you have everything you need to reproduce it yourself.

DavidS
  • 47
  • 5

1 Answers1

2

One way you could show arab-text in bibliography by wrapping that arab text with \txarb from the arabluatex package and using biblatex as citation pacakge.


---
title: "A fancy project"
author: "A reliable human being"
output:
  pdf_document:
    latex_engine: lualatex  
    citation_package: biblatex         
    keep_tex: yes
header-includes:
  - \usepackage{arabluatex}
  - \usepackage{fontspec}
  - \newfontfamily\arabicfont[Script=Arabic]{Lateef}
date: "2022-09-16"
bibliography: references.bib
csl: apa.csl
biblatexoptions:
  - citestyle = authoryear
  - bibstyle = authoryear
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Rmarkdown

Lorem ipsum dolor sit amet [@al2020الخصائص] consectetur.


# Reference

references.bib

@article{al2020الخصائص,
  title={\txarb{الخصائص السيكو مترية للصورة العربية للإصدار الثاني من قائمة الخمسة الكبار}},
  author={Al-Ansari, Bader M and Alali, Talal B},
  journal={BAU Journal-Society, Culture and Human Behavior},
  volume={1},
  number={2},
  pages={3},
  year={2020}
}

arab text in bibliography


shafee
  • 15,566
  • 3
  • 19
  • 47
  • Thank you Shafee. Now, I have problems with the Arabic fonts. This message appears: ! Package fontspec Error: The font "Lateef" cannot be found. I don't know how to install it since apparently it should already be installed with the code you gave. – DavidS Sep 24 '22 at 16:08
  • Well, `Lateef` font is installed in my system. You are having this error because this font is not installed in your system. So either You can remove the line **\newfontfamily\arabicfont[Script=Arabic]{Lateef}** then the default font `Amiri` will be used, or if you want to use the `Lateef` font, you can download the font ttf files from [Google Font](https://fonts.google.com/specimen/Lateef) and then install the font, maybe following [this post](https://www.howtogeek.com/787939/how-to-install-fonts-on-windows-10/) on internet. – shafee Sep 24 '22 at 17:50
  • I have used `Lateef` font, because it seems a bit better than the default `Amiri` font. – shafee Sep 24 '22 at 17:56
  • Thank you, now it is working but there are some minor details. The references appear always numbered which do not have to happen with apa.csl. Also, the withintext citations, don't have commas, which is weird. Apparently, the problem is the citation_package: biblatex line, because once I take it away, it prints the references without numbers, although the Arabic one does not get printed. – DavidS Sep 26 '22 at 17:05
  • @DavidS, see the updated answer. Basically just added one more option `- bibstyle = authoryear` to get rid of numbers in the bibliography. And I do not understand what are you trying to say about comma. Can you please make a separate question stating the problem specifiically.? – shafee Sep 27 '22 at 11:00
  • If you see your output, you will see that a comma is missing between the author and the year. Also, the "and" should be "&". Instead of (Al-Ansari and Alali 2020), it should be (Al-Ansari & Alali, 2020). I'll post a different question, but this is basically it. – DavidS Oct 01 '22 at 14:25
  • Here is the link to the [new question](https://stackoverflow.com/questions/73919168/missing-and-commas-in-in-text-citations-in-rmarkdown) – DavidS Oct 01 '22 at 14:35
  • Oh, got it now clearly :-). I have already answered your question – shafee Oct 02 '22 at 09:22