I recently started to use r-markdown to prepare journal articles with the handy templates from rticles. However, we ended up with submitting in Word rather than LaTex. Collaborators prefer Word, and at the moment, not all journals accept LaTex but all journals accept Word. Is there a place to get a collection of r-markdown templates to generate journal articles for Word document like rticles for LaTex?
Most likely you already found the option of editing the YAML:
output:
word_document:
reference_docx: template.docx
However, from experience, the best is to export the PDF as a word document (without figures) and add them later on.
I think what you are stating is really true and certainly helding Rmarkdown adoption.
Cheers
Related
Is there any way to take a Bookdown project, and build it as Markdown instead of HTML or TeX?
I ask because I need to post-process the final Markdown output from Bookdown, in order to extract R and Python notebooks for download.
In more detail, I am using Bookdown to build a textbook that embeds notebooks to download, where the notebooks contain subsets of the code and text in the bookdown .Rmd files. For example, a single chapter could contain more than one notebook.
In order to do this, I put start and end comment markers in the RMarkdown input text to identify the section that will be a notebook, and then post-process the generated Markdown files to extract the notebook section. As in something like:
<!--- notebook: first_section.Rmd
-->
Some explanation, maybe using Bookdown extra markup such as #a_citation.
```{r}
a <- 1
a
```
<!--- end of notebook
-->
More markdown.
```{r}
# More code not in notebook.
b <- 2
```
Obviously I could use the input RMarkdown pages, but this would be ugly, because all the extended Bookdown markup such as citations, cross-references and so on, would appear in raw and ugly form in the generated notebook. So I'd really like to be able to get the final output Markdown, after merging, resolving of citations and cross references. Is there any way of doing that?
My question is similar to this as-yet unanswered question, but adds my motivation for an official solution to this problem.
With the latest version of bookdown on CRAN, you can use the output format bookdown::markdown_document2, e.g.,
output:
bookdown::markdown_document2:
base_format: rmarkdown::md_document
variant: gfm
I am writing a paper in R markdown and need to format it with this .cls file supplied by an academic journal.
A minimal .tex file compiles perfectly well with the above cls file.
My .tex file (compiled on ShareLaTeX with clv3.cls saved in same directory):
\documentclass[shortpaper]{clv3}
\usepackage[utf8]{inputenc}
\title{Paper title}
\author{Name Surname}
\date{May 2018}
\begin{document}
\maketitle
\section{Introduction}
Some text.
\end{document}
However a comparable minimal document in R markdown, using the same cls file, fails to compile in Rstudio, with the following error: ! Package geometry Error: \paperwidth (0.0pt) too short.
My Rmd file (with clv3.cls file saved in same directory):
---
title: "Paper title"
author: "Name Surname"
documentclass: clv3
classoption: shortpaper
output: pdf_document
---
# Introduction
Some text.
Why is this error induced when I try to use this class file with an R markdown document and how may I fix it?
I've tried manually specifying a pagewidth setting in the YAML header, but I don't really know what I'm doing. This seems undesirable anyway, since the normal LaTeX document works fine without it (and surely page width is something that should be specified by a journal, not manually overwritten by an author).
I do not know where exactly the clv3.cls class and the default pandoc template clash. However, that template does so many things that do not make sense when writing with a specific style, that is best to use your own template. Using clv3-template.tex
\documentclass[shortpaper]{clv3}
\usepackage[utf8]{inputenc}
$if(title)$
\title{$title$}
$else$
\title{}
$endif$
$if(author)$
\author{$for(author)$$author$$sep$ \\ $endfor$}
$else$
\author{}
$endif$
\begin{document}
$if(title)$
\maketitle
$endif$
$body$
\end{document}
together with
---
title: "Paper title"
author: "Name Surname"
output:
pdf_document:
template:
clv3-template.tex
---
# Introduction
Some text.
should be a good starting point.
The accepted answer works perfectly for the minimal example presented. However it breaks again pretty quickly as the document is made more complex (for example, inserting a bibliography and in-text citations). I'd like to expand a little on my solution for the potential benefit of any future readers, as I found it a bit of steep learning curve:
The issue here is that Pandoc has a LaTeX template, which it uses to produce PDF documents. This is separate from a .cls class file, which defines a document class. Like Ralf Stubner says, something about my particular class file was not cooperating with Pandoc's default template. This is probably super basic and obvious to many, but I had not appreciated this extra step nor understood the distinction between these files.
If one does not wish to deal with raw LaTeX, it seems there are quite a few templates out there for various kinds of documents (see, for example, the rticle package). Using R Markdown to produce a PDF document in a particular custom format (such as for a particular journal) will require construction of a LaTeX template, however. This can be done by either of two ways:
Tinkering with an existing template until you get what you need, either by finding Pandoc's default template and starting from there (see comment by user2554330 for location) or by cloning someone else's template on Github etc.
Writing a template from scratch. In this case, Ralf Stubner's minimal example above plus this section of the Pandoc manual will be informative.
In my case, I went with the latter option. I have saved my eventual template as an R package which can be installed using devtools::install_github("JaydenM-C/CLtemplate"). So if anyone else would ever like to author a document for Computational Linguistics using this particular document style, this may save you some time.
I often find that in using RStudio R markdown, the resulting HTML can get quite long and heavy. What strategies can someone use to break down or otherwise manage long documents?
Create a table of contents (TOC) to move quickly to the different sections of your document. You do it by requesting a toc in the doc header, something like this:
---
title: "MyDoc"
output:
html_document:
toc: yes
---
Instead of being stuck at the top of a long document you can also produce a “floating toc" by adding a custom css-file. Have a look at this example.
This is the default behavior of bookdown. See Chapter 3 of its documentation for details. In particular, look for the option split_by in 3.1.1 and 3.4.
Currently there seem to be two ways to do presentations in R:
RStudio presentations, with .Rpres extension
rmarkdown, with .Rmd extension
To me, it looks like the latter is slightly more powerful. The input format is very similar, yet not identical. I'm thinking about converting an RStudio presentation to rmarkdown. What's the best way to do this? How about the conversion back?
On that note, I'd really like to see an "in-pane" preview for rmarkdown presentations in RStudio, just like for RStudio presentations. I wonder why this isn't implemented -- the preview forcibly shows up in a modal window. Technical issues?
To change from .Rpres to .Rmd you need to change file extension (easy) and the front matter of the markdown document (slightly more involved).
A .Rpres file places the front matter on the first slide:
Untitled
=============================
author: Your Name Here
date: 4 July, 2015
while a .Rmd document places the front matter in a special block:
---
title: "Untitled"
author: "Your Name Here"
date: "04 July, 2015"
output: ioslides_presentation
---
The rest of your presentation code remains in rmarkdown, and should require minimal work to convert.
Some exceptions that I can think of immediately include
ioslides/slidify don't support columns via *** (a real shame, as this is so convenient)
Rpres doesn't support citations and a bibliography (also a shame)
Additionally, when converting you will need to look for any speciall CSS or other directives that are only supported by one framework.
I was wondering whether there is a way for me to completely use Markdown language for writing a scientific paper along with R. I gave up on using Latex with knitr a while ago, since most of the journals need .docx files for submission, and converting from Latex to docx with pandoc is not always easy, especially when you get long scientific papers and you end up wasting hours debugging pandoc for trivial errors that Latex (and pdflatex) can easily pass. Anyway, I would like to use the power of knitr with flexibility of pandoc, markdown seems to be a good common ground. The only problem seems to be the bibliography and different citation styles that journals require. My question is: does markdown provide a simple to use (similar to biblatex, natbib, etc) bibliography engine? If not, what do you recommend for me to have a seamless transition from analyzing my data to submitting my papers? I'm sick of converting Latex to docx.
I basically use this setup, i.e. markdown in emacs but the concept is editor-independent. You can use a latex-like way to cite your paper in markdown and then use pandoc and the *.csl files. Check out this post for more details.