PDF page number clashes with LaTeX page number when included - r

Another day, another question!
I have created a documentation of an R package using R CMD Rd2pdf workdir/.
The documentation is done in roxygen2 comments.
I now wanted to include this pdf into my LaTeX script, which I have managed as follows:
\usepackage{pdfpages}
\includepdf[pages=-,pagecommand={\thispagestyle{plain}}]{docu.pdf}
which means that I included all pdf pages and used the pagecommand option to make the LaTeX page numbering visible again.
Which worked quiet well so far. Scrolling through the pages I liked the outcome very much - this was until I reached the last page of the included pdf, which is the Index page.
Sadly, the page numbering of both, LaTeX and included pdf, are both at the bottom - only for this very last page. I don't like this and maybe you can relate (see image).
I can think of three possibilities:
1) somehow remove the Index page
2) remove the pdf numbering for the Index page or at least move it.
3) remove the LaTeX page number for this page.
Which would you do? I think option 3) is the easiest, but maybe I am missing something.
Thank you!

Without a working example I can't confirm it but is this the answer? tex.stackexchange-includepdf-pages-with-page-numbering-of-new-document-and-remove-blank-page-after
Does the following work?
\usepackage{pdfpages}
\includepdf[pages=-,pagecommand={}]{docu.pdf}

Related

Edit text/comments of rmarkdown and knitr reports without rerunning code

I love knitr & rmarkdown, but I often find myself in situations where I have a lengthy report that takes some nontrivial amount of time to run. After it's generated, I notice my inevitable typos in text. However, re-knitting everything to just fix a couple typos (just in text, not code) takes a long time and seems avoidable. I was about to start taking a hack at developing my own solution to this, but I'm thinking it's the kind of thing that could already have a mature solution which would likely be more robust than the one I'd build.
I'm wondering if there is solution out there within knitr or third party that would allow me to edit just the text of my reports without rerunning code, generating plots and outputs etc. I know, I can simply edit the generated html text, but then those changes must be replicated in the R/Rmd code that generated it, or they get out of sync. I'm envisioning a function like this:
argument 1: the R/Rmd script with text edits (no code changes)... perhaps a warning is generated when code chunks change
argument 2: the html output file from the last time the R script in argument was knitted without the text edits.
return: the html report (argument 2) updated with the comments in the R/Rmd script (argument 1).
I use the cache option sometimes for large datasets. I toggle eval and echo on and off when developing if I'm just working on the text of my report. However, I'm looking for a function that would take care of all this for me, so one doesn't have to mess with the code and chunk options to make small edits to text.
Here's an interim solution that lets you retain the speed of making changes directly to the rendered text, but you have to do a little work after you're done making changes.
Assuming the following files:
input.knitr is the original Knitr file with text and code integrated.
output.html is the resulting HTML code that has been rendered by Knitr.
Consider making direct text edits to output.html and then running something like Meld visual merge tool:
meld output.html input.knitr
Then manually select the edits in output.html that are new and should be fixed in the original source input.knitr. Tools such as Meld do a pretty good job of aligning the texts so that the chunks and knitted output will appear as large "changes" that, in practice, you would ignore. You would focus on the small changes in the non-chunk sections.

How to format linked R code in Latex so that it can be copied and run directly from the pdf?

I have to submit a programming assignment in pdf format (produced using LaTeX), and the tutor expects to be able to copy and paste the code directly from the pdf into R to run it. I know I can do this by hard-copying the code into the LaTeX document in a \verbatim block, but I usually use the 'listings' package to link my R source file directly to my LaTeX document, and when I do that, the pdf output contains a lot of extra spaces that are picked up when the code is copied back into R. Sometimes the code will still run with the spaces, but with decimal points, underscores etc the inserted space will cause problems. I've copied the same line from the 'verbatim' environment (top) and 'listings' (bottom) to illustrate the difference:
par(mfrow = c(2,1), ps = 10, mar = c(3,3,2,2))
par ( mfrow = c(2 ,1) , ps = 10, mar = c(3 ,3 ,2 ,2))
I've been through the Source Codes documentation and tried removing whitespace and changing the basic style (my default is ttfamily), but this doesn't work, and Googling just brings me variations on the official documentation. Essentially, what I'd like to be able to do is apply the Verbatim font style to my Listings environment so that I can still format my code how I want to - but I suspect it won't be that easy. Any suggestions on how to get my R code into a document without copy-pasting each line, so that the output can be copied back into R, would be greatly appreciated! Thanks in advance...
An easy solution has been mentioned here:
https://tex.stackexchange.com/questions/119218/how-to-copy-paste-from-lstlistings
Add
\lstset{columns=fullflexible}
and you will be able to copy/paste the R code from the pdf document.
+1 to #Roland, he has the right idea with knitr.
I would however also assume with enough configuration of listings in LaTeX you would be able to get rid of the unwanted whitespace. It's been a while since I fiddled with the listings, but I recall them having a lot of customisability, as well as syntax support for R, that should clear most of the conversion issues, but I may be mistaken.

