Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few changes and improvements #15

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 67 additions & 13 deletions pdfpcnotes.sty
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
\ProvidesPackage{pdfpcnotes}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% pdfpcnotes.sty
%
% Create notes for PDFPC from a beamer file
%
% Copyright 2013 Carsten Brandt <[email protected]>
% Copyright 2013 Aggelos Karalias <[email protected]>
% Copyright 2014-2016 Raphaël Beamonte <[email protected]>
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ProvidesPackage%
{pdfpcnotes}%
[2016/05/04 \space ver 0.2 \space To generate notes to use with pdfpc]

\RequirePackage{forloop}
\RequirePackage{pdftexcmds}

\RequirePackage{kvoptions}
\DeclareStringOption{fontsize}[32130]
\ProcessKeyvalOptions*\relax

% create a new file handle
\newwrite\pdfpcnotesfile

% open file on \begin{document}
\AtBeginDocument{%
\immediate\openout\pdfpcnotesfile\jobname.pdfpc\relax
\immediate\write\pdfpcnotesfile{[file]}
\immediate\write\pdfpcnotesfile{\jobname.pdf}
\ifx\pdfpcnotes@fontsize\@empty
\else
\immediate\write\pdfpcnotesfile{[font_size]^^J\pdfpcnotes@fontsize}
\fi
\immediate\write\pdfpcnotesfile{[notes]}
}
% define a # http://tex.stackexchange.com/a/37757/10327
Expand All @@ -15,28 +42,55 @@
\endgroup


\def\lastframenumber{0}
\global\def\pdfpcnotes@lastframenumber{0}
\newcounter{pdfpcnotes@currentframenotes}
\newcounter{pdfpcnotes@checkifnoteexists}
\newif\ifpdfpcnotes@noteexists

% define command \pnote{} that works like note but
% additionally writes notes to file in pdfpc readable format
\newcommand{\pnote}[1]{%
% keep normal notes working
\note{#1}%

%
% if frame changed - write a new header
\ifdim\theframenumber pt>\lastframenumber pt
\let\lastframenumber\theframenumber
\begingroup
\let\#\hashchar
\ifdim\theframenumber pt>\pdfpcnotes@lastframenumber pt
\global\edef\pdfpcnotes@lastframenumber{\theframenumber}%
\setcounter{pdfpcnotes@currentframenotes}{0}%
\begingroup%
\let\#\hashchar%
\immediate\write\pdfpcnotesfile{\#\#\# \theframenumber}%
\endgroup
\fi

% write note to file
\immediate\write\pdfpcnotesfile{\unexpanded{#1}}%
\endgroup%
\fi%
%
% check if note was already stored
\pdfpcnotes@noteexistsfalse%
\forloop{pdfpcnotes@checkifnoteexists}{0}{%
\value{pdfpcnotes@checkifnoteexists} < \value{pdfpcnotes@currentframenotes}%
}{%
\ifnum\pdf@strcmp{\unexpanded{#1}}{\csname pdfpcnotes@currentframenotes@\thepdfpcnotes@checkifnoteexists\endcsname}=0
\pdfpcnotes@noteexiststrue%
\setcounter{pdfpcnotes@checkifnoteexists}{\value{pdfpcnotes@currentframenotes}}%
\else%
\fi%
}%
%
% and then, only if the note was not stored
\ifpdfpcnotes@noteexists%
\else%
% add note in stored notes
\expandafter\global\expandafter\def\csname pdfpcnotes@currentframenotes@\thepdfpcnotes@currentframenotes\endcsname{\unexpanded{#1}}%
\stepcounter{pdfpcnotes@currentframenotes}%
%
% write note to file
\begingroup%
\def\\{^^J}%
\def\par{^^J^^J}%
\immediate\write\pdfpcnotesfile{#1}%
\endgroup%
\fi%
}
% close file on \begin{document}
\AtEndDocument{%
\immediate\closeout\pdfpcnotesfile
}