2

I am trying to write a command that shortens for a command for writing proof. At the moment, I used to use

\newenvironment{proof}%
{\textbf{Proof:}}%
{\begin{flushright} $\blacksquare$ \end{flushright}}

Now I've gotten tired of writing \begin{proof} all the time, so I want to switch to \pf{ ...content... } or \pf[ ...content... ].

I tried doing

\def\pf[#2\]{\begin{proof} #2 \end{proof}}

It didn't like that. I should mention I already have

\def\[#1\]{\begin{align}#1\end{align}}

for align, that's why I didn't use that for proof.

  • My advice is - not shorten like this. Full form is more semantic. – user11232 Dec 17 '14 at 2:07
  • Please post a complete, compilable example. That is much more useful than a mere code fragment. It is not a good idea to use \def in LaTeX as you are doing. It is just too easy to inadvertently overwrite existing definitions. \newcommand does checks. \def does not. Generally, you should use the TeX commands only when it is really necessary and you know why it is necessary. Always use the LaTeX versions if you can. If you want more flexibility, see xparse. – cfr Dec 17 '14 at 2:07
  • My complete example is literally just \documentclass, \begin{document} everything in the post \end{document}. – Hawk Dec 17 '14 at 2:10
  • If you insist, \def\pf#1{\textbf{Proof:}\ #1\begin{flushright} $\blacksquare$ \end{flushright}}. The usage would be \pf{blah blah}. – Steven B. Segletes Dec 17 '14 at 2:11
  • 1
    apart from the question about the syntax, I'd agree with the other commenters that you would be better to define proof using ntheorem or amsthm or theorem packages, there is no control over white space or page breaking in the form you have here. – David Carlisle Dec 17 '14 at 9:16
5

I very strongly recommend not doing this. However, it is probably not as bad as what you've done for align so, if you must:

\documentclass{article}
\usepackage{xparse,amssymb}
\NewDocumentCommand \pf { +r[] } {%
  \noindent\textbf{Proof:}
    #1\hspace*{\fill}\nolinebreak$\blacksquare$}

\begin{document}

 \pf[
   Alice saw Nobody on the road, whereas the King did not.\\
   So, Alice has sharper eyes than the King and Nobody is travelling on the road.]
 \pf[
   Alice saw Nobody on the road, whereas the King did not.\\
   Hence, Alice has sharper eyes than the King.]

\end{document}

shorthand proof

EDIT: Deal slightly better with line/page breaks. [But, as I said above, this is really not a good way to do this. There are packages and environments designed to get this stuff right while also keeping your code intelligible!]

  • 1
    and the \blacksquare merrily goes onto a new page by itself if the proof is at the bottom of a page. – barbara beeton Dec 17 '14 at 13:47
  • 1
    @barbarabeeton This version may do slightly better but basically, I think that doing things this way is nuts. There are already much, much better ways to do this kind of thing... – cfr Dec 17 '14 at 15:00
3

I wouldn't advice this, but this works (without any warranty)

\documentclass{article}
\usepackage{amsmath,amssymb}
\newenvironment{proof}%
{\textbf{Proof:}}%
{\hfill$\blacksquare$}
\def\pf#1{\begin{proof} #1 \end{proof}}
\begin{document}
  \pf{some proof here}
\end{document}

enter image description here

It is better

  1. to use amsthm and its environments for proof etc.
  2. to use \newcommand instead of \def as former is LaTeX way of defining new macros that checks the existence of the macro.
  • ntheorem is better than amsthm for automatic placement of end-of-proof symbol. – Bernard Dec 17 '14 at 2:33
  • @Bernard I don't think so. I tried ntheorem and abandoned it several years ago. – egreg Dec 17 '14 at 7:59
  • @egreg, why? We use it all the time with good results. – daleif Dec 17 '14 at 8:10
  • @egreg: I didn't say ntheorem is intrinsically better. It's a fact that if a proof environmment ends in a displayed (group of) equation(s), you don't have to add \qedhere. Also, it's easier to customise, in my opinion – perhaps due to a better documentation. – Bernard Dec 17 '14 at 9:35
  • 1
    the definition here will put the \blacksquare at the beginning of the next line if you are unlucky enough to have proof text that ends near the end of a line, without enough space to accommodate the square. problem covered in appendix d of the texbook (dirty tricks). – barbara beeton Dec 17 '14 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.