Output of fa2latex command from psych causing LaTeX error in pandoc - latex

I am writing a report using knitr in RStudio. Also using the psych package for factor analysis:
```{r, results='asis'}
library(psych)
data(Thurstone)
fa.Thurstone<-fa(Thurstone)
fa2latex(fa.Thurstone)
```
When I run this code chunk it causes an error:
! LaTeX Error: Unknown float option `d'.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.124 \begin{scriptsize} \begin{table}[htdp]
pandoc: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
When I save the TeX code it runs fine in LaTeX, but not in knitr.
Any suggestions on how to resolve this?

Related

How to execxute a Latex file?

everyone I'm trying to compile a latex file in Windows using MiKTeX and Texmaker. But the file is not compiling and there is showing an error as " Could not start the command.
pdflatex -synctex=1 -interaction=nonstopmode %.tex"
Can anyone help in this regard as to how this file will execute?.

How to solve error with YAML, Preamble (LaTex) and Pandoc conversion

I started using markdown together with pandoc a few weeks ago. I'm especially fond of the markdown editor writemonkey v.3! I have one slight problem with converting my .md to .pdf, and I it's caused by the first line in my document. The first line in the document (see below) is how you give the document a name in writemonkey.
name: seminarium 1
---
author: my name
date: 22 Augusti 2020
bibliography: testlibrary.bib
geometry:
- top=2.5cm
- bottom=2.5cm
- left=2.5cm
- right=2.5cm
pagesize: a4
font: Times New Roman
fontsize: 12pt
header-includes:
- \usepackage{setspace}
- \setstretch{1.0}
- \pagenumbering{gobble}
---
If I remove this first line, the pandoc conversion works like a charm. Otherwise I get this:
pandoc sem1.md -o sem1.pdf --bibliography library.bib -V lang=sv
Error producing PDF.
! LaTeX Error: Can be used only in preamble.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.78 \usepackage
Now - I realize that I've combined a YAML with LaTex code, I am hoping that my formatting is "bad" and that I might improve it so I don't have to remove the first line every time. Maybe tell Pandoc/LaTex to ignore the first line or make a separate .yaml file would help?
Ok! This what I did. Works great with Writemonkey. Just copy-paste in Notepad and save as a .ps1 file and run in Powershell!
CD C:\Users\username\Desktop\ppp2020 # Filepath of .md, .yaml and .bib
Get-Content cap.md -Encoding UTF8 | Select-Object -Skip 2 | Set-Content cap_temp.md -Encoding UTF8 # Removes the first line (name:) from markdown document
pandoc cap_temp.md default.yaml -o cap.pdf --bibliography library.bib -V lang=sv # converts .md to .pdf
Remove-Item 'C:\Users\username\Desktop\ppp2020\cap_temp.md' # This removes the tempfile

R Markdown: PDF Document compile error (pdf backend)

I decided to write my thesis in rmarkdown and have issues in knitting the document to pdf. It is a very large file. The document works with html_output but has issues in compiling using pdf_output. As I save the latex file using keep_tex I can then run it and it safely outputs a pdf_document (with some formatting issues).
date: "8/12/2019"
output:
pdf_document:
keep_tex : true
latex_engine : lualatex
includes :
before_body : Title.sty
fig_width : 6
fig_height : 4
fig_caption : TRUE
citation_package: biblatex
bibliography: Bibliographytxt.bibtex
output file: Test.knit.md
tlmgr search --file --global "/biblatex-dm.cfg"
tlmgr search --file --global "/Test.bbl"
! error: (file "Test_files/figure-latex/""Decision_Trees-1".png) (pdf backend):
Error: Failed to compile Test.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See Test.log for more info.
In addition: Warning messages:
1: In readLines(log) : incomplete final line found on 'Test.log'
2: In parse_packages(logfile, quiet = c(TRUE, FALSE, FALSE)) :
Failed to find a package that contains biblatex-dm.cfg
3: In parse_packages(logfile, quiet = c(TRUE, FALSE, FALSE)) :
Failed to find a package that contains Test.bbl
Execution halted
Does anyone know why R is reading the file like:
! error: (file "Test_files/figure-latex/""Decision_Trees-1".png) (pdf backend):
where the file Decision_Trees-1 is being read somehow in double quotation marks!?
Should it not read "Test_files/figure-latex/Decision_Trees-1.png".
In addition, the knitr::include_graphics("Mypdf.pdf") does not seem to work either when I try to load a file, either in pdf or png format.
Please help.

pandoc.exe: Error producing PDF

I have tried running the following simple code;
```{r sample}
library(knitr)
library(kableExtra)
dt <- mtcars[1:5, 1:4]
# LaTeX Table
knitr::kable(dt,format = 'latex')%>%
column_spec(column = 1,width = '10cm',bold = T)
```
This runs fines with the Knit button. but get the following error when using rmarkdown::render();
! Undefined control sequence.
l.173 \centering\rowcolors
pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS tst.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output tst.pdf --template "C:\PROGRA~1\R\R-34~1.1\library\RMARKD~1\rmd\latex\DEFAUL~3.TEX" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' had status 43
Also note that without the format = 'latex' option it works fine with rmarkdown::render()
I tried the suggestions for similar errors but non of them worked (update Rmarkdown, install MikTex and the pdflatex.exe to path variable). Can someone please help me with this.Thanks
Calling the array package in the YAML worked for me.
header-includes:
- \usepackage{array}

Markdown to PDF using Pandoc since Xetex Deprecation

On my MacBook (OSX Mountain Lion), I used to use this Pandoc command to convert Markdown to PDF:
$ markdown2pdf -N -o pandoc_output.pdf --xetex --toc --template=mytemplate.tex myfile.md
But markdown2pdf no longer works, and --xetex option in markdown2pdf -N -o ../../Desktop/pandoc_output.pdf --xetex --toc --template=mytemplate-headers-garamond_date.tex is deprecated.
If I do this:
$ pandoc -N -o Desktop/pandoc_output.pdf --xetex --toc --template=mytemplate.tex myfile.md
I get this:
pandoc: unrecognized option `--xetex'
But if I take out --xetex and do this:
$ pandoc -N -o Desktop/pandoc_output.pdf --toc --template=mytemplate.tex myfile.md
then I get this:
pandoc: Error producing PDF from TeX source.
! Package hyperref Error: Wrong driver option `xetex',
(hyperref) because XeTeX is not detected.
See the hyperref package documentation for explanation.
Type H <return> for immediate help.
...
l.3925 \ProcessKeyvalOptions{Hyp}
What's the solution?
Try --latex-engine=xelatex instead of --xetex
The prior answers to this question were helpful to me, as I had installed pandoc a couple years ago, but never Tex Live. Consequently I had no idea if I had installed it correctly, so putting in the entire path helped me to see that it was working, as follows:
pandoc --latex-engine=/usr/local/texlive/2012basic/bin/universal-darwin/xelatex
This is the default install location for the BasicTex setup which you download from the Pandoc install page.
I had also forgotten about using pandoc -D Latex >my-latex-template.tex to generate a template. After giving a .tex template instead of my .html one (which caused a 'you don't have BEGIN {' error) , I got .PDF: In other words, the default template worked.
Also, I had inaccurately entered -t pdf (not shown above) to set pdf as an output format, but this was not correct. The output format is Latex, which is then translated to PDF. It is not necessary to specify an output format with the dash -t option.
I hope this record of my minor stumbles saves someone some time.
See the pandoc User's Guide (or man page) for the --latex-engine option.

Resources