# Partial indentation after theorem

Code:

\documentclass[a4paper]{report}
\usepackage{lipsum,amsthm,thmtools,xparse}
\newtheorem{defi}{Definizione}
\NewDocumentCommand{\xbegin}{mooo}
{\IfValueTF{#4}
{\begin{#1}[name={\contrel{#2}{#4}},continued={#3}]}
{\IfValueTF{#3}
{\begin{#1}[name={#2},label={#3}]}
{\IfValueTF{#2}
{\begin{#1}[name={#2}]}
{\begin{#1}}
}
}
}
\newcommand{\xend}[1]{\end{#1}\noindent}

\begin{document}
\xbegin{defi}
\lipsum[1]
\end{defi}
\lipsum[2]
\xbegin{defi}
\lipsum[3]
\xend{defi}
\lipsum[4]
\xbegin{defi}
\lipsum[5]
\end{defi}\noindent
\lipsum[6]
\end{document}
%5 and 1 comment. Then 6 more and 2 comment.


Output:

Basically, \xbegin makes (to my eyes) the code for theorem starts more readable by giving the keys as optional arguments, without the name=, label= or continues= part. \xend should suppress the indent of the first line after the theorem. We notice the following:

1. After the first Definizione, we have that indent;
2. Curiously, if I use the normal \begin, I get no indent;
3. After the second Definizione, we get a partial indent, i.e. and indent by something between zero and the normal indent; it may seem like there is extra vertical space too, but it is just split pictures;
4. After the third Definizione, we get no indent.

So my questions are two:

1. Why does the indent appear with \xbegin, as noted in points 1-2?
2. Why does the \noindent in \xend only partially suppress the indentation?
• \noindent\ignorespaces However, I can't see how a series of optional arguments can be better than a key-value interface. If you want to have #4 only, you have to add two optional arguments and then test for their emptyness. – egreg Mar 3 '15 at 10:50
• you are missing % from almost every line of your definition, but I would agree with egreg having two adjacent optional arguments is bad enough, I'd never do more than that. – David Carlisle Mar 3 '15 at 11:02
• OK, that removes the partial indent, which is in fact a space coming from the line end, which, after a \noindent, is turned into a space (right?). But why does the full indent appear with \let\xend\end? – MickG Mar 4 '15 at 20:50

The "partial indent" is not indentation it is just adjacent spaces coming from your source file, you need % at the ends of lines if you use white space to lay out your source that you do not want to appear in the output.
In comment you ask why you get full indent with \let\xend\end that is the normal behaviour for the start of a paragraph, which is the case after a theorem environment. Your \xindent suppresses the indentation but at the price of starting a new paragraph implicitly, which makes the markup very fragile, any space characters after the end of theorem environment will appear as space in the output, and a blank line or a display environment such as a list after the theorem environment would end the empty paragraph started by \noindent causing a spurious blank line,
• That gives a reason to the cases when I had the extra vertical space (mostly when starting a thm right after another one), which I solved by using plain \end in those cases. – MickG Jan 18 '16 at 21:50
• @MickG never use \noindent in a macro:-) – David Carlisle Jan 18 '16 at 21:51
• @MickG no if you use \noindent in the document then something is definitely wrong, it should be a document level style decision where paragraph indentation is needed. – David Carlisle Jan 18 '16 at 21:53
• @MickG look at latex sections and list items, they suppress indentation but never using \noindent – David Carlisle Jan 18 '16 at 21:54