Calligra font with RMarkdown - latex

This is my Rmarkdown code:
---
title: "My Title"
header-includes:
- \usepackage{calligra}
- \usepackage[T1]{fontenc}
output:
pdf_document:
latex_engine: xelatex
---
# Section 1
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:
I was studying the best way to change fonts in Rmarkdown. In texlive the installed calligra package appears and calligra-type1 also.
When I run the script with the calligra package it generates the pdf but the font does not match the calligra font.
And when I run the script for calligra-type1 the pdf is not even generated.
Any help, guys?

The calligra.sty does not set-up the Calligra as default font, but you can do so by adding
\renewcommand{\rmdefault}{calligra}
to header-includes.
BTW, there is no need to call fontenc.sty, since calligra.sty does so already. In addition, using xelatex is not necessary here.

Related

include Rmarkdown pdf output code into a seperate latex theisis tex file

I am trying to write a report.tex theists using TexMAKER,and I need to include a lot of r,
So I run my chunk code file with this preamble in Rmarkdow
title: "rcode"
author: ".."
date: "..."
output:
pdf_document:
keep_tex: yes
fig_caption: yes
html_document: default
then include the rcode.pdf output file in my original report.tex file using the command \includepdf[]{rcode.pdf}
this method is not so good because the page numbering in my report.pdf gets mixed up with the numbering of the Rmardown pdf output rcode.pdf,
So I am wondering if there is a new way to extract the rcode.tex code then include it in my report.tex file ?
Or is the better way just to start wring all of the theisis report in the rmardown file with out having any Latex complications ?
thanks for the help

Repeat Title and Date R Markdown PDF

I am struggling what what is likely a trivial markdown matter. I am hoping to avoid YAML and additional header templates and such if I can. So my question is straightforward and I welcome your feedback. For an R Markdown knitted as a PDF, how can I repeat the title and date on each printed page?
Alternatively I am happy to use headers using the '#' syntax. But if I can use the title parameters that would be preferred.
The Header thus far:
---
title: "Dashboard"
date: '`r paste(Sys.Date(), " to ", Sys.Date()+14)`'
output:
pdf_document:
latex_engine: xelatex
mainfont: Calibri
geometry: margin=1cm
classoption: landscape
params:
set_title: !r test_title
header-includes:
- \usepackage{titling}
- \pretitle{\begin{flushleft}\huge}
- \posttitle{\end{flushleft}}
- \preauthor{\begin{flushleft}}
- \postauthor{\end{flushleft}}
- \predate{\begin{flushleft}\large}
- \postdate{\end{flushleft}}
---
From the rmarkdown cookbook:
When a Rmd document is compiled, all of its metadata in the YAML section
will be stored in the list object rmarkdown::metadata. You can use this object
in your R code. For example, rmarkdown::metadata$title gives you the title
of the document.

change mathjax renderer in R notebooks (with "self_contained: false")

