# Problems with creating a new environment

I need to create a new environment that works like:

\begin{explanation}
Here starts the explanation ...
\end{explanation}


In the document it should look like:

Explanation. Here starts the explanation ...

Still being relatively new to TeX I struggle to get the result I want. I started with

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\newenvironment{explanation}{\textbf{Explanation.} }{}
\begin{document}
\end{document}


but I don't know how to continue. Does anyone know how to continue?

• Add \itshape and remove the space after the closing brace of \textbf{}. – TeXnician Sep 22 '18 at 12:02
• I changed it to \newenvironment{explanation}{\textbf{Explanation.}}{\itshape}, which is closer to what I want but the text (in this case: Here starts the explanation) is still not cursive. I get what I want, when I use \begin{explanation} \textit{Here …} \end{explanation} but ideally I don't want to use \textit{} – offline Sep 22 '18 at 12:06
• you are putting \itshape at wrong location (at end of environment) – user4686 Sep 22 '18 at 12:08
• You probably want something more like \newenvironment{pexplanation}{\par\textbf{Explanation. }\itshape\ignorespaces}{\par}. But I guess things should be slightly more sophisticated. Have a look at amsthm. – moewe Sep 22 '18 at 12:08
• Indeed. I'd suggest \usepackage{amsthm} \theoremstyle{plain} \newtheorem*{explanation}{Explanation}. – moewe Sep 22 '18 at 12:09

You will want to start a new paragraph for your environment and you need an \itshape. You could try

\newenvironment{pexplanation}{\par\textbf{Explanation. }\itshape\ignorespaces}{\par}


But I'd rather suggest to use a theorem package like amsthm. Things are much easier there

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{kantlipsum}% for the example text

% with amsthm
\usepackage{amsthm}
\theoremstyle{plain}
\newtheorem*{explanation}{Explanation}

% manually
\newenvironment{pexplanation}{\par\textbf{Explanation. }\itshape\ignorespaces}{\par}

\begin{document}
\kant[1]
\begin{explanation}
Here starts the explanation ...
\end{explanation}
\kant[2]
\begin{pexplanation}
Here starts the explanation ...
\end{pexplanation}
\kant[3]
\end{document}


You can have your explanations counted with amsthm if you use

\newtheorem{explanation}{Explanation}


(without the star) instead of \newtheorem*.

If you use pexplanation you'll need more code

\newcounter{pexplanation}
\newenvironment{pexplanation}{%
\par
\refstepcounter{pexplanation}%
\textbf{Explanation \thepexplanation. }%
\itshape
\ignorespaces}
{\par}

• Is there a way to count the Explanations like Explanation 1. ... Explanation 2. – offline Sep 22 '18 at 12:36
• @offline That is very easy with amsthm: just remove the * in \newtheorem*. – moewe Sep 22 '18 at 12:37