5

Is there anybody out there, with an idea how to speed things up? I need to run pdflatex ~ 100 times because of unresolved cross references.

I use refcount to add a number to each row of a table (list of requirements) to refer to it later on (Req. 1, Req. 2, ...) . I wrapped it in the following module:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{tabrowcounter}
\RequirePackage{etoolbox}
\RequirePackage{refcount}
\makeatletter
\let\rc@refused\refused
\makeatother
\preto\tabular{\setcounter{tab@rowcnt}{0}}
\preto\longtable{\setcounter{tab@rowcnt}{0}}
\newcounter{tab@rowcnt}
\newcommand{\tabrowno}[1]{
  \refstepcounter{tab@rowcnt}\label{#1}\setcounterref{tab@rowcnt}{#1}\arabic{tab@rowcnt}
}
\endinput

The number of requirements/rows is about 100. Everything works fine with one exception. I need to run pdflatex n - 1 times, where n is the number of requirements/rows in the table because of unresolved cross references.

I found out the following: On each run, refcount (or whatever component does it) adds +1 to the requirement number in file.aux until there are no references left (1, 2, ... , 100). I think about a workaround to solve my problem (parsing .aux file with a ruby script), but maybe there's a better way to do it.

Please see those the examples below:

Example 1 4 requirements

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{float}
\usepackage{tabrowcounter}

\begin{document}

\chapter{Chapter}

%page 6 to distinguish between value of reference and page
\setcounter{page}{6}

\begin{table}[H]
  \centering
  \caption{First table}
  \label{tab:num1}
  \begin{tabular}{r|r}
    \# & value \tabularnewline
    \tabrowno{ref:row1} & blub \tabularnewline
    \tabrowno{ref:row2} & blub \tabularnewline
  \end{tabular}
\end{table}

\qquad
\qquad

\begin{longtable}{r|r}
  \caption{Second table}\label{tab:num2} \\
  \# & value \tabularnewline
  \tabrowno{ref:row3} & blub \tabularnewline
  \tabrowno{ref:row4} & blub \tabularnewline
\end{longtable}

Reference 1 in Table \ref{tab:num1}: value \ref{ref:row1}, page \pageref{ref:row1} \\
Reference 2 in Table \ref{tab:num1}: value \ref{ref:row2}, page \pageref{ref:row2} \\
Reference 3 in Table \ref{tab:num2}: value \ref{ref:row3}, page \pageref{ref:row3} \\
Reference 4 in Table \ref{tab:num2}: value \ref{ref:row4}, page \pageref{ref:row4} \\

\end{document}

Example 2 (5 requirements):

\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{float}
\usepackage{tabrowcounter}

\begin{document}

\chapter{Chapter}

%page 6 to distinguish between value of reference and page
\setcounter{page}{6}

\begin{table}[H]
  \centering
  \caption{First table}
  \label{tab:num1}
  \begin{tabular}{r|r}
    \# & value \tabularnewline
    \tabrowno{ref:row1} & blub \tabularnewline
    \tabrowno{ref:row2} & blub \tabularnewline
  \end{tabular}
\end{table}

\qquad
\qquad

\begin{longtable}{r|r}
  \caption{Second table}\label{tab:num2} \\
  \# & value \tabularnewline
  \tabrowno{ref:row3} & blub \tabularnewline
  \tabrowno{ref:row4} & blub \tabularnewline
  \tabrowno{ref:row5} & blub \tabularnewline
\end{longtable}

Reference 1 in Table \ref{tab:num1}: value \ref{ref:row1}, page \pageref{ref:row1} \\
Reference 2 in Table \ref{tab:num1}: value \ref{ref:row2}, page \pageref{ref:row2} \\
Reference 3 in Table \ref{tab:num2}: value \ref{ref:row3}, page \pageref{ref:row3} \\
Reference 4 in Table \ref{tab:num2}: value \ref{ref:row4}, page \pageref{ref:row4} \\
Reference 5 in Table \ref{tab:num2}: value \ref{ref:row5}, page \pageref{ref:row5} \\

\end{document}
0

2 Answers 2

5

But why do that \setcounterref{tab@rowcnt}{#1}? The number is already available as soon as you do \refstepcounter{tab@rowcnt}.

\newcommand{\tabrowno}[1]{%
  \refstepcounter{tab@rowcnt}\label{#1}\arabic{tab@rowcnt}%
}
1
2

If all your table rows end with \tabularnewline, you should be able to patch \tabularnewline to increment your counter, then \tabrowno can just read out its current value. That way, the number of references is computed in one pass, rather than incrementally through the .aux file.

1
  • I'm not sure how to do that. Any good documentation where I can find something about it? Feb 4, 2012 at 12:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .