Search code examples
clojureorg-mode

Writing a document in org-mode: is it possible to refer to a code fragment?


I'm writing a document in org-mode that contains a lot of code fragments, like:

#+begin_src clojure
(+ 1 2 3)
#end_src

Is it possible to make a reference to such a fragment, so I can say in text: in this [[frag1][fragment]] the sum of 1, 2 and 3 is calculated?

Btw, I'm exporting the org document as latex/pdf and html.


Solution

  • Maybe it helps you:

    #+BEGIN_SRC emacs-lisp
    ;; (ref:some caption1) 
    (save-excursion
       (goto-char (point-min))
    #+END_SRC
    
         In block [[(some caption1)]] 
    
    #+BEGIN_SRC emacs-lisp
    ;; (ref:some caption2)
    (save-excursion
       (goto-char (point-min))
    #+END_SRC
    
         In block [[(some caption2)]]