4

I am not new to LaTeX, but I have never really written an actual LaTeX script and so I have trouble debugging the one I have. I will post the specific problem, so there is something I can grab unto, but I actually want to understand and solve the specific problem AND understand how this can be usually done. So the problem itself:

I am using beamer and am trying to use the package pdfpcnotes to increase the functionality of the note command (this is the git repo: https://github.com/cebe/pdfpc-latex-notes/blob/master/pdfpcnotes.sty)

Here's my mwe:

\documentclass[]{beamer}
\usepackage{pdfpcnotes}

\begin{document}
\frame{
\frametitle{1. frame}
}
\pnote{first note}

\frame{
\frametitle{2. frame}
}
\pnote{second note}
\end{document}

Running pdflatex on this produces the following output into mwe.pdfpc:

[notes]
### 1
first note
second note

but really it should be

[notes]
### 1
first note
### 2
second note

The problem itself is going to be around the if-else part of the script. Could somebody post a walkthrough on how such a problem could be solved? I find it extremely hard to wrap my head around how LaTeX works and how you can get internal information out of it.

  • So, to clarify, do you mean the if statement on lines 27-33 of pdfpcnotes.sty? – Arun Debray Nov 9 '15 at 14:14
  • @ArunDebray Yes, I think that is where the problem should be, since based on the output, line 31 in pdfpcnotes.sty only get called once. – fbence Nov 9 '15 at 16:07
4

The error is in

\let\lastframenumber\theframenumber

because \theframenumber is \@arabic\c@framenumber and not the value directly.

To see this add \show\theframenumber after begin{document} and compile from terminal. Execution will stop at this and display

> \theframenumber=macro:
->\@arabic \c@framenumber .
l.5 \show\theframenumber

? 

Pressing enter will resume execution.

Solution: \edef\lastframenumber{\theframenumber}

Full example (package code in the document):

\documentclass[]{beamer}
%\usepackage{pdfpcnotes}

\makeatletter
% 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 # http://tex.stackexchange.com/a/37757/10327
\begingroup
\catcode`\#=12
\gdef\three@hashchars@space{###\space}%
\endgroup

\def\lastframenumber{0}

% 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
    \edef\lastframenumber{\theframenumber}%
    \immediate\write\pdfpcnotesfile{\three@hashchars@space\theframenumber}%
  \fi
  % write note to file
  \immediate\write\pdfpcnotesfile{\unexpanded{#1}}%
}
% close file on \begin{document}
\AtEndDocument{%
  \immediate\closeout\pdfpcnotesfile
}
\makeatother

\begin{document}
\frame{
\frametitle{1. frame}
}
\pnote{first note}

\frame{
\frametitle{2. frame}
}
\pnote{second note}
\end{document}

Output file:

[notes]
### 1
first note
### 2
second note
  • Thank you for the fix! Could you please explain how you got to this solution? How did you figure out that \theframenumber is already define somewhere and is \@arabic\c@framenumber, how did you access the value of these variables during the runtime? (I checked the difference between \edef and \let there's a good answer to that on the site :) – fbence Nov 9 '15 at 17:23
  • @fbence I checked the definition of \theframenumber and that was it. ;-) – egreg Nov 9 '15 at 18:04
  • :D Okay, so I really don't know how to do that: what is the exact command that can pull this information into say the logs or stdout? Or did you just grep the beamer source files? – fbence Nov 9 '15 at 18:23
  • @fbence Add \show\theframenumber to the document, after \begin{document}. Compile from a terminal and see. – egreg Nov 9 '15 at 18:28
  • I was too fast to mark your answer accepted:) Changed the pdfpcnotes.sty at line 28 to \edef\lastframenumber\theframenumber. This now complains that [1{/usr/local/texlive/2015/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]! Extra \endgroup. and ! Use of \lastframenumber doesn't match its definition – fbence Nov 10 '15 at 9:49
1

Your document should be better structured with beamer, however I do not know if it'll resolve your troubles

\begin{frame}
\frametitle{}
\pnote{my note}
\end{frame}

Since \pnote acts like \note, it should be inside the frames.

  • actually, placing \note outside the frame makes sense. From the manual: " \note[⟨options⟩]{⟨note text⟩} Outside frames, this command creates a note page." – fbence Nov 9 '15 at 16:15
  • Placing the \pnote inside the frame actually does make it work as it should (but messes up the [notes] option of beamer, because \pnote[item] is not implemented), thanks for that! But I would still like to understand how I would debug this, see in some comprehensible why, where and how the variables change. – fbence Nov 9 '15 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.