1

I am trying to write a new environment for proving mathematical theorems.

What I have is

\newenvironment{proof}[1][]
        {\textbf{proof}\ifthenelse{\equal{#1}{}}{.}{of #1.}}
        {\begin{flushright}\textbf{qed}\end{flushright}}

This environment shall be getting an input, e.g. "Theorem" or "Lemma". Its output shall be "Proof of Lemma." If no input is given, it shall just give back "Proof."

No trying to run these few lines with an example like below, I get an error saying "Undefined control sequence \begin{proof} etc".

EDIT: I am quite new to LaTeX, so I am not so sure which packages etc will be important for solving this problem, this is why I extended the example below, so that it includes all the packages I am using in this case.

\documentclass[a4paper, 11pt, fleqn]{article}

\usepackage[latin1]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{amssymb}

\newenvironment{proof}[1][]
    {\textbf{proof}\ifthenelse{\equal{#1}{}}{.}{of #1.}}
    {\begin{flushright}\textbf{qed}\end{flushright}}

\begin{document}
    \begin{proof}[Test]
         This is a proof.
    \end{proof}
\end{document}

Besides the error Message, the output looks something like this:

ProofTest.of Test This is a proof

Any idea on what the problem here is?

6
  • the undefined command is \ifelsethen you meant \ifthenelse Commented May 31, 2020 at 18:21
  • Welcome to tex,sx. Please add a small compilable example, beginning with \documentclass and adding \end{document} that demobstrates the problem. Since different document classes and theorem packages treat theorems and proofs in different ways, without more information, all we can do is guess, and that is usually unsatisfactory. Commented May 31, 2020 at 18:23
  • @barbarabeeton sometimes you can make a good guess though:-) Commented May 31, 2020 at 18:24
  • As stated on your answer below, the correct command is certainly \ifthenelse. The error message keeps poping up though.
    – Octavius
    Commented May 31, 2020 at 18:48
  • the error message doesn't pop up randomly you get it everywhere you use an undefined command. There is no general solution, you just need to fix each case. Commented May 31, 2020 at 19:19

2 Answers 2

1

The error message is not

Undefined control sequence \begin{proof}

it is

! Undefined control sequence.
<recently read> \ifelsethen 

l.10 \begin{proof}[Test]

? h
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

? 

so the undefined command is \ifelsethen you intended \ifthenelse

2
  • you are right, I indeed wanted to use \ifthenelse. In fact, I have this version on my latex file but still the error keeps popping up.
    – Octavius
    Commented May 31, 2020 at 18:47
  • @Octavius Perhaps you have other typos elsewhere. The tex error message shows you the undefined command in each case. The code you post works without error if you use \ifthenelse Commented May 31, 2020 at 19:02
1

I'd go another way altogether and use the predefined proof environment in amsthm, with a few changes to support the syntax you seem to like better.

\documentclass[a4paper, 11pt, fleqn]{article}

%\usepackage[latin1]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}

\makeatletter
\renewcommand{\proof}[1][]{%
  \par
  \pushQED{\qed}%
  \normalfont \topsep6\p@\@plus6\p@\relax
  \trivlist
  \item[\hskip\labelsep
    \bfseries
    \proofname\if\relax\detokenize{#1}\relax\else\ des #1\fi\@addpunct{.}]\ignorespaces
}
\makeatother
\renewcommand{\qedsymbol}{\textbf{QED}}

\begin{document}

\begin{proof}[Test]
This is a proof.
\end{proof}

\begin{proof}
This is a proof without the optional argument and long enough text
to go to a new line.
\end{proof}

\end{document}

enter image description here

You must log in to answer this question.

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