u-fischer / newpax

12 stars 3 forks source link

Sort destinations to ensure constant order and prevent endless compilation #25

Open briha opened 12 months ago

briha commented 12 months ago

Tables lua are not sorted, and the order they are printed in is thus not constant. This means that, using the current implementation, the newpax file (and thus also the corresponding aux) change on every compilation round – resulting in a never-ending compilation loop. By simply first sorting the destinations, the order is ensured to stay constant, thereby resolving this issue.

I am aware that tests would be beneficial for this, unfortunately I have not had the opportunity to figure out how to write those for a TeX package.

u-fischer commented 12 months ago

Please provide some example document that demonstrates the problematic behaviour.

briha commented 12 months ago

Sure.

Here's one example: doc-input.tex (simplified AAS paper template; compiled with pdflatex):

\documentclass[letterpaper,11pt]{article}   % for preprint proceedings

\usepackage{bm}
\usepackage{amsmath}
\usepackage{subfigure}
\usepackage[colorlinks=true, pdfstartview=FitV, linkcolor=black, citecolor= black, urlcolor= black]{hyperref}
\usepackage{overcite}
\usepackage{footnpag}                   % make footnote symbols restart on each page
\usepackage{kantlipsum}

\author{The Author}

\begin{document}

% set page counter to match outer document
\InputIfFileExists{paper.pagenumber}{}{}

% creates toc and toc-adjascent files – taken from \@starttoc
\makeatletter\begingroup
   \newwrite\tf@toc\immediate\openout\tf@toc\jobname.toc\relax%
   \newwrite\tf@lof\immediate\openout\tf@lof\jobname.lof\relax%
   \newwrite\tf@lot\immediate\openout\tf@lot\jobname.lot\relax%
\endgroup\makeatother

\title{MANUSCRIPT TITLE (UP TO 6.0001 INCHES IN WIDTH AND CENTERED, 14 POINT BOLD FONT, MAJUSCULE)}

\section{Introduction}
\kant[1-5]

\section{This is a Sample of a General Section Heading}
\kant[6]

\subsection{This Is a Sample of a Secondary (Sub-Section) Heading}
\kant[7]
\begin{equation}
    \label{eq:ab}
    a = b^{2}
\end{equation}

\subsubsection{Equations.} 
Equations are centered with the equation number flush to the right. In the text, these equations should be referenced by name as Eq.~\eqref{eq:ab} or Equation~\eqref{eq:ab} (\emph{e.g}., not eq. 1, (1), or \emph{Equation 1}). To improve readability, scalar variable names such as $a$ and $b^{2}$ are usually italicized when appearing in text and equations.\footnote{A section on mathematical notation is provided in the sequel.}

\subsubsection{Abbreviations.} 
\kant[8]

\subsubsection{Figures.}   
Illustrations are referenced by name and without formatting embellishments, such as Figure~\ref{fig:xxx}, \kant[9]

\subsubsection{Graphic Formats.} 
\kant[10]

\subsubsection{References and Citations.} 
\kant[11]

\begin{table}[htbp]
    \fontsize{10}{10}\selectfont
    \caption{A Caption Goes Here}
   \label{tab:label}
        \centering 
   \begin{tabular}{c | r | r } % Column formatting, 
      \hline 
      Animal    & Description & Price (\$)\\
      \hline 
      Gnat      & per gram & 13.65 \\
                & each     &  0.01 \\
      Gnu       & stuffed  & 92.50 \\
      Emu       & stuffed  & 33.33 \\
      Armadillo & frozen   &  8.99 \\
      \hline
   \end{tabular}
\end{table}

\emph{Tables.} 
Tables are referred to by name in the text as Table~\ref{tab:label}, \kant[12-13]

\section{Manuscript Submission}
The Portable Document Format (PDF) is the preferred format for electronic submissions.\footnote{By contributing your manuscript for proceedings publication, you necessarily extend any copyrights to the AAS and its designated publisher, to allow the AAS to publish your manuscript content in all the forms that it wishes.}
 The page size should be 8.5 inches by 11 inches exactly. You should use ``press-quality'' or ``high-quality'' software settings to create your PDF file; these settings tend to keep the PDF file true to the original manuscript layout, and automatically embed the correct fonts, \emph{etc}. Otherwise, settings such as ``Embed All Fonts'', \emph{etc}., should be selected as available. The use of internal hyperlinks within the electronic file is not encouraged because hyperlinks may not be supported in the final version of the electronic proceedings.

