|
|
I am trying to chain another set of macros to the end of the \label,
\ref, and \pageref macros. Basically, I want to do later referencing
analysis in perl (such as what labels are used most often, where I have
useless labels, where I have forward references, etc. I plan to post
this for public consumption once it works). Therefore I have written a
short style file to just write every encounter to an '.mrl' file, and
use whatever the macros were. Alas, as soon as I usepackage hyperref,
it no longer works. The file is created, but nothing is ever written
to it.I believe hyperref prevents the chaining.
I have in mrl.sty:
% [1] squirrel away whatever the original definition is
\let\labelmrl\label
\let\refmrl\ref
\let\pagerefmrl\pageref
% [2] use the original, but also write it out to the .mrl file
\renewcommand\label[1]{\labelmrl{#1}\mrlwrite{label*#1}}
\renewcommand\ref[1]{\refmrl{#1}\mrlwrite{ref*#1}}
\renewcommand\pageref[1]{\pagerefmrl{#1}\mrlwrite{pageref*#1}}
% [3] provide the backend to save all the information
\providecommand\curfilename{\jobname}
\newwrite\mymrlptr % we need a file pointer
\immediate\openout\mymrlptr=\jobname.mrl
\makeatletter
\def\mrlwrite#1{%
\typeout{WRITING OUT RIGHT NOW #1}%
\@bsphack%
{\immediate\write\mymrlptr{***#1*\thepage*\the\inputlineno*\curfilename***}}
\@esphack%
}
\makeatother
----------------
\documentclass{article}
\usepackage{mrl}
\usepackage{hyperref} % renders mrl.sty useless; it does not matter
whether mrl is before or after
\begin{document}
\section{Hello}
This is an example.
\label{a-useless-label}
This is an example.
\label{label-on-p1} This is a ref to \ref{label-on-p2} on page
\pageref{label-on-p2}.
\ref{a-bad-reference}
\clearpage
\label{label-on-p2} This is a ref to \ref{label-on-p1} on page
\pageref{label-on-p1}.
\label{a-useless-label}
\end{document}
How am I supposed to do this?
regards,
/ivo
|
|