Skip to content

Commit a1fa9e7

Browse files
committed
factor out the code to wrap content in a raw latex block
1 parent 965d378 commit a1fa9e7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

R/jss_article.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ jss_article <- function(
5050
}
5151

5252
hooks <- knitr::hooks_sweave(c('CodeInput', 'CodeOutput', 'CodeChunk'))
53-
hook_chunk <- hooks[['chunk']]
54-
hooks[['chunk']] <- function(x, options) {
55-
x2 <- hook_chunk(x, options)
56-
if (identical(x, x2)) x else paste0('```{=latex}\n', x2, '\n```')
57-
}
58-
53+
hooks[['chunk']] <- latex_block(x, options, hooks[['chunk']])
5954
base$knitr$knit_hooks <- merge_list(base$knitr$knit_hooks, hooks)
6055

6156
base
6257
}
58+
59+
# wrap the content in a raw latex block
60+
latex_block <- function(x, options, hook) {
61+
force(hook)
62+
function(x, options) {
63+
x2 <- hook(x, options)
64+
if (identical(x, x2)) x else paste0('```{=latex}\n', x2, '\n```')
65+
}
66+
}

0 commit comments

Comments
 (0)