\documentclass[a4paper,11pt,twoside]{article}
\usepackage{a4wide}
\usepackage{latexsym,t1enc,lmodern,url}
\usepackage{amssymb, amsmath,indentfirst}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

%%--------------------------------------------
\hbadness=10000
\emergencystretch=\hsize
\tolerance=9999
\textheight=9.0in
%%--------------------------------------------

\def\chk{{\it chklref}}

\title{Check \LaTeX\ references: chklref \\
Version \input{../VERSION}}
\date{\today}
\author{Jérôme Lelong}

\begin{document}
\maketitle

\begin{abstract} Every \LaTeX\ user has once dreamt of cleaning its \TeX\ file of any useless labels right, for instance before submitting an article. The purpose of \chk\ is precisely to help to do this.
\end{abstract}

\section{What {\it chklref} can do for a \LaTeX\ user?}

While writing a \LaTeX document, it is quite common to add labels that will reveal unused in the end, this is especially true for equations or any other mathematical environments. It would be quite convenient to wipe out those labels from the final version of the document. \chk\ has been designed to help \LaTeX\ users do so.


\chk\ parses the \LaTeX\ file to detect labels that do not have any matching reference. At the end of the program, a summary is printed with the list of labels to be removed. Obviously, this search is performed in the whole document and not only within mathematical environments. Nonetheless, there is something specifically dedicated to environments that have a star version: it looks for the non star environments not containing any label.

For instance, consider you a have a \LaTeX\ file with the following piece of code
\begin{verbatim}
\begin{equation}
  x^2 + x + 1 = 0
\end{equation}
\end{verbatim}
\chk\ will advise you to consider using \verb!equation*! instead of \verb!equation! in order to remove the unneeded number appearing next to the equation.

Star environments with labels are also tracked because with most \LaTeX\ distributions it does not even raise a warning. However if you ever refer to this label, the printed number will most likely be nonsense.

The summary printed at the end of the program contains two sections (see Figure~\ref{fig:output}): the first one is about labels in star environments and the second one is about unneeded labels. Each of these output lines begins with a line number referring to the parsed \LaTeX\ file. Then, the action to take is printed: ``remove label'' or ``use a starred environment''. In the case of a ``remove label'' message, the label to be removed is also printed to avoid any possible confusion.

\begin{figure}[!ht]
  \centering
\begin{verbatim}
************************************
** Labels in starred environments **
************************************
line  264 : remove label eq:quantified
line  200 : consider using a STAR environment

*******************
** Unused Labels **
*******************
line  313 : remove label eq:prog_dyn_prix
\end{verbatim}
  \caption{Program output}
  \label{fig:output}
\end{figure}

Since version 2.5, bibliography entries have also been checked to detect if some entries are not explicitly cited in the text, see Figure~\ref{fig:output}. In this case, a ``remove bibitem'' message is printed.
\begin{figure}[!ht]
  \centering
\begin{verbatim}
**********************************
** Non cited Bibliography entries **
**********************************
remove bibitem : premia
\end{verbatim}
  \caption{Bibliography analysis}
  \label{fig:biblio}
\end{figure}


\section{Usage}

There are two ways of using the package.

\begin{enumerate}
  \item Directly calling \verb!perl chklref.pl file.tex!.
  \item Adding \verb!\usepackage{chklref}! to your main \LaTeX\ file and compiling it normally. This will create a file with extension \verb!.chk!, which can then be parsed by the Perl script:
\begin{verbatim}
  perl chklref.pl --parse-only file.tex
\end{verbatim}
  Note that you need to pass the \verb!.tex! file to the parser not the \verb!.chk! file.
\end{enumerate}


\section{Installation}

\subsection{Installation into the \TeX\ structure}

This package follows the TDS\footnote{TeX Directory Structure
  \url{http://www.tug.org/twg/tds/}}:
\begin{itemize}
  \item  put the \TeX\ package \verb!chklref.sty! into \verb!$(texmf_prefix)/tex/latex/chklref!
  \item  put the documentation \verb!doc/chklref.pdf! into \verb!$(texmf_prefix)/doc/latex/chklref!
  \item  put the man page \verb!doc/chklref.1! into \verb!$(texmf_prefix)/doc/man/man1!
  \item  put the Perl parser \verb!chklref.pl! into \verb!$(texmf_prefix)/scripts/chklref!
\end{itemize}
Note that you will also need to make a link or copy \verb!chklref.pl! to a location in your \texttt{PATH}. On Unix systems, you may need to set the script executable. \\

Depending on your OS and \TeX\ distribution, the TEXMF directory \verb!texmf_prefix! can have different values
\begin{description}
  \item[Single account installation under Linux] \verb!~/texmf!.
  \item[Single account installation under Mac OS X] \verb!~/texmf! or \verb!$HOME/Library/texmf!.
  \item[System wide installation under Linux] \verb!/usr/share/texmf-local/!.
  \item[System wide installation under Mac OS X] \verb!/usr/local/texlive/texmf-local/!.
  \item[Under Windows] something like \verb!C:\localtexmf\!. Check in your distribution settings.
\end{description}

\noindent \textbf{You may need to run \texttt{texhash} to update your \TeX\ Directory Structure.}

The fastest way to carry out the installation is to use the file \verb!chklref.tds.zip! included in the numbered releases (not available inside the git repository). You just have to unzip it inside the proper \verb!texmf_prefix!. Alternatively, you can copy the files by hand. On Unix systems, you may need to set the script as executable.

\subsection{Local installation}

Instead of carrying out a system wide installation, you can simply copy the package file \verb!chklref.sty! next to your main \LaTeX\ file and put the Perl script \verb!chklref.pl! next to it or in anywhere in your \texttt{PATH}. On Unix systems, you may need to set the script as executable.


\section{Requirements}

The \chk\ tool is written mainly in \TeX\ with a small Perl script to parse the output generated by the \TeX\ package. It should be working with any standard Perl installation. \\

The Perl script calls a LaTeX compiler to extract labels related information.

\section{Source code}

The source code is available from GitHub \url{https://github.com/jlelong/chklref}. \\

It is distributed under the GPL licence version 3 or any later version in the hope it will be useful but without any warranty. Should you find a bug in chklref, create an issue at \url{https://github.com/jlelong/chklref/issues} and please provide minimal a \LaTeX\ file to reproduce the problem.

\end{document}
