# Command for switching exercise styles

I am trying to create a command that allows me (or the user) to switch between two different styles for typesetting problems. One is the runin in the margin, while the other one is defined by subsection

• Is there a simple way to obtain consistent spacing for the two styles?
• In particular I want the runin style to start on the same line regardless of whether there is a blank line below or not. Also it would be nice if the space before \problem was the same regardless of style.

As can be seen in the image the second problem has a newline too much.

Is there a way for

\Problem
\lipsum[66]


and

\Problem

\lipsum[66]


to produce the same output?

• While not really the question the same output would be great in an enumerate environment. However, I was not able to emulate the \subsection apperance using a \item.

## Code

\documentclass{article}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{etoolbox}

\newtoggle{inline} \settoggle{inline}{true}

\newcounter{problem}
\newcommand{\Problem}{%
\stepcounter{problem}%
\iftoggle{inline}{%
\bigskip

%\vspace{-\baselineskip}
}{%
\subsection*{Problem~\theproblem}%
}%
}

\setlength\parindent{0pt}

\begin{document}

\Problem
\lipsum[66]

\Problem

\lipsum[66]

\settoggle{inline}{false}

\Problem

\lipsum[66]

\Problem
\lipsum[66]

\end{document}

• \section etc. use \@afterheading to affect the next paragraph. Nov 19 '19 at 17:07

Two \pars act the same as one \par (blank line).

\documentclass{article}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{etoolbox}

\newtoggle{inline} \settoggle{inline}{true}

\newcounter{problem}
\newcommand{\Problem}{%
\stepcounter{problem}%
\iftoggle{inline}{%
\bigskip\par
\par\vskip-\baselineskip\vskip-\parskip
}{%
\subsection*{Problem~\theproblem}%
}%
}

\setlength\parindent{0pt}

\begin{document}

\Problem
\lipsum[66]

\Problem

\lipsum[66]

\settoggle{inline}{false}

\Problem

\lipsum[66]

\Problem
\lipsum[66]

\end{document}