[Tex/LaTex] Make Notes from Lyx into Annotations on the PDF

commentsluatexlyxpdf

Lyx Supports Notes.
It would be great to have any notes in lyx show up as Annotations in a draft produced PDF.

For example:

LyX:

lyx screen shot

PDF:

Foxit screen shot

The use case I have in mind is when showing this draft work to someone for to get some early feedback, they can see that I have notes there reminding my of content I still need to work on.

I would like a method to do this using Luatex, as my current work (and my work in general) won't build in any other engine.

Closely related to: How to annotate PDF files generated by pdflatex?

I guess the trick would be getting LyX to convert the Notes into appropriate latex pdf annotation commands. I guess this could be done by insterting some kind of python or perl etc script in to the build pipe line.

Best Answer

As far as the yellow LyX notes are completely lost in the generated LaTeX source (i.e, the .tex file), your goal seem impossible without touching the LyX's guts or deal with the original .lyx file. An easier starting point could be use the black comments for this purpose.

With this approach, you only have to transform a \begin{comment} note \end{comment} of the verbatim package in a \pdfcomment{note} of the pdfcomment package.

How-to:

1) Go to Document > Configuration... > LaTex preamble

2) Paste the following lines:

% Change comments in PDF notes
\usepackage{pdfcomment}
\usepackage{environ}
\RenewEnviron{comment}{\pdfcomment{\BODY}}

3) Go to Insert > Note > Comment) and write some text.

This left a comment environment in the .tex file. Example of the ouput in LyX:

MWE1

(you will see "Comment" instead of "Comentario" in a english OS, obviously...)

3) Go to File > Export > PDF(pdflatex)

4) Open the PDF open in Acrobat Reader:

MWE2

LyX-generated LaTeX source:

%% LyX 2.0.5.1 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{verbatim}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
%add this in Lyx Preamble 
\usepackage{pdfcomment}
\usepackage{environ}
\RenewEnviron{comment}{\pdfcomment{\BODY}}

\makeatother

\usepackage{babel}
\begin{document}
Plain text %
\begin{comment}
This is a note (comment)
\end{comment}

\end{document}

Minimal working example in plain LaTeX

\documentclass{article}
\usepackage{verbatim}
\usepackage{pdfcomment}
\usepackage{environ}
\RenewEnviron{comment}{\pdfcomment{\BODY}}
\begin{document}
Plain text
\begin{comment}
This is a note (comment)
\end{comment}
\end{document}