27
votes

In RStudio, when i go for convert my Markdown file to PDF then it gives me the error:

output file: report.knit.md

! Package inputenc Error: Unicode char \u8: not set up for use with LaTeX.

See the inputenc package documentation for explanation. Type H for immediate help. ...

l.117 performance for 32 automobiles (1973â

Try running pandoc with --latex-engine=xelatex. pandoc.exe: Error producing PDF from TeX source Error: pandoc document conversion failed with error 43 In addition: Warning message: running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS report.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output report.pdf --template "C:\Users\USER\Documents\R\win-library\3.2\rmarkdown\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in"' had status 43 Execution halted

My R version (Windows 7):

R version 3.2.1 (2015-06-18) -- "World-Famous Astronaut" Copyright (C) 2015 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit)

8
A blind shot, have you defined encoding? \usepackage[utf8]{inputenc}Roman Luštrik
the error message suggests "Try running pandoc with --latex-engine=xelatex". This is done by adding latex_engine: xelatex in the yaml header under output: pdf_document.scoa
FYI neither \usepackage[utf8]{inputenc} nor latex_engine: xelatex nor @svannoy's answer worked for me. So this is still an open question, and should have a bounty put on it.warship
Update: I noticed that one of my double quotes (") was copy-pasted from a word processor (e.g., Microsoft Word), which was the culprit. Easy fix. Double-check those double quotes!warship
@warship - thx - did the same - found the errant character - thanks....malcook

8 Answers

42
votes

Given the almost identical error message, I tried following @scoa's suggestion, but putting that line in the YAML header did not change the error, so for whatever reason, Knitr wasn't looking there to determine the LaTex engine. However, next to the "Knit PDF" button in the control bar is a settings menu that allows you to specify the LaTex ending in the "Advanced" pane. This solved the problem for me. It produces a slight variation on the suggestion above, modifying the YAML header thus:

  output:
     pdf_document:
         latex_engine: xelatex

I can see that @scoa may have assumed the YAML output was already formatted this way, but what I was missing was the colon after 'pdf_document'. Using the settings dialogue created the proper syntax in the header.

RStudio version 0.99.896, knitr version 1.12.3.

enter image description here

1
votes

Here is a less technical solution but it worked for me when everything else didn't. Try deleting (after copying your code elsewhere) parts of your file and then kniting it. Then by process of elimination you will be able to narrow it down to the character/s that are causing the problem. Keep in mind there may be multiple occurrences of the problem. To make it easier to find the character the error message gave me the utf code of the character and I was able to look up what it was. Apparently there was a special 'fi' character used five times in the text I copied and pasted from so I looked for and replaced them with a normal 'fi'.

0
votes

I know I am a bit late for this, but I just had almost the same error (minus the pandoc part).

The problem was that I copy pasted a sentence from wikipedia, which had a dash character which was not utf8 formatted. I replaced the dash and it worked.

Latex fails (with an encoding error) to create a pdf if there are "special" characters in your document, like incorrect whitespace/newline characters, or characters with accents. An easy way to check copy-pasted text is to first paste it into a very basic text editor, like nedit.

0
votes

I do have the same problem recently.

I solve this problem in a straightforward way, maybe stupid you think. Obviously, the error suggests that some characters or signs in your code could not recognize properly by LaTeX.

So, I remove the code from the R markdown part by part to find which part caused this problem. Finally, I found the part that resulted in the error in my code. Just a very short description in my code.

### Platform:Affymetrix A-AFFY-2-Affymetrix GeneChip Arabidopsis Genome [ATH1-121501].

I remember I copy this information from webpage or other somewhere.

So I type this part to my code by myself. It can run and generate the pdf file without any error. Now, what is the difference between the copy version and the version of my typing?

To be clear, I show you in the below attached figure:

enter image description here.

This is just one example I think. I want to point out that it is always problematic when you copy something from an unknown resource file into your code.

Hope this can help you and other people who were frustrated by this problem.

0
votes

I had the same problem, but with a very long document. Rather than manually split the document to find the offending non-utf8 text, I found this solution (for users of RStudio), saving the document in the utf8 format, worked a treat and saved lots of time:

  • in Rstudio
  • from the menu choose "File" > "Save with encoding..."
  • from the dialog box choose "UTF-8"

Here are the original links:

0
votes

I solved my problem checking chunk by chunk, coping and paste to another script to test and find the error. And was an idiot error, I accidently add the character 'ẽ' in a comment. I fixed and the export pdf was pretty good. :)

0
votes

Further to this with

rstudio --version
1.3.1056

R version 4.0.5 (2021-03-31) -- "Shake and Throw"
Platform: x86_64-pc-linux-gnu (64-bit)

xelatex --version
XeTeX 3.14159265-2.6-0.999992 (TeX Live 2020 Gentoo Linux)
kpathsea version 6.3.2
Compiled with ICU version 67.1; using 67.1
Compiled with zlib version 1.2.11; using 1.2.11
Compiled with FreeType2 version 2.10.4; using 2.10.4
Compiled with Graphite2 version 1.3.14; using 1.3.14
Compiled with HarfBuzz version 2.7.4; using 2.7.4
Compiled with libpng version 1.6.37+apng; using 1.6.37+apng
Compiled with poppler version 21.02.0
Compiled with fontconfig version 2.13.1; using 2.13.1

Setting XeLateX in both the Global and Project options did not work. The only thing that worked was either setting it manually, in the YAML, as described above, or going to the knitr output options (which are set per file) and choosing XeLateX there, under the Advanced tab for PDF output.

This has bitten me more than once.

0
votes

Try changing options "Sweave" in RStudio.

enter image description here