# Going back to the end of the previous paragraph

Is there a way to define a TeX command that checks if the current position in the text is at the beginning of a paragraph, and if true, then to go back to the end of the previous paragraph?

Edit: The aim is to solve the following problem. I have a bunch of files that contain several multiple choice questions, in the following format:

\begin{problem}
... the statement of the question ...

\choices
\end{problem}


where \choices is some command that I defined to display the choices for the answer. The problem is that now I want to have the choices displayed in the last line of the previous paragraph (separated by \hfill from the statement of the question) in order to gain some space; instead, now the choices for the answer start a new paragraph. I want to modify \choices such that it automatically clears the previous empty line(s), if there is one (or more), so I don't have to do it manually (which would be quite painful).

-
No, when a paragraph has been typeset it won't be accessible any more. What's your aim? –  egreg Jan 12 '13 at 22:34
It would be helpful if you composed a fully compilable MWE that set up the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. I believe that there is a simpler solution to your problem, but need a test case to see how you are defining things. –  Peter Grill Jan 12 '13 at 23:24
This is one of the things we are trying to address in the LaTeX3 galley. The code for this is working, but currently breaks almost all LaTeX2e packages that do anything galley-related :-( So the current answer is I suspect 'no'. –  Joseph Wright Jan 12 '13 at 23:26

At a TeX level, once you have issued the \par primitive the answer is no, you can't 'back up' through the alread-typset material. However, it is possible to construct a 'galley' (system for laying out the text in paragraphs) which does not insert the \par primitive when you leave a blank line (insert a \par token: not necessarily the same as TeX's \par primitive!). This approach is explored in the LaTeX3 galley module, and there it is possible to add something to the end of the last paragraph as part of the code which starts the next one. The problem with this is that while this code works, it breaks anything that makes assumptions about \par (most of the LaTeX2e kernel, anything that does sections, display environments, ...). Thus at the moment it's not something read for 'general use'. A 'proof-of-principal' demo:

\documentclass{article}
\usepackage{l3galley,xparse}
\ExplSyntaxOn
\NewDocumentEnvironment { problem } { }
{
\cs_set_protected:Npn \choices
{
\s__par_omit
\tl_gset:Nn \g_galley_par_end_hook_tl { MARK }
}
}
{ }
\ExplSyntaxOff
\begin{document}
Some demo text.

\begin{problem}
Some demo text.

Some demo text.

Some demo text.

\choices
\end{problem}

\end{document}

-