Testing Markdown


Testing Markdown

The content on this page was generated from a standard Markdown file.

Markdown vs. Rmarkdown vs. Rmd

This section is included in three test files for three different markdown formats (.md, .Rmarkdown and .Rmd).

Some differences are:

  • You cannot run any R code in a plain md document, whereas in Rmarkdown and Rmd documents, you can embed R code chunks (```{r});
print("This text was written in R")

There are many differences in syntax between Blackfriday’s Markdown and Pandoc’s Markdown. For example, you can write a task list with Blackfriday but not with Pandoc:

- [x] Write an R package.
- [ ] Write a book.
- [ ] ...
- [ ] Profit!
  • Inline Math with \\( \\) rendered with Katex in all file formats: For any \( (x,y,z) \), if \( x^2 + y^2 + z^2 = R^2 \) then \( (x,y,z) \) is on the sphere, otherwise it’s not.

  • Dedicated line of Math with \\[ \\] rendered with Katex in all file formats:

\[ (x-x_0)^2 + (y-y_0)^2 + (z-z_0)^2 = R^2 \]

  • Inline Math with $ $ rendered only in rmd: $ Sn = \sum{i=1}^n X_i $

  • Dedicated line of Math with $$ $$ rendered only in rmd.

$$ Sn = \sum{i=1}^n X_i $$

  • Katex should support $ and $$ in md and Rmarkdown files as well, but I couldn’t make this work yet.

  • Note about previous MathJax implementation: Similarly, Blackfriday does not support LaTeX math and Pandoc does. you have to include math expressions in a pair of backticks (inline: `$ $`; display style: `$$ $$`), e.g., $S_n = \sum_{i=1}^n X_i$.1 For R Markdown posts, you do not need the backticks, because Pandoc can identify and process math expressions.

Other R Code

1 + 1  # not executed
1 + 1  
# ggplot2 examples
library(ggplot2)
#use color brewer as default discrete colors
scale_colour_discrete <- function(...) scale_color_brewer(palette="Set1", ...)
scale_fill_discrete <- function(...) scale_fill_brewer(palette="Set1", ...)

data('mtcars')
# create factors with value labels
mtcars$gear <- factor(mtcars$gear,levels=c(3,4,5),
     labels=c("3gears","4gears","5gears"))
mtcars$am <- factor(mtcars$am,levels=c(0,1),
     labels=c("Automatic","Manual"))
mtcars$cyl <- factor(mtcars$cyl,levels=c(4,6,8),
   labels=c("4cyl","6cyl","8cyl"))
head(mtcars)
# cool-plot, fig.width='80%', fig.cap='A cool plot.'}
qplot(mpg, data=mtcars, geom="density", fill=gear, alpha=I(.5),
   main="Distribution of Gas Milage", xlab="Miles Per Gallon",
   ylab="Density")
#data(mtcars)
#plot(mtcars, pch = 20)  # not really cool
#library(car) 
#scatterplot(mpg ~ wt | cyl, data=mtcars, 
#  	xlab="Weight of Car", ylab="Miles Per Gallon", 
#   main="Enhanced Scatter Plot", 
#   labels=row.names(mtcars))

Markdown Examples

Paragraph 1: Md is rendered through Blackfriday. Hard line break with two spaces:
Rmd is rendered through rmarkdown, bookdown, Pandoc.

Paragraph 2: Blank line in betweens

Setext Headers

Level 1 Header

Level 2 Header

ATX Style headers

Level 1 Header

Level 2 Header

Level 3 Header

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// GetTitleFunc returns a func that can be used to transform a string to
// title case.
//
// The supported styles are
//
// - "Go" (strings.Title)
// - "AP" (see https://www.apstylebook.com/)
// - "Chicago" (see http://www.chicagomanualofstyle.org/home.html)
//
// If an unknown or empty style is provided, AP style is what you get.
func GetTitleFunc(style string) func(s string) string {
  switch strings.ToLower(style) {
  case "go":
    return strings.Title
  case "chicago":
    tc := transform.NewTitleConverter(transform.ChicagoStyle)
    return tc.Title
  default:
    tc := transform.NewTitleConverter(transform.APStyle)
    return tc.Title
  }
}

A link and an emphasis

A header with identifier

Creates a div id=“foo” around the h1.

A header with class identifiers

creates div with id=“gerrit”” classes “section level1 class class” and attributes hello=“world” name=“unicone”

Header identifiers in HTML

And a link to [Header identifiers in HTML]

or [the section on header identifiers][header identifiers in HTML]

instead of giving id explicitly Header identifiers in HTML

explicit link references

See this article

This is a block quote. This paragraph has two lines.

  1. This is a list inside a block quote.
  2. Second item.

This is a block quote.

A block quote within a block quote.

code
if (a > 3) {
  moveShip(5 * gravity, DOWN);
}
~~~~~~~~~~
code including tildes
~~~~~~~~~~

~~~~ {#mycode .haskell .numberLines startFrom=“100”} qsort [] = [] qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

| The limerick packs laughs anatomical | In space that is quite economical. | But the good ones I’ve seen | So seldom are clean | And the clean ones so seldom are comical

| 200 Main St. | Berkeley, CA 94718

  • fruits
    • apples
      • macintosh
      • red delicious
    • pears
    • peaches
  • vegetables
    • broccoli
    • chard

#. one #. two

Right Left Center Default


 12     12        12            12
123     123       123          123
  1     1          1             1

Table: Demonstration of simple table syntax.

Sample grid table.

+—————+—————+——————–+ | Fruit | Price | Advantages | +===============+===============+====================+ | Bananas | $1.34 | - built-in wrapper | | | | - bright color | +—————+—————+——————–+ | Oranges | $2.10 | - cures scurvy | | | | - tasty | +—————+—————+——————–+

This text is emphasized with underscores, and this is emphasized with asterisks.

This is strong emphasis and with underscores.

This is * not emphasized *, and *neither is this*.

feasible, not feasable.

This is deleted text.

H~2~O is a liquid. 2^10^ is 1024.

What is the difference between >>= and >>?


  1. This is because we have to protect the math expressions from being interpreted as Markdown. You may not need the backticks if your math expression does not contain any special Markdown syntax such as underscores or asterisks, but it is always a safer choice to use backticks. When you happen to have a pair of literal dollar signs inside the same element, you can escape one dollar sign, e.g., \$50 and $100 renders “\$50 and $100”. [return]