How to realize cross reference

I want to implement cross references in documents, such as latex like cross references,like this:

\subsection{rel section}\label{subsection1}
in \ref{subsection1}  section, we show you how to reference a chapter in latex

I’m using prosemirror now, so I want to quote a figure, and my idea is to do this. Give this figure a unique ID, and record the ID in the referenced view,like this:

<cross-ref ref-id="e348ba0a-179c-45a1-9f7e-cd6a2b0cf3fb">figure 1</cross-ref>

This ref-id is the ID of the figure. Now the problem is how to give each figure a unique ID, and is this the best solution

Set a unique ID, I see How I can attach attribute with dynamic value when new paragraph is inserted?

It sounds like these IDs would better be stored at the document level, rather than with decorations. See for example this thread for some related discussion.

I don’t think the solution for this post is good enough, and the best way to do this is to set a unique ID to a node when you create it.

Hey @milu2003, in Fidus Writer (based on ProseMirror and with LaTeX export) we solved it by:

  1. Checking for unique IDs at the time of figure creation (create random id, check if it is used already, if yes, create another and check again, etc.).

  2. There is also some logic to check new content that appears for figures (and other items that have IDs). Those could have been copied/pasted from the same document and so we need to create an append transaction to give the inserted ones another ID.

  3. There is a plugin that keeps track of all the items with IDs that are being linked to via cross-references. If the linked-to item has been removed, we add warning-signs to the cross-references telling the user that the item that is being linked to is no longer in the document.

This works well for single documents. Recently users have told us they also want to do cross references between multiple documents that are all currently being edited. I’m, not yet sure how one can address that.

1 Like