I'm trying to use \marginpar to annotate the line where a piece of data occurs in the text. That means, I want them in the precise line where they are declared, there will frequently be more than one in the line, and I don't know in advance how many (may change when I modify the text or change the layout). The problem is that when more than one \marginpar is used, they are pushed down vertically. Ideally, I'd wish for concatenation (with whitespace and/or a comma inbetween). I looked if the marginnote and marginfix packages, but they don't do what I want (however, it's very possible that I didn't find the right configuration arguments). This feels like something that might have been solved before, but I couldn't find it, so please point me in the right direction.
I want this:
A pendulum of length $5\,\rm cm$\marginpar{$l$} and mass $10\,\rm g$\marginpar{$m$}
is displaced by $6^\circ$\marginpar{$\phi$} and released.
Calculate the momentum in the equilibrium position.
to produce "l, m" in the first line margin and "φ" in the second, if the linebreak occurs inbetween, but "l, m, φ" in the first line, if there is no linebreak (depending on the layout).
Don't pay attention to the rest of the markup, it's a stub to make the point.


\rmis deprecated. Use\textrm{cm}etc in appropiate mode. It would be nice to see more of your document, i.e a working document – Nov 05 '15 at 07:27{\rm ...}, but\mathrm{...}instead. Second, this seems to require a LuaTeXpost_linebreak_filter, this TUGboat article seems to be interesting. – Henri Menke Nov 05 '15 at 07:27siunitxanyway. This is just a quick stub. – orion Nov 05 '15 at 10:45