jkitchin / org-ref

org-mode modules for citations, cross-references, bibliographies in org-mode and useful bibtex tools to go with it.
GNU General Public License v3.0
1.36k stars 243 forks source link

Equation references exporting to markdown and HTML #1070

Closed drghirlanda closed 1 year ago

drghirlanda commented 1 year ago

I am having trouble understanding how to export cref: references to markdown and HTML. Example:

#+name: eq:x
\begin{equation}
   x = 1
\end{equation}
- eq:x within brackets: [[eq:xr]]
- eq:x with cref: cref:eq:x

Exports to markdown as:

\begin{equation}
\label{org0b88a49}
   x = 1#+name: eq:x
\end{equation}
-   eq:xr within brackets: [1](#org0b88a49)
-   eq:x with cref: <eq:x>

So the org-mode link [[eq:x]] works, but the cref:eq:x does not seem to. I have also tried using \label inside the equation, instead of #+name: but that also does not work for me. Similar story with HTML export. (I am not sure if <eq:x> should resolve further upon processing with markdown tools, but it does not work when displaying it via Shiny, which is my goal.)

I thought cref would work only for LaTeX export, but I then stumbled upon comments in refproc.el (or somewhere else) suggesting it should work... Any help appreciated! I am steps away from having a single org file that exports correctly to LaTeX and RMarkdown and this is one of the last remaining issues :)

jkitchin commented 1 year ago

your example isn't totally right I think. This org file:

#+name: eq:x
\begin{equation}
   x = 1
\end{equation}

- eq:x within brackets: [[eq:x]]
- eq:x with cref: cref:eq:x

* build                                                            :noexport:

#+BEGIN_SRC emacs-lisp
(require 'org-ref-refproc) ;; this is not loaded by default!

(let ((org-export-before-parsing-hook '(org-ref-refproc)))
  (org-open-file (org-html-export-to-html)))
#+END_SRC

#+RESULTS:

#+BEGIN_SRC emacs-lisp
(let ((org-export-before-parsing-hook '(org-ref-refproc)))
  (org-open-file (org-md-export-to-md)))
#+END_SRC

looks like this in html:

image

and this in markdown:

image
drghirlanda commented 1 year ago

Thanks, I was missing that org-ref-refproc is not loaded by default. A very useful addition!