When I knit an Rmd file with code that produces output, both the code AND the output have syntax highlighting applied.
Is there a way to prevent the highlighting being applied to the output? I just want to have the code highlighted.
OK, I have partially solved this. I had collapse=T in my knit settings, which means all code and output is smushed into a single html element and everything gets styled. I think this is probably still undesirable — collapse=F should just mean 2 elements, one for the code and one for the results, each with a different css class.
Related
i'm trying to insert an image into my gitbook themed bookdown book, but it doesn't seem to be working. I've used the code: knitr::include_graphics("https://i.imgur.com/uy6ePN0.png"). However, instead of putting in my image, it instead shows me the attached screenshot. Am I doing this wrong?
Not sure what's going on there (you may want to include a larger code snippet), but since you are not doing anything special, simple Markdown syntax should do:
![boolean operators](https://i.imgur.com/uy6ePN0.png)
There are few pre-defined snippets one can use in RStudio for Rmarkdown documents. I define my own snippets via Global Options > Code > Edit snippets > Markdown. But it doesn't work. If I type r and press Shift+Tab a pre-defined snippet is inserted. But when I want to insert my own snippet it doesn't work. For example, this is my snippet I'd like to have:
snippet custy
:::{custom-style="${1:style}"}
${0}
:::
I thought when I type custy and press Shift+Tab the snippet will be inserted into my document, but it doesn't. Should the snippet be defined differently?
I tried your snipped and it worked well.
Make sure you are on the "Markdown" tab. Plus, are indentations OK? the snippet should be colored blue.
Based on the answer to this question, I was able to get 2-column papaja with listings wrapping (rather than overflowing column width). But the listings package turns off various features that help code listings and R output stand out relative to the main text.
A simple solution would be if I could globally change the font faces and/or sizes selectively for code and R output. Is there a way to do that in papaja? I haven't been able to figure this out from papaja or Rmarkdown documentation. Thank you!
When you use the listings package in a papaja (or bookdown) document, what is technically happening is that all code is wrapped into an lstlisting LaTeX environment that comes with its own capabilities of customizing code appearance. Hence, you don't see the syntax highlighting that you would otherwise see if you would not use the listings package. The documentation of the listings package with instructions how to style your code can be found here.
To make use of this, you can extend the YAML header of your papaja document like this:
documentclass : "apa6"
classoption : "jou"
output :
papaja::apa6_pdf:
pandoc_args: --listings
header-includes:
- \lstset{breaklines=true,language=R,basicstyle=\tiny\ttfamily,frame=trB,commentstyle=\color{darkgray}\textit}
Here, I first specify the code's language, and use a tiny monospace font. With frame, I add a frame around the code block, and with commentstyle I set comments in italic and gray.
Minimal example
I wrote a program in org-mode using literate programming technique with :noweb extension(?). Typical piece of code looks like this:
* Section
In order to do foo with bar, we define a function ~do_foo~, which initializes object of a class ~BarParser~ with a value of parameter of the type ~bar_t~.
#+name: section_function_blockname
#+begin_src cpp
void do_foo
( bar_t bar
, <<additional_parameter_to_do_foo>>
) {
BarParser barParser(bar);
<<section_function_do_fooBody>>
}
#+end_src
The function will require additional parameter for the purposes of the /FizzBazz/ module. We will discuss them in a [[*Decoding FizzBazz messages][later_section]].
Entire content of the program is stored in a single file, which at the top has #+SETUP: theme-readtheorg.setup. The setup file is not the problem, because the HTML generates correctly, only with not the content I want.
Problem
To generate the code, I use (org-babel-tangle). This produces all the files I'd expect for all the blocks with :tangle parameter. The files have the content I expect them to have and code compiles and runs the way it should.
To generate the documentation I'd like to publish along the code, I use (org-html-export-to-html). What I expected to happen was that either:
the <<tags>> will get substituted with their expected value, which wouldn't be ideal but at least acceptable, or
the <<tags>> will be left untouched the way they are presented,when editing the org-file with Emacs.
However the output to (org-html-export-to-html) is quite different and unexpected - all the <<tags>> are replaced with a newline character. This leaves me with all the code blocks having incorrect content that cannot be understood without either looking at the generated code or original org-file which completely defeats the purpose of the documentation being in the separate file. I cannot force everyone I work with to switch to Emacs to let them browse the documentation!
Question
As stated above, the problem is with noweb <> being procesed by some call inside (org-html-export-to-html). The question I have regarding this issue is:
How can I force (org-html-export-to-html) to leave the contents of source blocks as they are, without stripping away the noweb <<tags>>?
IIUC, you need to specify an appropriate :noweb header. Try this:
#+begin_src cpp :noweb no-export
and refer to the noweb section in the manual for other values and more details.
I have added a big PNG (tall, with similar aspect ratio to A4 paper) image in my rmd between two paragraphs using the following chunk (caption was made that way since it will include citations):
(ref:cap-etlm) The ETLM.
```{r etlm, results = "asis", echo = FALSE, fig.cap = "(ref:cap-etlm)", out.width='\\textwidth'}
include_graphics("figures/etlm.png")
````
The problem is, when generating a pdf output, the previous page becomes sparse, with many empty lines (shown with red lines):
This (could) also be the case if the image didn't take the whole page, but was large enough.
How can I let some of the text (that, in the rmd, have been written after the chunk/its reference) appear before the image?
Thanks in advance.
Edit:
This Gist is rmd of a minimal reproducible example (updated screenshot). It also requires csl files, etc., which are in a zip file here on TinyUpload.
Your file template.tex contains the following lines:
\usepackage{float}
\floatplacement{figure}{H}
This forces LaTeX to place figures always HERE, i.e. where they are defined. Removing these two lines solves the problem for me.