From a previous question, take this example
\documentclass{book}
\usepackage{lipsum}
\usepackage[left, pagewise]{lineno} % LINE
\usepackage{ltxcmds}
\makeatletter
\newcommand{\OnlyIfPackageLoaded}[2]{\ltx@ifpackageloaded{#1}{#2}{}}
\makeatother
\makeatletter
\OnlyIfPackageLoaded{lineno}{
\def\makeLineNumberLeft{%
\linenumberfont\llap{\hb@xt@\linenumberwidth{\LineNumber\hss}\hskip\linenumbersep}% left line number
\hskip\columnwidth% skip over column of text
\rlap{\hskip\linenumbersep\hb@xt@\linenumberwidth{\hss\LineNumber}}\hss}% right line number
\leftlinenumbers% Re-issue [left] option
}
\makeatother
\begin{document}
\OnlyIfPackageLoaded{lineno}{\linenumbers}
\lipsum[1]
\end{document}
where \OnlyIfPackageLoaded is used to make lineno-related things disappear if I comment out its \usepackage.
Unfortunately:
- if I compile from a clean directory with
THATline commented, the compilation succeeds; - if I decomment
THATline and recompile, the compilation succeeds; - if I re-comment
THATline and recompile, the compilation fails:... (./main.aux ! Undefined control sequence. l.2 \@LN {0}{0} ? - if I delete the
.auxfile and recompile, the compilation succeeds.
What can I do to avoid having to manually delete the AUX file when I go from with-lineno to without-lineno?
.aux.hyperref,longtable, .... – David Carlisle Mar 04 '23 at 22:19\def\@LN#1#2{}in your no-package code – David Carlisle Mar 04 '23 at 22:21ltxcmdsrather than just use the standard latex\@ifpackageloaded? – David Carlisle Mar 04 '23 at 22:23