I need a macro to behave differently in case it's at the end of a line. Is there any way to check something like that?
\documentclass[11pt]{memoir}
\newcommand{\test}{
% if at the end of line
% Print A
% else
% Print B
}
\begin{document}
Hello, \test how are you doing? % Should print B
Hello, how are you doing? \test % Should print A
\test Hello, how are you doing? % Should print B
\end{document}
Thank you
Edit: I really meant at the end of a paragraph, but I'm going to leave the question as is, because there are good answers to check both the end of a line and the end of a paragraph.

