2

I used \input{settings.tex} to inlcude my settings file which contains \newcommand{\ende}{20:00}. If I try to build the project I get this error: Command \ende already defined. If I try to use \renewcommand{\ende}{20:00} to redefine the command I get the error: Command \ende undefined.. What's the problem here?

2 Answers 2

7

You should read the whole error message:

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

In your case the relevant bit is the second line. Macros starting with \end... are reserved for the closing code of environments: \newcommand checks 1) whether the macro isn't already defined and 2) that it does not start with \end..., but doesn't discriminate the two cases in the ensuing error message.

If you really must use that name you can use the low-level TeX construction

\def\ende{20:00}

but I'd suggest to choose a different name

\newcommand*{\Ende}{20:00}
0
2

Be aware that in LaTeX the macro \ende is considered the ending-macro of the e-environment in case the macro \e is defined "by hand" and afterwards invoked via \begin{e}...\end{e}.

Currently (August 2022) you cannot \newcommand but you can \renewcommand commands whose name is "illegal".

If you insist in defining a command whose name is "illegal" due to starting with \end... so that attempts at defining yield the same behavior as attempts at defining commands in terms of \newcommand whose name is not "illegal", you can try s.th. like this:

% When you uncomment the next but one line, then \ende is defined and
% the subsequent construct yields an error-message.
%\def\ende{\texttt{\string\ende}\space is defined}

\csname @ifundefined\endcsname{ende}%
{\def\ende{}\csname @firstoftwo\endcsname\renewcommand}{}%
\newcommand\ende{20:00}

In case you like to have this as a macro, you can do s.th. like this:

\makeatletter
\newcommand\newcommandwithendallowed{%
  \@star@or@long\newcommand@withendallowed
}%
\newcommand\newcommand@withendallowed[1]{%
  \begingroup\escapechar=-1
  \@ifundefined{\string#1}%
  {\endgroup\def#1{}\renew@command}%
  {\endgroup\new@command}{#1}%
}%
\makeatother

% When you uncomment the next but one line, then \ende is defined and
% the subsequent construct yields an error-message.
%\def\ende{\texttt{\string\ende}\space is defined}

\newcommandwithendallowed*\ende[0]{20:00}

\show\ende

\stop

A better way of circumventing the problem is defining things in terms of \NewDocumentCommand or the like which comes along with the package xparse and which also comes along with more recent LaTeX 2ε-releases.

You must log in to answer this question.

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