I am creating R notebooks that contain equations. I am using RStudio 1.2.5033 on Windows 10, R 3.5.1, and rmarkdown 2.1. When my R notebooks are rendered as HTML, MathJax (v2.7.2) uses the "HTML-CSS" output processor to render the equations. But I think that the output from the "CommonHTML" output processor looks better. So I want to include a directive, in my R notebooks, that forces MathJax to use the CommonHTML output processor. How may I do this?
If I were rendering an ordinary R Markdown document with output format html_document, I could solve the problem via the mathjax option in my YAML header. For example, when the following file is rendered to HTML, MathJax will use the CommonHTML output processor:
---
title: "Trouble with MathJax"
output:
html_document:
mathjax: "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML.js"
self_contained: false
---
\begin{equation}
R_3 = \alpha
\end{equation}
But this solution doesn't work well when I change the output format from html_document to html_notebook. In that case, I get output that looks like this:
The equation is rendered with CommonHTML, but there is a lot of cruft at the top of the page (note the four bullet points), and the default R Notebook CSS doesn't seem to be implemented.
The problem seems to be general to rendering R notebooks with self_contained: FALSE, as suggested in R notebooks don't render properly when "self_contained" is FALSE because the "files" directory is deleted after rendering. But I can't see a good workaround for that problem.
Dead Ends
The MathJax documentation seems to indicate that I can specify the output processor by adding the jax array in a call to MathJax.Hub.Config(). But when I've done that, my equations are still displayed via the HTML-CSS output processor. Here is a minimal example of an R Markdown document that exhibits the problem:
---
title: 'Trouble with MathJax'
output: html_notebook
---
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
jax: ["input/TeX", "output/CommonHTML"],
});
</script>
\begin{equation}
R_3 = \alpha
\end{equation}
The call to MathJax.Hub.Config() seems to do nothing here. In both Chrome and Edge, the equation is rendered via HTML-CSS, not CommonHTML. How can I change the rendering to Common HTML?
Related Posts
One year-old post, Is there a way in markdown to override default mathjax renderer?, is about Jupyter notebooks, but it's relevant. It hasn't received an answer.
Adapting the script in this post from the MathJax Google Group –– mainly by changing "HTML-CSS" to "CommonHTML" –– doesn't seem to have any effect.
The solution is simply to omit the self_contained line in the YAML header or, equivalently, to set self_contained to true. Here is a minimal example of an R notebook for which the user has chosen the mathjax renderer:
---
title: "Self-contained notebook with non-default Mathjax config"
output:
html_notebook:
mathjax: "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML.js"
---
$R_3 = 2$.
When the file is rendered to HTML, the equation is displayed with CommonHTML, not with HTML-CSS. And the Mathjax script is contained within the "nb.html" file that is produced.
I was surprised that this works, because the documentation for rmarkdown::html_document() says that "even for self contained documents MathJax is still loaded externally (this is necessary because of its size)." But Section 3.1.8 of the R Markdown book indicates that the restriction applies only when Mathjax is loaded from a local file. So perhaps it shouldn't be a surprise.
Side note: the default Mathjax configuration used by the rmarkdown package is given by rmarkdown:::mathjax_config(). As of rmarkdown v2.1, the function returns "MathJax.js?config=TeX-AMS-MML_HTMLorMML".

Pandoc Error producing PDF with markdown body text and YAML metadata file

I'm running the following Pandoc 2.0.3 command on the Mac Terminal command line:
pandoc one.md "metadata.yaml" -o two.pdf
This should take the markdown file one.md and output two.pdf using the yaml file metadata.yaml, a minimal version of which is:
---
header-includes:
- \usepackage{fancyhdr}
...
This Pandoc run produces a PDF as expected for the following version of one.md:
# Report
However, it fails to produce a PDF for the following version of one.md, which contains body text:
# Report
Lorem.
The resulting error message is:
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.65 header-includes: - \usepackage
I don't understand why including that one word creates a failure.
Your one.md likely doesn't end with a newline. Pandoc concatenates all input files, adding a single newline between files. So the resulting input will be:
# Report
Lorem.
---
header-includes:
- \usepackage{fancyhdr}
...
As a result, the opening dashes of the YAML block are interpreted as underlines for Lorem., which is then read as a second-level header. This doesn't happen if the line above the --- dashes is an ATX-style header.
Just add a newline to the end of one.md and everything should work the way you expected.

org-mode exclude fullpage.sty from latex preview preamble

Using fullpage.sty in a document preamble breaks latex preview by generating a full page preview images with page numbers. I.e., this code:
#+LATEX_CLASS: article
#+LATEX_CLASS_OPTIONS: [a4paper]
#+LATEX_HEADER: \usepackage{fullpage}
\begin{equation}
E=mc^2
\end{equation}
will generate the preview image:
How to exclude fullpage package from LaTeX preview preamble? Also, is it a bug and needs a bug report?
according to org-latex-preview#Minted if you add the fullpage.sty package to org-latex-packages-alist in your emacs configuration file like so:
(add-to-list 'org-latex-packages-alist '("" "fullpage" nil))
it should use it for exporting but not for the preview.

Resources