# Prologue

I'm using the exercise package and trying to harmonize its layout with memoir.

This question is quite involved to illustrate, so I'll break it up into several Acts. I'll present the relevant source and then screenshot of the output.

# Act I

Having everything at default, I create an Exercise environment.

\begin{Exercise}[title=Theory of Relativity]
The theory of relativity was not a eureka moment. It was the result of steady work over a period of 10~years.
\begin{align}
E &= mc^2
\end{align}
\Question Why does $$E = mc^2$$?
\end{Exercise}

# Act II

I want to customize the header a bit, so I issued the following \renewcommand in the preamble. The indent before "The theory of..." doesn't look right. My desired layout wants to make the indent disappear.

\hrule\medskip\noindent%
\textbf{%
\large%
}

# Act III

I looked around in texdoc exercise and it doesn't document anything about the layout of the Exercise body. Yes, there is documentation about Questions, subQuestions, and subsubQuestions, but those do not apply to the Exercise body. So I looked around and I came to the definition of \@@@ExeEnv, which looks like this

\newcommand{\@@@ExeEnv}{%
\vskip\ExerciseSkipBefore %
\@QuestionLevel1 %
\refstepExecounter %
\begingroup%
\ext@exercise}{\toc@exercise}{%
\ExerciseName\ %
\theExercise\ %
\expandafter{\itshape \ExerciseTitle}%
\hspace{.66em}%
} %
\endgroup%
}

# Act IV

So I try to dissect \@@@ExeEnv, adding and removing control sequences to see how they affect the output. With the following code in the preamble, I get what I want: the ugly indent disappears!

\makeatletter
\renewcommand{\@@@ExeEnv}{%
\vskip\ExerciseSkipBefore \@QuestionLevel1 \refstepExecounter%
\begingroup%
\endgroup%
}
\makeatother

# Act V

But alas! I have removed the \addcontentsline command, which I suppose is important to maintaining a Table of Contents. So I try to add back the \addcontentsline from the original definition, but the ugly indent is back! Even a dummy \addcontentsline brings back the hideous indent, this time much more sneakier than the original.

\renewcommand{\@@@ExeEnv}{%
\vskip\ExerciseSkipBefore \@QuestionLevel1 \refstepExecounter%
\begingroup%
\endgroup%
}

# Epilogue

Why does \addcontentsline add an unwanted indent? Where can I fix this? I'd also appreciate suggestions on better exercise packages which work better with memoir.

Adding a \noindent before the exercise body: (\noindent The theory of...) doesn't make the indent go away either. It's an inelegant solution as well.

-
That's a lot of code snippets! But I'd rather have one minimal working example. :-) –  lockstep Sep 4 '11 at 7:58
BTW, the problem seems to be not indentation, but a spurious space. I've changed the tags accordingly. –  lockstep Sep 4 '11 at 8:06
@lockstep, I did it this way to rule out as many "Have you tried..." responses as possible :) –  Kit Sep 4 '11 at 8:46
I see .. but such code snippets should be added to a MWE, not replace it. –  lockstep Sep 4 '11 at 8:53
@lockstep: Right, will keep that in mind :) –  Kit Sep 4 '11 at 13:27

There is an extra space ('Act III)', but you also want to \ignorespaces after your modified internal macro:

\documentclass{memoir}
\usepackage{amsmath,exercise}
\hrule
\medskip
\noindent
\begingroup
\bfseries
\large
\medskip
\\
\endgroup
}
\makeatletter
\renewcommand*\@@@ExeEnv{%
\vskip\ExerciseSkipBefore
\@QuestionLevel1 %
\refstepExecounter
\begingroup%
{%
\ExerciseName\ %
\theExercise\ %
\expandafter{\itshape \ExerciseTitle}%
\hspace{.66em}%
}%
\endgroup
\ignorespaces
}
\makeatother
\begin{document}
\begin{Exercise}[title=Theory of Relativity]
\noindent
The theory of relativity was not a eureka moment. It was the result of steady work over a period of 10~years.
\begin{align}
E &= mc^2
\end{align}
\Question Why does $$E = mc^2$$?
\end{Exercise}
\end{document}

Removing the space should deal with the issue.

-
I removed the space (and even the \hspace) but the indent becomes the one like in Act V. –  Kit Sep 4 '11 at 8:42
@Kit: What we need is a proper minimal example, i.e. a short document that we can compile and try editing. Snippets are not a good way to get solutions. –  Joseph Wright Sep 4 '11 at 8:45
@Kit: I've built a full minimal example, which seems to work for me. The key is to use \ignorespaces here to skip to the document content. –  Joseph Wright Sep 4 '11 at 8:57