Code and formulas can be formatted with PaperHive flavored Markdown inspired by GitHub. You can use L A T E X to typeset formulas. It counts how many times a value is repeated in a table.
This file is available here on RStudio Cloud.
Next in the R Markdown document you can use objects created in these scripts eg data objects or functions. Runs the R code embeds results and text into md file with knitr 2. The number of s at the beginning of the line indicates whether it is treated as a section sub-section sub-sub-section etc. You can use L A T E X to typeset formulas.