* No mathematics in Texinfo exports @ 2022-03-25 7:45 Rudolf Adamkovič 2022-03-26 16:07 ` [PATCH] " Rudolf Adamkovič 0 siblings, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-03-25 7:45 UTC (permalink / raw) To: emacs-orgmode; +Cc: mail Hello everyone! Today, I tried to export my notes from Org to Texinfo (and then HTML) and the result blew my mind. It produced a beautifully inter-linked website, similar to the glorious Emacs manual. Org also exported the citations in the correct format. I must say that I like the HTML output from Texinfo better than what the standard Org HTML exporter produces! But then, I found that the Texinfo exporter skips all mathematics, despite the fact that Texinfo uses the same language to encode it, namely (La)TeX and even MathJax for the HTML output (like Org does). Does anyone work on this, or do I have to tackle the problem myself? I would appreciate any tips. Rudy -- "Thinking is a momentary dismissal of irrelevancies." -- Richard Buckminster Fuller, 1969 Rudolf Adamkovic <salutis@me.com> [he/him] Studenohorska 25 84103 Bratislava Slovakia ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH] Re: No mathematics in Texinfo exports 2022-03-25 7:45 No mathematics in Texinfo exports Rudolf Adamkovič @ 2022-03-26 16:07 ` Rudolf Adamkovič 2022-04-20 20:14 ` Rudolf Adamkovič 0 siblings, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-03-26 16:07 UTC (permalink / raw) To: emacs-orgmode; +Cc: mail [-- Attachment #1: Type: text/plain, Size: 372 bytes --] Rudolf Adamkovič <salutis@me.com> writes: > […], or do I have to tackle the problem myself? I would appreciate > any tips. I pulled up my sleeves and added the functionality myself. See the attached patch. Please note that I have never contributed patches via mail, and I have never signed any FSF papers. I would appreciate your guidance. Thank you! [-- Attachment #2: A patch adding LaTeX to Texinfo exports --] [-- Type: text/x-patch, Size: 10846 bytes --] From 5fe65432c1a6440c86d0bbc0b66a6603e5a8f100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@me.com> Date: Sat, 26 Mar 2022 16:46:47 +0100 Subject: [PATCH] ox-texinfo: Include LaTeX in Texinfo exports * lisp/ox-texinfo.el (org-texinfo-latex-environment): New function. * lisp/ox-texinfo.el (org-texinfo-latex-fragment): New function. * lisp/ox-texinfo.el (texinfo): Set latex-environment. * lisp/ox-texinfo.el (texinfo): Set latex-fragment. * testing/lisp/test-ox-texinfo.el: Add basic tests. Include (La)TeX mathematics, both inline and display style, in Texinfo exports. --- lisp/ox-texinfo.el | 42 ++++++ testing/lisp/test-ox-texinfo.el | 221 ++++++++++++++++++++++++++++++++ 2 files changed, 263 insertions(+) create mode 100644 testing/lisp/test-ox-texinfo.el diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index a01bb268c..0bfd06550 100644 --- a/lisp/ox-texinfo.el +++ b/lisp/ox-texinfo.el @@ -55,6 +55,8 @@ (italic . org-texinfo-italic) (item . org-texinfo-item) (keyword . org-texinfo-keyword) + (latex-environment . org-texinfo-latex-environment) + (latex-fragment . org-texinfo-latex-fragment) (line-break . org-texinfo-line-break) (link . org-texinfo-link) (node-property . org-texinfo-node-property) @@ -1212,6 +1214,46 @@ CONTENTS is nil. INFO is a plist holding contextual information." (concat "@listoffloats " (org-export-translate "Listing" :utf-8 info)))))))) +;;;; LaTeX Environment + +(defun org-texinfo-latex-environment (environment _contents info) + "Transcode a LaTeX ENVIRONMENT from Org to Texinfo. CONTENTS is +nil. INFO is a plist holding contextual information." + (when (plist-get info :with-latex) + (let ((value (org-element-property :value environment))) + (string-join (list "@displaymath" + (string-trim (org-remove-indentation value)) + "@end displaymath") + "\n")))) + +;;;; LaTeX Fragment + +(defun org-texinfo-latex-fragment (fragment _contents info) + "Transcode a LaTeX FRAGMENT from Org to Texinfo. CONTENTS is +nil. INFO is a plist holding contextual information." + (when (plist-get info :with-latex) + (let ((value (org-remove-indentation + (org-element-property :value fragment)))) + (cond + ((or (string-match-p "^\\\\\\[" value) + (string-match-p "^\\$\\$" value)) + (concat "\n" + "@displaymath" + "\n" + (string-trim (substring value 2 -2)) + "\n" + "@end displaymath" + "\n")) + ((string-match-p "^\\$" value) + (concat "@math{" + (string-trim (substring value 1 -1)) + "}")) + ((string-match-p "^\\\\(" value) + (concat "@math{" + (string-trim (substring value 2 -2)) + "}")) + (t value))))) + ;;;; Line Break (defun org-texinfo-line-break (_line-break _contents _info) diff --git a/testing/lisp/test-ox-texinfo.el b/testing/lisp/test-ox-texinfo.el new file mode 100644 index 000000000..316b7cb1d --- /dev/null +++ b/testing/lisp/test-ox-texinfo.el @@ -0,0 +1,221 @@ +;;; test-ox-texinfo.el --- Tests for ox-texinfo.el + +;; Copyright (C) 2022 Rudolf Adamkovič + +;; Author: Rudolf Adamkovič <salutis@me.com> + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: + +(require 'cl-lib) +(require 'ox-texinfo) + +(unless (featurep 'ox-texinfo) + (signal 'missing-test-dependency "org-export-texinfo")) + +(ert-deftest test-org-export-texinfo/latex-fragment () + "Test `org-texinfo-latex-fragment' output." + + ;; inline TeX fragment + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "$a^2 = b$")) + nil + '(:with-latex t)))) + + ;; inline TeX fragment, padded + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "$ a^2 = b $")) + nil + '(:with-latex t)))) + + ;; inline LaTeX fragment + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "\\(a^2 = b\\)")) + nil + '(:with-latex t)))) + + ;; inline LaTeX fragment, padded + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "\\( a^2 = b \\)")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, inline + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "$$a ^ 2 = b$$")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, inline, padded + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "$$ a ^ 2 = b $$")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, multi-line + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "b ^ 2 = c" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list "$$" + "a ^ 2 = b" + "b ^ 2 = c" + "$$") + "\n"))) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, multi-line, indented + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "b ^ 2 = c" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list " $$" + " a ^ 2 = b" + " b ^ 2 = c" + " $$") + "\n"))) + nil + '(:with-latex t)))) + + ;; displayed LaTeX fragment, inline + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "\\[a ^ 2 = b\\]")) + nil + '(:with-latex t)))) + + ;; displayed LaTeX fragment, inline, padded + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "\\[ a ^ 2 = b \\]")) + nil + '(:with-latex t))))) + +(ert-deftest test-org-export-texinfo/latex-environment () + "Test `org-texinfo-latex-environment' output." + + ;; LaTeX environment + (should + (equal (string-join + (list "@displaymath" + "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}" + "@end displaymath") + "\n") + (org-texinfo-latex-environment + (org-element-create 'latex-environment + (list :value + (string-join + (list "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}") + "\n"))) + nil + '(:with-latex t)))) + + ;; LaTeX environment, indented + (should + (equal (string-join + (list "@displaymath" + "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}" + "@end displaymath") + "\n") + (org-texinfo-latex-environment + (org-element-create 'latex-environment + (list :value + (string-join + (list " \\begin{equation}" + " a ^ 2 = b" + " b ^ 2 = c" + " \\end{equation}") + "\n"))) + nil + '(:with-latex t))))) + +(provide 'test-ox-texinfo) +;;; test-ox-texinfo.el end here -- 2.35.1 [-- Attachment #3: Type: text/plain, Size: 308 bytes --] Rudy -- "'Contrariwise,' continued Tweedledee, 'if it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic.'" -- Lewis Carroll, Through the Looking Glass, 1871/1872 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-03-26 16:07 ` [PATCH] " Rudolf Adamkovič @ 2022-04-20 20:14 ` Rudolf Adamkovič 2022-04-21 6:11 ` Ihor Radchenko 0 siblings, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-04-20 20:14 UTC (permalink / raw) To: emacs-orgmode Hello everyone, My patch (from almost a month ago) has yet to appear at https://updates.orgmode.org Any ideas what to do? Could someone review it? Thank you! Rudy +++ The original message below. +++ Rudolf Adamkovič <salutis@me.com> writes: > Rudolf Adamkovič <salutis@me.com> writes: > >> […], or do I have to tackle the problem myself? I would appreciate >> any tips. > > I pulled up my sleeves and added the functionality myself. See the > attached patch. Please note that I have never contributed patches via > mail, and I have never signed any FSF papers. I would appreciate your > guidance. Thank you! > > From 5fe65432c1a6440c86d0bbc0b66a6603e5a8f100 Mon Sep 17 00:00:00 2001 > From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@me.com> > Date: Sat, 26 Mar 2022 16:46:47 +0100 > Subject: [PATCH] ox-texinfo: Include LaTeX in Texinfo exports > > * lisp/ox-texinfo.el (org-texinfo-latex-environment): New function. > * lisp/ox-texinfo.el (org-texinfo-latex-fragment): New function. > * lisp/ox-texinfo.el (texinfo): Set latex-environment. > * lisp/ox-texinfo.el (texinfo): Set latex-fragment. > * testing/lisp/test-ox-texinfo.el: Add basic tests. > > Include (La)TeX mathematics, both inline and display style, in Texinfo > exports. > --- > lisp/ox-texinfo.el | 42 ++++++ > testing/lisp/test-ox-texinfo.el | 221 ++++++++++++++++++++++++++++++++ > 2 files changed, 263 insertions(+) > create mode 100644 testing/lisp/test-ox-texinfo.el > > diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el > index a01bb268c..0bfd06550 100644 > --- a/lisp/ox-texinfo.el > +++ b/lisp/ox-texinfo.el > @@ -55,6 +55,8 @@ > (italic . org-texinfo-italic) > (item . org-texinfo-item) > (keyword . org-texinfo-keyword) > + (latex-environment . org-texinfo-latex-environment) > + (latex-fragment . org-texinfo-latex-fragment) > (line-break . org-texinfo-line-break) > (link . org-texinfo-link) > (node-property . org-texinfo-node-property) > @@ -1212,6 +1214,46 @@ CONTENTS is nil. INFO is a plist holding contextual information." > (concat "@listoffloats " > (org-export-translate "Listing" :utf-8 info)))))))) > > +;;;; LaTeX Environment > + > +(defun org-texinfo-latex-environment (environment _contents info) > + "Transcode a LaTeX ENVIRONMENT from Org to Texinfo. CONTENTS is > +nil. INFO is a plist holding contextual information." > + (when (plist-get info :with-latex) > + (let ((value (org-element-property :value environment))) > + (string-join (list "@displaymath" > + (string-trim (org-remove-indentation value)) > + "@end displaymath") > + "\n")))) > + > +;;;; LaTeX Fragment > + > +(defun org-texinfo-latex-fragment (fragment _contents info) > + "Transcode a LaTeX FRAGMENT from Org to Texinfo. CONTENTS is > +nil. INFO is a plist holding contextual information." > + (when (plist-get info :with-latex) > + (let ((value (org-remove-indentation > + (org-element-property :value fragment)))) > + (cond > + ((or (string-match-p "^\\\\\\[" value) > + (string-match-p "^\\$\\$" value)) > + (concat "\n" > + "@displaymath" > + "\n" > + (string-trim (substring value 2 -2)) > + "\n" > + "@end displaymath" > + "\n")) > + ((string-match-p "^\\$" value) > + (concat "@math{" > + (string-trim (substring value 1 -1)) > + "}")) > + ((string-match-p "^\\\\(" value) > + (concat "@math{" > + (string-trim (substring value 2 -2)) > + "}")) > + (t value))))) > + > ;;;; Line Break > > (defun org-texinfo-line-break (_line-break _contents _info) > diff --git a/testing/lisp/test-ox-texinfo.el b/testing/lisp/test-ox-texinfo.el > new file mode 100644 > index 000000000..316b7cb1d > --- /dev/null > +++ b/testing/lisp/test-ox-texinfo.el > @@ -0,0 +1,221 @@ > +;;; test-ox-texinfo.el --- Tests for ox-texinfo.el > + > +;; Copyright (C) 2022 Rudolf Adamkovič > + > +;; Author: Rudolf Adamkovič <salutis@me.com> > + > +;; This file is not part of GNU Emacs. > + > +;; This program is free software; you can redistribute it and/or modify > +;; it under the terms of the GNU General Public License as published by > +;; the Free Software Foundation, either version 3 of the License, or > +;; (at your option) any later version. > + > +;; This program is distributed in the hope that it will be useful, > +;; but WITHOUT ANY WARRANTY; without even the implied warranty of > +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +;; GNU General Public License for more details. > + > +;; You should have received a copy of the GNU General Public License > +;; along with this program. If not, see <https://www.gnu.org/licenses/>. > + > +;;; Code: > + > +(require 'cl-lib) > +(require 'ox-texinfo) > + > +(unless (featurep 'ox-texinfo) > + (signal 'missing-test-dependency "org-export-texinfo")) > + > +(ert-deftest test-org-export-texinfo/latex-fragment () > + "Test `org-texinfo-latex-fragment' output." > + > + ;; inline TeX fragment > + (should > + (equal "@math{a^2 = b}" > + (org-texinfo-latex-fragment > + (org-element-create 'latex-fragment > + '(:value "$a^2 = b$")) > + nil > + '(:with-latex t)))) > + > + ;; inline TeX fragment, padded > + (should > + (equal "@math{a^2 = b}" > + (org-texinfo-latex-fragment > + (org-element-create 'latex-fragment > + '(:value "$ a^2 = b $")) > + nil > + '(:with-latex t)))) > + > + ;; inline LaTeX fragment > + (should > + (equal "@math{a^2 = b}" > + (org-texinfo-latex-fragment > + (org-element-create 'latex-fragment > + '(:value "\\(a^2 = b\\)")) > + nil > + '(:with-latex t)))) > + > + ;; inline LaTeX fragment, padded > + (should > + (equal "@math{a^2 = b}" > + (org-texinfo-latex-fragment > + (org-element-create 'latex-fragment > + '(:value "\\( a^2 = b \\)")) > + nil > + '(:with-latex t)))) > + > + ;; displayed TeX fragment, inline > + (should > + (equal (string-join > + (list "" > + "@displaymath" > + "a ^ 2 = b" > + "@end displaymath" > + "") > + "\n") > + (org-texinfo-latex-fragment > + (org-element-create 'latex-fragment > + (list :value "$$a ^ 2 = b$$")) > + nil > + '(:with-latex t)))) > + > + ;; displayed TeX fragment, inline, padded > + (should > + (equal (string-join > + (list "" > + "@displaymath" > + "a ^ 2 = b" > + "@end displaymath" > + "") > + "\n") > + (org-texinfo-latex-fragment > + (org-element-create 'latex-fragment > + (list :value "$$ a ^ 2 = b $$")) > + nil > + '(:with-latex t)))) > + > + ;; displayed TeX fragment, multi-line > + (should > + (equal (string-join > + (list "" > + "@displaymath" > + "a ^ 2 = b" > + "b ^ 2 = c" > + "@end displaymath" > + "") > + "\n") > + (org-texinfo-latex-fragment > + (org-element-create 'latex-fragment > + (list :value > + (string-join > + (list "$$" > + "a ^ 2 = b" > + "b ^ 2 = c" > + "$$") > + "\n"))) > + nil > + '(:with-latex t)))) > + > + ;; displayed TeX fragment, multi-line, indented > + (should > + (equal (string-join > + (list "" > + "@displaymath" > + "a ^ 2 = b" > + "b ^ 2 = c" > + "@end displaymath" > + "") > + "\n") > + (org-texinfo-latex-fragment > + (org-element-create 'latex-fragment > + (list :value > + (string-join > + (list " $$" > + " a ^ 2 = b" > + " b ^ 2 = c" > + " $$") > + "\n"))) > + nil > + '(:with-latex t)))) > + > + ;; displayed LaTeX fragment, inline > + (should > + (equal (string-join > + (list "" > + "@displaymath" > + "a ^ 2 = b" > + "@end displaymath" > + "") > + "\n") > + (org-texinfo-latex-fragment > + (org-element-create 'latex-fragment > + (list :value "\\[a ^ 2 = b\\]")) > + nil > + '(:with-latex t)))) > + > + ;; displayed LaTeX fragment, inline, padded > + (should > + (equal (string-join > + (list "" > + "@displaymath" > + "a ^ 2 = b" > + "@end displaymath" > + "") > + "\n") > + (org-texinfo-latex-fragment > + (org-element-create 'latex-fragment > + (list :value "\\[ a ^ 2 = b \\]")) > + nil > + '(:with-latex t))))) > + > +(ert-deftest test-org-export-texinfo/latex-environment () > + "Test `org-texinfo-latex-environment' output." > + > + ;; LaTeX environment > + (should > + (equal (string-join > + (list "@displaymath" > + "\\begin{equation}" > + "a ^ 2 = b" > + "b ^ 2 = c" > + "\\end{equation}" > + "@end displaymath") > + "\n") > + (org-texinfo-latex-environment > + (org-element-create 'latex-environment > + (list :value > + (string-join > + (list "\\begin{equation}" > + "a ^ 2 = b" > + "b ^ 2 = c" > + "\\end{equation}") > + "\n"))) > + nil > + '(:with-latex t)))) > + > + ;; LaTeX environment, indented > + (should > + (equal (string-join > + (list "@displaymath" > + "\\begin{equation}" > + "a ^ 2 = b" > + "b ^ 2 = c" > + "\\end{equation}" > + "@end displaymath") > + "\n") > + (org-texinfo-latex-environment > + (org-element-create 'latex-environment > + (list :value > + (string-join > + (list " \\begin{equation}" > + " a ^ 2 = b" > + " b ^ 2 = c" > + " \\end{equation}") > + "\n"))) > + nil > + '(:with-latex t))))) > + > +(provide 'test-ox-texinfo) > +;;; test-ox-texinfo.el end here > -- > 2.35.1 > > > Rudy > -- > "'Contrariwise,' continued Tweedledee, 'if it was so, it might be; and > if it were so, it would be; but as it isn't, it ain't. That's logic.'" > -- Lewis Carroll, Through the Looking Glass, 1871/1872 > > Rudolf Adamkovič <salutis@me.com> [he/him] > Studenohorská 25 > 84103 Bratislava > Slovakia -- "It is no paradox to say that in our most theoretical moods we may be nearest to our most practical applications." -- Alfred North Whitehead, 1861-1947 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-04-20 20:14 ` Rudolf Adamkovič @ 2022-04-21 6:11 ` Ihor Radchenko 2022-04-21 7:31 ` Nicolas Goaziou 0 siblings, 1 reply; 26+ messages in thread From: Ihor Radchenko @ 2022-04-21 6:11 UTC (permalink / raw) To: Rudolf Adamkovič, Nicolas Goaziou; +Cc: emacs-orgmode Rudolf Adamkovič <salutis@me.com> writes: > My patch (from almost a month ago) has yet to appear at > > https://updates.orgmode.org This is strange. Marking the patch manually. In any case, thanks for your contribution and patience. > Any ideas what to do? Could someone review it? The idea sounds good and having tests is very good. Though I am not expert in texinfo. CC-ing Nicolas. He is the maintainer. A more general comment is rather about our org-element.el (maybe Nicolas can answer) > + (cond > + ((or (string-match-p "^\\\\\\[" value) > + (string-match-p "^\\$\\$" value)) > ... > + ((string-match-p "^\\$" value) > ... > + ((string-match-p "^\\\\(" value) Why don't we just have an extra element property with the bracket info in the output of org-element-latex-fragment-parser? > Please note that I have never contributed patches via mail, and I have > never signed any FSF papers. I would appreciate your guidance. See https://orgmode.org/worg/org-contribute.html#copyright Best, Ihor ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-04-21 6:11 ` Ihor Radchenko @ 2022-04-21 7:31 ` Nicolas Goaziou 2022-04-21 9:59 ` Ihor Radchenko 0 siblings, 1 reply; 26+ messages in thread From: Nicolas Goaziou @ 2022-04-21 7:31 UTC (permalink / raw) To: Ihor Radchenko; +Cc: emacs-orgmode, Rudolf Adamkovič Hello, Ihor Radchenko <yantar92@gmail.com> writes: > Rudolf Adamkovič <salutis@me.com> writes: > > The idea sounds good and having tests is very good. Though I am not > expert in texinfo. CC-ing Nicolas. He is the maintainer. My Texinfo 6.7 manual does not contain any reference to displaymath environment, which is used throughout the patch. Where is it coming from? > A more general comment is rather about our org-element.el (maybe Nicolas > can answer) > >> + (cond >> + ((or (string-match-p "^\\\\\\[" value) >> + (string-match-p "^\\$\\$" value)) >> ... >> + ((string-match-p "^\\$" value) >> ... >> + ((string-match-p "^\\\\(" value) > > Why don't we just have an extra element property with the bracket info > in the output of org-element-latex-fragment-parser? Because we didn't need it so far, as Org doesn't make a difference between the different markers. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-04-21 7:31 ` Nicolas Goaziou @ 2022-04-21 9:59 ` Ihor Radchenko 2022-04-21 11:20 ` Nicolas Goaziou 0 siblings, 1 reply; 26+ messages in thread From: Ihor Radchenko @ 2022-04-21 9:59 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: emacs-orgmode, Rudolf Adamkovič Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: >> Rudolf Adamkovič <salutis@me.com> writes: >> >> The idea sounds good and having tests is very good. Though I am not >> expert in texinfo. CC-ing Nicolas. He is the maintainer. > > My Texinfo 6.7 manual does not contain any reference to displaymath > environment, which is used throughout the patch. Where is it coming > from? I do see @displaymath in my TeXinfo 6.8. Also, https://www.gnu.org/software/texinfo/manual/texinfo/html_node/Inserting-Math.html >> Why don't we just have an extra element property with the bracket info >> in the output of org-element-latex-fragment-parser? > > Because we didn't need it so far, as Org doesn't make a difference > between the different markers. Fair point. I somehow assumed that knowing about latex fragment type is commonly needed in exporters. Grepping through the code revealed that it is not the case. Best, Ihor ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-04-21 9:59 ` Ihor Radchenko @ 2022-04-21 11:20 ` Nicolas Goaziou 2022-04-21 13:36 ` Ihor Radchenko 0 siblings, 1 reply; 26+ messages in thread From: Nicolas Goaziou @ 2022-04-21 11:20 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Rudolf Adamkovič, emacs-orgmode Ihor Radchenko <yantar92@gmail.com> writes: > Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: > >>> Rudolf Adamkovič <salutis@me.com> writes: >>> >>> The idea sounds good and having tests is very good. Though I am not >>> expert in texinfo. CC-ing Nicolas. He is the maintainer. >> >> My Texinfo 6.7 manual does not contain any reference to displaymath >> environment, which is used throughout the patch. Where is it coming >> from? > > I do see @displaymath in my TeXinfo 6.8. Also, > https://www.gnu.org/software/texinfo/manual/texinfo/html_node/Inserting-Math.html So it is a fairly recent addition, since Texinfo 6.8 was released last July. For example, it is not available in Debian stable. I don't know if displaymath was stealthily supported before. Anyway, AFAIU, we need FSF papers from Rudolf Adamkovič before processing. Regards, ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-04-21 11:20 ` Nicolas Goaziou @ 2022-04-21 13:36 ` Ihor Radchenko 2022-05-15 19:37 ` Rudolf Adamkovič 0 siblings, 1 reply; 26+ messages in thread From: Ihor Radchenko @ 2022-04-21 13:36 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: Rudolf Adamkovič, emacs-orgmode Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: >>> My Texinfo 6.7 manual does not contain any reference to displaymath >>> environment, which is used throughout the patch. Where is it coming >>> from? >> >> I do see @displaymath in my TeXinfo 6.8. Also, >> https://www.gnu.org/software/texinfo/manual/texinfo/html_node/Inserting-Math.html > > So it is a fairly recent addition, since Texinfo 6.8 was released last > July. For example, it is not available in Debian stable. I don't know if > displaymath was stealthily supported before. I see. Compatibility may indeed be an issue. However, I still believe that the feature may be useful for users aiming for newer TeXinfo. Maybe, this feature can be disabled by default unless the user explicitly customize some variable. > Anyway, AFAIU, we need FSF papers from Rudolf Adamkovič before > processing. Yeah. The patch is certainly over 15LOC. Rudolf Adamkovič, feel free to ask questions if you find the copyright assignment instructions unclear. Best, Ihor ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-04-21 13:36 ` Ihor Radchenko @ 2022-05-15 19:37 ` Rudolf Adamkovič 2022-05-16 2:17 ` Ihor Radchenko 0 siblings, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-05-15 19:37 UTC (permalink / raw) To: Ihor Radchenko, Nicolas Goaziou; +Cc: emacs-orgmode Ihor Radchenko <yantar92@gmail.com> writes: > Rudolf Adamkovič, feel free to ask questions if you find the copyright > assignment instructions unclear. I think I need help with the copyright assignment. On April 23, I sent a request to assign@gnu.org, and I have yet to receive a reply as of May 15. Rudy -- "Genius is 1% inspiration and 99% perspiration." -- Thomas Alva Edison, 1932 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-05-15 19:37 ` Rudolf Adamkovič @ 2022-05-16 2:17 ` Ihor Radchenko 2022-05-20 12:52 ` Rudolf Adamkovič 0 siblings, 1 reply; 26+ messages in thread From: Ihor Radchenko @ 2022-05-16 2:17 UTC (permalink / raw) To: Rudolf Adamkovič; +Cc: Nicolas Goaziou, emacs-orgmode Rudolf Adamkovič <salutis@me.com> writes: > Ihor Radchenko <yantar92@gmail.com> writes: > >> Rudolf Adamkovič, feel free to ask questions if you find the copyright >> assignment instructions unclear. > > I think I need help with the copyright assignment. On April 23, I sent a > request to assign@gnu.org, and I have yet to receive a reply as of May 15. Sorry for this delay. Then, can you send them a followup email reminder? If they do not reply within another week, we will contact FSF directly. Best, Ihor P.S. The precise procedure is the following as in https://www.gnu.org/prep/maintain/maintain.html >>> When the contributor emails the form to the FSF, the FSF sends per >>> an electronic (usually PDF) copy of the assignment. This, or >>> whatever response is required, should happen within five business >>> days of the initial request. If no reply from the FSF comes after >>> that time, please send a reminder. If there is still no response >>> after an additional week, please write to maintainers@gnu.org about >>> it. (the last thing is what I (or other Org maintainers) need to do). ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-05-16 2:17 ` Ihor Radchenko @ 2022-05-20 12:52 ` Rudolf Adamkovič 2022-05-23 11:30 ` Rudolf Adamkovič 0 siblings, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-05-20 12:52 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Nicolas Goaziou, emacs-orgmode Ihor Radchenko <yantar92@gmail.com> writes: > Sorry for this delay. Then, can you send them a followup email reminder? > If they do not reply within another week, we will contact FSF directly. Thank you. I sent a followup email just now, FYI. Rudy -- "Logic is a science of the necessary laws of thought, without which no employment of the understanding and the reason takes place." -- Immanuel Kant, 1785 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-05-20 12:52 ` Rudolf Adamkovič @ 2022-05-23 11:30 ` Rudolf Adamkovič 2022-05-23 11:37 ` Ihor Radchenko 0 siblings, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-05-23 11:30 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Nicolas Goaziou, emacs-orgmode Rudolf Adamkovič <salutis@me.com> writes: > Ihor Radchenko <yantar92@gmail.com> writes: > >> Sorry for this delay. Then, can you send them a followup email reminder? >> If they do not reply within another week, we will contact FSF directly. > > Thank you. I sent a followup email just now, FYI. FYI, I did receive a reply after the follow-up mail. I signed the papers and sent them back to FSF just now. I will revive the thread once FSF does its part. Hopefully, I will not wait for yet another (third) month. :) Rudy -- "Programming reliably -- must be an activity of an undeniably mathematical nature […] You see, mathematics is about thinking, and doing mathematics is always trying to think as well as possible." -- Edsger W. Dijkstra, 1981 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-05-23 11:30 ` Rudolf Adamkovič @ 2022-05-23 11:37 ` Ihor Radchenko 2022-05-27 7:04 ` Rudolf Adamkovič 0 siblings, 1 reply; 26+ messages in thread From: Ihor Radchenko @ 2022-05-23 11:37 UTC (permalink / raw) To: Rudolf Adamkovič; +Cc: Nicolas Goaziou, emacs-orgmode Rudolf Adamkovič <salutis@me.com> writes: > FYI, I did receive a reply after the follow-up mail. I signed the papers and > sent them back to FSF just now. I will revive the thread once FSF does its > part. Hopefully, I will not wait for yet another (third) month. :) Do not wait one month. Just 5 working days. Then, do not hesitate to follow up. Best, Ihor ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-05-23 11:37 ` Ihor Radchenko @ 2022-05-27 7:04 ` Rudolf Adamkovič 2022-05-28 2:42 ` Ihor Radchenko 0 siblings, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-05-27 7:04 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Nicolas Goaziou, emacs-orgmode Ihor Radchenko <yantar92@gmail.com> writes: > Do not wait one month. Just 5 working days. Then, do not hesitate to > follow up. And ... done! So, what happens next? Rudy -- "The whole science is nothing more than a refinement of everyday thinking." -- Albert Einstein, 1879-1955 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-05-27 7:04 ` Rudolf Adamkovič @ 2022-05-28 2:42 ` Ihor Radchenko 2022-06-05 9:08 ` Rudolf Adamkovič 0 siblings, 1 reply; 26+ messages in thread From: Ihor Radchenko @ 2022-05-28 2:42 UTC (permalink / raw) To: Rudolf Adamkovič; +Cc: Nicolas Goaziou, emacs-orgmode Rudolf Adamkovič <salutis@me.com> writes: > Ihor Radchenko <yantar92@gmail.com> writes: > >> Do not wait one month. Just 5 working days. Then, do not hesitate to >> follow up. > > And ... done! So, what happens next? We are back to the previous comments on the patch itself. You need to address the problem with older versions of texinfo. What will happen if one tries to open a document generated with your patch using old texinfo version? Will it render correctly? Best, Ihor ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-05-28 2:42 ` Ihor Radchenko @ 2022-06-05 9:08 ` Rudolf Adamkovič 2022-06-05 12:22 ` Ihor Radchenko 0 siblings, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-06-05 9:08 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Nicolas Goaziou, emacs-orgmode Ihor Radchenko <yantar92@gmail.com> writes: > We are back to the previous comments on the patch itself. You need to > address the problem with older versions of texinfo. What will happen > if one tries to open a document generated with your patch using old > texinfo version? Will it render correctly? I compiled Texinfo 6.7, tried it, and it indeed trips over math. So, do we declare a new Texinfo-specific "include math" variable that defaults to nil? I ask because we already have 'org-export-with-latex' which, when set to nil, results in math-less exports. The new variable would have the same effect, but just for Texinfo exports. Does that raise any red flags? Do you have any other thoughts? Thank you! Rudy -- "It is no paradox to say that in our most theoretical moods we may be nearest to our most practical applications." -- Alfred North Whitehead, 1861-1947 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-06-05 9:08 ` Rudolf Adamkovič @ 2022-06-05 12:22 ` Ihor Radchenko 2022-06-15 20:26 ` Rudolf Adamkovič 0 siblings, 1 reply; 26+ messages in thread From: Ihor Radchenko @ 2022-06-05 12:22 UTC (permalink / raw) To: Rudolf Adamkovič; +Cc: Nicolas Goaziou, emacs-orgmode Rudolf Adamkovič <salutis@me.com> writes: > Ihor Radchenko <yantar92@gmail.com> writes: > >> We are back to the previous comments on the patch itself. You need to >> address the problem with older versions of texinfo. What will happen >> if one tries to open a document generated with your patch using old >> texinfo version? Will it render correctly? > > I compiled Texinfo 6.7, tried it, and it indeed trips over math. So, do > we declare a new Texinfo-specific "include math" variable that defaults > to nil? I ask because we already have 'org-export-with-latex' which, > when set to nil, results in math-less exports. The new variable would > have the same effect, but just for Texinfo exports. Does that raise any > red flags? Do you have any other thoughts? Thank you! Sounds reasonable in general. `org-export-with-latex' is a global setting. I do not think that texinfo equivalent should be global. It should only be declared inside ox-texinfo. As for the default value, it would be better if the option were set depending on the installed Texinfo version. If the installed Texinfo supports math, set it to t. Otherwise, nil. Of course, users will be able to override the default as they wish. Best, Ihor ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-06-05 12:22 ` Ihor Radchenko @ 2022-06-15 20:26 ` Rudolf Adamkovič 2022-06-19 8:23 ` Ihor Radchenko 0 siblings, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-06-15 20:26 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Nicolas Goaziou, emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 1060 bytes --] Ihor Radchenko <yantar92@gmail.com> writes: > Sounds reasonable in general. Ihor, thank you for guiding me through the process! > `org-export-with-latex' is a global setting. I do not think that > texinfo equivalent should be global. It should only be declared inside > ox-texinfo. That makes perfect sense. Please see the new patch attached to this message. What do you think? > As for the default value, it would be better if the option were set > depending on the installed Texinfo version. If the installed Texinfo > supports math, set it to t. Otherwise, nil. Of course, users will be > able to override the default as they wish. I looked at both ox-texinfo.el and texinfo.el, and I found no function or variable that would give the installed Texinfo version. Do we pull the version from "makeinfo --version" and then parse it? If so, does that functionality belong to Org (ox-texinfo.el) or Emacs (texinfo.el) instead? I also wonder how we could test it so that it will not break. I would appreciate any ideas and/or pointers from you. Rudy [-- Attachment #2: 0001-ox-texinfo-Include-LaTeX-in-Texinfo-exports.patch --] [-- Type: text/x-patch, Size: 11934 bytes --] From 776b85955181709f440e55be56f8ad9d4211f931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@me.com> Date: Sat, 26 Mar 2022 16:46:47 +0100 Subject: [PATCH] ox-texinfo: Include LaTeX in Texinfo exports * lisp/ox-texinfo.el (org-texinfo-latex-environment): New function. * lisp/ox-texinfo.el (org-texinfo-latex-fragment): New function. * lisp/ox-texinfo.el (texinfo): Set latex-environment. * lisp/ox-texinfo.el (texinfo): Set latex-fragment. * testing/lisp/test-ox-texinfo.el: Add basic tests. Include (La)TeX mathematics, both inline and display style, in Texinfo exports. --- lisp/ox-texinfo.el | 57 +++++++- testing/lisp/test-ox-texinfo.el | 221 ++++++++++++++++++++++++++++++++ 2 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 testing/lisp/test-ox-texinfo.el diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index a01bb268c..d5bb75ce8 100644 --- a/lisp/ox-texinfo.el +++ b/lisp/ox-texinfo.el @@ -55,6 +55,8 @@ (italic . org-texinfo-italic) (item . org-texinfo-item) (keyword . org-texinfo-keyword) + (latex-environment . org-texinfo-latex-environment) + (latex-fragment . org-texinfo-latex-fragment) (line-break . org-texinfo-line-break) (link . org-texinfo-link) (node-property . org-texinfo-node-property) @@ -120,7 +122,9 @@ (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist) (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function) (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function) - (:texinfo-compact-itemx nil "compact-itemx" org-texinfo-compact-itemx))) + (:texinfo-compact-itemx nil "compact-itemx" org-texinfo-compact-itemx) + ;; Redefine regular options. + (:with-latex nil "tex" org-texinfo-with-latex))) \f ;;; User Configurable Variables @@ -355,6 +359,17 @@ The function should return the string to be exported." :group 'org-export-texinfo :type 'function) +;;;; LaTeX + +(defcustom org-texinfo-with-latex org-export-with-latex + "Non-nil means process LaTeX math snippets. + +When set, the exporter will process LaTeX environments and +fragments, using Texinfo \"@displaymath\" and \"@math\" commands, +respectively." + :group 'org-export-texinfo + :type 'boolean) + ;;;; Itemx (defcustom org-texinfo-compact-itemx nil @@ -1212,6 +1227,46 @@ CONTENTS is nil. INFO is a plist holding contextual information." (concat "@listoffloats " (org-export-translate "Listing" :utf-8 info)))))))) +;;;; LaTeX Environment + +(defun org-texinfo-latex-environment (environment _contents info) + "Transcode a LaTeX ENVIRONMENT from Org to Texinfo. CONTENTS is +nil. INFO is a plist holding contextual information." + (when (plist-get info :with-latex) + (let ((value (org-element-property :value environment))) + (string-join (list "@displaymath" + (string-trim (org-remove-indentation value)) + "@end displaymath") + "\n")))) + +;;;; LaTeX Fragment + +(defun org-texinfo-latex-fragment (fragment _contents info) + "Transcode a LaTeX FRAGMENT from Org to Texinfo. CONTENTS is +nil. INFO is a plist holding contextual information." + (when (plist-get info :with-latex) + (let ((value (org-remove-indentation + (org-element-property :value fragment)))) + (cond + ((or (string-match-p "^\\\\\\[" value) + (string-match-p "^\\$\\$" value)) + (concat "\n" + "@displaymath" + "\n" + (string-trim (substring value 2 -2)) + "\n" + "@end displaymath" + "\n")) + ((string-match-p "^\\$" value) + (concat "@math{" + (string-trim (substring value 1 -1)) + "}")) + ((string-match-p "^\\\\(" value) + (concat "@math{" + (string-trim (substring value 2 -2)) + "}")) + (t value))))) + ;;;; Line Break (defun org-texinfo-line-break (_line-break _contents _info) diff --git a/testing/lisp/test-ox-texinfo.el b/testing/lisp/test-ox-texinfo.el new file mode 100644 index 000000000..316b7cb1d --- /dev/null +++ b/testing/lisp/test-ox-texinfo.el @@ -0,0 +1,221 @@ +;;; test-ox-texinfo.el --- Tests for ox-texinfo.el + +;; Copyright (C) 2022 Rudolf Adamkovič + +;; Author: Rudolf Adamkovič <salutis@me.com> + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: + +(require 'cl-lib) +(require 'ox-texinfo) + +(unless (featurep 'ox-texinfo) + (signal 'missing-test-dependency "org-export-texinfo")) + +(ert-deftest test-org-export-texinfo/latex-fragment () + "Test `org-texinfo-latex-fragment' output." + + ;; inline TeX fragment + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "$a^2 = b$")) + nil + '(:with-latex t)))) + + ;; inline TeX fragment, padded + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "$ a^2 = b $")) + nil + '(:with-latex t)))) + + ;; inline LaTeX fragment + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "\\(a^2 = b\\)")) + nil + '(:with-latex t)))) + + ;; inline LaTeX fragment, padded + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "\\( a^2 = b \\)")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, inline + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "$$a ^ 2 = b$$")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, inline, padded + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "$$ a ^ 2 = b $$")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, multi-line + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "b ^ 2 = c" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list "$$" + "a ^ 2 = b" + "b ^ 2 = c" + "$$") + "\n"))) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, multi-line, indented + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "b ^ 2 = c" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list " $$" + " a ^ 2 = b" + " b ^ 2 = c" + " $$") + "\n"))) + nil + '(:with-latex t)))) + + ;; displayed LaTeX fragment, inline + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "\\[a ^ 2 = b\\]")) + nil + '(:with-latex t)))) + + ;; displayed LaTeX fragment, inline, padded + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "\\[ a ^ 2 = b \\]")) + nil + '(:with-latex t))))) + +(ert-deftest test-org-export-texinfo/latex-environment () + "Test `org-texinfo-latex-environment' output." + + ;; LaTeX environment + (should + (equal (string-join + (list "@displaymath" + "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}" + "@end displaymath") + "\n") + (org-texinfo-latex-environment + (org-element-create 'latex-environment + (list :value + (string-join + (list "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}") + "\n"))) + nil + '(:with-latex t)))) + + ;; LaTeX environment, indented + (should + (equal (string-join + (list "@displaymath" + "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}" + "@end displaymath") + "\n") + (org-texinfo-latex-environment + (org-element-create 'latex-environment + (list :value + (string-join + (list " \\begin{equation}" + " a ^ 2 = b" + " b ^ 2 = c" + " \\end{equation}") + "\n"))) + nil + '(:with-latex t))))) + +(provide 'test-ox-texinfo) +;;; test-ox-texinfo.el end here -- 2.36.1 [-- Attachment #3: Type: text/plain, Size: 300 bytes --] -- "Mathematics takes us still further from what is human into the region of absolute necessity, to which not only the actual world, but every possible world, must conform." -- Bertrand Russell, 1902 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-06-15 20:26 ` Rudolf Adamkovič @ 2022-06-19 8:23 ` Ihor Radchenko 2022-06-24 19:33 ` Rudolf Adamkovič 2022-08-14 19:28 ` Rudolf Adamkovič 0 siblings, 2 replies; 26+ messages in thread From: Ihor Radchenko @ 2022-06-19 8:23 UTC (permalink / raw) To: Rudolf Adamkovič; +Cc: Nicolas Goaziou, emacs-orgmode Rudolf Adamkovič <salutis@me.com> writes: >> `org-export-with-latex' is a global setting. I do not think that >> texinfo equivalent should be global. It should only be declared inside >> ox-texinfo. > > That makes perfect sense. Please see the new patch attached to this > message. What do you think? > - (:texinfo-compact-itemx nil "compact-itemx" org-texinfo-compact-itemx))) > + (:texinfo-compact-itemx nil "compact-itemx" org-texinfo-compact-itemx) > + ;; Redefine regular options. > + (:with-latex nil "tex" org-texinfo-with-latex))) Looks reasonable. >> As for the default value, it would be better if the option were set >> depending on the installed Texinfo version. If the installed Texinfo >> supports math, set it to t. Otherwise, nil. Of course, users will be >> able to override the default as they wish. > > I looked at both ox-texinfo.el and texinfo.el, and I found no function > or variable that would give the installed Texinfo version. > > Do we pull the version from "makeinfo --version" and then parse it? If > so, does that functionality belong to Org (ox-texinfo.el) or Emacs > (texinfo.el) instead? I also wonder how we could test it so that it > will not break. I would appreciate any ideas and/or pointers from you. First of all, checking version should probably be controlled by some customization. Especially when we export to .texi (which does not involve calling makeinfo), not to .info. This customization might be set to 'auto by default, making ox-texinfo check makeinfo version. Parsing version is probably the easiest way. Another alternative is trying to run makeinfo on a small test file with math environment and checking if it gets exported as expected. Best, Ihor ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-06-19 8:23 ` Ihor Radchenko @ 2022-06-24 19:33 ` Rudolf Adamkovič 2022-06-25 5:51 ` Ihor Radchenko 2022-08-14 19:28 ` Rudolf Adamkovič 1 sibling, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-06-24 19:33 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Nicolas Goaziou, emacs-orgmode Ihor Radchenko <yantar92@gmail.com> writes: > First of all, checking version should probably be controlled by some > customization. Especially when we export to .texi (which does not > involve calling makeinfo), not to .info. > > This customization might be set to 'auto by default, making ox-texinfo > check makeinfo version. > > Parsing version is probably the easiest way. Another alternative is > trying to run makeinfo on a small test file with math environment and > checking if it gets exported as expected. After thinking about this for a while, I realized I do not know when I will have the time to implement the proposed improvements. So I wonder, should we merge what we have, with the feature disabled by default using the existing customization variable? That way, some people can enable the feature today. Rudy -- "It is no paradox to say that in our most theoretical moods we may be nearest to our most practical applications." -- Alfred North Whitehead, 1861-1947 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-06-24 19:33 ` Rudolf Adamkovič @ 2022-06-25 5:51 ` Ihor Radchenko 0 siblings, 0 replies; 26+ messages in thread From: Ihor Radchenko @ 2022-06-25 5:51 UTC (permalink / raw) To: Rudolf Adamkovič; +Cc: Nicolas Goaziou, emacs-orgmode Rudolf Adamkovič <salutis@me.com> writes: > After thinking about this for a while, I realized I do not know when I > will have the time to implement the proposed improvements. So I wonder, > should we merge what we have, with the feature disabled by default using > the existing customization variable? That way, some people can enable > the feature today. The problem is that people may not know this feature exists and should be enabled. You still need to add NEWS entry (in any case) and manual entry (if the feature should be enabled manually). Best, Ihor ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-06-19 8:23 ` Ihor Radchenko 2022-06-24 19:33 ` Rudolf Adamkovič @ 2022-08-14 19:28 ` Rudolf Adamkovič 2022-08-19 4:48 ` Ihor Radchenko 1 sibling, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-08-14 19:28 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Nicolas Goaziou, emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 1608 bytes --] Ihor Radchenko <yantar92@gmail.com> writes: > Looks reasonable. Thank you for guiding me through, Ihor. I had some time today, so I pushed the envelope a bit further, hopefully in the right direction! > First of all, checking version should probably be controlled by some > customization. Especially when we export to .texi (which does not > involve calling makeinfo), not to .info. I could not figure out how to tell between the two kinds of export. My attempt, in 'org-texinfo-latex-environment': (message "filename1: %s" (plist-get info :output-file)) (message "filename2: %s" (plist-get info :texinfo-filename)) I always got the following, not matter what: filename1: test.texi filename2: nil > This customization might be set to 'auto by default, making ox-texinfo > check makeinfo version. We now set the customization to 'detect. If you think 'auto makes for a better name, for consistency or some other reason, please let me know. > Parsing version is probably the easiest way. Another alternative is > trying to run makeinfo on a small test file with math environment and > checking if it gets exported as expected. I went for the latter, see 'org-texinfo-supports-math-p' in the attached patch. Please take a look. [From the other thread:] > The problem is that people may not know this feature exists and should > be enabled. You still need to add NEWS entry (in any case) and manual > entry (if the feature should be enabled manually). I decided NOT to "chicken out", so I added just a NEWS entry, now that we attempt to auto-detect whether Texinfo supports math or not. Rudy [-- Attachment #2: 0001-ox-texinfo-Include-LaTeX-in-Texinfo-exports.patch --] [-- Type: text/x-patch, Size: 14274 bytes --] From e03b29319b602b0dea3c15604d711010bddaa3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@me.com> Date: Sat, 26 Mar 2022 16:46:47 +0100 Subject: [PATCH] ox-texinfo: Include LaTeX in Texinfo exports * lisp/ox-texinfo.el (org-texinfo-with-latex): New customize. * lisp/ox-texinfo.el (org-texinfo-latex-environment): New function. * lisp/ox-texinfo.el (org-texinfo-latex-fragment): New function. * lisp/ox-texinfo.el (org-texinfo-supports-math-p): New function. * lisp/ox-texinfo.el (texinfo): Set latex-environment. * lisp/ox-texinfo.el (texinfo): Set latex-fragment. * testing/lisp/test-ox-texinfo.el: Add basic tests. Include inline and display style (La)TeX mathematics in Texinfo exports. --- etc/ORG-NEWS | 1 + lisp/ox-texinfo.el | 86 ++++++++++++- testing/lisp/test-ox-texinfo.el | 221 ++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 testing/lisp/test-ox-texinfo.el diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 00fe101dc..52fa881f3 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -270,6 +270,7 @@ example, prints a sub-bibliography containing the book entries with =ai= among their keywords. +*** Support for LaTeX mathematics in Texinfo exports ** New options *** A new custom setting =org-hide-drawer-startup= to control initial folding state of drawers diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index 1eec586fd..a88224197 100644 --- a/lisp/ox-texinfo.el +++ b/lisp/ox-texinfo.el @@ -55,6 +55,8 @@ (italic . org-texinfo-italic) (item . org-texinfo-item) (keyword . org-texinfo-keyword) + (latex-environment . org-texinfo-latex-environment) + (latex-fragment . org-texinfo-latex-fragment) (line-break . org-texinfo-line-break) (link . org-texinfo-link) (node-property . org-texinfo-node-property) @@ -120,7 +122,9 @@ (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist) (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function) (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function) - (:texinfo-compact-itemx nil "compact-itemx" org-texinfo-compact-itemx))) + (:texinfo-compact-itemx nil "compact-itemx" org-texinfo-compact-itemx) + ;; Redefine regular options. + (:with-latex nil "tex" org-texinfo-with-latex))) \f ;;; User Configurable Variables @@ -355,6 +359,22 @@ The function should return the string to be exported." :group 'org-export-texinfo :type 'function) +;;;; LaTeX + +(defcustom org-texinfo-with-latex (and org-export-with-latex 'auto) + "If non-nil, the Texinfo exporter attempts to process LaTeX math. + +When set to t, the exporter always processes LaTeX environments +and fragments as Texinfo \"@displaymath\" and \"@math\" commands +respectively. Alternatively, when set to 'detect, the exporter +does so only if the installed version of Texinfo supports the +necessary commands." + :group 'org-export-texinfo + :type '(choice + (const :tag "Detect" detect) + (const :tag "Yes" t) + (const :tag "No" nil))) + ;;;; Itemx (defcustom org-texinfo-compact-itemx nil @@ -1212,6 +1232,52 @@ CONTENTS is nil. INFO is a plist holding contextual information." (concat "@listoffloats " (org-export-translate "Listing" :utf-8 info)))))))) +;;;; LaTeX Environment + +(defun org-texinfo-latex-environment (environment _contents info) + "Transcode a LaTeX ENVIRONMENT from Org to Texinfo. CONTENTS is +nil. INFO is a plist holding contextual information." + (let ((with-latex (plist-get info :with-latex))) + (when (or (eq with-latex t) + (and (eq with-latex 'detect) + (org-texinfo-supports-math-p))) + (let ((value (org-element-property :value environment))) + (string-join (list "@displaymath" + (string-trim (org-remove-indentation value)) + "@end displaymath") + "\n"))))) + +;;;; LaTeX Fragment + +(defun org-texinfo-latex-fragment (fragment _contents info) + "Transcode a LaTeX FRAGMENT from Org to Texinfo. CONTENTS is +nil. INFO is a plist holding contextual information." + (let ((with-latex (plist-get info :with-latex))) + (when (or (eq with-latex t) + (and (eq with-latex 'detect) + (org-texinfo-supports-math-p))) + (let ((value (org-remove-indentation + (org-element-property :value fragment)))) + (cond + ((or (string-match-p "^\\\\\\[" value) + (string-match-p "^\\$\\$" value)) + (concat "\n" + "@displaymath" + "\n" + (string-trim (substring value 2 -2)) + "\n" + "@end displaymath" + "\n")) + ((string-match-p "^\\$" value) + (concat "@math{" + (string-trim (substring value 1 -1)) + "}")) + ((string-match-p "^\\\\(" value) + (concat "@math{" + (string-trim (substring value 2 -2)) + "}")) + (t value)))))) + ;;;; Line Break (defun org-texinfo-line-break (_line-break _contents _info) @@ -1948,6 +2014,24 @@ Return INFO file name or an error if it couldn't be produced." (message "Process completed.") output)) +(defun org-texinfo-supports-math-p () + "Return t if the installed version of Texinfo supports \"@math\"." + (let ((math-example "1 + 1 = 2")) + (let* ((input-file (make-temp-file "test" nil ".info")) + (input-content (concat (format "@setfilename %s" input-file) "\n" + "@node Top" "\n" + (format "@math{%s}" math-example) "\n"))) + (with-temp-file input-file + (insert input-content)) + (let* ((output-file (org-texinfo-compile input-file)) + (output-content (with-temp-buffer + (insert-file-contents output-file) + (buffer-string)))) + (let ((result (string-match-p (regexp-quote math-example) + output-content))) + (delete-file input-file) + (delete-file output-file) + (if result t nil)))))) (provide 'ox-texinfo) diff --git a/testing/lisp/test-ox-texinfo.el b/testing/lisp/test-ox-texinfo.el new file mode 100644 index 000000000..316b7cb1d --- /dev/null +++ b/testing/lisp/test-ox-texinfo.el @@ -0,0 +1,221 @@ +;;; test-ox-texinfo.el --- Tests for ox-texinfo.el + +;; Copyright (C) 2022 Rudolf Adamkovič + +;; Author: Rudolf Adamkovič <salutis@me.com> + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: + +(require 'cl-lib) +(require 'ox-texinfo) + +(unless (featurep 'ox-texinfo) + (signal 'missing-test-dependency "org-export-texinfo")) + +(ert-deftest test-org-export-texinfo/latex-fragment () + "Test `org-texinfo-latex-fragment' output." + + ;; inline TeX fragment + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "$a^2 = b$")) + nil + '(:with-latex t)))) + + ;; inline TeX fragment, padded + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "$ a^2 = b $")) + nil + '(:with-latex t)))) + + ;; inline LaTeX fragment + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "\\(a^2 = b\\)")) + nil + '(:with-latex t)))) + + ;; inline LaTeX fragment, padded + (should + (equal "@math{a^2 = b}" + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "\\( a^2 = b \\)")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, inline + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "$$a ^ 2 = b$$")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, inline, padded + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "$$ a ^ 2 = b $$")) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, multi-line + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "b ^ 2 = c" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list "$$" + "a ^ 2 = b" + "b ^ 2 = c" + "$$") + "\n"))) + nil + '(:with-latex t)))) + + ;; displayed TeX fragment, multi-line, indented + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "b ^ 2 = c" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list " $$" + " a ^ 2 = b" + " b ^ 2 = c" + " $$") + "\n"))) + nil + '(:with-latex t)))) + + ;; displayed LaTeX fragment, inline + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "\\[a ^ 2 = b\\]")) + nil + '(:with-latex t)))) + + ;; displayed LaTeX fragment, inline, padded + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "\\[ a ^ 2 = b \\]")) + nil + '(:with-latex t))))) + +(ert-deftest test-org-export-texinfo/latex-environment () + "Test `org-texinfo-latex-environment' output." + + ;; LaTeX environment + (should + (equal (string-join + (list "@displaymath" + "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}" + "@end displaymath") + "\n") + (org-texinfo-latex-environment + (org-element-create 'latex-environment + (list :value + (string-join + (list "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}") + "\n"))) + nil + '(:with-latex t)))) + + ;; LaTeX environment, indented + (should + (equal (string-join + (list "@displaymath" + "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}" + "@end displaymath") + "\n") + (org-texinfo-latex-environment + (org-element-create 'latex-environment + (list :value + (string-join + (list " \\begin{equation}" + " a ^ 2 = b" + " b ^ 2 = c" + " \\end{equation}") + "\n"))) + nil + '(:with-latex t))))) + +(provide 'test-ox-texinfo) +;;; test-ox-texinfo.el end here -- 2.37.1 [-- Attachment #3: Type: text/plain, Size: 178 bytes --] -- "Genius is 1% inspiration and 99% perspiration." -- Thomas Alva Edison, 1932 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-08-14 19:28 ` Rudolf Adamkovič @ 2022-08-19 4:48 ` Ihor Radchenko 2022-09-16 21:50 ` Rudolf Adamkovič 0 siblings, 1 reply; 26+ messages in thread From: Ihor Radchenko @ 2022-08-19 4:48 UTC (permalink / raw) To: Rudolf Adamkovič; +Cc: Nicolas Goaziou, emacs-orgmode Rudolf Adamkovič <salutis@me.com> writes: >> First of all, checking version should probably be controlled by some >> customization. Especially when we export to .texi (which does not >> involve calling makeinfo), not to .info. > > I could not figure out how to tell between the two kinds of export. > > My attempt, in 'org-texinfo-latex-environment': > > (message "filename1: %s" (plist-get info :output-file)) > (message "filename2: %s" (plist-get info :texinfo-filename)) > > I always got the following, not matter what: > > filename1: test.texi > filename2: nil I did not mean that the behaviour should necessarily be different. In any case, you cannot really distinguish this easily. The difference between info and texinfo exports is simply in the arguments to org-export-to-file. When exporting to info, the normal texinfo export is post-processed using org-texinfo-compile. See org-texinfo-export-to-info and org-texinfo-export-to-texinfo. >> This customization might be set to 'auto by default, making ox-texinfo >> check makeinfo version. > > We now set the customization to 'detect. If you think 'auto makes for a > better name, for consistency or some other reason, please let me know. 'detect is OK. > --- a/etc/ORG-NEWS > +++ b/etc/ORG-NEWS > @@ -270,6 +270,7 @@ example, > > prints a sub-bibliography containing the book entries with =ai= among > their keywords. > +*** Support for LaTeX mathematics in Texinfo exports Please provide a bit mode info here. At least, mention the new customization and its default value. > +(defcustom org-texinfo-with-latex (and org-export-with-latex 'auto) I guess that you meant (and org-export-with-latex 'detect). > + "If non-nil, the Texinfo exporter attempts to process LaTeX math. > + > +When set to t, the exporter always processes LaTeX environments > +and fragments as Texinfo \"@displaymath\" and \"@math\" commands > +respectively. Alternatively, when set to 'detect, the exporter 'detect will trigger unescaped quote warning in Emacs 29. Use `detect'. > +(defun org-texinfo-latex-environment (environment _contents info) > + "Transcode a LaTeX ENVIRONMENT from Org to Texinfo. CONTENTS is > +nil. INFO is a plist holding contextual information." > +(defun org-texinfo-latex-fragment (fragment _contents info) > + "Transcode a LaTeX FRAGMENT from Org to Texinfo. CONTENTS is > +nil. INFO is a plist holding contextual information." Please Use a single sentence at the first line of the docstring. "CONTENTS is nil" is misleading. If you want to mention CONTENTS argument at all, just say that it is ignored. > +(defun org-texinfo-supports-math-p () > + "Return t if the installed version of Texinfo supports \"@math\"." This function may be called frequently. Its value should better be cached. We really only need to calculate it once per Emacs session and store in some variable. > + ;; inline TeX fragment Please use full sentences in comments. Start sentences with capitalized words and end with ".". > + (should > + (equal "@math{a^2 = b}" > + (org-texinfo-latex-fragment > + (org-element-create 'latex-fragment > + '(:value "$a^2 = b$")) > + nil > + '(:with-latex t)))) Please note that the test results may depend on the installed texinfo version. Please guard the tests with (let ((org-texinfo-with-latex t)) ...) -- Ihor Radchenko, Org mode contributor, Learn more about Org mode at https://orgmode.org/. Support Org development at https://liberapay.com/org-mode, or support my work at https://liberapay.com/yantar92 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-08-19 4:48 ` Ihor Radchenko @ 2022-09-16 21:50 ` Rudolf Adamkovič 2022-09-21 7:33 ` Ihor Radchenko 0 siblings, 1 reply; 26+ messages in thread From: Rudolf Adamkovič @ 2022-09-16 21:50 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Nicolas Goaziou, emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 310 bytes --] Ihor Radchenko <yantar92@gmail.com> writes: > [snip] Please see the attached patch where I attempt to fix every issue you pointed out. I also split the tests into smaller functions for better maintainability. Please, let me know what you think about my latest attempt. Thank you for your guidance! Rudy [-- Attachment #2: 0001-ox-texinfo-Include-LaTeX-in-Texinfo-exports.patch --] [-- Type: text/x-patch, Size: 18397 bytes --] From dd07f22269f64bb2c688853543e137355178c2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@me.com> Date: Sat, 26 Mar 2022 16:46:47 +0100 Subject: [PATCH] ox-texinfo: Include LaTeX in Texinfo exports * lisp/ox-texinfo.el (org-texinfo-with-latex): New customize. * lisp/ox-texinfo.el (org-texinfo-latex-environment): New function. * lisp/ox-texinfo.el (org-texinfo-latex-fragment): New function. * lisp/ox-texinfo.el (org-texinfo-supports-math-p): New function. * lisp/ox-texinfo.el (org-texinfo-supports-math--cache): New variable. * lisp/ox-texinfo.el (texinfo): Set latex-environment. * lisp/ox-texinfo.el (texinfo): Set latex-fragment. * testing/lisp/test-ox-texinfo.el: Add basic tests. --- etc/ORG-NEWS | 7 + lisp/ox-texinfo.el | 95 +++++++++- testing/lisp/test-ox-texinfo.el | 296 ++++++++++++++++++++++++++++++++ 3 files changed, 396 insertions(+), 2 deletions(-) create mode 100644 testing/lisp/test-ox-texinfo.el diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index a7f32671e..e51bb6233 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -489,6 +489,13 @@ support in LaTeX. The new =babel= syntax for loading languages via =ini= files and the new command =\babelprovide= (see: https://mirrors.ctan.org/macros/latex/required/babel/base/babel.pdf) are also supported. +*** Texinfo exports include LaTeX + +With the new customization option ~org-texinfo-with-latex~ set to (its +default value) ~'detect~, if the system runs Texinfo 6.8 (3 July 2021) +or newer, Org will export all LaTeX fragments and environments using +Texinfo ~@math~ and ~@displaymath~ commands respectively. + * Version 9.5 ** Important announcements and breaking changes diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index 623c1632c..a2959d027 100644 --- a/lisp/ox-texinfo.el +++ b/lisp/ox-texinfo.el @@ -33,7 +33,7 @@ (require 'ox) (defvar orgtbl-exp-regexp) - +(defvar org-texinfo-supports-math--cache) \f ;;; Define Back-End @@ -58,6 +58,8 @@ (italic . org-texinfo-italic) (item . org-texinfo-item) (keyword . org-texinfo-keyword) + (latex-environment . org-texinfo-latex-environment) + (latex-fragment . org-texinfo-latex-fragment) (line-break . org-texinfo-line-break) (link . org-texinfo-link) (node-property . org-texinfo-node-property) @@ -123,7 +125,9 @@ (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist) (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function) (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function) - (:texinfo-compact-itemx nil "compact-itemx" org-texinfo-compact-itemx))) + (:texinfo-compact-itemx nil "compact-itemx" org-texinfo-compact-itemx) + ;; Redefine regular options. + (:with-latex nil "tex" org-texinfo-with-latex))) \f ;;; User Configurable Variables @@ -358,6 +362,22 @@ The function should return the string to be exported." :group 'org-export-texinfo :type 'function) +;;;; LaTeX + +(defcustom org-texinfo-with-latex (and org-export-with-latex 'detect) + "If non-nil, the Texinfo exporter attempts to process LaTeX math. + +When set to t, the exporter will process LaTeX environments and +fragments as Texinfo \"@displaymath\" and \"@math\" commands +respectively. Alternatively, when set to `detect', the exporter +does so only if the installed version of Texinfo supports the +necessary commands." + :group 'org-export-texinfo + :type '(choice + (const :tag "Detect" detect) + (const :tag "Yes" t) + (const :tag "No" nil))) + ;;;; Itemx (defcustom org-texinfo-compact-itemx nil @@ -1215,6 +1235,52 @@ CONTENTS is nil. INFO is a plist holding contextual information." (concat "@listoffloats " (org-export-translate "Listing" :utf-8 info)))))))) +;;;; LaTeX Environment + +(defun org-texinfo-latex-environment (environment _contents info) + "Transcode a LaTeX ENVIRONMENT from Org to Texinfo. CONTENTS is +nil. INFO is a plist holding contextual information." + (let ((with-latex (plist-get info :with-latex))) + (when (or (eq with-latex t) + (and (eq with-latex 'detect) + (org-texinfo-supports-math-p))) + (let ((value (org-element-property :value environment))) + (string-join (list "@displaymath" + (string-trim (org-remove-indentation value)) + "@end displaymath") + "\n"))))) + +;;;; LaTeX Fragment + +(defun org-texinfo-latex-fragment (fragment _contents info) + "Transcode a LaTeX FRAGMENT from Org to Texinfo. +INFO is a plist holding contextual information." + (let ((with-latex (plist-get info :with-latex))) + (when (or (eq with-latex t) + (and (eq with-latex 'detect) + (org-texinfo-supports-math-p))) + (let ((value (org-remove-indentation + (org-element-property :value fragment)))) + (cond + ((or (string-match-p "^\\\\\\[" value) + (string-match-p "^\\$\\$" value)) + (concat "\n" + "@displaymath" + "\n" + (string-trim (substring value 2 -2)) + "\n" + "@end displaymath" + "\n")) + ((string-match-p "^\\$" value) + (concat "@math{" + (string-trim (substring value 1 -1)) + "}")) + ((string-match-p "^\\\\(" value) + (concat "@math{" + (string-trim (substring value 2 -2)) + "}")) + (t value)))))) + ;;;; Line Break (defun org-texinfo-line-break (_line-break _contents _info) @@ -1951,6 +2017,31 @@ Return INFO file name or an error if it couldn't be produced." (message "Process completed.") output)) +(defun org-texinfo-supports-math-p () + "Return t if the installed version of Texinfo supports \"@math\". + +Once computed, the results remains cached." + (unless (boundp 'org-texinfo-supports-math--cache) + (setq org-texinfo-supports-math--cache + (let ((math-example "1 + 1 = 2")) + (let* ((input-file + (make-temp-file "test" nil ".info")) + (input-content + (concat (format "@setfilename %s" input-file) "\n" + "@node Top" "\n" + (format "@displaymath{%s}" math-example) "\n"))) + (with-temp-file input-file + (insert input-content)) + (let* ((output-file (org-texinfo-compile input-file)) + (output-content (with-temp-buffer + (insert-file-contents output-file) + (buffer-string)))) + (let ((result (string-match-p (regexp-quote math-example) + output-content))) + (delete-file input-file) + (delete-file output-file) + (if result t nil))))))) + org-texinfo-supports-math--cache) (provide 'ox-texinfo) diff --git a/testing/lisp/test-ox-texinfo.el b/testing/lisp/test-ox-texinfo.el new file mode 100644 index 000000000..51fdb3606 --- /dev/null +++ b/testing/lisp/test-ox-texinfo.el @@ -0,0 +1,296 @@ +;;; test-ox-texinfo.el --- Tests for ox-texinfo.el + +;; Copyright (C) 2022 Rudolf Adamkovič + +;; Author: Rudolf Adamkovič <salutis@me.com> + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: + +(require 'cl-lib) +(require 'ox-texinfo) + +(unless (featurep 'ox-texinfo) + (signal 'missing-test-dependency "org-export-texinfo")) + +\f +;;; TeX fragments + +(ert-deftest test-ox-texinfo/tex-fragment-inline () + "Test inline TeX fragment." + (should + (equal "@math{a^2 = b}" + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "$a^2 = b$")) + nil + '(:with-latex t)))))) + +(ert-deftest test-ox-texinfo/tex-fragment-inline-padded () + "Test inline TeX fragment padded with whitespace." + (should + (equal "@math{a^2 = b}" + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "$ a^2 = b $")) + nil + '(:with-latex t)))))) + +(ert-deftest test-ox-texinfo/tex-fragment-displayed () + "Test displayed TeX fragment." + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "$$a ^ 2 = b$$")) + nil + '(:with-latex t)))))) + +(ert-deftest test-ox-texinfo/tex-fragment-displayed-padded () + "Test displayed TeX fragment padded with whitespace." + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "$$ a ^ 2 = b $$")) + nil + '(:with-latex t)))))) + +(ert-deftest test-ox-texinfo/tex-fragment-displayed-multi-line () + "Test displayed TeX fragment with multiple lines." + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "b ^ 2 = c" + "@end displaymath" + "") + "\n") + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list "$$" + "a ^ 2 = b" + "b ^ 2 = c" + "$$") + "\n"))) + nil + '(:with-latex t)))))) + +(ert-deftest test-ox-texinfo/tex-fragment-displayed-indented () + "Test displayed TeX fragment with indentation." + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "b ^ 2 = c" + "@end displaymath" + "") + "\n") + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list " $$" + " a ^ 2 = b" + " b ^ 2 = c" + " $$") + "\n"))) + nil + '(:with-latex t)))))) + +\f +;;; LaTeX fragments + +(ert-deftest test-ox-texinfo/latex-fragment-inline () + "Test inline LaTeX fragment." + (should + (equal "@math{a^2 = b}" + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "\\(a^2 = b\\)")) + nil + '(:with-latex t)))))) + +(ert-deftest test-ox-texinfo/latex-fragment-inline-padded () + "Test inline LaTeX fragment padded with whitespace." + (should + (equal "@math{a^2 = b}" + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + '(:value "\\( a^2 = b \\)")) + nil + '(:with-latex t)))))) + +(ert-deftest test-ox-texinfo/latex-fragment-displayed () + "Test displayed LaTeX fragment." + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "\\[a ^ 2 = b\\]")) + nil + '(:with-latex t)))))) + +(ert-deftest test-ox-texinfo/latex-fragment-displayed-padded () + "Test displayed LaTeX fragment with multiple lines." + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "@end displaymath" + "") + "\n") + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value "\\[ a ^ 2 = b \\]")) + nil + '(:with-latex t)))))) + +(ert-deftest test-ox-texinfo/latex-fragment-displayed-multi-line () + "Test displayed LaTeX fragment with multiple lines." + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "b ^ 2 = c" + "@end displaymath" + "") + "\n") + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list "\\[" + "a ^ 2 = b" + "b ^ 2 = c" + "\\]") + "\n"))) + nil + '(:with-latex t)))))) + +(ert-deftest test-ox-texinfo/latex-fragment-displayed-indented () + "Test displayed LaTeX fragment with indentation." + (should + (equal (string-join + (list "" + "@displaymath" + "a ^ 2 = b" + "b ^ 2 = c" + "@end displaymath" + "") + "\n") + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-fragment + (org-element-create 'latex-fragment + (list :value + (string-join + (list " \\[" + " a ^ 2 = b" + " b ^ 2 = c" + " \\]") + "\n"))) + nil + '(:with-latex t)))))) + +\f +;;; LaTeX environments + +(ert-deftest test-ox-texinfo/latex-environment () + "Test LaTeX environment." + (should + (equal (string-join + (list "@displaymath" + "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}" + "@end displaymath") + "\n") + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-environment + (org-element-create 'latex-environment + (list :value + (string-join + (list "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}") + "\n"))) + nil + '(:with-latex t)))))) + +(ert-deftest test-ox-texinfo/latex-environment-indented () + "Test LaTeX environment with indentation." + (should + (equal (string-join + (list "@displaymath" + "\\begin{equation}" + "a ^ 2 = b" + "b ^ 2 = c" + "\\end{equation}" + "@end displaymath") + "\n") + (let ((org-texinfo-with-latex t)) + (org-texinfo-latex-environment + (org-element-create 'latex-environment + (list :value + (string-join + (list " \\begin{equation}" + " a ^ 2 = b" + " b ^ 2 = c" + " \\end{equation}") + "\n"))) + nil + '(:with-latex t)))))) + +(provide 'test-ox-texinfo) +;;; test-ox-texinfo.el end here -- 2.37.3 [-- Attachment #3: Type: text/plain, Size: 174 bytes --] -- "Simplicity is complexity resolved." -- Constantin Brâncuși, 1876-1957 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-09-16 21:50 ` Rudolf Adamkovič @ 2022-09-21 7:33 ` Ihor Radchenko 2022-09-21 20:36 ` Rudolf Adamkovič 0 siblings, 1 reply; 26+ messages in thread From: Ihor Radchenko @ 2022-09-21 7:33 UTC (permalink / raw) To: Rudolf Adamkovič; +Cc: Nicolas Goaziou, emacs-orgmode Rudolf Adamkovič <salutis@me.com> writes: > Please see the attached patch where I attempt to fix every issue you > pointed out. I also split the tests into smaller functions for better > maintainability. Please, let me know what you think about my latest > attempt. Thank you for your guidance! Applied onto main with minor amendments. Thanks for your contribution! https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=c940b460c7bb31e98089286a5a45306cc27034cc -- Ihor Radchenko, Org mode contributor, Learn more about Org mode at https://orgmode.org/. Support Org development at https://liberapay.com/org-mode, or support my work at https://liberapay.com/yantar92 ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH] Re: No mathematics in Texinfo exports 2022-09-21 7:33 ` Ihor Radchenko @ 2022-09-21 20:36 ` Rudolf Adamkovič 0 siblings, 0 replies; 26+ messages in thread From: Rudolf Adamkovič @ 2022-09-21 20:36 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Nicolas Goaziou, emacs-orgmode Ihor Radchenko <yantar92@gmail.com> writes: > Applied onto main with minor amendments. Amazing! Thank you so much for guiding me through. Rudy -- "It is no paradox to say that in our most theoretical moods we may be nearest to our most practical applications." -- Alfred North Whitehead, 1861-1947 Rudolf Adamkovič <salutis@me.com> [he/him] Studenohorská 25 84103 Bratislava Slovakia ^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2022-09-21 20:37 UTC | newest] Thread overview: 26+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-03-25 7:45 No mathematics in Texinfo exports Rudolf Adamkovič 2022-03-26 16:07 ` [PATCH] " Rudolf Adamkovič 2022-04-20 20:14 ` Rudolf Adamkovič 2022-04-21 6:11 ` Ihor Radchenko 2022-04-21 7:31 ` Nicolas Goaziou 2022-04-21 9:59 ` Ihor Radchenko 2022-04-21 11:20 ` Nicolas Goaziou 2022-04-21 13:36 ` Ihor Radchenko 2022-05-15 19:37 ` Rudolf Adamkovič 2022-05-16 2:17 ` Ihor Radchenko 2022-05-20 12:52 ` Rudolf Adamkovič 2022-05-23 11:30 ` Rudolf Adamkovič 2022-05-23 11:37 ` Ihor Radchenko 2022-05-27 7:04 ` Rudolf Adamkovič 2022-05-28 2:42 ` Ihor Radchenko 2022-06-05 9:08 ` Rudolf Adamkovič 2022-06-05 12:22 ` Ihor Radchenko 2022-06-15 20:26 ` Rudolf Adamkovič 2022-06-19 8:23 ` Ihor Radchenko 2022-06-24 19:33 ` Rudolf Adamkovič 2022-06-25 5:51 ` Ihor Radchenko 2022-08-14 19:28 ` Rudolf Adamkovič 2022-08-19 4:48 ` Ihor Radchenko 2022-09-16 21:50 ` Rudolf Adamkovič 2022-09-21 7:33 ` Ihor Radchenko 2022-09-21 20:36 ` Rudolf Adamkovič
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).