Org-mode mailing list
 help / color / mirror / Atom feed
From: Timothy <>
To: org-mode-email <>
Subject: [PATCH] Wrap LaTeX snippets in $$ with markdown export
Date: Thu, 01 Apr 2021 00:41:29 +0800
Message-ID: <> (raw)

[-- Attachment #1: Type: text/plain, Size: 936 bytes --]

Hi All,

I anticipate that this change may be somewhat contentions because ox-md
explicitly follows only the original Markdown spec from 2003, however
I've thought this over and come to the conclusion that this change is
still in keeping with that, and beneficial.

Currently ox-md simply inherits the output from ox-html's handling of
LaTeX snippets. Needless to say, the original Markdown specification
does not mention LaTeX snippets. As such, by subtly tweaking the output
(either adding $$ or substituting out LaTeX-style \(\) / \[\] for $ /
$$) we are not deviating from the original specification any more than we
already are.

While I don't see any issue with this, I do see some benefits. Namely
that, of the many Markdown variants that now exist, many support LaTeX
snippets, but exclusively in the TeX $$ form. Hence, by applying this
change the overall utility of ox-md is increased.

Let me know what you think,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-md-Use-TeX-style-math-wrapping.patch --]
[-- Type: text/x-patch, Size: 2721 bytes --]

From b7f1b89a50752398672a642519534818d23c72a4 Mon Sep 17 00:00:00 2001
From: TEC <>
Date: Thu, 1 Apr 2021 00:25:41 +0800
Subject: [PATCH] ox-md: Use TeX-style $ math wrapping

* lisp/ox-md.el (org-md-latex-environment, org-md-latex-fragment):
These two new filters wrap LaTeX maths in $ / $$ TeX-style notation.
While ox-md endeavours to adhere to the original Markdown specification,
and not any particular variant, the original specification does not deal
with LaTeX fragments at all, and so this change does not reduce how
faithfully the original specification is followed.
There is a major upside to this though. Of the many Markdown variants
that have emerged, those that support LaTeX very often exclusively
support TeX style notation.  This change thus improves the utility of
the Markdown export for many use cases, and deviates no more from the
original specification that the current method.
 lisp/ox-md.el | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index b6b2c1728..c5c0e05a5 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -100,6 +100,8 @@ (org-export-define-derived-backend 'md 'html
 		     (italic . org-md-italic)
 		     (item . org-md-item)
 		     (keyword . org-md-keyword)
+                     (latex-environment . org-md-latex-environment)
+                     (latex-fragment . org-md-latex-fragment)
 		     (line-break . org-md-line-break)
 		     (link . org-md-link)
 		     (node-property . org-md-node-property)
@@ -460,6 +462,32 @@ (defun org-md-keyword (keyword contents info)
     (_ (org-export-with-backend 'html keyword contents info))))
+;;;; Latex Environment
+(defun org-md-latex-environment (latex-environment contents info)
+  "Transcode a LATEX-ENVIRONMENT object from Org to Markdown.
+CONTENTS is nil.  INFO is a plist holding contextual information."
+  (when (plist-get info :with-latex)
+    (concat "$$\n"
+            (org-html-latex-environment latex-environment contents info)
+            "$$\n")))
+;;;; Latex Fragment
+(defun org-md-latex-fragment (latex-fragment contents info)
+  "Transcode a LATEX-FRAGMENT object from Org to Markdown.
+CONTENTS is nil.  INFO is a plist holding contextual information."
+  (when (plist-get info :with-latex)
+    (let ((frag (org-html-latex-fragment contents info)))
+      (cond
+       ((string-match-p "^\\\\(" frag)
+        (concat "$" (substring frag 2 -2) "$"))
+       ((string-match-p "^\\\\\\[" frag)
+        (concat "$$" (substring frag 2 -2) "$$"))
+       (t (message "unrecognised fragment: %s" frag)
+          frag)))))
 ;;;; Line Break
 (defun org-md-line-break (_line-break _contents _info)

             reply	other threads:[~2021-03-31 16:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31 16:41 Timothy [this message]
2021-03-31 20:59 ` Berry, Charles via General discussions about Org-mode.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ \
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:

AGPL code for this site: git clone