diff options
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/support/chklref/Makefile.doc | 13 | ||||
-rw-r--r-- | Master/texmf-dist/doc/support/chklref/README.md | 51 | ||||
-rw-r--r-- | Master/texmf-dist/doc/support/chklref/VERSION | 1 | ||||
-rw-r--r-- | Master/texmf-dist/doc/support/chklref/chklref.pdf | bin | 0 -> 298764 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/support/chklref/chklref.tex | 136 | ||||
-rwxr-xr-x | Master/texmf-dist/doc/support/chklref/release.sh | 48 | ||||
-rwxr-xr-x | Master/texmf-dist/scripts/chklref/chklref.pl | 334 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/chklref/chklref.sty | 137 |
8 files changed, 720 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/support/chklref/Makefile.doc b/Master/texmf-dist/doc/support/chklref/Makefile.doc new file mode 100644 index 00000000000..4faf33d8917 --- /dev/null +++ b/Master/texmf-dist/doc/support/chklref/Makefile.doc @@ -0,0 +1,13 @@ +.PHONY: all clean cleanall + +all: chklref.pdf clean + +chklref.pdf: chklref.tex + pdflatex chklref.tex + pdflatex chklref.tex + +clean: + rm -f chklref.log chklref.aux chklref.out chklref.fls chklref.fdb_latexmk chklref.synctex.gz + +cleanall: clean + rm -f chklref.pdf diff --git a/Master/texmf-dist/doc/support/chklref/README.md b/Master/texmf-dist/doc/support/chklref/README.md new file mode 100644 index 00000000000..a39c0948f15 --- /dev/null +++ b/Master/texmf-dist/doc/support/chklref/README.md @@ -0,0 +1,51 @@ +# Installation + +## System wide installation + +### Installation into the TeX structure + +This package follows the TDS[1] + +- put the TeX package `chklref.sty` into `$(texmf_prefix)/tex/latex/chklref` +- put the manual `chklref.pdf` into `$(texmf_prefix)/doc/latex/chklref` +- put the Perl parser `chklref.pl` into `$(texmf_prefix)/scripts/chklref` + +Note that you will also need to make a link or copy `chklref.pl` to a location in your `PATH`. On Unix systems, you may need to set the script as executable. + +Depending on your OS and TeX distribution, the `TEXMF` directory `texmf_prefix` can have different values + +- **Single account installation under Linux** `~/texmf`. +- **Single account installation under Mac OS X** `~/texmf` or `$HOME/Library/texmf`. +- **System wide installation under Linux** `/usr/share/texmf-local/`. +- **System wide installation under Mac OS X** `/usr/local/texlive/texmf-local/`. +- **Under Windows** something like `C:\localtexmf\`. Check in your distribution settings. + +**You may need to run `texhash` to update your TeX Directory Structure.** + +The fastest way to carry out the installation is to use the file `chklref.tds.zip` included in the numbered releases (not available inside the git repository). You just have to unzip it inside the proper `texmf_prefix`. Alternatively, you can copy the files by hand. On Unix systems, you may need to set the script as executable. + +#### Local installation + +Instead of carrying out a system wide installation, you can simply copy the package file `chklref.sty` next to your main LaTeX file and put the Perl script `chklref.pl` next to it or in anywhere in your `PATH`. On Unix systems, you may need to set the script as executable. + +## Requirements + +The `chklref` tool is mainly written 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. + +## Usage + +You typically just run: `perl chklref.pl file.tex` + +The full calling syntax is `perl chklref.pl [options] file.tex`, where `options` can be + +- `--tex <compiler>`, `-t`: Specify the TeX compiler to be used. Default is `pdflatex`. +- `--tex-options`: List of options to pass to the TeX compiler. Note that we always add `-interaction nonstopmode` on top of these options. +- `--debug`, `-d`: Run in debug mode. Do not clean the generated `.chk` file. +- `--quiet`, `-q`: Run in quiet mode. Do not print the output of the TeX compiler. +- `--parse-only`: Do not run the LaTeX compiler but use the already existing `.chk` file. When this option is passed, the following other options are meaningless: `--tex`, `--tex-options`, `--quiet`, `--debug`. +- `--version`, `-v`: Print the version of this script. +- `--help,h`: Print this help. + +[1] : TeX Directory Structure http://www.tug.org/twg/tds/ diff --git a/Master/texmf-dist/doc/support/chklref/VERSION b/Master/texmf-dist/doc/support/chklref/VERSION new file mode 100644 index 00000000000..cb2b00e4f7a --- /dev/null +++ b/Master/texmf-dist/doc/support/chklref/VERSION @@ -0,0 +1 @@ +3.0.1 diff --git a/Master/texmf-dist/doc/support/chklref/chklref.pdf b/Master/texmf-dist/doc/support/chklref/chklref.pdf Binary files differnew file mode 100644 index 00000000000..df3d7637c11 --- /dev/null +++ b/Master/texmf-dist/doc/support/chklref/chklref.pdf diff --git a/Master/texmf-dist/doc/support/chklref/chklref.tex b/Master/texmf-dist/doc/support/chklref/chklref.tex new file mode 100644 index 00000000000..4a9b0baf8d6 --- /dev/null +++ b/Master/texmf-dist/doc/support/chklref/chklref.tex @@ -0,0 +1,136 @@ +\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 manual \verb!chklref.pdf! into \verb!$(texmf_prefix)/doc/latex/chklref! + \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} diff --git a/Master/texmf-dist/doc/support/chklref/release.sh b/Master/texmf-dist/doc/support/chklref/release.sh new file mode 100755 index 00000000000..3455541c971 --- /dev/null +++ b/Master/texmf-dist/doc/support/chklref/release.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# This script creates a new releas of chklref +CWD="$(pwd)/$0" +CHKLREFGIT=$(dirname $"CWD") +DATE=$(date +%Y%m%d) +# Local temporary directory +LOCAL_TMPDIR="$HOME/tmp/chklref-$DATE" +CHKLREF_DIR="$LOCAL_TMPDIR/chklref" + +# Perform git archive +git_archive() { + cwd=$(pwd) + [[ -d "$LOCAL_TMPDIR" ]] && rm -rf "$LOCAL_TMPDIR" + mkdir -p "$CHKLREF_DIR" + cd "$CHKLREFGIT" + git archive --format=tar master | tar -x -C "$CHKLREF_DIR" + cd "$cwd" +} + +compile_doc() { + cwd=$(pwd) + cd "$CHKLREF_DIR/doc" + make + cd "$cwd" +} + +create_tds() { + cwd=$(pwd) + mkdir -p "$CHKLREF_DIR/chklref.tds" + cd "$CHKLREF_DIR/chklref.tds" + mkdir -p tex/latex/chklref + mkdir -p doc/latex/chklref + mkdir -p scripts/chklref + cp ../chklref.sty tex/latex/chklref + cp ../doc/chklref.{tex,pdf} doc/latex/chklref + cp ../README.md doc/latex/chklref + cp ../chklref.pl scripts/chklref + cd .. + zip -r chklref.tds.zip chklref.tds + rm -rf chklref.tds + cd "$cwd" +} + +git_archive +compile_doc +create_tds +zip -r "$CHKLREF_DIR.zip" "$CHKLREF_DIR"
\ No newline at end of file diff --git a/Master/texmf-dist/scripts/chklref/chklref.pl b/Master/texmf-dist/scripts/chklref/chklref.pl new file mode 100755 index 00000000000..9360708e413 --- /dev/null +++ b/Master/texmf-dist/scripts/chklref/chklref.pl @@ -0,0 +1,334 @@ +#!/usr/bin/env perl -w + +######################################################################### +# Written and (C) by Jérôme Lelong <jerome.lelong@gmail.com> # +# # +# This program is free software; you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <http://www.gnu.org/licenses/>. # +######################################################################### + +use strict; +use warnings; +use File::Basename; +use Cwd; +use Getopt::Long; +# recognised math environments +my @have_star_modes = qw( equation eqnarray align multline table gather); +my $have_star_mode = join('|', @have_star_modes); +$have_star_mode = "($have_star_mode)"; + + +my $TEX = 'pdflatex'; +my $TEXOPTIONS = ' -interaction nonstopmode '; +my $USERTEXOPTIONS = ''; +my $RUNQUIET = 0; +my $RUNDEBUG = 0; +my $PARSEONLY = 0; +my $PRINTVERSION = 0; +my $HELP = 0; +my $VERSION = 'Version 3.0.1'; + +# Create a hash with three keys "str", "line", "file" and returns a +# reference to it +# +# Input: 3 args +# a string +# a line number +# a filename +sub new_ref { + my ($str, $line, $file) = @_; + my $ref = {}; + $ref->{str} = $str; + $ref->{line} = $line; + $ref->{file} = $file; + return $ref; +} + +# Create a hash with six keys "str", "begin", "end", "star", +# "label_line" and "label" and returns a reference to it. +# +# Input : 7 args +# a string (the env name) +# line of beginning +# line of end +# has the env a star? +# line on which the label appears +# value of the label +# file name +sub new_math_env { + my ($str, $begin, $end, $star, $label_line, $label, $file) = @_; + my $this = {}; + $this->{str} = $str; + $this->{begin} = $begin; + $this->{end} = $end; + $this->{star} = $star; + $this->{label_line} = $label_line; + $this->{label} = $label; + $this->{file} = $file; + return $this; +} + + +# Parse .chk file and looks for the environments defined by +# @have_star_modes. The first and last line of the environment are stored +# along with the name of the environment. One last variable is +# used to remember if the star version was used. +# +# Input: +# a chk file content +# entries +# refs +# labels +# the last 3 args are passed as references and are modified +sub chk_parse { + my ($txt, $entries, $refs, $labels, $citations, $bibcites) = @_; + my ($str, $begin, $end, $star, $labelled_env, $label, $file, $entry, $l); + + while (defined($l = shift(@$txt))) { + if ($l =~ m/^label (.+) line (\d+) file (.+)\n$/o) { + push(@$labels, new_ref($1, $2, $3)); + } + elsif ($l =~ m/^ref (.+) line (\d+) file (.+)$/o) { + push(@$refs, new_ref($1, $2, $3)); + } + elsif ($l =~ m/^citation (.+) line (\d+) file (.+)$/o) { + foreach my $c (split(/\s*,\s*/, $1)) { + ${$citations}{$c} = 1; + } + } + elsif ($l =~ m/^bibcite (.+) line (\d+) file (.+)$/o) { + push(@$bibcites, $1); + } + elsif ($l =~ m/^begin\{$have_star_mode(\**)\} line (\d+) file (.+)$/o) { + $str = $1; + $star = 1; + $star = 0 unless ($2); + $begin = $3; + $file = $4; + $label = ""; + $labelled_env = 0; + while (defined($l = shift(@$txt))) { + if ($l =~ m/^label (.+) line (\d+) file (.+)$/o) { + push(@$labels, new_ref($1, $2, $3)); + $label = $1; + $labelled_env = $2; + } + elsif ($l =~ m/^ref (.+) line (\d+) file (.+)$/o) { + push(@$refs, new_ref($1, $2, $3)); + } + elsif ($l =~ m/^end\{$str\*{$star}\} line (\d+) file (.+)$/) { + $end = $1; + $entry = new_math_env($str, $begin, $end, $star, $labelled_env, + $label, $file); + push(@$entries, $entry); + last; + } + } + } + } + return; +} + +# Find environments with both labels and stars +# Input : list of entries +sub star_label { + my ($entries) = @_; + print "************************************\n"; + print "** Labels in starred environments **\n"; + print "************************************\n"; + foreach my $e (@$entries) { + printf("-- %-20s line %4d: remove label %s \n", + $e->{file}, $e->{label_line}, $e->{label}) + if (($e->{star} == 1) && ($e->{label_line} > 0)); + + printf("-- %-20s line %4d: consider using a STAR environment\n", + $e->{file}, $e->{begin}) + if (($e->{star} == 0) && ($e->{label_line} == 0)); + } + print "\n"; + return; +} + +# Find labels without any corrsponding references. +# references must be sorted +sub unused_label { + my ($labels, $refs) = @_; + my $found; + + print "*******************\n"; + print "** Unused Labels **\n"; + print "*******************\n"; + foreach my $l (@$labels) { + $found = 0; + foreach my $r (@$refs) { + if ($r->{str} eq $l->{str}) { + $found = 1; + last; + } + elsif ($r->{str} ge $l->{str}) { + last; + } + } + printf("-- %-20s line %4d: remove label %s\n", + $l->{file}, $l->{line}, $l->{str}) + if (!$found); + } + print "\n"; + return; +} + +# Find bibitems without any corresponding \cite +sub unused_cites { + my ($bibcites, $citations) = @_; + print "**********************************\n"; + print "** Uncited Bibliography entries **\n"; + print "**********************************\n"; + foreach my $c (@$bibcites) { + print("remove bibitem : $c\n") unless exists ${$citations}{$c}; + } + return; +} + +# Find and remove duplicates in an +# array of { str, line } entries. +# Note that the array must be sorted according to str +# Input : ref or label list +# Return the corresponding list +sub rm_duplicate { + my ($array) = @_; + my $prev = '___________not_a_true_label______'; + my @uniq_array = + grep { $_->{str} ne $prev && (($prev) = $_->{str}) } @$array; + return \@uniq_array; +} + +# Display all math envs with their characteristics +# Input args +# line of beginning +# line of end +# starred or not +# label +sub disp_msg { + my ($entries) = @_; + my @entries = @$entries; + + foreach my $e (@entries) { + print("env $e->{str} \n"); + print("\tbeginning : $e->{begin}\n\tend : $e->{end}\n"); + print("\tstar environment\n") if ($e->{star} == 1); + print("\tlabelled environement\n") if ($e->{label} > 0); + print("\n"); + } + return; +} + +sub parse { + my ($chkfile) = @_; + my @entries = (); + my @refs = (); + my @labels = (); + my %citations = (); + my @bibcites = (); + my $FIC; + + # Read the whole file to an array because label and end commands + # generally need to be swapped. + open($FIC, '<', $chkfile) or die("open: $!"); + my @txt = <$FIC>; + close($FIC); + + chk_parse(\@txt, \@entries, \@refs, \@labels, \%citations, \@bibcites); + + @labels = sort { $a->{line} cmp $b->{line} } @labels; + @refs = sort { $a->{str} cmp $b->{str} } @refs; + my $uniq_refs = rm_duplicate(\@refs); + star_label(\@entries); + #disp_msg( \@entries ); + unused_label(\@labels, $uniq_refs); + unused_cites(\@bibcites, \%citations); +} + +sub usage { +print << 'EOT'; +chklref -- Check unused labels and bibitems + +Copyright (C) 2005-2019 Jérôme Lelong <jerome.lelong@gmail.com> +This program comes with ABSOLUTELY NO WARRANTY; +This is free software, and you are welcome to redistribute it under certain conditions; + +Usage: + chklref [options] texfile + +Options: + --tex <compiler>, -t : Specify the TeX compiler to be used. Default = pdflatex. + --tex-options : List of options to pass to the TeX compiler. + --debug, -d : Run in debug mode. Do not clean the generated `.chk` file. + --quiet, -q : Run in quiet mode. Do not print the output of the TeX compiler. + --parse-only : Do not run the LaTeX compiler but use the already existing `.chk` file. When this option is passed, the following other options are meaningless: `--tex`, `--tex-options`, `--quiet`, `--debug`. + --version, -v : Print the version of this scirpt. + --help,h : Print this help. +EOT +} + +sub texcompile { + my ($texfile, $basetexfile) = @_; + print "Running $TEX $TEXOPTIONS $USERTEXOPTIONS \"$texfile\" to collect labels references and environment declarations\n\n"; + my $texoutput = `$TEX $TEXOPTIONS $USERTEXOPTIONS "$texfile" 2>&1`; + print($texoutput) unless $RUNQUIET; + unlink($basetexfile . '.chk'); + $texoutput = `$TEX $TEXOPTIONS $USERTEXOPTIONS --jobname "$basetexfile" '\\RequirePackage{chklref}\\input' "{$texfile}" 2>&1`; + print($texoutput) unless $RUNQUIET; +} + +Getopt::Long::Configure ("bundling"); +GetOptions ( + 'version|v!' => \$PRINTVERSION, + 'quiet|q!' => \$RUNQUIET, + 'debug|d!' => \$RUNDEBUG, + 'tex|t=s' => \$TEX, + 'texoptions=s' => \$USERTEXOPTIONS, + 'parse-only' => \$PARSEONLY, + 'help|h' => \$HELP +) || usage(); + +if ($HELP) { + usage(); + exit(0); +} + +if ($PRINTVERSION) { + print "chklref $VERSION\n"; + exit(0) +} + +if (@ARGV != 1) { + usage(); + exit 0; +} + +my $texfile = $ARGV[0]; +my $cwd = getcwd(); +my $dirtexfile = dirname($texfile); +my $basetexfile = basename($texfile, '.tex'); +my $chkfile = $basetexfile . '.chk'; +chdir($dirtexfile); +if ($PARSEONLY) { + parse($chkfile); +} +else { + texcompile($texfile, $basetexfile); + parse($chkfile); + if (! $RUNDEBUG) { + unlink($chkfile); + } +}
\ No newline at end of file diff --git a/Master/texmf-dist/tex/latex/chklref/chklref.sty b/Master/texmf-dist/tex/latex/chklref/chklref.sty new file mode 100644 index 00000000000..3a570251b52 --- /dev/null +++ b/Master/texmf-dist/tex/latex/chklref/chklref.sty @@ -0,0 +1,137 @@ +%% -*-mode: tex-mode -*- + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Written and (C) by Jérôme Lelong <jerome.lelong@gmail.com> %% +%% %% +%% This program is free software; you can redistribute it and/or modify %% +%% it under the terms of the GNU General Public License as published by %% +%% the Free Software Foundation; either version 3 of the License, or %% +%% (at your option) any later version. %% +%% %% +%% This program is distributed in the hope that it will be useful, %% +%% but WITHOUT ANY WARRANTY; without even the implied warranty of %% +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %% +%% GNU General Public License for more details. %% +%% %% +%% You should have received a copy of the GNU General Public License %% +%% along with this program. If not, see <http://www.gnu.org/licenses/>. %% +%% %% +%% This file is part of the chklref package. %% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\NeedsTeXFormat{LaTeX2e}% +\ProvidesPackage{chklref}% +\RequirePackage{afterpackage}% + +\gdef\CHK@stack{} + +\newwrite\CHK@write +\immediate\openout\CHK@write\jobname.chk% +\def\CHK@immediate@write{\immediate\write} +\def\CHK@print#1{% + \protect\CHK@immediate@write\CHK@write{#1}% +} + +% Make sure the auxiliary files are still suitable for usage without the +% chklref package. +\RequirePackage{auxhook} +\AddLineBeginAux{\string\let\string\CHK@immediate@write\string\@gobbletwo} +\let\@starttoc@orig\@starttoc +\def\@starttoc#1{% + \@starttoc@orig{#1}% + \addtocontents{#1}{\string\let\string\CHK@immediate@write\string\@gobbletwo} +} + +% Track the name of the file currently processed. +% This is successfuly done by currfile for +% \include{toto}, \input{toto} but NOT \input toto +% So we need an extra trick, but do it as late as possible. +\RequirePackage{currfile} +\def\CHK@currentfile{\expandafter\expandafter\currfilename} +\def\CHK@@input#1 {\input{#1}} +\AtBeginDocument{% + \def\input{\@ifnextchar\bgroup\@iinput\CHK@@input} +} + +\def\CHK@redefine#1#2{% + \expandafter\let\csname CHK@#1@orig\expandafter\endcsname\csname#1\endcsname% + \expandafter\def\csname#1\endcsname##1{% + \CHK@print{#2{##1} line \the\inputlineno\space file \CHK@currentfile}% + \expandafter\expandafter\csname CHK@#1@orig\endcsname{##1}} +} + +\def\CHK@redefine@#1#2{% + \expandafter\let\csname CHK@#1@orig\expandafter\endcsname\csname#1\endcsname% + \expandafter\def\csname#1\endcsname##1{% + \CHK@print{#2 ##1 line \the\inputlineno\space file \CHK@currentfile}% + \expandafter\expandafter\csname CHK@#1@orig\endcsname{##1}} +} + +\CHK@redefine{begin}{begin} +\CHK@redefine{end}{end} + +\AfterPackage{hyperref}{ + \AtBeginDocument{% + \let\CHK@label@orig=\label + \def\label#1{% + \CHK@print{label #1 line \the\inputlineno\space file \CHK@currentfile}% + \CHK@label@orig{#1}} + + \Hy@SetCatcodes + \def\HyPsd@ref#1{\HyPsd@@ref#1*\END}% + \def\HyPsd@@ref#1*#2\END{% + \ifx\\#2\\% + \HyPsd@@@ref{#1}% + \else + \expandafter\HyPsd@@@ref + \fi + }% + \def\HyPsd@@@ref#1{% + \expandafter\ifx\csname r@#1\endcsname\relax + ??% + \else + \expandafter\expandafter\expandafter\@car\csname r@#1\endcsname\@nil + \fi + \CHK@print{ref #1 line \the\inputlineno\space file \CHK@currentfile}% + } + \let\ref=\HyPsd@ref + \Hy@RestoreCatcodes + } +} + +\AtBeginDocument{% + \newif\ifCHK@hyperref + \newif\ifCHK@amsmath + \@ifpackageloaded{hyperref}{\CHK@hyperreftrue}{} + \@ifpackageloaded{amsmath}{\CHK@amsmathtrue}{} + + \ifCHK@amsmath% %With AMS-LaTeX tags + %%\CHK@redefine{label@in@display}{label@in@display} + \let\CHK@label@in@display@orig=\label@in@display + \def\label@in@display#1{% + \CHK@print{label #1 line \the\inputlineno\space file \CHK@currentfile} + \CHK@label@in@display@orig{#1}} + + \CHK@redefine@{eqref}{ref} + \CHK@redefine@{ref}{ref} + \CHK@redefine@{label}{label} + \CHK@redefine@{citation}{citation} + \CHK@redefine@{bibcite}{bibcite} + + \else + \ifCHK@hyperref\else + \CHK@redefine@{label}{label} + \CHK@redefine@{ref}{ref} + \CHK@redefine@{citation}{citation} + \CHK@redefine@{bibcite}{bibcite} + \fi + \fi +} + +\AtEndDocument{ + \message{\CHK@stack} +} +% To prevent error with packages already defining the \AfterPackage macro. +\let\AfterPackage=\relax +\endinput |