8

In the following code, would it be possible to automatically generate the desired output (2nd paragraph) form the given input (1st paragraph)?

\documentclass[parskip]{scrbook}

\usepackage{xparse}

\NewDocumentCommand{\mref}{ m o }{
   \IfValueT{#2}{%
      \textbf{#2}
   }%
   \marginpar{$\to$ \ref{#1}}%
}

\usepackage{lipsum}

\begin{document}
   Input:\\
   Text \mref{foo}[Foo] with two Refs \mref{bar}[Bar-Text] in a line.
   \lipsum[2]

   Desired Output:\\
   Text \textbf{Foo} with two Refs \textbf{Bar-Text}
   \marginpar{$\to$ \ref{foo} \enskip $\to$ \ref{bar}}
   in a line.
   \lipsum[2]

   \chapter{Foo}\label{foo}
   \chapter{Bar}\label{bar}
\end{document}

My idea would be to test and save the y position on the page and collect all margin pars until the shipout. Then combine this with the same y value and add them to the page as an overlay. I didn’t implement that yet as I want to wait if there is an easier more elegant way …

Tobi
  • 56,353
  • 1
    Does the answer to this question answer your question? (That one does it per line as that's what that OP wanted, but it should be simple to do it per paragraph instead if that's what you want.) – ShreevatsaR May 23 '17 at 07:33
  • You might want to have a look at reledmac's ledsidenote-mechanism, which does this. I didn't look closely at it but perhaps the code can be extracted and used separately. – Florian May 23 '17 at 08:20
  • @ShreevatsaR: Thanks! I didn’t found that question, seems to work for me. – Tobi May 23 '17 at 21:21
  • @Florian: Thanks, I’ll take a look at it if the solution linked by ShreevatsaR doesn’t work … :-) – Tobi May 23 '17 at 21:21
  • @ShreevatsaR: Your link was a good starting point. I just postet an alternative solution over there and vote to close my question as duplicate as soon as the bounty expired. – Tobi May 24 '17 at 16:42

0 Answers0