From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id wA2mLFDBkGB5fgEAgWs5BA (envelope-from ) for ; Tue, 04 May 2021 05:36:48 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id GOZgKFDBkGCfbgAA1q6Kng (envelope-from ) for ; Tue, 04 May 2021 03:36:48 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id CB2039C96 for ; Tue, 4 May 2021 05:36:47 +0200 (CEST) Received: from localhost ([::1]:36596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldlra-0004pY-Vq for larch@yhetil.org; Mon, 03 May 2021 23:36:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldlq1-0004pS-Ti for emacs-orgmode@gnu.org; Mon, 03 May 2021 23:35:09 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:37878) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldlpz-000413-Tw for emacs-orgmode@gnu.org; Mon, 03 May 2021 23:35:09 -0400 Received: by mail-pf1-x42c.google.com with SMTP id b15so6074608pfl.4 for ; Mon, 03 May 2021 20:35:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:message-id :date:mime-version; bh=YTFY+ntLo8kC5SosQB0SFJUgvIHsCtGVrXBCWrFZCHg=; b=oVcFYgzANoClXhpgboAqN+qlRCSf0U7QmTe4/9Fw9zCymYP5eF1ToiAJfyzc7RHFfS Ttgzl6l8xfUDdrN+/sHryHjXq4Bjivkib4BhGzjTtRPOK9ECDXN3RI8vZgx294YkxpAE tIx2/tsCmuVmxUbuk/30q2Q9CR36UNc+7ZuXitWtWlfBHGaJE78K+Liza10mluA48ptT 0l8FYuO1czskrMkN3px5q04E9XvsmUqyy93rkg18WU1arQh2u5Fb0gl34ICk4da5cGE6 aAgBLBzzzwk1NEg+YT3pxVml6whKjCT2hb6M9I4xTbMx3orzYsoxgHjMhhsfgGBEyowW S+Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:message-id:date:mime-version; bh=YTFY+ntLo8kC5SosQB0SFJUgvIHsCtGVrXBCWrFZCHg=; b=sFhYozr/YxIwY0Ehauc1tnh3Q7Jiot+UioX1haDpCbhT0MibIVxjXueNcdWrp8d4RF gAFAaX1gQmnFra6TbNk3VwhVbnXJDD3En/ZcwakkKAWXYITHF5TFLDHQBsOuPnMpZ8X/ zyTtNDOZHnpozV9etLN+BMcVwuR53X00T28TDCP5n95g/MuNJ17CqE+Z8dfawIxunumY wSNU4gzL5uJOvYaZKle4PD/5o63OJF4ZOjX6SfhbKij3eDB2GNkFqmUXNgcq2cYOSeYH W9bw+9nfpLIEiYwIiuzeOX2uoYJJPsUo6Q0MXHmWKAAsJz2OseSLBg1A7OZyjk8EAhzV 9HjQ== X-Gm-Message-State: AOAM531QQDUh5TZqQ/agO1GdNRf6NM0INlhn+kI3wi1YM7c+yNdRNUbD LRsHpNmA+znkXIQxC36s1FWYTVYzeE0= X-Google-Smtp-Source: ABdhPJw0E/Y+o/HVHovIOpX3JgGWVaNkvEZl6UwCOV1SxObiLn45KmiN4qwFyW2dlTiMSxadkAhy7w== X-Received: by 2002:a62:2c46:0:b029:245:6391:b631 with SMTP id s67-20020a622c460000b02902456391b631mr21577959pfs.67.1620099306383; Mon, 03 May 2021 20:35:06 -0700 (PDT) Received: from localhost (180-150-91-8.b4965b.per.nbn.aussiebb.net. [180.150.91.8]) by smtp.gmail.com with ESMTPSA id j10sm10760278pff.69.2021.05.03.20.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 May 2021 20:35:05 -0700 (PDT) References: <87ft0bff7q.fsf@gmail.com> <87lf8v7q2z.fsf@nicolasgoaziou.fr> <87h7jjitkb.fsf@gmail.com> <87zgxb5syo.fsf@nicolasgoaziou.fr> User-agent: mu4e 1.4.15; emacs 28.0.50 From: Timothy To: Nicolas Goaziou Subject: Re: [PATCH] Wrap LaTeX snippets in $$ with markdown export In-reply-to: <87zgxb5syo.fsf@nicolasgoaziou.fr> Message-ID: <874kfjmasa.fsf@gmail.com> Date: Tue, 04 May 2021 11:35:01 +0800 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=tecosaur@gmail.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: org-mode-email Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1620099408; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=YTFY+ntLo8kC5SosQB0SFJUgvIHsCtGVrXBCWrFZCHg=; b=g65a1VC6EdECJOJFYvmVse/FKU4fNxdKbUc/SpzSZu/0oHRaMPdy963wtVk7aI8NniYLG6 RPPfJsTlKmUfKDQM1L0ScRZnhdXlw6Qv6DcVNQxVwcrc+ckLdjJFArt9SU0h+CFCxVTB5b NYbWJBRe6rEgAhLMIIQQmWZTmLJxVhgG9Mmr0lajRixNnAMDUUUxX6yWjukgHtioM4kCTc W+BRV22wekZuXgg4+UmzOLyoymRW6jAmwhz5BiBa/I5wLiTWmWGY3VCJH2K4W3vwjRsEqi 72ZFMu2BPmBUgD+K5wMpv7wFaAYr59qkGzGUI6CBBymTHCu9XA92Aus4KY3oQg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1620099408; a=rsa-sha256; cv=none; b=pWJrbKXqrmPrjeswpnkMjLOG7rhwiVJ2rg5nZjgnd63k36/XYTfl8k08kgiKIvyb7Baojw 5wj8UW1C1ZQbNxO19OTz1uHZqqE9+GRIpsuH8Ikw/wQj5VCVb4uMPZIxgIp56Q0ofqI1lJ OzQopSwioHRHyrHag/HOFoUej/l4fXRh4CxDa3rOpx6ruyvioH4C4BI3x2v3SSl2NqT0x8 7M784+AEZkFDCHIKwGkgHxvrR3BEhHOIWefwVSHyi9TE91T5D4CMUm9yHzVqRIoF/02wLr v8IeEsNGd/TE35Ll/GexOZhGGYSWPrm2FAIsCX6AVG+bOCt0qNaIc/FLD4Y5cQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=oVcFYgzA; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -2.16 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=oVcFYgzA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: CB2039C96 X-Spam-Score: -2.16 X-Migadu-Scanner: scn0.migadu.com X-TUID: MSQRH/XetpIt --=-=-= Content-Type: text/plain Hi Nicolas, So, I've now fixed the handling of already-$-delaminated fragments, and removed the $$ from around environments. Sorry to complicate things, but, looking at what the HTML fallback actually is, I've had some further thoughts. The HTML backend will either leave the content as-is, run `org-latex-to-html-convert-command', or run something from `org-preview-latex-process-alist' and include an . Should one want to convert LaTeX images say to an SVG for HTML export, I do not think one would want this behaviour to also apply to LaTeX being exported to markdown. As such I see two 'sensible' paths forward: (1) just include LaTeX verbatim when :with-latex is non-nil, or (2) introduce `org-markdown-with-latex' which can be set to t/'verbatim or 'html. In the attached patch, I've taken the first approach. Let me know if you'd like to take the second approach, or just inherit the HTML behaviour for LaTeX after all. -- Timothy --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ox-md-Use-TeX-style-math-wrapping.patch >From a02dbcb21dddb6d9239d13308a78a45738d9b7e6 Mon Sep 17 00:00:00 2001 From: Timothy Date: Thu, 1 Apr 2021 00:41:29 +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 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lisp/ox-md.el b/lisp/ox-md.el index b6b2c1728..1ae0cf2d9 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,35 @@ (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) + (let ((latex-frag (org-remove-indentation + (org-element-property :value latex-environment))) + (label (org-html--reference latex-environment info t))) + (if (org-string-nw-p label) + (replace-regexp-in-string "\\`.*" + (format "\\&\n\\\\label{%s}" label) + latex-frag) + latex-frag)))) + +;;;; 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-element-property :value latex-fragment))) + (cond + ((string-match-p "^\\\\(" frag) + (concat "$" (substring frag 2 -2) "$")) + ((string-match-p "^\\\\\\[" frag) + (concat "$$" (substring frag 2 -2) "$$")) + (t frag))))) ; either already $-deliminated or a macro + ;;;; Line Break (defun org-md-line-break (_line-break _contents _info) -- 2.31.1 --=-=-=--