I am trying to update my portfolio website with new Quarto-generated HTML files rather than my older RMarkdown-generated HTML files. I have rendered these updated files and they look great!
However, when I have uploaded this HTML to my GitHub Pages website, using htmlpreview, I get a very different picture...
Keep in mind that htmlpreview works perfectly well for my RMarkdown-renderd documents:
Here is my YAML for the Quarto document if it is of help:
author: "Brian Lookabaugh"
toc: true
number-sections: true
format:
html:
code-background: true
I think using self-contained: true would solve your case, since you would need a standalone HTML file.
author: "Brian Lookabaugh"
toc: true
number-sections: true
format:
html:
self-contained: true
code-background: true
For reference, see this page from Quarto Docs.
Related
I am using R Markdown to create a long html document with multiple images inserted throughout. I need automatically numbered figure captions, but cannot figure out how to generate them.
I insert figures this way:
![An informative figure caption](path.png)
The YAML metadata looks like this:
title: "My Title"
author: "me"
bibliography: References.bibtex
output:
bookdown::html_document2:
number_sections: TRUE
fig_caption: TRUE
I am using the bookdown package to produce a large document with tables using the knitr::kable function. I can get the document to produce tables in HTML perfectly, but in PDF, the table contents just appear as a list of numbers. This is also true for the output to Word. The compiled LaTeX just appears to be a list of numbers as well.
This is also true of output from other packages like sjplot.
The same problem also appears when the sample code from the bookdown book.
knitr::kable(
list(
head(iris[, 1:2], 3),
head(mtcars[, 1:3], 5)
),
caption = 'A Tale of Two Tables.', booktabs = TRUE
)
Produces the expected output in HTML:
But, produces the following in PDF:
The YAML header in index.rmd are:
#output ~~~~~~~~~~~ [see _output.yml]
site: bookdown::bookdown_site
output: [bookdown::gitbook, bookdown::pdf_book, bookdown::word_document2, bookdown::html_document2]
documentclass: book
The output settings in the _output.yml are:
bookdown::pdf_book:
keep_tex: true
latex_engine: xelatex
includes:
in_header: tex/biblio.tex
number_sections: yes
pandoc_args: ["--top-level-division=chapter"]
It turns out the problem arises from some interaction with the kableExtra package
So, even if you specify (as I did in my sample code) the knitr namespace (knitr::kable), there is still some downstream interference if kableExtra is loaded. So, this will not work when rendering to PDF:
library(kableExtra, warn.conflicts = TRUE)
knitr::kable(head(iris, 20), caption = 'Here is a nice table!', booktabs = TRUE)
While everything works for the HTML output, the rendering to PDF does not work for the tables and you just end up with a list of the table cell values (for both PDF and Word) - as shown in the image above.
To solve, remove any library statements
Then, ensure you unload the package:
detach("package:kableExtra", unload = TRUE)
And, finally, for me, I found that I needed to "Restart R and Clear All Outputs" or "Terminate R" from the R-Studio "Session" menu.
I am currently exploring the R Markdown configurations and the possibilities for the HTML output. My goal is to have a local html template as well as a local css theme file which behaves exactly the same as if I would select theme/highlight options in in the yaml configurations.
I used the following configuration:
output:
html_document:
theme: united
highlight: tango
toc: true
toc_depth: 3
toc_float: # set to false if you do no want a floating toc
collapsed: true
smooth_scroll: true
I now want to be able to customize the HTML structure and the CSS by my own. I started with the HTML template as follows:
Downloaded the standard pandoc HTML5 template and copied it into a local template.html file. I changed my configuration to
output:
html_document:
template: template.html
theme: united
highlight: tango
toc: true
toc_depth: 3
toc_float: # set to false if you do no want a floating toc
collapsed: true
smooth_scroll: true
There are several problems arizing:
the TOC is not shown anymore
the rendered HTML design of the output changed, i.e. I have no margin at all - all javascript functionality is gone, so no DT support, no tabs, no scrolling etc.
My question is: How can I achive the exactly same design and functionality I had before with my configuration but having the template/theme/highlight files stored locally? (So a template.html and a styles.css and all the needed JS files)
Let me know if I need to give further details. Thanks!
The Pandoc default you linked to is not the default used in rmarkdown. That one is stored in system.file("rmd/h/default.html", pkg = "rmarkdown"), and a current version is online here: https://github.com/rstudio/rmarkdown/blob/master/inst/rmd/h/default.html.
You should also study the source to rmarkdown::html_document if you decide to modify the default template. You'll also have to make some other changes if template != "default".
I'm creating a document with rmarkdown (pandoc), which includes some bibliography in a .bib file. What I'd like to do is add a link to the title of the references, so that each of them links to a page of the form http://sample.com/citation-key.html, like this:
Author. (2017). Sample Title. Journal, 1(1), 1–2.
I've tried modifying the .csl file by adding prefixes and suffixes to the title, but everything I put in there is escaped, whether I use markdown or HTML syntax. Unfortunately, I can't change the .bib file. The relevant part of the .csl file is this:
<text variable="title"/>
Sample files are:
literature.Rmd:
---
output: html_document
bibliography: literature.bib
csl: literature.csl
---
#author2017word says this doesn't work.
## References
literature.bib
#article{author2017word,
author = {Author},
journal = {Journal},
number = {1},
pages = {1--2},
title = {{Sample Title}},
volume = {1},
year = {2017}
}
literature.csl: I'm using the APA style from here (line 231).
My pull request to citeproc adding support this feature was recently merged, and as a result, the latest release of Pandoc (v2.14.2) now hyperlinks titles by default when the citation does not already show a raw URL! From the citeproc readme:
When linkBibliography=True automatically linkifies any identifiers (DOI, PMCID, PMID, or URL) appearing in a bibliography entry. When an entry has a DOI, PMCID, PMID, or URL available but none of these are rendered by the style, add a link to the title (or, if no title is present, the whole entry), using the URL for the DOI, PMCID, PMID, or URL (in that order of priority). See Appendix VI of the CSL v1.0.2 spec.
In pandoc, this option is controlled by the link-bibliography metadata field, which is True by default.
I'm writing a document in R Markdown and I'd like it to include a footer on every page when I knit a PDF document. Does anyone have any idea on how to do this?
Yes, this question has been asked and answered here: Adding headers and footers using Pandoc. You just need to sneak a little LaTeX into the YAML header of your markdown document.
This markdown header does the trick:
---
title: "Test"
author: "Author Name"
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{This is fancy header}
- \fancyfoot[CO,CE]{And this is a fancy footer}
- \fancyfoot[LE,RO]{\thepage}
output: pdf_document
---
Works for me with an Rmd file in RStudio Version 0.98.1030 for Windows.
Another option would be to use the argument includes provided by rmarkdown::pdf_document() (documentation). This allows you to keep the footer in a separate file. If your footer is defined in footer.tex, the header of your R Markdown file would look like this:
---
output:
pdf_document:
includes:
after_body: footer.tex
---
This also assumes that footer.tex is in the same directory as the R Markdown file.
Update: The file footer.tex can contain any valid LaTeX that you want to be inserted at the end of your PDF document. For example, footer.tex could contain the following:
This \textbf{text} will appear at the end of the document.
To manage the height of the footer, you can use the following:
date: '`r paste("Date:",Sys.Date())`'
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \setlength{\footskip}{-50pt} # set the footer size
Keep Coding!