我正在使用 beamer 的一项功能,可以在幻灯片旁边显示注释,但出来的页码太乱,导致无法将特定幻灯片提取到其他文档中\includegraphics[page=n]{presentation.pdf}
。
例如,在这个 MWE 中,有两个框架,每个框架包含 1 张幻灯片,然后有一个框架包含 4 张幻灯片。Acrobat 中显示的 PDF 页面标签如下:2、3、3、3、3 和 7。它从第 2 页开始,而不是第 1 页,然后有 4 个第 3 页,但它们甚至不属于同一框架!
\documentclass{beamer}
\usepackage{pgfpages}
\setbeameroption{show notes on second screen=left}
\setbeamertemplate{note page}{frame \insertframenumber \\ \insertnote}
\def\pg#1{pgfpages says this is page #1 but it is really page \arabic{page}}
\begin{document}
\setcounter{page}{0}
\frame{hi \note{\pg{2}}}
\frame{there \note{\pg{3}}}
\frame{how \pause are \pause you \pause today
\note<1-3>{\pg{3}}
\note<4>{\pg{7}}}
\end{document}
输出内容如下:
我知道手册上说“pgfpages 会在 .aux 文件中产生错误的页码”,并给出了手动解决方法。但计数器page
仍然有效,那么难道不应该有某种方法将其传递给 PDF 吗?我想修复这个问题,但不知道从哪里开始。具体来说,当手册上说“TeX 仅在物理页面被发送出去时才在编写 .aux 文件时实例化页码”时,它到底在说什么?它的源代码在哪里?
答案1
文件中的页面标签.pdf
实际上与文件中的页码无关.aux
。页面标签也是在发货时设置的,但由包裹设置hyperref
。
pgfpages
但是,在下一个/下一个逻辑页面完成后,软件包会发出一个物理页面。这对于“两个屏幕,可选第二个”布局是必要的,以便设置第二个屏幕后主屏幕。但是,副作用是,hyperref
当(前一个)物理页面交付时,页面计数器和包的一些页面状态(如页面转换)已经为下一个逻辑页面设置,这会导致错误pdfpagelabels
和页面转换发生得太早。
为了解决这个问题,可以在物理页面的第一个逻辑页面即将发货时保存相关的页面状态,并在相应的物理页面发货之前恢复相关的页面状态。
需要注意的是,这一切只有在pgfpages
加载时才有效后 hyperref
因为hyperref
的 shipout hook 只能针对物理页面进行调用。
% Save and restore pdfpage related information for hyperref.
\@ifpackageloaded{hyperref}{
% Create new counter to save the page counter.
\newcount\pgfpages@state@c@page
% The special per-page label 'thispdfpagelabel' is set/cleared
% globally during hyperref's shipout hook for physical pages.
% Therefore it must be saved temporarily before physical shipout.
\def\pgfpages@state@save@temp{%
\ifHy@pdfpagelabels%
% \HyPL@thisLabel is only defined if pdfpagelabels are activated.
\let\pgfpages@state@thisLabel@temp\HyPL@thisLabel%
\fi%
}
% Save all relevant page states if the first logical page is shipped.
\def\pgfpages@state@save#1{%
% Probably it should be configurable which logical page is
% considered, but the first page seems reasonable for now.
\ifnum#1=\pgf@firstshipout\relax%
% Save the special per-page label 'thispdfpagelabel', which is
% temporarily saved before.
\ifHy@pdfpagelabels%
\ifx\pgfpages@state@thisLabel@temp\relax%
\global\let\pgfpages@state@thisLabel\relax%
\else%
\xdef\pgfpages@state@thisLabel{\pgfpages@state@thisLabel@temp}%
\fi%
\fi%
% Save the page counter and its formatting.
\global\pgfpages@state@c@page=\c@page%
\global\let\pgfpages@state@thepage\thepage%
% Save the page transition and duration.
\global\let\pgfpages@state@pdfpagetransition\@pdfpagetransition%
\global\let\pgfpages@state@pdfpageduration\@pdfpageduration%
\fi%
}
% Restore all relevant page states.
\def\pgfpages@state@restore{%
% Restore the special per-page label 'thispdfpagelabel'.
\ifHy@pdfpagelabels%
% \HyPL@thisLabel is only defined if pdfpagelabels are activated.
\let\HyPL@thisLabel\pgfpages@state@thisLabel%
\fi%
% Restore the page counter and its formatting.
\c@page=\pgfpages@state@c@page%
\let\thepage\pgfpages@state@thepage%
% Restore the page transition and duration.
\let\@pdfpagetransition\pgfpages@state@pdfpagetransition%
\let\@pdfpageduration\pgfpages@state@pdfpageduration%
}
}{
% Do nothing if hyperref is not loaded.
\def\pgfpages@state@save@temp{}
\def\pgfpages@state@save#1{}
\def\pgfpages@state@restore{}
}
% "Patch" macros of pgfpages.
\def\pgfpages@shipoutshipoutbox{%
\begingroup
\let \protect \noexpand
\@resetactivechars
\global\let\@@if@newlist\if@newlist
\global\@newlistfalse
\@parboxrestore%
% Restore page states before physical shipout:
\pgfpages@state@restore%
\pgfpages@originalshipout%
\vbox{\hbox{%
\hskip-1in%
\vbox to \pgfphysicalheight{%
\vss\box\pgfpages@shipoutbox%
\vskip1in%
}}}%
\endgroup%
}
\def\pgfpages@interceptshipout{%
% Temporarily save some page states which are globally set during
% physical shipout:
\pgfpages@state@save@temp%
\ifnum\pgf@shipoutnextto>0\relax
\def\pgf@next{%
\expandafter\global\expandafter\setbox\csname pgfpages@box@\the\pgf@shipoutnextto\endcsname=\box\voidb@x%
\afterassignment\pgfpages@shipouttestnext%
\pgfpagesshipoutlogicalpage{\the\pgf@shipoutnextto}%
}%
\else%
\ifpgf@holdingphysicalpage% shipout physical page now
{\pgfshipoutphysicalpage}%
\fi%
\ifnum\pgf@logicalpages=0\relax
\def\pgf@next{\pgfpages@originalshipout}%
\else%
\def\pgf@next{%
\expandafter\global\expandafter\setbox\csname pgfpages@box@\the\pgf@currentshipout\endcsname=\box\voidb@x%
\afterassignment\pgfpages@shipouttest%
\pgfpagesshipoutlogicalpage{\the\pgf@currentshipout}%
}%
\fi%
\fi%
\pgf@next%
}
\renewcommand\pgfpagesshipoutlogicalpage[1]{%
\global\pgfphysicalpageemptyfalse%
% Save page states before logical shipout:
\pgfpages@state@save{#1}%
\expandafter\global\expandafter\setbox\csname pgfpages@box@#1\endcsname=}