0

Given the following example org-document:

* For Loops

This is a for loop in Python:

  #+name: lst:src-ref
  #+caption: This is an example for loop.
  #+begin_src python
    for i in range(0, 10):
        print(i)
  #+end_src

* References

Remember the for-loop example\nbsp{}[[lst:src-ref]].

The link lst:src-ref is never actually (properly) set, at least for exports to HTML and LaTeX (PDF). The only workaround I've found so far is to use the double-bracket link <<lst:src-ref>> above the source block, but that will refer to the section, not the block itself.

What is the correct way to create internal links to source blocks such that they can be referenced in at least HTML and LaTeX export?

Notice that this is similar to this question, however, the answers are seemingly out of date, or just not working in many cases, hence a complete (and current) answer would be appreciated.

4
  • 4
    Does this answer your question? How to reference source blocks in org text
    – Drew
    Commented Feb 1, 2023 at 16:16
  • As you said, the question is a duplicate. The fact that the original question doesn't have adequate or up-to-date questions doesn't change that. Instead of adding a dup question, add a comment to the OP asking for better or more up-to-date answers.
    – Drew
    Commented Feb 1, 2023 at 16:18
  • Org citations are probably the future, but it's not clear to me that it's ready from prime time yet (but that is an uninformed opinion, based on no factual information). Last I knew, John Kitchin was reworking org-ref to make it converge with the generic org-cite framework and I see he has an answer based on org-ref in the duplicate question. Also I tested Melioratus's answer with current Org mode and bleeding-edge Emacs and it all works for me (with some limitations) but there is no mention of HTML in that answer.
    – NickD
    Commented Feb 1, 2023 at 18:05
  • Does org-cite support internal references though? I can only find documentation regarding external references so far
    – Xaldew
    Commented Feb 3, 2023 at 10:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.