10

Possible Duplicate:
How to annotate PDF files generated by pdflatex?

Is there a way to annotate pdfs with LaTeX annotations? I mean a pdf that I do not have the source code for (or may not have even been written in LaTeX itself, for that matter).

The motivation behind my question is that I would really like to annotate my lecture notes digitally to stop me losing important notes, but the lecturer does not like the idea of releasing the source code to his notes to students. (i.e. I don't think asking for the source code went down well and I would like to not feel the need to ask another lecturer the same question if I can avoid it :-))

I could try to type them out myself but when time is limited it would be ambitious at best, to try it when there are more urgent work I need to prioritise.

I use linux, my pdf viewer is okular and it mainly for maths/physics type work if that is useful information to add. It would be handy to be able to do it one way or another so I am open to any suggestions that might help out!

Magpie
  • 2,294
  • 1
    Two possibilities: if doing "real time" (ie in the lecture) then I wouldn't bother with LaTeX annotations and would just annotated the PDF directly using a PDF annotation tool (my favourites are xournal for Linux and GoodNotes for iPad). If afterwards, simply load the PDF with something like pdfpages and "write on top" using normal LaTeX commands. – Andrew Stacey Dec 05 '12 at 17:40
  • 2
    This question is very similar to http://tex.stackexchange.com/questions/6306/how-to-annotate-pdf-files-generated-by-pdflatex. Please take a look at it as the information there might help you. If so, that's great, and we'll probably close this question as a duplicate just to keep the place tidy and to help people find answers quickly. If not, please edit your question here to explain why so that people can better focus their attention to help you. – doncherry Dec 05 '12 at 17:42
  • pdf pages? Can you elaborate? @AndrewStacey – Magpie Dec 05 '12 at 17:43
  • @doncherry thanks, I took a look, but I am not sure if this is the same thing. That person seems to have access to the source code of the pdf they are trying to annotate. I will try to check more thoroughly to see what the mean could work though. – Magpie Dec 05 '12 at 17:46
  • 2
    There's a package on CTAN called pdfpages: http://www.ctan.org/pkg/pdfpages and it defines a command where you include pages from a PDF as the background to some pages which you can then draw on top of using normal LaTeX commands. I use it for filling in PDF forms and I use TikZ to place the text at specific points relative to the form. The documentation for pdfpages is worth a look to see if it would do what you want. – Andrew Stacey Dec 05 '12 at 17:48
  • 2
    @Magpie That is a difference, of course. It looks to me like the OP over there was looking for a way to annotate finished PDFs as well, so the top answer (pdfcomment) actually doesn't address the problem. Many of the other answers address that problem though, it seems. I guess @Andrew could add his answer over there as well. (Btw, Kurt's edit was perfectly valid, perhaps except for the conversion of British spelling to American, but I'm sure that was an honest mistake on his side.) – doncherry Dec 05 '12 at 17:52
  • @AndrewStacey I am having trouble visualising this? Is there a screen shot somewhere? – Magpie Dec 05 '12 at 19:45
  • @doncherry I am impressed you recognised that was the reason why I didn't accept the edit! I was not offended or anything though so not a problem there. – Magpie Dec 05 '12 at 19:46
  • @Magpie Well, I am an English Literature and Language major, so I should pick up on things like that :) – doncherry Dec 05 '12 at 22:55
  • This question is about commenting PDFs without a tex-source. The question linked as answer is about »Thus, what are the alternatives for annotating PDF files generated by pdflatex?«. So closing this question here never was ok. – Keks Dose Sep 02 '21 at 07:46

2 Answers2

14

Here's an example using pdfpages to load the PDF as a background with TikZ to draw on top of it. The following code will complain about a missing image (tikzmark_example.pdf) but hopefully will give you the idea of what I was saying in the comments. I've left the grid in place as that's how I figure out the coordinates. This is adapted from code I use to "fill in" PDF forms by writing on top of them - in other situations I'd probably end up with a different set of helper macros to make it easier to place the annotations.

