How to use non-English characters in a bib file in RMarkdown with vitae package?

This is an RMarkdown file that I use to knit a cv in pdf.
I have no problem using Portuguese characters in the body of the Rmd file.

But the same characters imported in the bib file (test.bib) when I do pubs <- bibliography_entries("test.bib") are not well encoded.

This only happens in Windows. When I use my Mac the output is fine!

---
header-includes:
   - \usepackage[T1]{fontenc}
   - \usepackage[utf8]{inputenc}
   - \usepackage[portuges]{babel}
   - \usepackage{apalike}
output: vitae::hyndman
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
library(vitae)
```

# Publicações
Sérgio Conceição é o autor de um trabalho sobre habitação.

```{r publications}
library(dplyr)
pubs <- bibliography_entries("test.bib")
pubs
```

This is my test.bib file:

@article{conc2021,
  title={História da Habitação},
  author={Conceição, Sérgio},
  journal={Portuguese History},
  number={1},
  year={2021}
}

This is the output:
enter image description here

Could be related to this ?

1 Like

@cderv Please see my post edit. Yes it is the same problem with Windows 10. Not with MacOS or Linux.

1 Like

If it is windows only, it may be link to non-UTF8 by default on windows and a file that may not be read with the correct encoding.

You should also be sure that your files are all UTF8 encoded.

I would follow the issue on Github from there if it is the same.

I can't do much more. Hope it helps

1 Like

I tried to change Windows default to utf-8 and also the language to Portuguese but none of succeeded.
It is strange because when I open test.bib with Notepad on Windows it reads well. The file is utf-8 coded.

Seems like an issue with vitae then. I don't know how this package works so I can't help further. Sorry

1 Like

Encoding is pain - and the English speaking guys have it easy.

I am not familiar with {vitae}, but two tricks that I found helpful when hacking character encoding in general are:

  • using the unicode escape function stringi::stri_escape_unicode() to encode characters that the current codepage has difficulty handling
  • re-encoding characters from unicode back to unicode stringi::stri_encode(yer_string, from = 'UTF-8', to = 'UTF-8') - this is a truly ugly hack, but it has worked for me when nothing else would...
2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.