How to break lines in knitr output with the listings package
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
% see http://yihui.name/knitr/demo/listings/ for output | |
\documentclass{article} | |
% define a new environment to break lines for error messages | |
\lstnewenvironment{Serror}{\lstset{style=Routstyle,breaklines=true}}{} | |
<<setup, include=FALSE>>= | |
render_listings() | |
@ | |
\begin{document} | |
This is an example of breaking lines in listings. We only show how to deal with the error messages; it is straightforward to generalize to other types of output. | |
<<my-error-hook>>= | |
# the error messages are written in the Serror environment defined in preamble | |
knit_hooks$set(error = function(x, options) { | |
sprintf('\\begin{Serror}\n%s\\end{Serror}\n', x) | |
}) | |
@ | |
<<error-chunk>>= | |
stop('I am a long long long long long long long long long long long long long long long long string') | |
<<session>>= | |
sessionInfo() | |
@ | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment