rstudio / rticles

LaTeX Journal Article Templates for R Markdown
https://pkgs.rstudio.com/rticles/
1.47k stars 518 forks source link

MDPI issue with unicode characters #325

Closed etiennebr closed 3 years ago

etiennebr commented 3 years ago

Using rticles::mdpi_article by @dleutnant (thank you sir), I have an issue with Unicode characters contained in the text (and probably the bibliography as well). I can reproduce the bug on the default mdpi_article Rmd by throwing e.g. Δ somewhere in the text.

! Package inputenc Error: Unicode character Δ (U+0394)
(inputenc)                not set up for use with LaTeX.

xelatex seemed like the solution but mdpi_article doesn't seem to support it. Using:

output: 
  rticles::mdpi_article: 
    latex_engine: xelatex

on the default mdpi_article template gives

! Undefined control sequence.
\set@color ->\pdfcolorstack 
                            \@pdfcolorstack push{\current@color }\aftergroup...
l.1457 \color{black}

So I used a preamble to insert definitions

\DeclareUnicodeCharacter{2009}{\,}
\DeclareUnicodeCharacter{2300}{$\oslash$}
% ... more unicode characters!

With

output: 
  rticles::mdpi_article: 
    includes:
      latex_engine: pdflatex
      in_header: "preamble.tex"

But the list of unicode characters I need to define is increasingly long an it seems like I'll have to define the whole UTF-8 set!

Is there a way to make the mdpi package use xelatex, or support utf8 and resolve the issue once for all, or I should just spend that time declaring utf characters in the preamble?

For context, I'm converting papers originally written in Word and Google docs. I would probably have used the math notation if I was writing the Rmd directly, although I like having the symbols in the RMD (in Rstudio at least), it reads nicely.


By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

cderv commented 3 years ago

I will require some Latex expert here to help on this one.

Maybe @dleutnant will be able to help to make this template work for xelatex.

If someone know the changes to be made in the tex template, I'll be happy to do it but I don't know yet what to fix here.

cderv commented 3 years ago

While reviewing #381 I saw that a special pdftex option is set https://github.com/rstudio/rticles/blob/b348d8322c6f8dc993f01140ea9a1bfbb5f6ea40/inst/rmarkdown/templates/mdpi/resources/template.tex#L5

it may not be compatible with xelatex. From MDPI official template

%--------- % pdftex %--------- % The option pdftex is for use with pdfLaTeX. If eps figures are used, remove the option pdftex and use LaTeX and dvi2pdf.

Would you be able to try without it maybe ?

Also @etiennebr you could try #381 if maybe the updated template fix this.

etiennebr commented 3 years ago

Thanks for following up @cderv, I now better understand the differences between xelatex and pdf latex and I see it is a requirement of the editor anyway. Using xelatex doesn't work with #381 either, so using a preamble is the best bet. Closing now.

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.