From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thibault Marin Subject: ox-md: Export links to equations for use with MathJax Date: Sat, 10 Feb 2018 23:21:53 -0600 Message-ID: <87d11cdrta.fsf@dell-desktop.WORKGROUP> Reply-To: thibault.marin@gmx.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekk5R-0007HI-VK for emacs-orgmode@gnu.org; Sun, 11 Feb 2018 00:22:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekk5O-0000XE-5J for emacs-orgmode@gnu.org; Sun, 11 Feb 2018 00:22:01 -0500 Received: from mout.gmx.net ([212.227.17.21]:57519) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ekk5N-0000WW-Q8 for emacs-orgmode@gnu.org; Sun, 11 Feb 2018 00:21:58 -0500 Received: from dell-desktop ([99.47.196.62]) by mail.gmx.com (mrgmx103 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MKpQ4-1ekk5L2CK8-0007YX for ; Sun, 11 Feb 2018 06:21:56 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-org list --=-=-= Content-Type: text/plain Hi list, Similar to a change introduced recently to ox-html (ba6c0f1ea9), I'd like to be able to export (in markdown, using ox-md.el) links to LaTeX equations with "\eqref{org0000000}" and rely on MathJax for rendering instead of the default markdown format ("[description][#org0000000]"). The attached patch is my first attempt at this. It is almost identical to the ox-html version. I have added an option to select which mode to use (markdown or MathJax). Could this patch be considered for a merge? Please let know if there are any suggestions or comments. Thanks, thibault --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-ox-md.el-Add-option-to-export-equation-links-to-eqre.patch >From bf03749fe18726f43684d0818a75a2affbe3e546 Mon Sep 17 00:00:00 2001 From: thibault Date: Sat, 10 Feb 2018 22:58:35 -0600 Subject: [PATCH] ox-md.el: Add option to export equation links to "\eqref" (MathJax) * lisp/ox-md.el (org-md-link): Export link to LateX equation as "\eqref" (for use with MathJax) when the new option `:md-link-mathjax' is non-nil. (org-export-define-derived-backend 'md): Add new option `:md-link-mathjax' to control the export of equation links. Its value is set to that of the new customization variable `org-md-link-mathjax'. (org-md-link-mathjax): Add customization variable to enable export to MathJax "\eqref" (disabled by default). --- lisp/ox-md.el | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/lisp/ox-md.el b/lisp/ox-md.el index e2a000bd0..575499072 100644 --- a/lisp/ox-md.el +++ b/lisp/ox-md.el @@ -70,6 +70,17 @@ The %s will be replaced by the footnote reference itself." :version "26.1" :package-version '(Org . "9.0")) +;;;; Links + +(defcustom org-md-link-mathjax nil + "Non-nil means process LaTeX equation links for MathJax. + +When non-nil, links to LaTeX equations will be exported to \"\\eqref\"." + + :group 'org-export-md + :package-version '(Org . "9.2") + :type 'boolean) + ;;; Define Back-End @@ -111,7 +122,8 @@ The %s will be replaced by the footnote reference itself." :options-alist '((:md-footnote-format nil nil org-md-footnote-format) (:md-footnotes-section nil nil org-md-footnotes-section) - (:md-headline-style nil nil org-md-headline-style))) + (:md-headline-style nil nil org-md-headline-style) + (:md-link-mathjax nil nil org-md-link-mathjax))) ;;; Filters @@ -419,17 +431,26 @@ a communication channel." (or (org-element-property :CUSTOM_ID destination) (org-export-get-reference destination info)))) (_ - (let ((description - (or (org-string-nw-p contents) - (let ((number (org-export-get-ordinal destination info))) - (cond - ((not number) nil) - ((atom number) (number-to-string number)) - (t (mapconcat #'number-to-string number "."))))))) - (when description - (format "[%s](#%s)" - description - (org-export-get-reference destination info)))))))) + (if (and destination + (plist-get info :md-link-mathjax) + (eq 'latex-environment (org-element-type destination)) + (eq 'math (org-latex--environment-type destination))) + ;; Caption and labels are introduced within LaTeX + ;; environment. Use "eqref" macro to refer to those in + ;; the document. + (format "\\eqref{%s}" + (org-export-get-reference destination info)) + (let ((description + (or (org-string-nw-p contents) + (let ((number (org-export-get-ordinal destination info))) + (cond + ((not number) nil) + ((atom number) (number-to-string number)) + (t (mapconcat #'number-to-string number "."))))))) + (when description + (format "[%s](#%s)" + description + (org-export-get-reference destination info))))))))) ((org-export-inline-image-p link org-html-inline-image-rules) (let ((path (let ((raw-path (org-element-property :path link))) (cond ((not (equal "file" type)) (concat type ":" raw-path)) -- 2.15.1 --=-=-=--