Created
December 1, 2016 03:05
-
-
Save zr-tex8r/84746fefd54fce0dfae0eb33e8f15377 to your computer and use it in GitHub Desktop.
LaTeX: To get the current page number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% bxcurpage.sty | |
%% package declaration | |
\NeedsTeXFormat{LaTeX2e} | |
\ProvidesPackage{bxcurpage}[2016/12/01 v0.2] | |
\def\bxpg@pkgname{bxcurpage} | |
%--------------------------------------- helpers | |
%% packages | |
\RequirePackage{zref} | |
%% LaTeX counters | |
\newcounter{bxpg@id} | |
\newcounter{currentpage} | |
\def\thecurrentpage{??} | |
%% variables | |
\let\bxpg@label@name\relax | |
%--------------------------------------- main | |
%% zref settings | |
\zref@newprop*{bxpg@pageval}[0]{\number\c@page}% | |
\zref@addprop{main}{bxpg@pageval} | |
%%<*> \getcurrentpage | |
\@ifdefinable{\getcurrentpage}{% | |
\DeclareRobustCommand*\getcurrentpage{% | |
\refstepcounter{bxpg@id}% | |
\edef\bxpg@label@name{bxpg:\the\c@bxpg@id}% | |
\edef\bxpg@next{% | |
\noexpand\zref@label{\bxpg@label@name}% | |
}\bxpg@next | |
\zref@refused\bxpg@label@name | |
\zref@ifrefundefined\bxpg@label@name{% | |
\global\c@currentpage=\c@page | |
\global\let\thecurrentpage\thepage | |
}{% | |
\global\c@currentpage=% | |
\zref@extract\bxpg@label@name{bxpg@pageval}\relax | |
\zref@def@extract\bxpg@next\bxpg@label@name{page}% | |
\global\let\thecurrentpage\bxpg@next | |
}% | |
}% | |
} | |
%--------------------------------------- all done | |
\endinput | |
%% EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment