emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* No mathematics in Texinfo exports
@ 2022-03-25  7:45 Rudolf Adamkovič
  2022-03-26 16:07 ` [PATCH] " Rudolf Adamkovič
  0 siblings, 1 reply; 21+ 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] 21+ 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; 21+ 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	[flat|nested] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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] 21+ 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; 21+ 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	[flat|nested] 21+ 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č
  0 siblings, 1 reply; 21+ 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] 21+ 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
  0 siblings, 1 reply; 21+ 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] 21+ 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; 21+ 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] 21+ messages in thread

end of thread, other threads:[~2022-06-25  5:55 UTC | newest]

Thread overview: 21+ 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

Code repositories for project(s) associated with this 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).