From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id EPpcEdlGVGJnGQAAgWs5BA (envelope-from ) for ; Mon, 11 Apr 2022 17:18:49 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id CP6zDtlGVGJAcAEA9RJhRA (envelope-from ) for ; Mon, 11 Apr 2022 17:18:49 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D26A3B16F for ; Mon, 11 Apr 2022 17:18:47 +0200 (CEST) Received: from localhost ([::1]:45122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ndvoU-0007k6-G7 for larch@yhetil.org; Mon, 11 Apr 2022 11:18:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nddSt-00028a-Ko for emacs-orgmode@gnu.org; Sun, 10 Apr 2022 15:43:15 -0400 Received: from udcm-wwu2.uni-muenster.de ([128.176.118.28]:8237) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nddSq-0004Oq-Ja for emacs-orgmode@gnu.org; Sun, 10 Apr 2022 15:43:15 -0400 X-IronPort-AV: E=Sophos;i="5.90,250,1643670000"; d="scan'208,217";a="160865849" Received: from secmail.uni-muenster.de ([128.176.118.4]) by UDCM-RELAY2.UNI-MUENSTER.DE with ESMTP; 10 Apr 2022 21:43:08 +0200 Received: from vitus (ip-088-152-009-158.um26.pools.vodafone-ip.de [88.152.9.158]) by SECMAIL.UNI-MUENSTER.DE (Postfix) with ESMTPSA id 2F126202DB71; Sun, 10 Apr 2022 21:43:08 +0200 (CEST) From: Vitus =?utf-8?Q?Sch=C3=A4fftlein?= To: emacs-orgmode@gnu.org, thibault.marin@gmx.com Subject: Suggestions to handle LaTeX environments in ox-html Date: Sun, 10 Apr 2022 21:41:14 +0200 User-agent: mu4e 1.6.10; emacs 28.1 Message-ID: <87a6cslo6s.fsf@uni-muenster.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=128.176.118.28; envelope-from=v_scha12@uni-muenster.de; helo=UDCM-WWU2.UNI-MUENSTER.DE X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, HTML_MESSAGE=0.001, MANY_SPAN_IN_TEXT=1.336, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 11 Apr 2022 11:08:22 -0400 X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1649690328; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=kxx0Y6Vy6Dj2GNagvyCZRwM26fD83RaX28x0ZUti2Qc=; b=KwRg+zHa7a1Meiqe6wjuQngUByXBpDwDkuGWsJsZNGhIGnQ4bRdwmZGQ81yRkQLBA+A1Np 6Ji0t0ng5R8n+raX0NJ21EsnKuehnhx2eMpxZ9GA/rMSDe3v0EsAMWRPT/c0JQWTnn2Fjg 6p1wZZw+kOG0YYCaspVM7RxCI/Dniy7DJXm34OEEFHMobqDTYmrLRI0uuXvCXIuFi0UzUA ReLMd2zTZpriMFb6i1UV1q8i2J2Xd7hskqIiI4Cu8QEMz7Bm8pHa+hUouNwFcYV95apM3G PVzIqcuY+OWOFfUT89EditybMXt/7TuBIjlTbdDVxQq/xZjikRrrilOA2Z7j9g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1649690328; a=rsa-sha256; cv=none; b=bnF1S8xpsgrGUe3yICPl2fCRgvpe3RSmcFIbEsJUVqGFxTFV9p8Tx6r0Sc2z1jMj94N1Sk 3wyIYMpJYL4PIZKhI7T/hbzurtuOjzhw4P36Dsbkh/5QfJuXVGvTgJakshYbeAeA/ctIpV +q9QqV/C1PTZaSAx63RZF8Y2PQTUXzpfN2l9eIdPm7OtxihIbXDHisXqhOdt05/rxm82J1 2JZp4enujMLYGwSy921QRzWtSqsfrs5p2ZJ+admoSNJWgwC8dUK2w4LTm2OTv/9FMLRjtP u8ehXY7ogMHwWkkdY7cV7rDgA5pvtpUjCpAx4ZMyz5hJt2lDy0YBOeTpD9YNbQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.77 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: D26A3B16F X-Spam-Score: -1.77 X-Migadu-Scanner: scn1.migadu.com X-TUID: LkA7p/jKE2Kb --=-=-= Content-Type: multipart/alternative; boundary="==-=-=" --==-=-= Content-Type: text/plain Content-Disposition: inline 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\n%s\n" `---- 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 --==-=-= Content-Type: text/html; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable

Dear org-mode mailing list, dear Thibault,

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

My name is Vitus, and I=E2=80=99m writing to you because I am setting up my= blog, for which I need fully-fledged LaTeX support, so I am inserting my c= ode via svg images. There are quite some problems to get it working, t= hough, 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 ha= ve (html) equation numbers, like tcolorbox.
  2. Any LaTeX environment name <= code style=3D"font-size:10pt;font-family:monospace;background:#f9f9f9;">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 nee= ding an extra width-argument, so the export won=E2=80=99t work properly.

I have put quite some elbow-grease into possible solutions, which I would l= ike 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 = ht= ml span class equation-label, where the equation number is then= inserted. Specifically, it adds this string:

"\n<span class=3D\"equ=
ation-label\">\n%s\n&=
lt;/span>"

Now the newline commands \n before and after %s are exported as w= hitespace. Just replacing \n%s\n by %s (that is, leaving the newl= ines 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 th= eory:

  1. Create a new variable ox-html-la= tex-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-numbere= d-p. It is currently defined like this:
(defun org-html--latex-environment-numbered-p (element)
  "Non-nil when ELEMENT contains a num=
bered LaTeX math environment.
Starred and \"displaymath\" envir=
onments 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 environmen= t name is a member of ox-html-latex-environments-no-number), it also r= eturns nil. I think this is doable. I thought about adding something like

  (not=20
    (or
 ; starred or display math
      (string-match-p "\\`[ \t]*\\\\begin{\\(.*\\*\\|displaymath\\)}"=

      (org-element-property :value element)
 ; environment of ox-html-latex-environment=
s-no-number
    (string-match-p (format "\\begi=
n{%s}" [any element of ox-html-latex-environments-no-number])
               (org-element-property=
 :value element))
))

I don=E2=80=99t know how to express in elisp what is in brackets, though. D= oes 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= o= rg-html-latex-environment:

(let ((formula-link
            (org-html-format-latex
             (org-html--unlabel-late=
x-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 = or= g-html--latex-environments-leave-unlabelled of the same form as abov= e 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--unla=
bel-latex-environment
            (if (string-match-p <=
span style=3D"color: #90a890;">(format "\\begin{%s}"=20
                                   [any element of org-html--latex-environm=
ents-leave-unlabelled])
               latex-frag)=20
                   ; 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)<=
span style=3D"color: #97b098;">))

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 t= ell 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 writ= e full-fledged LaTeX in html using svg images created with ox-html<= /code>, and this is the last step I need for everything to work smoothly.

Warm Regards,

Vitus

--==-=-=-- --=-=-=--