When I use RStudio to Generate PDF File,I Met this Error :! Missing number, treated as zero - r-markdown

When I use RStudio to Generate PDF File,I Met this Error :
Missing number, treated as zero.
<to be read again>
(
l.349 \begin
{minipage}[b]{\linewidth}\raggedright
错误: LaTeX failed to compile bookdown.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See bookdown.log for more info.
停止执行
When I open the tex file:
\begin{minipage}[b]{\linewidth}\raggedright
独立性和可持续性
\end{minipage}
the Rmd file is
---
CJKmainfont: PingFangSC-Regular
fontsize: "12pt"
indent: true
header-includes:
- \usepackage{xeCJK}
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
toc: yes
toc_depth: 1
template: latex/template.tex
documentclass: ctexbook
link-citations: yes
geometry: [b5paper, tmargin=2.5cm, bmargin=2.5cm, lmargin=3.5cm, rmargin=2.5cm]
colorlinks: yes
---
latex/template.tex:
https://github.com/yihui/bookdown-chinese/blob/master/latex/template.tex
How can I fix it? if I comment the code (#template:latex/template.tex) the Errors would be gone

You will successfully render the following Rmd to a pdf without any error.
Although #Stéphane Laurent commented here that you may need to add a diameter to \linewidth, I do not think that is cause of the problem you faced, since the Rmd below using \linewidth, not 1\linewidth, works fine.
The real problem may lay in other parts of your Rmd file, I suspect. However, you must post a reproducible example like the one I show in this answer, as I commented here, and present the contents of the .log file that is created when you knit your Rmd file.
---
header-includes:
- \usepackage{ctex}
output:
pdf_document: default
---
\begin{minipage}[b]{\linewidth}\raggedright
独立性和可持续性
\end{minipage}

Related

How to print special Latin characters in Markdown pdfs

I need to knit my Markdown script into a pdf file, but when knitted, the pdf file does not show special Latin characters, such as those used in the International Phonetic Alphabet (IPA).
---
title: "MarkdownIPA"
date: '2022-07-06'
output:
pdf_document:
latex_engine: xelatex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
`Print IPA`
```{r}
'[aɪ.pʰiː.ɛɪ]'
```
Which rends:
How can I fix this?
You'll need to use a font that supports those glyphs. A (IMHO) rather nice one is Source Sans Pro and the monospace variant Source Code Pro.
To use Source Code Pro, you can add the respective LaTeX code directly:
---
title: "MarkdownIPA"
date: '2022-07-06'
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{sourcecodepro}
---
Result:
The sourcecodepro package is likely already installed; otherwise you'd have to install it first.

Problem with ligatures in Rmarkdown / bookdown pdf output

In my Rmarkdown project, I'm having trouble in correctly exporting ligatures in PDF file.
font-config.tex file -
\usepackage{fontspec}
\setmainfont{Noto Sans}
YAML front-matter in Rmd file -
---
title: "test"
author: "author"
date: "22/02/2021"
output:
pdf_document:
latex_engine: xelatex
includes:
in_header: font-config.tex
---
The following text is in hindi language.
गुरु
Output shown in PDF -
Output expected -
The Nakula font is correctly displayed, but it does not have bold-face type font.
The Noto Sans font I'm using works fine in html output, but have problem with ligature in PDF output.
I tried, the pandoc documentation and other similar questions on stackoverflow and tex.stackexchange, but no luck.
I'm new to TeX, and hopefully it has a very simple solution.
This may work for you, following the information given here:
---
title: "Hindi"
author: "bttomio"
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{fontspec}
- \setmainfont{Noto Sans}
- \usepackage{polyglossia}
- \setdefaultlanguage{hindi}
- \setotherlanguage{english}
- \newfontfamily\devanagarifont[Scale=MatchUppercase]{Nakula}
- \newfontfamily\devtransl[Mapping=DevRom]{Times New Roman}
---
The following text is in hindi language.
गुरु
-output

Bookdown/rmarkdown: "Could not find data file templates/--number-sections.latex Error: pandoc document conversion failed with error 97"

Following: render_book("index.Rmd")
I was getting this other error associated with three part table:
LaTeX Error: Environment ThreePartTable undefined
I applied the solution suggested there(remotes::install_github('rstudio/rmarkdown')). Now I have this error:
"Could not find data file templates/--number-sections.latex
Error: pandoc document conversion failed with error 97"
My index.Rmd looks like this:
title: "Figures and Tables"
author: "name"
date: "`r Sys.Date()`"
output:
bookdown::pdf_book:
includes:
in_header: preamble.tex
keep_tex: yes
citation_package: natbib
fontsize: 12pt
classoption: oneside
linestretch: 2
documentclass: book
bibliography: "bibs.bib"
biblio-style: "apalike"
geometry: "left=1.5in, right=1in, top=1in, bottom=1in"
---
preamble.tex has:
\usepackage[none]{hyphenat}
\usepackage{booktabs}
\pagestyle{plain}
\raggedbottom
While render_book("index.Rmd") does not generate a pdf and gives me this pandoc error, it successfully generates a merged markdown file "FiguresTables.Rmd." When I try to knit the merged file it works, it does generate the pdf. I just cannot figure-out why I am unable to generate the pdf from render_book("index.Rmd").
Never mind! Writing the question made me think of an answer. I just re-installed r-markdown from the cran repository instead of github and tried again. And it works fine now.

R Markdown + bib file: unused argument error

My .rmd file fails to compile when including citations as a .bib file.
I attached the code and error message here and very appreciate if someone could help.
The indentation of the YAML options is important. You currently have bibliography within the output section, but it should be placed in as a top-level YAML.
title: "Title"
author: "Author"
output:
pdf_document:
keep_tex: true
bibliography: bib.bib
Edit: Make sure you have moved the bibliography out of the pdf_document options completely, as follows:
author: "Author"
output:
pdf_document:
keep_tex: true
fig_caption: yes
number_sections: yes
bibliography: bib.bib
---

Where to put header.tex to change page to Landscape Rmarkdown

I read here how to add what is needed to give me the ability to change my page to landscape:
enter link description here
However I have saved the header.tex file everyplace I could think of and I still end up getting the following error:
Called from: (function (e)
{
if (inherits(e, "shiny.silent.error"))
return()
handle <- getOption("shiny.error")
if (is.function(handle))
handle()
})(list(message = "pandoc document conversion failed with error 43",
call = NULL))
Browse[1]>
I know this is do to me typing \blandscape and \elandscape because the PDF works as soon as I delete those commands. What I need help with is figuring out where to save the header.tex file to so that Rmarkdown knows how to locate it. Thanks in advance for everyone's your help!
Follow up:
Taking scoa's advice about adding it to my header I edited the top of my Rmd file to the following. Unfortunately it still didn't work.
---
title: "Lake Report"
output: pdf_document
header-includes:
- \usepackage{lscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
---
\newpage
\blandscape
```{r Non-Seasonal MK results, echo=FALSE}
# MKanalysis <- reactive(HM_MK(data = NonSeasonalData(),n = 4))
kable(MKanalysis(), caption = "Non-Seasonal Trend Analysis")
```
The results of the Mann Kendall analysis....
\elandscape
Latex program/verision: pdfTex, Version 3.14159265-2.6-1.40.17
Save the header.tex in the same directory your Rmd file is. Also, rather than an external file, you could just add those commands in your yaml front matter, a more portable solution:
---
title: "Lake Report"
output: pdf_document
header-includes:
- \usepackage{lscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
---