2

I'm writing some kind of a notebook using \LaTeX. I have a lot of notes. (EDIT: Like, a lot. Almost one per day for the past couple years. They range from very short, single line, notes to very long ones including equations, figures, references, web links, etc.) In order not to recompile all notes whenever I add a new note (EDIT: I used to have a single tex file, but it was becoming too large, and compiling too slow), I now put them into separate folders (EDIT: e.g., YYYY/MM/DD/note.tex), compile only the new ones, and then merge the PDFs together using gs. (EDIT: I'm running "gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Notebook.pdf -dBATCH "+full_filenames where I build full_filenames in python using os.walk.)

Everything is pretty smooth, but the merge is pretty slow. Is there a way to rapidly merge many PDFs together? (EDIT: I tried pdftk before, it's definitely faster, but the merged pdf is huge!)

EDIT: Another reason why I split the big notebook into many folders, is that I have a now a small handwriting device, so I also take notes manually now, and I would like to merge all pdfs, from LaTeX and the handwriting software, into a single pdf.

EDIT: Sorry for being sentimental, but thanks for the help guys, I really appreciate!

Martin
  • 153
  • 1
    How are you merging them currently? And what operating system do you use? In Linux, pdftk pdf1 pdf2 ... pdfn cat output final-pdf could be a solution. – Jay Dec 16 '14 at 12:29
  • Have you considered the subfiles package? – darthbith Dec 16 '14 at 12:38
  • 1
    You can also use pdfpages. –  Dec 16 '14 at 12:52
  • Moreover, have you read the whole Topic sub­docs in CTAN?. In general, merge PDF instead of the main document is a bad idea except for some simple notes as you lost most advantages of a main document (common toc, references, counters, headers, index, etc.). – Fran Dec 16 '14 at 18:12
  • @Fran With pdfpages you can set it up so that you at least get a ToC and headers. – cfr Dec 16 '14 at 23:09
  • @cfr Yes, but even with the experimental addtotoc or some other amazing feature never will be a good substitute of a true LaTeX subdocument. What happen if you have numbered sections in each PDF? You can make a fake ToC, but how change the section titles inside each PDF? The list of drawbacks is endless. I often use the great pdfpages, but for this specific task IMHO is not the appropiate tool ... at least if you are the owner of the LaTeX source code. – Fran Dec 17 '14 at 00:19
  • @Fran I use it in this way for constructing course packets which combine various documents, even when I have the source code. It is convenient and saves taking even longer to compile things. Of course, it has its limitations. But if not constantly recompiling everything is a desideratum, it is worth knowing that some of these things are possible even within the constraints imposed by the process of combining PDFs. (It is a reason to favour pdfpages over pdftk, for example.) – cfr Dec 17 '14 at 01:15
  • @cfr But to avoid recompiling constantly a big document,instead of a \include, the packages as docmute save your day without noticeable constrains. I compile stand alone articles that lately are merged as chapters of a big book. I do not need to recompile the book often, since I detect most problems after compiling each article. – Fran Dec 17 '14 at 02:49
  • @Fran I know what you're saying but there are other use cases where an alternative approach just works better. I use standalone as well. I'm not against your approach: it is often best. But sometimes, you just don't need it or it just isn't worth the extra hassle! – cfr Dec 17 '14 at 03:19
  • @cfr I also know what you're saying. :) just a few days ago one of my answers and some other were based in this nice package. Whether to use a screwdriver or a wrench to remove a screw? Depends on the screw type! :) – Fran Dec 17 '14 at 12:58

2 Answers2

2

The canonical tool for this task is pdftk, which is available on most Linux distros out ouf the box, on MacOS via MacPorts/fink/homebrew, on Windows via cygwin or as a binary from https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/.

To concatenate all PDFs from a folder folder just write:

pdftk folder/*.pdf cat output binder.pdf

pdftk is a pretty powerful utility that also supports arbitrary merging (page-wise), encryption and meta-data handling.

Daniel
  • 37,517
1

As Harish suggested, the pdfpages package seems a good way to do it, when you don't want do use ghostscript.

The example below should give you a start for a main document. I don't know if it's more rapid than the solution you have now, but it's what I'd use.

\documentclass{article}
\usepackage{pdfpages}

\title{Some kind of a notebook}
\author{Martin}
\date{\today}

\begin{document}
\maketitle

Here is the introduction to \emph{some kind of notebook}.

\includepdf{somefolder/file1.pdf}

Here's maybe some text in between.

\includepdf[pages={2-3}]{anotherfolder/onlyincludepartially.pdf}

And here might be some end-notes.

\end{document}
Habi
  • 7,694
  • This method will only work when all the pages are of same size. If the pdf contains different page sizes then the page sizes will not be as it in the output – Santhosh Sep 15 '20 at 03:50
  • @SanthoshYedidi: No, this also works if the PDFs are of different size. Your PDF viewer should be able to cope with it easily. – Habi Sep 16 '20 at 19:49
  • Its not about pdf viewer, its about pdfpages. Check the documentation By default the first inserted page will be used as a template.This means that all further pages are scaled such that they match within the contour of this first page. – Santhosh Sep 17 '20 at 06:19
  • Sorry, I misunderstood you. Merging differently sized PDFs works, but - as you correctly state from the documentation - that the final output size is the same as the first inserted page. – Habi Sep 18 '20 at 12:21
  • As specified here it might be 'better' to use a non-LaTeX tool to merge differently sized PDFs, my preference is pdftk. – Habi Sep 18 '20 at 12:23