I am creating a html report using R Markdown. The first paragraph contains a list of categories represented by certain samples with short descriptions. Here is an example:
This is the test list:
* **first group**:
+ **item 1** - this is the description of an item
* **second group**:
+ **item 2** - this is the description of an item
+ **item 3** - this is the description of an item
* **third group**:
+ **item 4** - this is the description of an item
* **fourth group**:
+ **item 5** - this is the description of an item
+ **item 6** - this is the description of an item
The text was inserted outside the code chunks. I would like to preserve this (even) spacing between the lines in knitted document, so it would be easy readable. Otherwise it looks too squished. Unfortunately R Markdown changes spacing, so some of them are uneven. I tried using trailing spaces and defining line breaks with br, but nothing changed. I could off course edit the html file manually after knitting, but this is a brute force way. R Markdown has to have some option to deal with it - but I was not able to figure it out myself. Would appreciate any help.
You could add a css tag at the start of your rmarkdown document to specify how you would like the html output to interpret line heights:
```{css}
li {
line-height: 3;
}
...
Related
I want to write an equation in Jupyter notebook's markdown cell which contains text with space. I tried writing the following.
\begin{equation*}
e^{i\pi} + 1 + some text = 0
\end{equation*}
Which results like this.
How to add space between "some" and "text"? Thank you.
You can try wrapping your text in \text{}.
\begin{equation}
e^{i\pi} + 1 + \text{some text} = 0
\end{equation}
Note: this is more of a latex question, to which you can get answers from here.
In addition, you could consider " \ " and "\quad" directives to add horizontal space between elements in a LaTeX environment, also "\hskip".
https://github.com/rstudio/cheatsheets/raw/master/rmarkdown-2.0.pdf
The cheat sheet above lists the following syntax to generate a bulleted list in R Markdown. * is the primary solid bullet. + is a secondary hollow bullet. And - is a tertiary solid square.
* unordered list
+ sub-item 1
+ sub-item 2
- sub-sub-item 1
After I render the output with knitr I don't get the expected output. I get what's shown below. The second and third lines are not indented. Only the very last line is indented, and only one indent instead of the expected two. And all bullets are the secondary hollow style. It's as if I put the following syntax into R Studio, but I didn't.
+ unordered list
+ sub-item 1
+ sub-item 2
+ sub-sub-item 1
How do I get what I intended, the first chunk of pasted syntax?
For each sub-level instead of one tab, include two:
* unordered list
+ sub-item 1
+ sub-item 2
- sub-sub-item 1
Output:
See the Pandoc documentation under Block content in list items.
Was looking for the same, you may do also something like
<body>
<h3>Today's shopping list:</h3>
<ul>
<li>Milk</li>
<li>Eggs</li>
<li>Cereal</li>
<li>Fruit</li>
</ul>
</body>
This link may help too as well.
I want to make an indented list, but I don't want it to have bullet points or numbers. I am using Rmarkdown in RStudio, and knitting to html.
#### bla bla bla
* Example indented line with bullet point
* Another indent with another bullet point
* Yea this is good except for the stupid bullets!
1. Example indented line with numbers
* sure and an indent with a bullet too
2. But there's these stupid numbers now!
two spaces doesn't indent at all
or nest indent with 4
yea still no indent with 2.
four spaces ALSO doesn't indent
just makes some stupid code
why do you hate indents rmd??
This can be achieved using Line Blocks which are built-in to the R Markdown syntax. If you want the indentation to be respected, you can start a line with |.
This approach works across multiple output formats and doesn't require any additional CSS styling:
---
output:
html_document: default
pdf_document: default
---
Here is some text with no indentation
| A list
| A sublist
| Sublist Item 2
| Sublist Item 3
If you want to change how a list looks and you're outputting to HTML, use css:
---
title: "ListTest"
output: html_document
---
<style>
.nobullet li {
list-style-type: none;
}
</style>
<div class="nobullet">
* This list
* Doesn't have bullets
</div>
* This list
* Is normal
This won't work for other output formats.
I am trying to implement a syntax highlighter for markdown for my project in PySide. The current code covers the basic, with bold, italic, code blocks, and some custom tags. Below is an extract of the relevant part of the current code.
What is blocking me right now is how to implement the highlighting for titles (underlined with ===, for the main title, or --- for sub-titles). The method that is used by Qt/PySide to highlight the text is highlightBlock, which processes only one line at a time.
class MySyntaxHighlighter(QtGui.QSyntaxHighlighter):
def highlightBlock(self, text):
# do something with this line of text
self.setCurrentBlockState(0)
startIndex = 0
if self.previousBlockState() != 1:
startIndex = self.blockStartExpression.indexIn(text)
while startIndex >= 0:
endIndex = self.blockEndExpression.indexIn(
text, startIndex)
...
There is a way to recover the previousBlockState, which is useful when a block has a defined start (for instance, the ~~~ syntax at the beginning of a code-block). Unfortunately, there is nothing that defines the start of a title, except for the underlining with === or --- that take place on the next line. All the examples I found only handle cases where there is a defined start of the expression, and so that the previousBlockState gives you an information (as in the example above).
The question is then: is there a way to recover the text of the next line, inside the highlightBlock? To perform a look-ahead, in some sense.
I though about recovering the document currently being worked on, and find the current block in the document, then find the next line and make the regular expression check on this. This would however break if there is a line in the document that has the exact same wording as the title. Plus, it would become quite slow to systematically do this for all lines in the document. Thanks in advance for any suggestion.
If self.currentBlock() gives you the block being highlighted, then:
self.currentBlock().next().text()
should give you the text of the following block.
I wish to insert a R code chunk in a LaTeX document. The default settings for the listings package also changes the font, but not the colour, which I need.
Although I understand that I can set the colours using the lstset function, I am not very sure of the combination that would look good. Thus, can anyone share their lstset settings for the listings package to colour R syntax? This way everyone who sees this post can use the same settings!
\documentclass[12pt]{article}
\usepackage{listings}
\usepackage[usenames,dvipsnames]{color}
\lstset{
language=R, % the language of the code
basicstyle=\tiny\ttfamily, % the size of the fonts that are used for the code
numbers=left, % where to put the line-numbers
numberstyle=\tiny\color{Blue}, % the style that is used for the line-numbers
stepnumber=1, % the step between two line-numbers. If it is 1, each line
% will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
frame=single, % adds a frame around the code
rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. commens (green here))
tabsize=2, % sets default tabsize to 2 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
keywordstyle=\color{RoyalBlue}, % keyword style
commentstyle=\color{YellowGreen}, % comment style
stringstyle=\color{ForestGreen} % string literal style
}
\begin{document}
\begin{lstlisting}
library(foreign)
foo <- rnorm(100)
# writing a function
bar <- apply(foo, 1, function(x){
y <- sqrt(x)
cat(paste('The result is ', x )))
})
bar
str(bar)
foo + bar
\end{lstlisting}
\end{document}