Skip to content

Commit 383659d

Browse files
committed
further factor out the common code in jss_article() and rjournal_article() into a function set_sweave_hooks()
1 parent ab3797d commit 383659d

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

R/jss_article.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ jss_article <- function(
4949
)
5050
}
5151

52-
hooks <- knitr::hooks_sweave(c('CodeInput', 'CodeOutput', 'CodeChunk'))
53-
hooks[['chunk']] <- latex_block(x, options, hooks[['chunk']])
54-
base$knitr$knit_hooks <- merge_list(base$knitr$knit_hooks, hooks)
55-
56-
base
52+
set_sweave_hooks(base, c('CodeInput', 'CodeOutput', 'CodeChunk'))
5753
}
5854

5955
# wrap the content in a raw latex block
@@ -64,3 +60,11 @@ latex_block <- function(x, options, hook) {
6460
if (identical(x, x2)) x else paste0('```{=latex}\n', x2, '\n```')
6561
}
6662
}
63+
64+
# use knitr's sweave hooks, but wrap chunk output in raw latex blocks
65+
set_sweave_hooks <- function(base, ...) {
66+
hooks <- knitr::hooks_sweave(...)
67+
hooks[['chunk']] <- latex_block(x, options, hooks[['chunk']])
68+
base$knitr$knit_hooks <- merge_list(base$knitr$knit_hooks, hooks)
69+
base
70+
}

R/rjournal_article.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,5 @@ rjournal_article <- function(..., keep_tex = TRUE, citation_package = 'natbib')
129129
# Mostly copied from knitr::render_sweave
130130
base$knitr$opts_chunk$comment <- "#>"
131131

132-
hooks <- knitr::hooks_sweave()
133-
hooks[['chunk']] <- latex_block(x, options, hooks[['chunk']])
134-
base$knitr$knit_hooks <- merge_list(base$knitr$knit_hooks, hooks)
135-
136-
base
132+
set_sweave_hooks(base)
137133
}

0 commit comments

Comments
 (0)