TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

... the statement of the question ...


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).

share|improve this question
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
up vote 4 down vote accepted

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:

\NewDocumentEnvironment { problem } { }
    \cs_set_protected:Npn \choices
        \tl_gset:Nn \g_galley_par_end_hook_tl { MARK }
  { }
Some demo text.

  Some demo text.

  Some demo text.

  Some demo text.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.