3

It is a pain to type

\begin{theorem}
...
\end{theorem}

\begin{proof}
...
\end{proof}

when live texing a document in class.

When I declare

\newcommmand{\theorem}[2]{\begin{theorem} {#1} \begin{proof} {#2} \end{proof} \end{theorem}}

I get that \theorem is already defined.

If I try

\renewcommmand{\theorem}[2]{\begin{theorem} {#1} \begin{proof} {#2} \end{proof} \end{theorem}}

I get a fatal error.

Is there any way to prevent myself from having to type the words beginning, end and proof several times? This is important when I am live texing notes in class.

3
  • 2
    This is mainly a problem with the editor. Most editors nowadays have syntax completion and macros that allow to type environments with a simple shortcut.
    – Bernard
    Jan 18, 2017 at 21:53
  • or you could make a new command with a custom name, like \newcommand{\mythm}
    – Marijn
    Jan 18, 2017 at 21:54
  • 3
    You're shooting to your own foot. Don't do that.
    – egreg
    Jan 18, 2017 at 21:56

2 Answers 2

2

You can do it with

\newcommand{\thmpr}[2]{%
  \begin{theorem}#1\end{theorem}%
  \begin{proof}#2\end{proof}%
}

but I warn you that this is much worse: you need to keep track of braces that can end up very far away from each other.

If you're taking class notes, it's much easier to tag:

THEOREM\\
Whatever the guy at the blackboard is saying

PROOF\\
Something even more mysterious that I'll go through later

It's then easy to place the required \begin and \end tag when you revise the material.


The problem is that \newtheorem{theorem}{Theorem} does define a \theorem macro for its internal purposes. So LaTeX refuses to do \newcommand{\theorem}[2]{...}; but with

\renewcommand{\theorem}[2]{\begin{theorem}...}

you're defining \theorem in terms of itself and this will cause an infinite loop.

3
  • Isn't this basically my answer?
    – Ruben
    Jan 18, 2017 at 22:07
  • @Ruben The explanation of the error is similar. Your proposed workaround is useless.
    – egreg
    Jan 18, 2017 at 22:10
  • I think not showing the whole workaround does not make it useless. Nontheless I added the last bit.
    – Ruben
    Jan 18, 2017 at 22:17
0

The problem in your definition is that \begin{theorem} implicitly calls \theorem. Thats why in your first attempt you get an 'alredy-defined'-error. (The environment in the end is really just that macro.) In the second try you call your macro inside the one you want to redefine. Hence you end up in an infinite loop. Try to store a version of \theorem by saying

\let\oldtheorem\theorem

and then your second attempt basically should work:

\documentclass{article}
\usepackage{amsthm}

\newtheorem{theorem}{Theorem}
\let\oldtheorem\theorem
\let\endoldtheorem\endtheorem
\renewcommand\theorem[2]{\begin{oldtheorem}#1\end{oldtheorem}\begin{proof}#2\end{proof}}

\begin{document}
\theorem{a theorem}{with proof}
\end{document}

Also note that the proof environment usually does not get nested inside the theorem and the grouping around the arguments, i.e. '{#1}' is needless.

4
  • I think it is really not the preferred way of marking up the document, but the OP described a particular case and first of all I tried to explain the misbehaviour. In this specific case I think it is good advice actually.
    – Ruben
    Jan 18, 2017 at 22:03
  • Seen edit, now it’s much better! But I still prefer @egreg’s answer.
    – GuM
    Jan 18, 2017 at 22:15
  • @GustavoMezzetti -- where does it differ exactly? (the only difference is the naming of the command.)
    – Ruben
    Jan 18, 2017 at 22:16
  • 2
    I prefer @egreg’s answer exactly and solely because it recommend using a different name for the command: I think that reusing the same name isn’t good practice. Edit: Well, actually there’s also the issue pointed out by D.C., but that one is easy to correct! :-)
    – GuM
    Jan 18, 2017 at 22:20

You must log in to answer this question.

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