[Tex/LaTex] How to do a conditional line break

conditionalsline-breaking

I want to know how to do a conditional line break. Whenever the error message "There is no line to end here" comes, I want to disable the line break, otherwise to enable it, with a \\ command or \newline command.

As suggested, I am now explaining below my problem, with a minimal sample tex file.

I am using two macros that allow me to "eat" a question or an answer, while allowing me to keep both of them together in the source. When I conduct an exam, I eat the answers and give only the questions, for example.

This example results in the following error message:

LaTeX Error: There's no line here to end.  

The reason is that I have the \\ [1ex] command at the beginning of the macro, \ans.

If I remove the \\ [1ex] command from the macro \ans, the error goes away. Unfortunately, however, the answer does not begin on a new line for the first question.

I would also like to disable the \\ [1ex] command when it is not required. For example, the behaviour is the same in the second question, whether or not this command is present. In fact, in some situations, this command could create unnecessary additional space.

\documentclass[12pt,a4paper]{article}
\newcommand{\quest}[1]{#1}
\newcommand{\eatquest}[0]{\renewcommand{\quest}[1]{}}
\newcommand{\ans}[1]{\\ [1ex] Answer: #1}
\newcommand{\eatans}[0]{\renewcommand{\ans}[1]{}}
\begin{document}
%\eatquest
%\eatans
\begin{enumerate}
\item
\quest{What is the effect of bad zeros?  How can it be overcome?
}
\ans{
 This results in poor performance of the system.  The bad zeros
  cannot be changed by feedback.  The only way to change them is to
  redesign the system (not controller) itself.
}
\item 
\quest{This question is on 2-DOF pole placement controller
  design. Answer the following: 
\begin{enumerate}
\item In the class, a method was proposed to handle unstable 2-DOF
  controllers.  This method also has unstable pole-zero cancellation.
  Why was this acceptable? 
\end{enumerate}
}
\ans{A short answer is given now:
\begin{enumerate}
\item The pole and zero come for the same, ``identical'', source.  In
  fact, one can even say that this is NOT a case of pole-zero
  cancellation. 
\end{enumerate}
}
\end{enumerate}
\end{document}

Best Answer

Use \par\addvspace{1ex} instead of \\[1ex]

\documentclass[12pt,a4paper]{article}
\newcommand{\quest}[1]{#1}
\newcommand{\eatquest}[0]{\renewcommand{\quest}[1]{}}
\newcommand{\ans}[1]{\par\addvspace{1ex}Answer: #1}
\newcommand{\eatans}[0]{\renewcommand{\ans}[1]{}}
\begin{document}
%\eatquest
%\eatans
\begin{enumerate}
\item
\quest{What is the effect of bad zeros?  How can it be overcome?
}
\ans{
 This results in poor performance of the system.  The bad zeros
  cannot be changed by feedback.  The only way to change them is to
  redesign the system (not controller) itself.
}
\item 
\quest{This question is on 2-DOF pole placement controller
  design. Answer the following: 
\begin{enumerate}
\item In the class, a method was proposed to handle unstable 2-DOF
  controllers.  This method also has unstable pole-zero cancellation.
  Why was this acceptable? 
\end{enumerate}
}
\ans{A short answer is given now:
\begin{enumerate}
\item The pole and zero come for the same, ``identical'', source.  In
  fact, one can even say that this is NOT a case of pole-zero
  cancellation. 
\end{enumerate}
}
\end{enumerate}
\end{document}

enter image description here