R-code linebreaks AND themes in knitrR-code linebreaks AND code highlighting in knitrR-code linebreaks AND code highlighting in knitrMore sophisticated syntax highlighting of Prolog codeHow to get listings that both feature line breaking of long identifiers and keywords highlighting?Knitr/LaTeX: conditional execution based on external parametersDifferent colors for default and language-specific listingsknitr in RStudio produces 'Undefined control sequence', alongside other issuesR data.table and knitrHow does knitr inject TeX code into the document?Latex code in knitr script?Using knitr and Latex problem
Why are there 40 737 Max planes in flight when they have been grounded as not airworthy?
Counting certain elements in lists
Bastion server: use TCP forwarding VS placing private key on server
Making a sword in the stone, in a medieval world without magic
SQL Server Primary Login Restrictions
What options are left, if Britain cannot decide?
Humanity loses the vast majority of its technology, information, and population in the year 2122. How long does it take to rebuild itself?
My story is written in English, but is set in my home country. What language should I use for the dialogue?
Good allowance savings plan?
Informing my boss about remarks from a nasty colleague
Where is the 1/8 CR apprentice in Volo's Guide to Monsters?
How to generate globally unique ids for different tables of the same database?
Why doesn't the EU now just force the UK to choose between referendum and no-deal?
Employee lack of ownership
Provisioning profile doesn't include the application-identifier and keychain-access-groups entitlements
Did CPM support custom hardware using device drivers?
Is it normal that my co-workers at a fitness company criticize my food choices?
The use of "touch" and "touch on" in context
Does this AnyDice function accurately calculate the number of ogres you make unconcious with three 4th-level castings of Sleep?
My adviser wants to be the first author
Do I need life insurance if I can cover my own funeral costs?
Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?
It's a yearly task, alright
Russian cases: A few examples, I'm really confused
R-code linebreaks AND themes in knitr
R-code linebreaks AND code highlighting in knitrR-code linebreaks AND code highlighting in knitrMore sophisticated syntax highlighting of Prolog codeHow to get listings that both feature line breaking of long identifiers and keywords highlighting?Knitr/LaTeX: conditional execution based on external parametersDifferent colors for default and language-specific listingsknitr in RStudio produces 'Undefined control sequence', alongside other issuesR data.table and knitrHow does knitr inject TeX code into the document?Latex code in knitr script?Using knitr and Latex problem
hpesoj626 provides two great minimal working examples for how to get R-code linebreaks AND code highlighting in knitr. I was wondering if it was possible to use Yihui's knitr themes within either of the two examples? And if so, how?
Here is the code for the example that I personally prefer (I added language=R
and the three lines between hashtags in the setup chunk, and deleted highlight = FALSE
in the chunk in the document):
documentclass[twocolumn]article
usepackagelistings
usepackageinconsolata
lstsetbreaklines=true,showstringspaces=false,language=R
<<setup, include=FALSE, cache=FALSE>>=
opts_chunk$set(fig.path = 'figure/listings-')
options(replace.assign = TRUE, width=60)
render_listings()
################################################
# not part of hpesoj626's example and not working:
opts_chunk$set(fig.path = 'figure/listings-')
opts_knit$set( out.format="latex" )
################################################
@
titleFunction listings with linebreaks and code highlighting
begindocument
maketitle
Two ways of printing the code.
<<tidy=TRUE>>=
theFunction <- function(x)
tmp <- "A really long string that should be line-broken but it would be nice to also see code highlighting colors. The function is in the real code sourced, but for the sake of easier reproducibility, it is written here instead."
theFunction
@
enddocument
I was wondering if it was possible to integrate knitr themes into this minimal working example, similar to what Michael suggested here:
opts_knit$set( out.format="latex" )
knit_theme$set("print")
Adding these two lines to the minimal working example above does not do anything (when I delete all other options in the setup chunk and only include these two lines, syntax highlighting works fine).
Alternatively, if adding themes does not work, is it possible to redefine the default listings style such that it exactly resembles a theme (similar to what hpesoj626 suggested in his first answer, but then with R syntax highlighting of all keywords, numbers, commas...)? I tried writing down all definitions based on Carsten Heinz' drivers manual for the listings package (lstdrvs.pdf here) but did not manage.
line-breaking highlighting r knitr
bumped to the homepage by Community♦ 10 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
hpesoj626 provides two great minimal working examples for how to get R-code linebreaks AND code highlighting in knitr. I was wondering if it was possible to use Yihui's knitr themes within either of the two examples? And if so, how?
Here is the code for the example that I personally prefer (I added language=R
and the three lines between hashtags in the setup chunk, and deleted highlight = FALSE
in the chunk in the document):
documentclass[twocolumn]article
usepackagelistings
usepackageinconsolata
lstsetbreaklines=true,showstringspaces=false,language=R
<<setup, include=FALSE, cache=FALSE>>=
opts_chunk$set(fig.path = 'figure/listings-')
options(replace.assign = TRUE, width=60)
render_listings()
################################################
# not part of hpesoj626's example and not working:
opts_chunk$set(fig.path = 'figure/listings-')
opts_knit$set( out.format="latex" )
################################################
@
titleFunction listings with linebreaks and code highlighting
begindocument
maketitle
Two ways of printing the code.
<<tidy=TRUE>>=
theFunction <- function(x)
tmp <- "A really long string that should be line-broken but it would be nice to also see code highlighting colors. The function is in the real code sourced, but for the sake of easier reproducibility, it is written here instead."
theFunction
@
enddocument
I was wondering if it was possible to integrate knitr themes into this minimal working example, similar to what Michael suggested here:
opts_knit$set( out.format="latex" )
knit_theme$set("print")
Adding these two lines to the minimal working example above does not do anything (when I delete all other options in the setup chunk and only include these two lines, syntax highlighting works fine).
Alternatively, if adding themes does not work, is it possible to redefine the default listings style such that it exactly resembles a theme (similar to what hpesoj626 suggested in his first answer, but then with R syntax highlighting of all keywords, numbers, commas...)? I tried writing down all definitions based on Carsten Heinz' drivers manual for the listings package (lstdrvs.pdf here) but did not manage.
line-breaking highlighting r knitr
bumped to the homepage by Community♦ 10 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
hpesoj626 provides two great minimal working examples for how to get R-code linebreaks AND code highlighting in knitr. I was wondering if it was possible to use Yihui's knitr themes within either of the two examples? And if so, how?
Here is the code for the example that I personally prefer (I added language=R
and the three lines between hashtags in the setup chunk, and deleted highlight = FALSE
in the chunk in the document):
documentclass[twocolumn]article
usepackagelistings
usepackageinconsolata
lstsetbreaklines=true,showstringspaces=false,language=R
<<setup, include=FALSE, cache=FALSE>>=
opts_chunk$set(fig.path = 'figure/listings-')
options(replace.assign = TRUE, width=60)
render_listings()
################################################
# not part of hpesoj626's example and not working:
opts_chunk$set(fig.path = 'figure/listings-')
opts_knit$set( out.format="latex" )
################################################
@
titleFunction listings with linebreaks and code highlighting
begindocument
maketitle
Two ways of printing the code.
<<tidy=TRUE>>=
theFunction <- function(x)
tmp <- "A really long string that should be line-broken but it would be nice to also see code highlighting colors. The function is in the real code sourced, but for the sake of easier reproducibility, it is written here instead."
theFunction
@
enddocument
I was wondering if it was possible to integrate knitr themes into this minimal working example, similar to what Michael suggested here:
opts_knit$set( out.format="latex" )
knit_theme$set("print")
Adding these two lines to the minimal working example above does not do anything (when I delete all other options in the setup chunk and only include these two lines, syntax highlighting works fine).
Alternatively, if adding themes does not work, is it possible to redefine the default listings style such that it exactly resembles a theme (similar to what hpesoj626 suggested in his first answer, but then with R syntax highlighting of all keywords, numbers, commas...)? I tried writing down all definitions based on Carsten Heinz' drivers manual for the listings package (lstdrvs.pdf here) but did not manage.
line-breaking highlighting r knitr
hpesoj626 provides two great minimal working examples for how to get R-code linebreaks AND code highlighting in knitr. I was wondering if it was possible to use Yihui's knitr themes within either of the two examples? And if so, how?
Here is the code for the example that I personally prefer (I added language=R
and the three lines between hashtags in the setup chunk, and deleted highlight = FALSE
in the chunk in the document):
documentclass[twocolumn]article
usepackagelistings
usepackageinconsolata
lstsetbreaklines=true,showstringspaces=false,language=R
<<setup, include=FALSE, cache=FALSE>>=
opts_chunk$set(fig.path = 'figure/listings-')
options(replace.assign = TRUE, width=60)
render_listings()
################################################
# not part of hpesoj626's example and not working:
opts_chunk$set(fig.path = 'figure/listings-')
opts_knit$set( out.format="latex" )
################################################
@
titleFunction listings with linebreaks and code highlighting
begindocument
maketitle
Two ways of printing the code.
<<tidy=TRUE>>=
theFunction <- function(x)
tmp <- "A really long string that should be line-broken but it would be nice to also see code highlighting colors. The function is in the real code sourced, but for the sake of easier reproducibility, it is written here instead."
theFunction
@
enddocument
I was wondering if it was possible to integrate knitr themes into this minimal working example, similar to what Michael suggested here:
opts_knit$set( out.format="latex" )
knit_theme$set("print")
Adding these two lines to the minimal working example above does not do anything (when I delete all other options in the setup chunk and only include these two lines, syntax highlighting works fine).
Alternatively, if adding themes does not work, is it possible to redefine the default listings style such that it exactly resembles a theme (similar to what hpesoj626 suggested in his first answer, but then with R syntax highlighting of all keywords, numbers, commas...)? I tried writing down all definitions based on Carsten Heinz' drivers manual for the listings package (lstdrvs.pdf here) but did not manage.
line-breaking highlighting r knitr
line-breaking highlighting r knitr
edited Feb 12 at 23:06
Flo
asked Apr 13 '15 at 9:27
FloFlo
1536
1536
bumped to the homepage by Community♦ 10 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 10 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I was able to get themes working as follows:
<<echo=FALSE>>=
knit_theme$set("biogoo")
@
<<results='asis', echo=FALSE>>=
x <-1:10
y <- x^2
@
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f238331%2fr-code-linebreaks-and-themes-in-knitr%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I was able to get themes working as follows:
<<echo=FALSE>>=
knit_theme$set("biogoo")
@
<<results='asis', echo=FALSE>>=
x <-1:10
y <- x^2
@
add a comment |
I was able to get themes working as follows:
<<echo=FALSE>>=
knit_theme$set("biogoo")
@
<<results='asis', echo=FALSE>>=
x <-1:10
y <- x^2
@
add a comment |
I was able to get themes working as follows:
<<echo=FALSE>>=
knit_theme$set("biogoo")
@
<<results='asis', echo=FALSE>>=
x <-1:10
y <- x^2
@
I was able to get themes working as follows:
<<echo=FALSE>>=
knit_theme$set("biogoo")
@
<<results='asis', echo=FALSE>>=
x <-1:10
y <- x^2
@
answered Feb 12 at 22:51
StatsStudentStatsStudent
15116
15116
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f238331%2fr-code-linebreaks-and-themes-in-knitr%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown