Created
February 26, 2012 03:39
-
-
Save ramnathv/1912800 to your computer and use it in GitHub Desktop.
Collection of knitr Hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Full Screen Environment for Beamer Slides | |
\newenvironment{changemargin}[2]{% | |
\begin{list}{}{% | |
\setlength{\topsep}{0pt}% | |
\setlength{\leftmargin}{#1}% | |
\setlength{\rightmargin}{#2}% | |
\setlength{\listparindent}{\parindent}% | |
\setlength{\itemindent}{\parindent}% | |
\setlength{\parsep}{\parskip}% | |
}% | |
\item[]}{\end{list}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wraps chunk in a fragile frame environment for beamer | |
fragile = function(before, options, envir){ | |
if (before) { | |
return('\\begin{frame}[fragile]\n') | |
} else { | |
return('\\end{frame}') | |
} | |
} | |
# Wraps figures inside a full figure environment for beamer | |
fullfig = function(before, options, envir) { | |
if (before) { | |
return('\\begin{changemargin}{-1cm}{-1cm}\n') | |
} else { | |
return('\n\\end{changemargin}') | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Higher Order Functions for Latex Hooks | |
wrap_in_env <- function(begin, end = begin){ | |
function(x, options){ | |
str_c("\n\\begin{", begin, "}\n", x, "\n\\end{", end, "}") | |
} | |
} | |
# Example Usage | |
frame_hook <- wrap_in_env('frame') |
yes you can return(x)
; in this case, print(x)
is equivalent to return(print(x))
and the function both prints x
and returns x
, because print(x)
returns x
in short, print(x)
brings the side effect of printing, which is not necessary here
Got it. Makes sense. I have updated the gist based on your comment.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So instead of
print(x)
, I could just doreturn(x)
? Is there any advantage to doing it this way?