Chunk that does not produce any output generates two empty lines in LaTeX output #231

Closed
krlmlr opened this Issue May 15, 2012 · 9 comments

Comments

Projects
None yet
2 participants
Contributor

krlmlr commented May 15, 2012

The following minimal.Rnw input file

\documentclass{article}
\begin{document}
a
<<q,echo=FALSE,results='hide'>>=
getwd()
@
b
\end{document}

generates on output (using R --no-save <<<"library(knitr); knit('minimal.Rnw')" in a bash shell)

% ... header stripped for brevity
\begin{document}
a


b
\end{document}

That's two empty lines too much for my understanding. Sweave used to leave out these empty lines.

Is this a bug or a (hopefully configurable) feature?

Contributor

krlmlr commented May 15, 2012

There's a workaround that consists of defining a command that gobbles all following empty lines:

http://tex.stackexchange.com/questions/55914/command-that-gobbles-all-following-empty-lines

Owner

yihui commented May 16, 2012

I do not know if this is a bug, and unfortunately this is not configurable. Why do you want to remove the two empty lines? Because it makes a and b separate paragraphs?

Contributor

krlmlr commented May 17, 2012

Exactly. If I want to back up a written sentence in a report with an R assertion, I want to keep both next to each other.

Owner

yihui commented May 18, 2012

Fair enough. Can you move the chunk before a or after b? Since you do not want to output anything from the chunk, moving it might not hurt.

Contributor

krlmlr commented May 18, 2012

Yes, I could, but I prefer keeping code and text as close as possible to each other. For now, I use a TeX macro that gobbles all following empty lines to achieve what I want, see the link in one of my former comments.

Owner

yihui commented May 22, 2012

The main reason that I do not want to change this is due to the concordance feature. It requires a little bit more careful thinking; I will think about it later.

Owner

yihui commented May 26, 2012

I decided not to change this. Sorry.

yihui closed this May 26, 2012

Contributor

krlmlr commented May 26, 2012

No problem, I'm fine with the workaround. You might want to list this behavior (and a hint how to work around it) in your documentation somewhere. Please feel free to use the code in the TeX.SX answer.

Owner

yihui commented May 27, 2012

Thanks!

@yihui yihui added a commit that referenced this issue Jun 5, 2012

@yihui yihui put #231 in doc 9d2f4ed

@yihui yihui added a commit that referenced this issue Oct 12, 2016

@yihui yihui put #231 in doc c86106e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment