Trying to knit to pdf from RStudio using a custom mystyles.sty file. This used to work fine but now that I have upgraded to RStudio 1.044 I get an error.
Example:
---
title: "Test"
output:
pdf_document:
includes:
in_header: mystyles.sty
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
With this style file:
\usepackage{titlesec}
\definecolor{airforceblue}{rgb}{0.36, 0.54, 0.66}
\definecolor{coolblack}{rgb}{0.0, 0.18, 0.39}
\titleformat{\title}
{\color{airforceblue}\normalfont\Large\bfseries}
{\color{airforceblue}\thesection}{1em}{}
\titleformat{\section}
{\color{coolblack}\normalfont\Large\bfseries}
{\color{coolblack}\thesection}{1em}{}
Gives me this error:
output file: test.knit.md
! Argument of \paragraph has an extra }.
<inserted text>
\par
l.1290 \ttl@extract\paragraph
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted
If I look at the tex file it produces I can't see any missing braces, and there isn't a line 1290. This is using the latest releases of RStudio, R and MacTex. AsI say, this used to work with an older version of RStudio but no more. If I take the includes:... bit out of the YAML it renders without complaint. Anyone able to help?
The problem is linked to the rmarkdown latex template redefining \subparagraph{}
in a way titlesec
doesn't like, as hinted at by this answer on tex.SE. This is the part of the template that causes the problem:
$if(subparagraph)$
$else$
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
$endif$
Since the \subparagraph
redefinition only happens if there is no subparagraph variable set, an easy workaround would be to set it in the yaml front matter. This compiles fine:
---
title: "Test"
output:
pdf_document:
includes:
in_header: mystyles.sty
subparagraph: true
---
This might not be the best solution however: it might be best to fix the subparagraph definition from the template.
Please see this link . See twsh's answer. It worked for me. The following is his answer.
I think that another option is to set the 'subparagraph' variable to true (--variable=subparagraph on the command line). Then titlesec.sty works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With