Change Font Size for All Inline Equations R Markdown

Change font size for all inline equations R markdown

Try adding the following CSS after your YAML, or include it in an external CCS document. Pandoc automatically wraps inline math in <span> tags with class math. By modifying the math class, we can adjust the font size.

<style>
.math {
font-size: small;
}
</style>

R Markdown: Set math font size for an entire notebook output

@stschn the solution of the other post is applicable to Rmd's html_document and/or html_notebook output.

If you want to keep the css code within your document, Rmd allows you to specify a css code chunk.
Place the following at the top of your Rmd. Instead of ```{r ...} use ```{css} to tell RMarkdown to interpret the chunk as css.
For demo purposes, I set the font-size to x-large, you can use other standard sizes, e.g. small, large, x-small, etc. or define size in terms of measures like 8px.

# remember to use css as engine in the {} of this chunk
.math {
font-size: x-large;
}

Then write something like this to see it work:

This allows me to set the size of math in inline equations, e.g. $c^2 = a^2 + b^2$.
That is awesome.
Does this also apply to regular equation?
$$\frac{sin(a)}{sqrt(D^2)}$$

This will produce the following output, if you render (knit) it to html_document or html_notebook output.

P.S. The 2nd formula is obvious for demo purposes :)

Sample Image

R Markdown - changing font size and font type in html output

I think fontsize: command in YAML only works for LaTeX / pdf. Apart, in standard latex classes (article, book, and report) only three font sizes are accepted (10pt, 11pt, and 12pt).

Regarding appearance (different font types and colors), you can specify a theme:. See Appearance and Style.

I guess, what you are looking for is your own css. Make a file called style.css, save it in the same folder as your .Rmd and include it in the YAML header:

---
output:
html_document:
css: style.css
---

In the css-file you define your font-type and size:

/* Whole document: */
body{
font-family: Helvetica;
font-size: 16pt;
}
/* Headers */
h1,h2,h3,h4,h5,h6{
font-size: 24pt;
}

Changing math formulas font size in RPres

Math formulas in RPres documents and Rmarkdown documents are LateX chunks of code embedded in the Rmarkdown document.

Hence, the font size of a math formula or, more generally, of LaTeX text, can by modified with an argument ranging from \tiny to \HUGE:

$$\Huge textblog.org$$

will affect the size of the font according to:

img1

Code chunk font size in Rmarkdown with knitr and latex

Picking up the idea to alter a knitr hook we can do the following:

def.chunk.hook  <- knitr::knit_hooks$get("chunk")
knitr::knit_hooks$set(chunk = function(x, options) {
x <- def.chunk.hook(x, options)
ifelse(options$size != "normalsize", paste0("\n \\", options$size,"\n\n", x, "\n\n \\normalsize"), x)
})

This snippet modifies the default chunk hook. It simply checks if the chunk option size is not equal to its default (normalsize) and if so, prepends the value of options$size to the output of the code chunk (including the source!) and appends \\normalsize in order to switch back.

So if you would add size="tiny" to a chunk, then all the output generated by this chunk will be printed that way.

All you have to do is to include this snippet at the beginning of your document.

display math expression as non-italic using R Markdown and HTML output

Here is the way:

---
title: "Change MathJax font"
author: "Stéphane Laurent"
date: "05/11/2020"
output: html_document
---

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
"HTML-CSS" : {
availableFonts : ["STIX"],
preferredFont : "STIX",
webFont : "STIX-Web",
imageFont : null
}
});
</script>

$$
\int_0^1 f(x) dx = 0
$$


EDIT

Now that does not work. To use different fonts, you have to download them and to use a local copy of MathJax. I tried all the available fonts and the rendering is not nice for all of them.

I think the better solution is to use the standard font and use \mathrm:

$$
\mathrm{\int_0^1 f(x) dx = 0}
$$

Is there a way to control the font size in the equation in JupyterNotebook?

The dollar signs start and end LaTex boundaries, and so you need to use the tag inside.

c = $\Large\frac{a}{b}$

UPDATE:

I have a comment below that points to an image listing the tags and illustrating the relative sizes. I'm putting that link here in the post so that it is better featured.



Related Topics



Leave a reply



Submit