[LaTeX] Removing space after \include statement

TheEcologist

Global Moderator
Hee TS,

So I integrate my tex documents with R without Sweave cause Sweave really really really doesn't make your documents any easier to read... also you really don't need it to have it's functionality - so I would love a sweave free solution.

So here is an example document;

Code:
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}

This is my random number (\input{temp.txt})

\end{document}
With a parallel R-script

Code:
write(rnorm(1),"temp.txt")
Only problem is that it always leaves a trailing space... e.g. (-1.234567 ). Anybody got an idea on how to remove this trailing space?

Thanks for any input you may have,

TE

TheEcologist

Global Moderator
Oke, by chance, I just used /input in an in-line equation; putting your input between  solves this!

Code:
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}

This is my random number ($\input{temp.txt}$)

\end{document}
Done!

Dason

Sweave really really really doesn't make your documents any easier to read...
I'm going to replace Sweave with knitr in my mind but I disagree with your statement. Your example document if I'm just reading the tex/Rnw file I need to have outside knowledge of what is contained in temp.txt to understand what will happen in the produced document. With knitr I can at least understand what is being put into the document without having to go to those external sources (for the most part).

I used to avoid Sweave but knitr has helped make reproducible documents a lot easier to use/create.

TheEcologist

Global Moderator
I'm going to replace Sweave with knitr in my mind but I disagree with your statement. Your example document if I'm just reading the tex/Rnw file I need to have outside knowledge of what is contained in temp.txt to understand what will happen in the produced document. With knitr I can at least understand what is being put into the document without having to go to those external sources (for the most part).

I used to avoid Sweave but knitr has helped make reproducible documents a lot easier to use/create.
I would advise Swaeve to anyone who has simple R-scripts to include in a document, but mine are mostly huge, requiring large datasets and computation, which sadly makes it far less comprehensible.

So now I work clean.. I have two scripts, 1 in R and 1 in tex. If you were my co-author you would just need to run the r-script, generate all statistics, tables and figures. Then you would only need to run the tex file.

Super reproducible, without needing sweave.

Frankly if all my co-authors used sweave I would too (to the extend of loading pre-calculated subsets of data - were the heavy lifting was done), but they complain that the tex files with sweave are illegible/too long/ too complex and I think they are correct. This way I have one R file and one tex file. I am glad enough as it is that they are accepting LaTex!!

You mentioned knitr before, what is the advantage?

TheEcologist

Global Moderator
Silly old me, I just realized I can use sweave in an "\include" like fashion!
Trying it now and it is so much better, why didn't I think of this before?!
Still does not solve all problem, but it makes some simple statistical work in documents feasible again.

Last edited: