4

Consider this code, adapted from the command \incompatible@package of RevTex4-2.
The relevant part is just the \string\usepackage\ statement in the line beginning with \def\@tempa:

\documentclass[12pt]{article}
\usepackage{cite}
\makeatletter

\def\class@name{SomeClass}
\def\incompatible@package#1{%
 \@ifpackageloaded{#1}{%
  \def\@tempa{I cannot continue. You must remove the \string\usepackage\ statement that caused that package to be loaded.}%
  \ClassError{\class@name}{The #1 package cannot be used with \class@name}%
  \@tempa\stop
 }{%
%   \class@info{#1 was not loaded (OK!)}% This is uncommented in the original, but I don't need it
 }%
}%

\incompatible@package{cite}
\makeatother

\begin{document}

\end{document}

In the .log file, there will be a message that reads (pay attention to the \usepackage part),

I cannot continue. You must remove the \usepackage\ statement that caused that package to be loaded.

Presumably, we want the output to read \usepackage statement, not \usepackage\ statement.

The following fixes don't work:

\string\usepackage statement gives \usepackagestatement
\string\usepackage~statement gives \usepackage\nobreakspace {}statement
{\string\usepackage} statement gives {\usepackage} statement
\string\usepackage {}statement gives \usepackage{}statement

I did find one way to fix it:

\expandafter\string\csname usepackage \endcsname gives \usepackage statement

But that seems heavy-handed.

Is there a simpler, better way to get the desired result (using just core LaTeX)?

1 Answer 1

5

You can use \noexpand instead of \string.

I cannot continue. You must remove the \usepackage statement that caused that p
ackage to be loaded.

Also \string\usepackage\space would do, but \noexpand is shorter.

I don't see why defining \@tempa:

\def\class@name{SomeClass}
\def\incompatible@package#1{%
 \@ifpackageloaded{#1}{%
  \ClassError{\class@name}{%
    The #1 package cannot be used with \class@name
  }{I cannot continue. You must remove the \noexpand\usepackage statement
    that caused that package to be loaded.%
  }%
  \stop
 }{%
%   \class@info{#1 was not loaded (OK!)}% This is uncommented in the original,
%               but I don't need it
 }%
}%
1
  • One could argue that \string\usepackage\space, while not the shortest solution, is the solution that's most 'in the spirit of the question', in the sense that it's closest to the coder's original idea. But that's of course a matter of taste! No idea why the coder chose to go through \@tempa, either. Feb 22 at 0:43

You must log in to answer this question.

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