\documentclass{article}
%\url{http://tex.stackexchange.com/q/85651/86}
\usepackage[svgnames]{xcolor}
\usepackage{pdfpages}
\usepackage{tikz}

\tikzset{
  every node/.style={
    anchor=mid west,
  }
}

\makeatletter
\pgfkeys{/form field/.code 2 args={\expandafter\global\expandafter\def\csname field@#1\expandafter\endcsname\expandafter{#2}}}

\newcommand{\place}[3][]{\node[#1] at (#2) {\csname field@#3\endcsname};}
\makeatother

\newcommand{\xmark}[1]{\node at (#1) {X};}



\begin{document}

\foreach \mykey/\myvalue in {
  ctsfn/{Defined in Week 1},
  metsp/{Defined in Week 3},
} {
  \pgfkeys{/form field={\mykey}{\myvalue}}
}

\includepdf[
  pages=1,
  picturecommand={%
    \begin{tikzpicture}[remember picture,overlay]
%%% The next lines draw a useful grid - get rid of them (comment them out) on the final version
    \draw[gray] (current page.south west) grid (current page.north east);
\foreach \k in {1,...,28} {
      \path (current page.south east) ++(-2,\k) node {\k};
}
\foreach \k in {1,...,20} {
      \path (current page.south west) ++(\k,2) node {\k};
}
%%% grid code ends here
\tikzset{every node/.append style={fill=Honeydew,font=\large}}
\place[name=ctsfn]{14cm,17cm}{ctsfn}
\place[name=metsp]{11cm,9cm}{metsp}
\draw[ultra thick,blue,->] (ctsfn) to[out=135,in=90] (9cm,17.3cm);
\draw[ultra thick,blue,->] (metsp) to[out=155,in=70] (6cm,9cm);
    \end{tikzpicture}
  }
]{tikzmark_example.pdf}

\end{document}

The result of the above is:

lecture slide with annotations

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
  • That looks like the sort of thing I need! Thanks. Can you advise how to get rid of the square grid though? – Magpie Dec 05 '12 at 22:35
  • 2
    @Magpie I've added some comments to the code as to where the grid bit is. – Andrew Stacey Dec 05 '12 at 22:47
  • For equations: It seems that the above solution does not work for the \begin{equation} E=mc^2 \end{equation} environment - but you can at least write comments of the form $\displaystyle a=\frac{b}{c}$ where displaystyle helps to render the equation bigger. – exchange May 20 '20 at 14:06
4

Although there might be a way to comment third party PDFs by using LaTeX, this is not a usefull way.

EDIT:

My answer from 2012 (below) is outdated. Under Linux there are many tools to comment or even change PDFs. Okular can annotate PDFs nicely, e.g. »Master PDF Editor« is a commercial tool.

Under Windows there is PDF XChange Editor (not tested) for free, I'm using a commercial tool called PDF Annotator.

But there are many more, depending on your needs.

To annotate a PDF, I often »print« it virtually on a large landscape page. If the to-be-annotated page is DIN A4, I put the page on a DIN A3 landscape and have much space to comment.

\documentclass[DIV=30, paper=A3, paper=landscape]{scrartcl}

\usepackage{pdfpages}

\begin{document}

\includepdf[pages=-, offset= -300 0]{Origin.pdf}

\end{document}

(OLD ANSWER FROM 2012: There are lots of software to deal with your needs, but more on the windows side. Under Linux, I employ flpsed, http://flpsed.org/flpsed.html.)

Keks Dose
  • 30,892
  • As of 0.7.3, currently in Debian unstable (20th August 2016), I can confirm that PDF annotation works with flpsed. I've installed it on Debian stable (jessie). – Faheem Mitha Aug 20 '16 at 19:06
  • I would love to know the ones from Windows too – Homero Esmeraldo Sep 01 '21 at 21:56
  • @HomeroEsmeraldo See updated answer. – Keks Dose Sep 02 '21 at 07:42
  • I use Adobe Reader and it annotates fine too. But I wanted to be able to have equations in the annotations, and that I haven't seen anything do, neither Adobe reader nor okular. Is the latex solution you gave the only way to have equations be rendered on top of a pdf? – Homero Esmeraldo Sep 04 '21 at 05:25
  • @HomeroEsmeraldo I'm not in the equation business, sorry. Go ahead and ask in a separate question precisely what you need to know! – Keks Dose Sep 04 '21 at 09:21