Dear org-mode mailing list, dear Thibault,

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.

My name is Vitus, and 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'.

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)'. 
1. /Any/ environment (except in-line-math) gets an equation number. But some 
environments should not have (html) equation numbers, like `tcolorbox'.
2. /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 via email to