# Math 'Example' formatting

I have a simple macro that takes an input and bold prints Example followed by the input then a line break. Except it breaks after the first [ with no bold.

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}

\newcommand{\exm}[1]{\textbf{Example{#1}}\\}
\begin{document}
\begin{exm} [6.1]
This is an example
\end{exm}

\end{document}


What am I doing wrong?

Your \exm definition had mandatory argument, not optional. This means, that when you use it, it had to be written as \exm{6.1}:

For above image I slightly change your MWE:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}

\newcommand{\exm}[1]{\par\noindent\textbf{Example~#1}\\}
\begin{document}
\exm{6.1}
This is an example\\
\end{document}


As you can see, it is used as command (as it is defined) and not as environment as you did.

• Should there be a \par directive before \noindent?
– Mico
Mar 10, 2017 at 13:22
• @Mico, yes, this will make use of command more safe. (always in new line). However, correct solution for OP needs is suggestion in your answer :-) Mar 10, 2017 at 13:28

Since you've defined a macro, not an environment, the way to invoke it is to write

\exm{6.1}


However, it looks to me like you do want to create a standalone environment, possibly like this:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}

\newenvironment{exm}[1]{%
\par  % start a new paragraph
\bigskip  % insert some vertical whitespace
\noindent % no paragraph indentation
\textbf{Example #1}}{%
\par\bigskip % insert another paragraph break and more vert. whitespace
}

\begin{document}
\begin{exm}{6.1}
This is an example.
\end{exm}

\end{document}


It'll produce the following output:

• +1. I've accepted Zarko's answer, but I'll consider this for the project. Thx. Mar 10, 2017 at 13:05