emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Timothy <tecosaur@gmail.com>
Cc: org-mode-email <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] Wrap LaTeX snippets in $$ with markdown export
Date: Mon, 03 May 2021 18:13:40 +0200	[thread overview]
Message-ID: <87lf8v7q2z.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87ft0bff7q.fsf@gmail.com> (Timothy's message of "Thu, 01 Apr 2021 00:41:29 +0800")

Hello,

Timothy <tecosaur@gmail.com> writes:

> 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.

This sounds reasonable.

> +(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")))

Nitpick: I would use `format', also the final newline character is
useless, since it will be removed later during the export process.

> +;;;; 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)))))

Nitpick: I suggest to use `rx' macro. It really makes the code base
a better place.

You are missing some cases. The fragment could be $...$ or $$...$$
already, so you can return it as-is without sending the message.

Otherwise, it is a macro. We can assume it lives outside math mode. So
maybe the "Unrecognized fragment: %S" is in order in that situation. We
could also let HTML export back-end deal with it. I don't know what is
better.

WDYT?

Regards,
-- 
Nicolas Goaziou


  parent reply	other threads:[~2021-05-03 16:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31 16:41 [PATCH] Wrap LaTeX snippets in $$ with markdown export Timothy
2021-03-31 20:59 ` Berry, Charles via General discussions about Org-mode.
2021-05-02 20:20   ` Timothy
2021-05-02 20:23 ` Timothy
2021-05-03 16:13 ` Nicolas Goaziou [this message]
2021-05-03 18:03   ` Timothy
2021-05-03 22:54     ` Nicolas Goaziou
2021-05-04  3:35       ` Timothy
2021-05-04 13:03         ` Nicolas Goaziou
2021-05-04 13:31           ` Timothy
2021-05-06 21:56             ` Nicolas Goaziou
2021-05-09 20:12               ` Timothy
2021-05-10 20:54                 ` Nicolas Goaziou

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=87lf8v7q2z.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=tecosaur@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).