Extract all \note tags from beamer as a simple text file

There is a nice presenter tool I am using called pdfpc.

Sadly it does not show notes I put in my latex presentation with \note{}.

Is there a way to extract the content of all my \note{} tags to a file that I can convert to a format readable by pdfpc then?

• Hmm, I suppose this is less a TeX question and more a "programming" question (probably best asked on stack overflow). Anyhow, which OS are you using? Grep (Linux/Windows) can probably handle this with ease. – Tom Bombadil Jun 14 '13 at 22:48
• It is not possible to achive this with grep because grep uses regular expressions who are not able to deal with nested brackets like this: \note{\begin{itemize}\item ...\end{itemize}} you would need a parser to remember the state of nesting while reading the input. Thats why I thought there maybe is a latex way as latex is already parsing this an may be able to just ouput the note content to a file. – cebe Jun 15 '13 at 4:58
• Just noticed that even if I am able to do it with grep I still need the number of the current frame to be able to show the correct nodes on the right slide. – cebe Jun 15 '13 at 5:42
• Btw: regex can work in this situation but it is limited for nested brackets. This regex matches all notes in a tex document that do not have a nesting deeper than 2: \\note\{(?:[^}]*?(\{[^}]*?(\{[^}]*?\})?\})?)+\} – cebe Jun 15 '13 at 5:43
• You should know that if you compile your beamer presentation with the notes on the side, pdfpc can now handle this large presentation format and show you the notes in your laptop. This is available in the github version of pdfpc, using the --notes option. – YuppieNetworking Dec 6 '13 at 21:39

I came up with a quite nice solution I created based on these two questions on file IO:

Here is the code to put before \begin{document}:

% create a new file handle
\newwrite\pdfpcnotesfile

% open file on \begin{document}
\AtBeginDocument{%
\immediate\openout\pdfpcnotesfile\jobname.pdfpc\relax
\immediate\write\pdfpcnotesfile{[notes]}
}
% define a # https://tex.stackexchange.com/a/37757/10327
\begingroup
\catcode\#=12
\gdef\hashchar{#}%
\endgroup
% define command \pnote{} that works exactly like \note but
\newcommand{\pnote}[1]{%
% keep normal notes working
\note{#1}%
% write notes to file
\begingroup
\let\#\hashchar
\immediate\write\pdfpcnotesfile{\unexpanded{#1}}%
\endgroup
}
% close file on \end{document}
\AtEndDocument{%
\immediate\closeout\pdfpcnotesfile
}


You can then use the \pnote{} command like you used \note{} before. The behavior will be the same but it will additionally write notes to file in pdfpc readable format.

There are a few thing not yet working:

• It does not preserve newlines, so everything in a \pnote will end up in one line of the output file. To replace newlines and pars you may use the following commands:

• sed -i "s/\\\\\\\\/\n/g" slides.pdfpc
• sed -i "s/\\\\par/\n\n/g" slides.pdfpc
• Multiple \pnote{}` commands per frame are not working right now.