knitr: Document does not change anymore

I have a .Rnw document in which I include childs. The childs produce tables via the 'latex' command of the Hmisc library in R.
When I make changes in the child documents, these changes do not anymore change the pdf document. My first guess was to use the chunk option 'eval=TRUE', but this does not change anything. Then, I saw, that the tables are actually saved to a .tex file with same name as the .Rnw document. I deleted this file and after compilation with knitr I got an error:
Error: Latexmk: Could not find file documentname.tex.
I assume, this is not the way to do it. Now I am out of ideas what to do. I appreciate some help on my problem.
Best
Simon
Allright, when trying to construct a simple example, I actually found out, that neither the packages I included nor the nesting of child documents interfere with the compilation via knitr. The reason was a simple error in the low-level .Rnw document, where a Hmisc latex table had a label, that missed a closing speech mark.
This causes then the output pdf not to change - I assume, that in this case the already constructed .tex file is included instead of letting knitr recompile the .Rnw documents and this hasn't changed since the last compilation?
What I wonder about is the different format of the landscape ctable in the document. Using a simple knitr document just with \documentclass{article} produces well placed tables. In my document using a template for the JFE, I get a table that extends over the whole page and even in footnotesize it is far away from the great appearance in the simple document. There is only a margin of less than half a cm on the right and the left. Page size is the same: both US letter... Can I probably control that via knitr or only via resizebox?

Lyx - how to create sections without titles

I'm currently looking into lyx because I'm starting to get fed up with writing LaTeX by hand. The problem is, LyX seems to be a bit opiniated about how sections should be written - I'm used to writing
\subsection{}
\subsubsection{}
...
\subsubsection{}
etc., because in the documents I'm writing I don't want titles for my sections. I just want them to be numbered. LyX doesn't seem to like that though, and ends up deleting my sections (and subsections, and subsubsections) when I don't have any text in their titles.
I can just insert a hard space, but this feels kind of weird. I don't understand why lyx wouldn't just let me hit enter and be done with it.
Try to us a 'hard space' as title of the sections, through <Ctrl>+<space>, that should do the trick (it's the keyboard shortcut for LaTeX's "~").
You can insert Evil Red Text (raw LaTeX commands) in LyX. Look for Insert -> TeX Code menu. I just tried it and inserted \subsection{} inside the ERT, and it compiled successfully and showed the section numbers.

Annotating Adobe Reader PDFs with math symbols

Many of the math textbooks and other literature I read is in PDF format, so I frequently find myself annotating these with the Adobe Reader comments tool.
I did find a helpful guide here, but sometimes I'd like the option of inserting math symbols, too. Has anyone found a reliable way to insert math symbols, TeX, or other arbitrary formatting into the annotations?
So far, the best I've come up with is to enter the unicode prefixed by "0x" and hit alt+X after it. Maybe with the Adobe javascript SDK you could write a script to shortcut this.
I don't think any of the current commercial editors make this easy, which is too bad. I am sure the vendors monitor this site, so there is hope.
In the meantime, here is a manual workaround.
Use tikz to create your comment boxes. Here are the two examples I found to be most relevant: Boxes and Positioning. Play around with the options to get both the shape and the placement you want. Generate a pdf file from the latex source that contains your comments.
IMPORTANT: if your comments end before the last page of the original document, insert:
\pagebreak{} % create empty page
\thispagestyle{empty} % get rid of page numbers et al
~ % put a space so the page gets generated
before your \end{document}, to get an empty last page. The following command will reuse the last page of your comments document on all subsequent pages of the original document.
Use a recent version of pdftk with the multistamp command to overlay your equations file with your original file like so:
pdftk original.pdf multistamp comments.pdf output out.pdf
Also see this question.
The free (as speech) PDF tool, Okular, supports this functionality by putting latex formula directly between $$...$$.

Resources