3

I am trying to define a proof-environment using the ntheorem package. However, I can't seem to get the "end of proof"-symbol printed into my document, even though I get no error messages from the compiler.

Here's a tiny example in which the \Box-symbol is not being displayed for me.

\documentclass[parskip]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsmath}
\usepackage[amsmath,thmmarks]{ntheorem}
\theoremstyle{nonumberplain}
\theoremheaderfont{\bfseries}
\theorembodyfont{\normalfont}
\theoremseparator{:}
\theoremsymbol{\ensuremath{\Box}}
\newtheorem{Proof}{Proof}
\begin{document}
\begin{Proof}abc.\end{Proof} 
\end{document}

Can anyone tell me what's wrong with my code?

  • Remark: if you expand \endProof, which is what happens at \end{Proof}, you find this bit inside \@endtrivlist: \ifhmode \ifdim \lastskip >\z@ #1\unskip \par \else \unskip \par \fi \fi, which means that, if in horizontal mode with \lastskip zero, it will not execute the #1 of \@endtrivlist, which contains the Proof symbol instruction. However not smart this may be, this is what is causing the problem. Redefining \@endtrivlist to avoid this might solve the problem. Trying in 3…2…1… :). – MickG Dec 22 '15 at 13:40
  • Just making sure that there is a line break affter abc. was enough for me. I tend to prefer \begin/end{...} to be on separate lines anyway. – daleif Dec 22 '15 at 13:56
4

TL;DR

There is a hacky way to solve this, but the best thing is to have \ends on separate lines. And I advise you to have \begins on separate lines as well.

Long version

A "hack" is to add the following to the preamble:

\makeatletter
\renewcommand{\@endtrivlist}[1]{\if@inlabel \indent \fi \if@newlist \@noitemerr \fi \ifhmode #1\unskip \par \if@noparlist \else \ifdim \lastskip >\z@ \@tempskipa \lastskip \vskip -\lastskip \advance \@tempskipa \parskip \advance \@tempskipa -\@outerparskip \vskip \@tempskipa \fi \@endparenv \fi}
\makeatother

This makes the proof symbol appear:

enter image description here

But you use this hack at your own risk, since I do not know what it may cause in other situations where \@endtrivlist is used. One idea might be to define a macro that carries this redefinition out and typing it at every end of proof. BOring, but it would work and cause no trouble anywhere, provided you do not do a proof inside a list (but that should anyway not cause trouble since the redefinition would end with the proof end) and you put the redefinition right at the end of the proof, not in the middle of or before a list in the proof.

Waiting for others to give a less "cheaty" way :).

Update

As daleif noted in his comment, putting the \end on a separate line, besides making the code more readable as it shows the end of an environment instead of hiding it on the last line of the env itself, solves the problem without this cheating. I wonder why though. In any case, it is decidedly advisable to have \begins and \ends on lines by themselves, as the code is made more readable.

Interestingly enough, putting the \end on a line by itself makes \lastskip 12.0pt plus 4.0pt minus 6.0pt instead of the 0.0pt it is when \end is on the same line with abc.. That is the reason why the proof symbol then appears. No idea why this happens though… I mean, that end-of-line should be turned to a space by TeX since it is single. Were it double, we'd have a line break, thus a skip, and OK, but then the symbol would be on the wrong line, as happens in Christian's solution. But this way, I wonder why this \lastskip is changing. Might ask a question about it.

Update 2

Wikibooks comes to the rescue, explaining what \lastskip is:

This command has the length value of the last item if the last item is a (m)glue. In that case \lastskip can be used to refer to that length. If the last item was not a (m)glue then this \lastskip is 0.0pt.

So the name is a bit misleading. This explains why the space alters things: a space inserts glue, thus the last item is a glue, and \lastskip varies consequently.

  • Thank you very much for this detailed answer. In fact, I usually do put the \begin and \end markers into separate lines, I just didn't do it this time because I just wanted to quickly test the proof-environment and didn't think it mattered whether or not the begin and end-commands were in the same line. – Oliver Braun Dec 23 '15 at 21:47
  • Ans as the answer shows, I was surprised to find that out as well :). You're welcome. – MickG Dec 23 '15 at 21:49
2

A quick way is to use \theorempostwork{\hfill$\Box$} (or whatever symbol).

\documentclass[parskip]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsmath}
\usepackage[amsmath,thmmarks]{ntheorem}
\theoremstyle{nonumberplain}
\theoremheaderfont{\bfseries}
\theorembodyfont{\normalfont}
\theoremseparator{:}
%\theoremsymbol{\ensuremath{\Box}}
\theorempostwork{\hfill$\Box$}
\newtheorem{Proof}{Proof}
\begin{document}
\begin{Proof}abc.\end{Proof} 
\end{document}

enter image description here

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.