Skip to content

fixed figures by using Sweave environments in hooks #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions R/rjournal_article.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ rjournal_article <- function() {
# Mostly copied from knitr::render_sweave
base$knitr$opts_chunk$comment <- "#>"

hook_chunk <- function(x, options) {
hook_chunk = function(x, options) {
if (knitr:::output_asis(x, options)) return(x)
paste0('\\begin{example}\n', x, '\\end{example}')
paste('\\begin{Schunk}\n', x, '\\end{Schunk}', sep = '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer preferred style for the R Journal. I think the only bit you really need is the knit_hooks$plot below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because the example environment is an extension of Verbatim, and you can't includegraphics inside it.

Could use the example environment in the input and output hooks?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. I thought example was alltt so you could include plots.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example* is!

}
hook_input <- function(x, options) paste0(x, "\n")
hook_output <- function(x, options) paste0(x, "\n")
hook_input <- function(x, options)
paste(c('\\begin{Sinput}', knitr:::hilight_source(x, 'sweave', options), '\\end{Sinput}', ''),
collapse = '\n')
hook_output <- function(x, options) paste('\\begin{Soutput}\n', x, '\\end{Soutput}\n', sep = '')

base$knitr$knit_hooks$chunk <- hook_chunk
base$knitr$knit_hooks$source <- hook_input
base$knitr$knit_hooks$output <- hook_output
base$knitr$knit_hooks$message <- hook_output
base$knitr$knit_hooks$warning <- hook_output
base$knitr$knit_hooks$plot <- knitr:::hook_plot_tex

base
}
Expand Down