emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Vitus Schäfftlein" <vitusschaefftlein@live.de>
To: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Cc: "thibault.marin@gmx.com" <thibault.marin@gmx.com>
Subject: ox-html: exporting LaTeX-environments
Date: Mon, 11 Apr 2022 19:38:13 +0000	[thread overview]
Message-ID: <AM0PR04MB564988345CDA0E3275F65BBDA8EA9@AM0PR04MB5649.eurprd04.prod.outlook.com> (raw)

Dear org-mode mailing list,

first of all I want to express my appreciation for your work and the efforts you put into getting
org-mode together! You guys are awesome.

I’m writing to you because I am setting up my blog, for which I need
fully-fledged LaTeX support, so I am inserting my code via svg images. There are quite some
problems to get it working, though, and I am giving my best to try and report the issues I found.
All of them regard ox-html. Most of what I wrrite can be found in this github discussion: 
https://github.com/kaushalmodi/ox-hugo/discussions/618.

1. The current code in ox-html does not support equation numbers in parentheses. If you add

span.equation-label:before {
    content: '(';
}

span.equation-label:after {
    content: ')';
}

to your css file, strings of the form ( no ) are produced instead of strings of the form (no); for
example, you get ( 1 ) instead of (1).

2. Any environment (except in-line-math) gets an equation number. But some environments
 should not have (html) equation numbers, like tcolorbox.
3. Any LaTeX environment name foo is changed to foo* (except it already ends with an
 asterisk). For example, \begin{tabular} is changed to \begin{tabular*}; same for
 \end{tabular}. But tabular* differs from tabular in needing an extra width-argument, so
 the export won’t work properly.

I have put quite some elbow-grease into possible solutions, which I would like to share with you.
I am an emacs lisp beginner with background only in philosophical logic, so bear with me.

Changing (1) is simple. org-html--wrap-latex-environment produces the html span class
equation-label, where the equation number is then inserted. Specifically, it adds this string:

"\n<span class=\"equation-label\">\n%s\n</span>"

Now the newline commands \n before and after %s are exported as whitespace. Just replacing
\n%s\n by %s (that is, leaving the newlines out) solves the problem. HTML ignores newlines
anyway.

Changing (2) seems to be doable, too, and I think I know how to do it in theory:

1 Create a new variable ox-html-latex-environments-no-number of the form ("foo"
 "bar" "baz" ...), which contains all environments that should not receive equation
 numbers.
2 Change org-html--latex-environment-numbered-p. It is currently defined like this:

(defun org-html--latex-environment-numbered-p (element)
  "Non-nil when ELEMENT contains a numbered LaTeX math environment.
Starred and \"displaymath\" environments are not numbered."
  (not (string-match-p "\\`[ \t]*\\\\begin{\\(.*\\*\\|displaymath\\)}"
               (org-element-property :value element))))

Now we need to adjust the regular expression in such a way that if element has \begin{foo}
or \begin{bar} etc. (that is, the environment name is a member of
ox-html-latex-environments-no-number), it also returns nil. I think this is doable. I thought
about adding something like

  (not
    (or
 ; starred or display math
      (string-match-p "\\`[ \t]*\\\\begin{\\(.*\\*\\|displaymath\\)}"
      (org-element-property :value element))
 ; environment of ox-html-latex-environments-no-number
    (string-match-p (format "\\begin{%s}" [any element of ox-html-latex-environments-no-number])
               (org-element-property :value element))
))

I don’t know how to express in elisp what is in brackets, though. Does this make sense to you? I
am a beginner with elisp, so I can only state the ideas I have but not implement them (yet).

As to (3): Which images receive label numbers is controlled by this part of
org-html-latex-environment:

(let ((formula-link
            (org-html-format-latex
             (org-html--unlabel-latex-environment latex-frag)
             processing-type info)))

As you can see, at the moment, org-html--unlabel-latex-environment is applied to every
latex-frag. So we would again need a variable
org-html--latex-environments-leave-unlabelled of the same form as above whose
members are all latex environments which should not be unlabelled. Then, we could implement
a condition like

 (let ((formula-link
             (org-html-format-latex
   ; if latex-frag is one of org-html--unlabel-latex-environment
            (if (string-match-p (format "\\begin{%s}"
                                   [any element of org-html--latex-environments-leave-unlabelled])
               latex-frag)
                   ; then do not apply org-html-format-latex to latex-frag
             (org-html-format-latex latex-frag)
                       ; else do apply org-html--unlabel-latex to latex-frag
(org-html--unlabel-latex-environment latex-frag)
              processing-type info)))

It would be great if you could have a look at my solutions. The code surely is awful, but the ideas
behind it might be of value to you. If you could tell me how to solve these problems (or add a
commit which addresses them), this would be awesome! I am planning to do an in-depth guide
on how to write full-fledged LaTeX in html using svg images created with ox-html, and this is
the last step I need for everything to work smoothly.

Warm Regards,

Vitus



             reply	other threads:[~2022-04-11 19:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11 19:38 Vitus Schäfftlein [this message]
2022-04-12  5:15 ` ox-html: exporting LaTeX-environments Thibault Marin
2022-04-15 10:23   ` AW: " Vitus Schäfftlein
2022-04-20 18:46     ` WG: " Vitus Schäfftlein

Reply instructions:

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

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

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

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

  git send-email \
    --in-reply-to=AM0PR04MB564988345CDA0E3275F65BBDA8EA9@AM0PR04MB5649.eurprd04.prod.outlook.com \
    --to=vitusschaefftlein@live.de \
    --cc=emacs-orgmode@gnu.org \
    --cc=thibault.marin@gmx.com \
    /path/to/YOUR_REPLY

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

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

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

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