\section{Conclusion}\label{sec:conclusion}
Your final manuscript should be camera-ready as submitted --- free from technical, typographical, and formatting errors. Manuscripts not suitable for publication are omitted from the final proceedings.

\section{Acknowledgment}
Any acknowledgments by the author may appear here. The acknowledgments section is optional.

\section{Notation}
\begin{tabular}{r l}
    $a$ & a real number \\
    $b$ &  the square root of $a$ \\
\end{tabular} \\

If extensive use of mathematical symbols requires a table of notation, that table may appear here. Where the first mathematical symbol is introduced, a footnote should direct the attention of the reader to this table.\footnote{The footnote symbols are a standard sequence: $\ast$, $\dagger$, $\ddag$, \emph{etc}. This sequence of footnote symbols should restart with each new page.}  The notation table should be simple and reasonably consistent with the standards of modern technical journals, as illustrated above. The notation table does not need its own caption like an ordinary table, since the section heading serves this purpose. The notation section is optional.

\appendix
\section*{Appendix: Title here}
Each appendix is its own section with its own section heading. The title of each appendix section is preceded by ``APPENDIX: '' as illustrated above, or ``APPENDIX A: '', ``APPENDIX B: '', \emph{etc}., when multiple appendixes are necessary. Appendices are optional and normally go after references; however, appendices may go ahead of the references section whenever the word processor forces superscripted endnotes to the very end of the document. The contents of each appendix must be called out at least once in the body of the manuscript.

\subsection*{Miscellaneous Physical Dimensions}
The page size shall be the American standard of 8.5 inches by 11 inches (216 mm x 279 mm). Margins are as follows: Top -- 0.75 inch (19 mm); Bottom -- 1.5 inches (38 mm); Left -- 1.25 inches (32 mm); Right -- 1.25 inch (32 mm). The title of the manuscript starts one inch (25.4 mm) below the top margin. Column width is 6 inches (152.5 mm) and column length is 8.75 inches (222.5 mm). The abstract is 4.5 inches (114 mm) in width, centered, justified, 10 point normal (serif) font.

\end{document}

doc-use-newpax.tex:

\DocumentMetadata{}
\documentclass{scrarticle}

\usepackage{pdfpages,xcolor}

\usepackage{hyperref}
\hypersetup{linkbordercolor=blue}
\usepackage{kantlipsum}

\makeatletter 
\input{doc-input.aux}
\makeatother

\usepackage{newpax}

\directlua
{
  require("newpax")
  newpax.writenewpax("doc-input")
}
\newpaxsetup{dests=all} %force import of all destinations

% a helper command to make the change in the toc easier ...
\NewDocumentCommand\setdestfilter{mm}%
 {\def\HyperDestNameFilter##1{#1##1#2}}  

\begin{document}
\tableofcontents

\section{Main}
\kant[1-3]
\section{Next}
\kant[4]

% the destinations of the included PDF have the prefix `doc-input.newpax@`:
\addtocontents{toc}{\setdestfilter{doc-input.newpax@}{}} 
\addtocontents{toc}{\string\input{doc-input.toc}}
\addtocontents{toc}{\setdestfilter{}{}}

\includepdf[pages=-]{doc-input}

\setcounter{section}{5}
\section{Last}
\kant[5-7]

\end{document}

The message from latexmk:

----------------------
This message may duplicate earlier message.
Latexmk: Failure in processing file 'doc-use-newpax.tex':
   'lualatex' needed too many passes
----------------------

An example of differences found in the newpax file between two passes (here: the last two entries):

\[{dest}{2}{20}{XYZ}{
  DestX={125.798},
  DestY={185.574},
  DestName={section.2},
}\\
\[{dest}{5}{21}{XYZ}{
  DestX={125.798},
  DestY={662.217},
  DestName={subsubsection.2.1.4},
}\\

second pass:

\[{dest}{3}{20}{XYZ}{
  DestX={125.798},
  DestY={498.38},
  DestName={subsection.2.1},
}\\
\[{dest}{1}{21}{XYZ}{
  DestX={125.798},
  DestY={662.217},
  DestName={Doc-Start},
}\\

The is fixed by this here pull-request, i.e., using the fix, the newpax file is identical between passes.