9

I'm using package lineno for proofreading of my documents. So I usually have something like the following MWE:

\documentclass{article}

\usepackage{blindtext}

\usepackage{ifthen}           % to use if then else
\newboolean{korrektur}        % for proofreading: true/false
 \setboolean{korrektur}{true} % choose one, comment the other
%\setboolean{korrektur}{false}

% What we need for proofreading
\ifthenelse{\boolean{korrektur}}% proofreading wanted?
{% YES:
  \usepackage{showframe}          % shows type area
  \usepackage{lineno}             % numbers lines
  \pagewiselinenumbers            % lines per page
}%
{% NO:
% error if lineno was used before:
  \typeout{***** Please delete .aux files if you get errors! *****}
% What to add here so that I get no errors?  %<=================
}

\begin{document}
\Blindtext
\end{document}

Run it two times. Everything should be well, blindtext is numbered.

Now please move the % sign from line 8 (false) to line 7 (true).

Because we had had the run before there is an .aux-file, including lines with the macro \@LN.

If you compile now you will get the following error message (and some more):

***** Please delete .aux files if you get errors! *****
(C:\Users\...\LaTeX\_TeX.SX\lineno\test-lineno.aux
! Undefined control sequence.
l.2 \@LN
        {0}{0}

Question: Is it possible to add in line 20 (see %<===========) something to get rid of the error messages? Something that resets the meaning of macro \@LN?

Mensch
  • 65,388

2 Answers2

10

Note that the error involving \@LN reports the macro to possibly take 2 arguments. This is confirmed from within lineno.sty:

\def\@LN#1#2{{\expandafter\@@LN
                 \csname LN@P#2C\@LN@column\expandafter\endcsname
                 \csname LN@PO#2\endcsname
                 {#1}{#2}}}

So, just add

\makeatletter
\providecommand{\@LN}[2]{}
\makeatother

at the "base level" in your preamble (for example, just after \documentclass{article}). This will define \@LN (the missing macro) only if it is not already defined. Since the package defines \@LN via \def, it will be redefined if lineno is loaded.

If you which to provide this command within another command (like within the false clause of your conditional), then you need to place the \makeatletter...\makeatother pair outside the main conditional:

\makeatletter
\ifthenelse{..}
  {% YES:
    %...
  }{% NO:
    %...
    \providecommand{\@LN}[2]{}%
  }
\makeatother
Werner
  • 603,163
1

Did you try to recompile from scratch (i.e., removing the aux file)?

My understanding is that the error is caused by the fact that the lineno package inserts the \@LN command in the aux file; as a consequence, the following steps

  1. Compile the document with the package
  2. Comment out the package
  3. Compile again

will create an error, because the command \@LN is still in the aux file, but it is not defined.

Roberto Tron
  • 81
  • 1
  • 2
  • My understanding is that OP wrote the original ***** Please delete .aux files if you get errors! *****, so they're aware that removing the aux file is a solution. But they're trying to find a more automated way to handle the issue. – Teepeemm Dec 08 '21 at 22:04