# Removing indentation from macro

I've created two macros for my math book project. One is an enumerate environment that numbers problems as "Example 1.1" and so on. The other is a command that writes metadata about each problem to a text file.

The problem is that for some reason when I combine these two macros, there's an unnecessary indentation that I'm not sure how to get rid of.

\documentclass{article}

\newcounter{myenumi}
\renewcommand{\themyenumi}{\textbf{Example \thesection.\arabic{myenumi}.}}
\newenvironment{myenumerate}{%
% stuff for beginning of environment goes here
\setlength{\parindent}{0pt}% don't indent paragraphs
\setcounter{myenumi}{0}% restart numbering
\bigskip% skip a line
\renewcommand{\item}{% new definition of item
\par% start a new line
\medskip
\makebox[8em][l]{\themyenumi}% print counter to width of 3em, aligned to left
}% end of definition of item
}{% at end of environment
\par% start new paragraph
\bigskip% skip a line
\noindent% don't indent new paragraph
\ignorespacesafterend% ignore spaces after environment
}

\makeatletter
\newwrite\@datawrite
\immediate\openout\@datawrite=\jobname.data

\newcommand\exampledata[3]{%
\immediate\write\@datawrite{Example \thesection.\theenumi}
\immediate\write\@datawrite{Source: #1}
\immediate\write\@datawrite{Checked: #2}
\immediate\write\@datawrite{Difficulty: #3}
\immediate\write\@datawrite{}}

\AtEndDocument{\closeout\@datawrite}

\makeatother

\begin{document}
\section{A section}

\begin{myenumerate}
\item
\exampledata{A nice book}{yes}{easy}
Show that $a=b$.
\item
\exampledata{Another nice book}{no}{impossible}
Show that $c=d$.
\end{myenumerate}

\begin{enumerate}
\item
\exampledata{A nice book}{yes}{easy}
Show that $a=b$.
\item
\exampledata{Another nice book}{no}{impossible}
Show that $c=d$.
\end{enumerate}

\end{document}


The problem is that for the first items, Example 1.1 and Example 1.2, there's an indentation before the problem statement that I do not want. Could someone help me get rid of it?

Thanks in advance for the help. Here's a picture of the above document.

Your mistake is the spaces after \write{...} in your macro \exampledata. You need to correct your macro:

\newcommand\exampledata[3]{%
\immediate\write\@datawrite{Example \thesection.\theenumi}%
\immediate\write\@datawrite{Source: #1}%
\immediate\write\@datawrite{Checked: #2}%
\immediate\write\@datawrite{Difficulty: #3}%
\immediate\write\@datawrite{}%
}


and you need to use

\exampledata{A nice book}{yes}{easy}%


\exampledata{A nice book}{yes}{easy}


or you need to add \ignorespaces at the end of your macro.

You can simply reduce the length of the box containing \themyenumi when defining the myenumerate environment.

Reduce it from 8em to 5.5em:

\makebox[5.5em][l]{\themyenumi}


Complete code:

\documentclass{article}

\newcounter{myenumi}
\renewcommand{\themyenumi}{\textbf{Example \thesection.\arabic{myenumi}.}}
\newenvironment{myenumerate}{%
% stuff for beginning of environment goes here
\setlength{\parindent}{0pt}% don't indent paragraphs
\setcounter{myenumi}{0}% restart numbering
\bigskip% skip a line
\renewcommand{\item}{% new definition of item
\par% start a new line
\medskip
\makebox[5.5em][l]{\themyenumi}% print counter to width of 3em, aligned to left
}% end of definition of item
}{% at end of environment
\par% start new paragraph
\bigskip% skip a line
\noindent% don't indent new paragraph
\ignorespacesafterend% ignore spaces after environment
}

\makeatletter
\newwrite\@datawrite
\immediate\openout\@datawrite=\jobname.data

\newcommand\exampledata[3]{%
\immediate\write\@datawrite{Example \thesection.\theenumi}
\immediate\write\@datawrite{Source: #1}
\immediate\write\@datawrite{Checked: #2}
\immediate\write\@datawrite{Difficulty: #3}
\immediate\write\@datawrite{}}

\AtEndDocument{\closeout\@datawrite}

\makeatother

\begin{document}
\section{A section}

\begin{myenumerate}
\item
\exampledata{A nice book}{yes}{easy}
Show that $a=b$.
\item
\exampledata{Another nice book}{no}{impossible}
Show that $c=d$.
\end{myenumerate}

\begin{enumerate}
\item
\exampledata{A nice book}{yes}{easy}
Show that $a=b$.
\item
\exampledata{Another nice book}{no}{impossible}
Show that $c=d$.
\end{enumerate}

\end{document}

• that won't work in general, the extra space is word spaces so may stretch/shrink but you have changed by a fixed amount. Dec 3, 2014 at 8:27
• @DavidCarlisle You're right... Dec 3, 2014 at 8:33