Skip to content

Instantly share code, notes, and snippets.

@nanofi
Created February 5, 2015 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanofi/f96a59d0fe31724fc216 to your computer and use it in GitHub Desktop.
Save nanofi/f96a59d0fe31724fc216 to your computer and use it in GitHub Desktop.
The macros for exporting and importing the counters by using `zref`
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{count}
[2015/2/6 v0.01 Import and Export counters ]
\RequirePackage[lastpage,xr]{zref}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{proposition}{Proposition}
\newtheorem{corollary}{Corollary}
\newtheorem{lemma}{Lemma}
\theoremstyle{definition}
\newtheorem{definition}{Definition}
\newtheorem{assumption}{Assumption}
\def\zref@addcounter#1{%
\zref@newprop{#1value}{\number\value{#1}}\zref@addprop{LastPage}{#1value}}
\def\zref@importcounter#1#2{%
\setcounter{#2}{\zref@extractdefault{#1-LastPage}{#2value}{0}}}
\zref@addcounter{table}
\zref@addcounter{figure}
\zref@addcounter{section}
\zref@addcounter{equation}
\zref@addcounter{definition}
\zref@addcounter{theorem}
\zref@addcounter{proposition}
\zref@addcounter{corollary}
\zref@addcounter{lemma}
\zref@addcounter{assumption}
\newcommand\importcounter[1]{%
\zexternaldocument[#1-]{#1}%
\zref@ifrefundefined{#1-LastPage}{%
\@latex@error{Zref label `LastPage' of `#1' is undefined}\@ehc}{%
\zref@importcounter{#1}{table}%
\zref@importcounter{#1}{figure}%
\zref@importcounter{#1}{section}%
\zref@importcounter{#1}{equation}%
\zref@importcounter{#1}{definition}%
\zref@importcounter{#1}{theorem}%
\zref@importcounter{#1}{proposition}%
\zref@importcounter{#1}{corollary}%
\zref@importcounter{#1}{lemma}%
\zref@importcounter{#1}{assumption}%
}}
\endinput
\documentclass{article}
\usepackage{count}
\begin{document}
\begin{theorem} a \end{theorem}
\begin{theorem} b \end{theorem}
\begin{theorem} c \end{theorem}
\begin{theorem} d \end{theorem}
\begin{theorem} e \end{theorem}
\end{document}
\documentclass{article}
\usepackage{count}
\importcounter{first}
\begin{document}
\begin{theorem} f \end{theorem}
\begin{theorem} g \end{theorem}
\begin{theorem} h \end{theorem}
\begin{theorem} i \end{theorem}
\begin{theorem} j \end{theorem}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment