f



LaTeX Error: ... Or name \end... illegal, see p.192 of the manual

I've lost about 75 minutes because of a poor error message.
(Of course, that's my opinion of the message.)


Here's what happened.

I'm dealing with some legacy style files.
Containing duplicate definitions.

So I'm trying to remove errors.

Here's an example:
==
*\def\wibble{} % buried in a legacy style file

*\newenvironment{wibble}{}{} % in my style file

! LaTeX Error: Command \wibble already defined.
               Or name \end... illegal, see p.192 of the manual.
==

Here's the fix:
==
*\def\wibble{} % buried in a legacy style file

*\let\wibble\undefined % added to my style file

*\newenvironment{wibble}{}{} % in my style file
==

This works fine, some of the time.  But then I had:
==
*\not@telling@you@whats@buried@here

*\let\wibble\undefined % in my style file

*\newenvironment{wibble}{}{} % this used to work

! LaTeX Error: Command \wibble already defined.
               Or name \end... illegal, see p.192 of the manual.

==

I get the error as if the \let was not there.

So what's going on?  It took me 75 minutes to find out.

You can find out in 10 seconds.  Scroll down to see.

But please spend a minute figuring out what might be wrong.
Recall, the message is:
==
! LaTeX Error: Command \wibble already defined.
               Or name \end... illegal, see p.192 of the manual.
==































\def\endwibble{}

BWT, I've been caught by this error message before:
*\let\wibble\relax

*\newenvironment{wibble}{}{}

* % no error, no warning, nothing.  It's fine.

See:
<http://groups.google.co.uk/group/comp.text.tex/msg/53723234b56bfda3?hl=en>

-- 
Jonathan


0
J.Fine (440)
5/6/2005 4:41:24 PM
comp.text.tex 39027 articles. 3 followers. Post Follow

4 Replies
7123 Views

Similar Articles

[PageSpeed] 29

"Jonathan Fine" <J.Fine@open.ac.uk>  schrieb:

> I've lost about 75 minutes because of a poor error message.
> (Of course, that's my opinion of the message.)
> 
[snip]

> This works fine, some of the time.  But then I had:
> ==
> *\not@telling@you@whats@buried@here
> 
> *\let\wibble\undefined % in my style file
> 
> *\newenvironment{wibble}{}{} % this used to work
> 
> ! LaTeX Error: Command \wibble already defined.
>                Or name \end... illegal, see p.192 of the manual.
> 
> ==
> 
> I get the error as if the \let was not there.
> 
> So what's going on?  It took me 75 minutes to find out.
> 
> You can find out in 10 seconds.  Scroll down to see.

Where is the problem? The error message has an "or". So if it isn't the 
first (\wibble already defined) it is the second: You shouldn't define 
commands starting with \end (see the manual p. 192). If you are 
bypassing LaTeX by using \def, you should know what you are doing and 
not wonder, when errors arised a bit later than when using 
\newcommand\end....

-- 
Ulrike Fischer
e-mail: zus�tzlich meinen Vornamen vor dem @ einf�gen.
e-mail: add my first name between the news and the @.
0
news9686 (1970)
5/6/2005 5:07:05 PM
Ulrike Fischer wrote:
> "Jonathan Fine" <J.Fine@open.ac.uk>  schrieb:
> 
> 
>>I've lost about 75 minutes because of a poor error message.
>>(Of course, that's my opinion of the message.)
>>
> 
> [snip]
> 
> 
>>This works fine, some of the time.  But then I had:
>>==
>>*\not@telling@you@whats@buried@here
>>
>>*\let\wibble\undefined % in my style file
>>
>>*\newenvironment{wibble}{}{} % this used to work
>>
>>! LaTeX Error: Command \wibble already defined.
>>               Or name \end... illegal, see p.192 of the manual.
>>
>>==
>>
>>I get the error as if the \let was not there.
>>
>>So what's going on?  It took me 75 minutes to find out.
>>
>>You can find out in 10 seconds.  Scroll down to see.
> 
> 
> Where is the problem? The error message has an "or". So if it isn't the 
> first (\wibble already defined) it is the second: 

This is assuming what you wish to conclude.
Namely that the error message is sound.

There are two possible types of error:
a)  some command is already defined
b)  an illegal name has been passed as a parameter

The error is of type (A).  But with the wrong name.


> You shouldn't define 
> commands starting with \end (see the manual p. 192). If you are 
> bypassing LaTeX by using \def, you should know what you are doing and 
> not wonder, when errors arised a bit later than when using 
> \newcommand\end....


I'm going to ignore this, and see if we can't improve the situation.

(However, please recall that I am dealing with legacy macro code.
Which I did not write.)


Let's make a list of error conditions and matching error messages.

I won't cover \newcommand, just \newenvironment.

Each example starts from scratch.

\def\wibble{} \newenvironment{wibble}{}{}
! Command \wibble already defined

\newenvironment{endwibble}{}{}
! Environment name 'endwibble' illegal - starts with 'end'

\def\endwibble{} \newenvironment{wibble}{}{}
! Command \endwibble already defined


There we are.  This is, I hope you agree, better.

-- 
Jonathan

0
jfine (686)
5/6/2005 5:48:35 PM
Jonathan Fine wrote:

<snip>

> Let's make a list of error conditions and matching error messages.
> 
> I won't cover \newcommand, just \newenvironment.
> 
> Each example starts from scratch.
> 
> \def\wibble{} \newenvironment{wibble}{}{}
> ! Command \wibble already defined
> 
> \newenvironment{endwibble}{}{}
> ! Environment name 'endwibble' illegal - starts with 'end'
> 
> \def\endwibble{} \newenvironment{wibble}{}{}
> ! Command \endwibble already defined
> 
> 
> There we are.  This is, I hope you agree, better.
> 

Here's the relevant part of
==
\tracingall
\def\endwibble{}
\newenvironment{wibble}{}{}
==

==
\@newenv #1#2#3#4->\@ifundefined {#1}{\expandafter \let \csname 
#1\expandafter
\endcsname \csname end#1\endcsname }\relax \expandafter \new@command 
\csname #1
\endcsname #2{#3}\l@ngrel@x \expandafter \def \csname end#1\endcsname {#4}
#1<-wibble
#2<-[0]
#3<-
#4<-
==

I'll explain what happens, quietly replacing
   \csname wibble\endcsname
by
   \wibble
and the same for \endwibble.

And I'll ignore the \relax side-effect of \csname.


1.  Is \wibble defined?  No.
2.  Make an assignment
     \let\wibble\endwibble
3.  \new@command\wibble ( ... }
4.  \l@ngrel@x (which has been \let equal to \long)
5.  \def\endwibble{ ... }

It should now be clear that step 3 is giving the error.
But only because of step 2.

And that step 5 will never give the error.

I don't see why the \l@ngrel@x?
Perhaps I'll look at the source.


I suggest that the following would be an improved algorithm.

1.  Is \wibble defined?  No.
2.  \new@command\wibble{ ... }
3.  \new@command\endwibble{ ... }

This algorithm would give an improved error message.
More along the lines of the above.

Problem solved (in my opinion).

-- 
Jonathan

0
jfine (686)
5/6/2005 6:14:06 PM
Jonathan Fine <jfine@pytex.org> wrote:

> I'm going to ignore this, and see if we can't improve the situation.
 
> Let's make a list of error conditions and matching error messages.
> 
> I won't cover \newcommand, just \newenvironment.
> 
> Each example starts from scratch.
> 
> \def\wibble{} \newenvironment{wibble}{}{}
> ! Command \wibble already defined
> 
> \newenvironment{endwibble}{}{}
> ! Environment name 'endwibble' illegal - starts with 'end'
> 
> \def\endwibble{} \newenvironment{wibble}{}{}
> ! Command \endwibble already defined
> 
> 
> There we are.  This is, I hope you agree, better.

Quite incomplete.

My try for a better behaviour of LaTeX:

%%% cut %%% test.tex %%% cut %%%
\NeedsTeXFormat{LaTeX2e}
\makeatletter
\long\def\@ifdefinable #1#2{%
  \edef\reserved@a{\expandafter\@gobble\string #1}%
  \@ifundefined\reserved@a{%
    \edef\reserved@b{\expandafter\@carcube \reserved@a xxx\@nil}%
    \ifx \reserved@b\@qend \@notdefinable@end
    \else
      \ifx \reserved@a\@qrelax \@notdefinable@relax
      \else
        #2%
      \fi
    \fi
  }{%
    \edef\reserved@b{\expandafter\@carcube \reserved@a xxx\@nil}%
    \ifx\reserved@b\@qend
      \@notdefinable@end
    \else
      \@notdefinable
    \fi
  }%
}
\def\@notdefinable@relax{%
  \@latex@error{%
    You must not define command \@backslashchar relax %
    or environment 'relax'%
  }\@eha
}
\def\@notdefinable@end{%
  \@latex@error{%
    Illegal command \@backslashchar\reserved@a\space or environment %
      '\reserved@a'.\MessageBreak
    The name must not start with 'end', %
    see p.192 of the manual%
  }\@eha
}
\def\@notdefinable{%
  \@latex@error{%
    Command \@backslashchar\reserved@a\space or environment %
      '\reserved@a' already defined%
  }\@eha
}

 
% Tests

% shorter error messages in the .log file
\errorcontextlines=-1
\def\@eha{ }%
\nonstopmode 
\def\status#1#2{%
  \typeout{%
    *** Status: \string\wibble: \ifcase #1 un\fi defined, %
    \string\endwibble: \ifcase #2 un\fi defined%
  }%
  \typeout{}%
  \def\setup{%
    \ifcase #1 \let\wibble\@undefined \or \let\wibble\@empty\fi
    \ifcase #2 \let\endwibble\@undefined \or \let\endwibble\@empty\fi
  }%
  \setup
}
\def\deftest#1{%
  \setup
  \typeout{%
    *** Define: #1%
  }%
}   
    
\status00

\deftest{command \string\relax}
\newcommand{\relax}{}

\deftest{environment 'relax'}
\newenvironment{relax}{}{}   

\deftest{command \string\endwibble}
\newcommand{\endwibble}{}

\deftest{environment 'endwibble'}
\newenvironment{endwibble}{}{}   

\status10

\deftest{command \string\wibble}
\newcommand{\wibble}{}

\deftest{environment 'wibble'}
\newenvironment{wibble}{}{}   

\deftest{command \string\endwibble}
\newcommand{\endwibble}{}

\deftest{environment 'endwibble'}
\newenvironment{endwibble}{}

\status11
    
\deftest{command \string\wibble}
\newcommand{\wibble}{}

\deftest{environment 'wibble'}
\newenvironment{wibble}{}{}

\deftest{command \string\endwibble}
\newcommand{\endwibble}{}

\deftest{environment 'endwibble'}
\newenvironment{endwibble}{}

\status01

\deftest{command \string\wibble}
\newcommand{\wibble}{}
\typeout{--> no error (!?)}
\typeout{}

\deftest{environment 'wibble'}
\newenvironment{wibble}{}{}   

\deftest{command \string\endwibble}
\newcommand{\endwibble}{}

\deftest{environment 'endwibble'}
\newenvironment{endwibble}{}

\@@end   
%%% cut %%% test.tex %%% cut %%%

Yours sincerely
  Heiko <oberdiek@uni-freiburg.de>
0
oberdiek (2375)
5/6/2005 7:27:50 PM
Reply: