Get code output nicer in R Markdown Knit? Breaking into two parts - html

I am knitting R Markdown (Rmd) to HTML, but some code outputs are not pretty, e.g., like the picture attached.console
How can I make output in one part if possible? Thanks.

Related

knitr: Knitting to HTML - add a prefix to figure and table numbers

R Markdown with knitr can add a prefix (usually a letter) to figure and table numbers when knitting/compling to PDF. When knitting to PDF, the following code will do the job:
```{=tex}
\renewcommand{\thetable}{S\arabic{table}}
\renewcommand{\thefigure}{S\arabic{figure}}
```
The result will be
Figure S1.1.
rather than
Figure 1.1
Is there a way to achieve the same when knitting to HTML?

In RMarkdown, how to include latex code when using an HTML or Word output

I have a very basic question. I did not find an answer anywhere. My fear is that the answer is simply no.
Using R Markdown, I would like to use LaTex code with an HTML or Word output.
A very simple MVE :
I would like to execute the following code :
This text has been written with both \LaTeX{} and Rmd codes.
With a LaTex/PDF output, no problem. I get 'This text has been written with both Latex and Rmd codes.' (with the nice LaTeX logo !)
With an HTML or Word output, I get 'This text has been written with both and Rmd codes.'
So the LateX code disappears with non-LateX output.
Do you know if there is a way to fix this?
Thanks in advance,
Eric
EDIT: Here is another example using a simple table
\begin{table}[h]
\centering
\caption{A simple table}
\begin{tabular}{|l|c|c|}
\hline
a & b & c \\
d & e & f \\
\hline
\end{tabular}
\end{table}
It will work if you put the LaTeX output between dollar signs. In HTML, it will not work if you are offline though! :
This text has been written with both $\LaTeX{}$ and Rmd codes.
In R Markdown, Pandoc converts LaTeX into Office Math Markup (OMML). So you can get LaTeX output in Word, but you won't get the logo, as far as I know.
For LaTeX output in Word, remove the backslash and add the dollar signs, like this:
This text has been written with both $LaTeX{}$ and Rmd codes.
Or leave a space between the backslash and the output:
This text has been written with both $\ LaTeX{}$ and Rmd codes
Here is a snapshot from a document generated in Word:

dfSummary - formatting factor levels in html output in Rmarkdown?

I'm trying to put together an html rmd report and having an issue with how summarytools::dfSummary displays factor levels. When I print to browser or R-Studio viewer, levels are formatted so that they are stacked vertically:
When I print to html in R Markdown they are formatted inline, which is annoying and less readable:
Any ideas on how to deal with this? I've looked around and haven't seen any way to deal with this in the print() function for summarytools::, maybe there's a way for me to reformat this in rmd?
Thanks.
I spent a day looking for a solution, so apparently summarytools’ CSS has been included in the following manner, with chunk option echo = FALSE:
` ``{r echo=FALSE, results='asis'}
st_css()
` ``

ruby tags for Sphinx/rst

I create HTML documents from a rst-formated text, with the help of Sphinx. I need to display some Japanese words with furiganas (=small characters above the words), something like that :
I'd like to produce HTML displaying furiganas thanks to the < ruby > tag.
I can't figure out how to get this result. I tried to:
insert raw HTML code with the .. raw:: html directive but it breaks my line into several paragraphs.
use the :superscript: directive but the text in furigana is written beside the text, not above.
use the :role: directive to create a link between the text and a CSS class of my own. But the :role: directive can only be applied to a segment of text, not to TWO segments as required by the furiganas (=text + text above it).
Any idea to help me ?
As long as I know, there's no simple way to get the expected result.
For a specific project, I choosed not to generate the furiganas with the help of Sphinx but to modify the .html files afterwards. See the add_ons/add_furiganas.py script and the result here. Yes, it's a quick-and-dirty trick :(

Compare two HTML documents ignoring multiple and trailing whitespaces

Is there a tool that compares an HTML document like:
<p b="1" a="0 "> a b
c </p>
(as a C string: "<p> a b\nc </p>") equal to:
<p a="0 " b="1">a b c</p>
Note how:
text multiple whitespaces were converted to a single whitespace
newlines were converted to whitespaces
text trailing and heading whitespaces were stripped
attributes were put on a standard order
attribute values were unchanged, including trailing whitespaces
Why I want that
I am working on the Markdown Test Suite that aims to measure markdown engine compliance and portability.
We have markdown input, expected HTML output, and want to determine if the generated HTML output is equal to the expected one.
The problem is that Markdown is underspecified, so we cannot compare directly the two HTML strings.
The actual test code is here, just modify run-tests.py#dom_normalize if you want to try out your solution.
Things I tried
beautifulsoup. Orders the attributes, but does not deal well with whitespaces?
A function formatter regex modification might work, but I don't see a way to differentiate between the inside of nodes and attributes.
A Python only solution like this would be ideal.
looking for a Javascript function similar to isEqualNode() (does not work because ignores nodeVaue) + some headless JS engine. Couldn't find one.
If there is nothing better, I'll just have to write my own output formatter front-end to some HTML parser.
I ended up cooking up a custom HTML renderer that normalizes things based on Python's stdlib HTMLParser.
You can see it at: https://github.com/karlcow/markdown-testsuite/blob/749ed0b812ffcb8b6cc56f93ff94c6fdfb6bd4a2/run-tests.py#L20
Usage and docstrig tests at: https://github.com/karlcow/markdown-testsuite/blob/749ed0b812ffcb8b6cc56f93ff94c6fdfb6bd4a2/run-tests.py#L74