1

My question is very similar to this one, however my situation is more specific and I'm wondering whether there isn't a simpler (and more performant) solution than executing code for every paragraph:

I wrote a small macro to structure lengthy proofs and highlight key steps, called \proofpart. To set apart the step in question from the preceding step of the proof it uses \noindent and, before, adds some \vspace. Now the problem arises when I use it at the very beginning of a proof: In this case \vspace influences the positioning of my entire proof and increases its top margin. How can I fix this?

MWE:

\documentclass[12pt,a4paper]{memoir}

\usepackage{fontspec}
\usepackage{xunicode}

\usepackage{mathtools}
\usepackage{unicode-math}

\usepackage{blindtext}

\usepackage{amsthm}
\usepackage{thmtools}

\newcommand{\proofpart}[1]{%
  \vspace{0.7em}%
  \noindent%
  \textsc{#1}%
}

\declaretheoremstyle[
  spaceabove=2em,
  spacebelow=2em,
  postheadspace=1em,
  headfont=\upshape\bfseries,
  notefont=\mdseries,
  notebraces={(}{)},
  bodyfont=\normalfont,
]{mytheoremstyle}

\declaretheoremstyle[
  spaceabove=-1em, % <-- reduce margin, so that it is clear that the
  % proof belongs to the previous theorem/lemma/…
  %
  spacebelow=2em,
  postheadspace=1em,
  % headfont=\itshape,
  headfont=\upshape\bfseries,
  bodyfont = \normalfont,
  qed=$\qedsymbol$,
  headpunct={:},
]{myproofstyle}

\newcounter{mathcounter}
\numberwithin{mathcounter}{chapter}

\declaretheorem[
  name={Theorem},
  style=mytheoremstyle,
  numberlike=mathcounter
]{theorem}

% Remove amsthm's proof environment, so that we can override it below.
\let\proof\undefined
\let\endproof\undefined

\declaretheorem[
  name={Proof},
  style=myproofstyle,
  numbered=no
]{proof}


\begin{document}


\begin{theorem}
  \blindtext
\end{theorem}
\begin{proof}
  Some preliminary remarks.

  \proofpart{Step 1:} % <-- No problem here
    Foo

  \proofpart{Step 2:} % <-- No problem here
    Bar
\end{proof}


\begin{theorem}
  \blindtext
\end{theorem}
\begin{proof}
  \proofpart{Step 1:} % <-- This will increase spacing between theorem and proof
    Foo

  \proofpart{Step 2:} % <-- No problem here
    Bar
\end{proof}


\end{document}

1 Answer 1

1

Here I make use of the fact that token list \everypar is non-empty at the beginning of trivlist environment when the first paragraph is not yet stated, and after the beginning of first paragraph. Since all theorem environments internally use trivlist, I use it to test whether we are at the beginning of proof environment.

\newcommand{\proofpart}[1]{%
  % store contents of \everypar in \@tempa
  \expandafter\def\expandafter\@tempa\expandafter{\the\everypar}%
  \ifx\@tempa\@empty
    % if \@tempa is empty, insert vspace
    \vspace{.7em}%
  \else
    % otherwise, reconstruct \everypar
    \everypar\expandafter{\@tempa}%
  \fi
  \noindent
  \textsc{#1}%
}

Full example

\documentclass[12pt,a4paper]{memoir}

\usepackage{fontspec}
\usepackage{xunicode}

\usepackage{mathtools}
\usepackage{unicode-math}

\usepackage{blindtext}

\usepackage{amsthm}
\usepackage{thmtools}

\makeatletter
\newcommand{\proofpart}[1]{%
  % token list \everypar is non-empty at the beginning of proof env 
  % (inherited from trivlist env)
  \expandafter\def\expandafter\@tempa\expandafter{\the\everypar}%
  \ifx\@tempa\@empty
    \vspace{.7em}%
  \else
    \everypar\expandafter{\@tempa}%
  \fi
  \noindent
  \textsc{#1}%
}
\makeatother

\declaretheoremstyle[
  spaceabove=2em,
  spacebelow=2em,
  postheadspace=1em,
  headfont=\upshape\bfseries,
  notefont=\mdseries,
  notebraces={(}{)},
  bodyfont=\normalfont,
]{mytheoremstyle}

\declaretheoremstyle[
  spaceabove=-1em, % <-- reduce margin, so that it is clear that the
  % proof belongs to the previous theorem/lemma/…
  %
  spacebelow=2em,
  postheadspace=1em,
  % headfont=\itshape,
  headfont=\upshape\bfseries,
  bodyfont = \normalfont,
  qed=$\qedsymbol$,
  headpunct={:},
]{myproofstyle}

\newcounter{mathcounter}
\numberwithin{mathcounter}{chapter}

\declaretheorem[
  name={Theorem},
  style=mytheoremstyle,
  numberlike=mathcounter
]{theorem}

% Remove amsthm's proof environment, so that we can override it below.
\let\proof\undefined
\let\endproof\undefined

\declaretheorem[
  name={Proof},
  style=myproofstyle,
  numbered=no
]{proof}


\begin{document}


\begin{theorem}
  \blindtext
\end{theorem}
\begin{proof}
  Some preliminary remarks.

  \proofpart{Step 1:} % <-- No problem here
    Foo

  \proofpart{Step 2:} % <-- No problem here
    Bar
\end{proof}


\begin{theorem}
  \blindtext
\end{theorem}
\begin{proof}\showthe\everypar
  \proofpart{Step 1:} % <-- This will increase spacing between theorem and proof
    Foo

  \proofpart{Step 2:} % <-- No problem here
    Bar
\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 .