I'd like to know if it's possible to have something added automatically to any paragraph in a given environment.

I use LaTeX mostly for doing fill-in-the-blank worksheets at the school where I work. I have an environment called FillInTheBlanks(*). It outputs the page twice---once with certain words that I've indicated with \blank{} blanked out with an underline in their place, and another page(s) with the answers filled in.

I also find it useful to have the paragraphs numbered, to make it easier to talk with the students about the content (e.g. "At the end of paragraph 3, you'll notice..."). In my Worksheets.sty file, I added:


so I can add a paragraph number in the margin to each paragraph. The only thing is, using this I have to add \marginlabel{"a number"} at the beginning of each paragraph manually. I'd like it to be done automatically. If I made a \newcommand to wrap around each paragraph, it could write the command so that it would save me the effort of manually inputting the paragraph numbers, but given that there are usually half a dozen paragraphs per page or less, it doesn't actually save much labour.

Is there some way I could have the \marginlabel{} command inserted automatically whenever a new paragraph starts?

(*) I know the exam class does something like this, but it doesn't do it the way I wanted to, so I rolled my own.


1 Answer 1


\everypar can help, but be careful: some LaTeX macros redefine it.

However, this works:




enter image description here

Since this uses \refstepcounter, you can use \label and \ref mechanism to reference your paragraphs.

  • This did exactly what I wanted. Thanks so much!
    – angus77
    Commented Nov 7, 2011 at 3:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .