From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id OIWYJzFZcWNMegEAbAwnHQ (envelope-from ) for ; Sun, 13 Nov 2022 21:53:05 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 0EKYJzFZcWN4zwAA9RJhRA (envelope-from ) for ; Sun, 13 Nov 2022 21:53:05 +0100 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 2447626968 for ; Sun, 13 Nov 2022 21:53:04 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouJxp-0004WL-Q1; Sun, 13 Nov 2022 15:52:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouJxn-0004W7-Ui for emacs-orgmode@gnu.org; Sun, 13 Nov 2022 15:52:23 -0500 Received: from mr85p00im-ztdg06021801.me.com ([17.58.23.195]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouJxj-0003a8-CL for emacs-orgmode@gnu.org; Sun, 13 Nov 2022 15:52:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1668372737; bh=IUwD0AZuU6ONxRlJnd8BALkGPeRXqq3ol4QZRH77n8U=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Tf+UFxIEGBGCxhXWdpW7xYML69bwAt0hCQIjbKr81fr089HZilHVt2I/rigXBWwU4 YKtYNtIN1nrjWRqqtFsCP5bv0EMft5b5sLBkR10c8m8epy0zmXMYH8XoIBKi4KGhN4 68gamci7NvIwcaAov5fUeQ6MfVt86tHewwZ/WotHuou4eddg+W8TWh1EwNB62D+d4Z 2DRAmRZIux8lrPzDteIghuYxSVSto2+90FaXXSxfmZ1EcG5hI/4NAq5mg5V4LGpcm0 8EB5V09JAlP7H5D5HRoMSPKvcMvXHwtx06hWrOQw2RgMn8TBJEVNlEbagizvM/yQB0 JC4ukCRyt79xQ== Received: from Rudolfs-MacBook-Air.local (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-ztdg06021801.me.com (Postfix) with ESMTPSA id 91C6BD008CF; Sun, 13 Nov 2022 20:52:13 +0000 (UTC) From: Rudolf =?utf-8?Q?Adamkovi=C4=8D?= To: Ihor Radchenko Cc: Ihor Radchenko , emacs-orgmode@gnu.org Subject: Re: [PATCH] Re: Update Org to MathJax 3 In-Reply-To: <87leof8os1.fsf@localhost> References: <87h70ekci6.fsf@localhost> <87sfixk3u3.fsf@localhost> <87v8nslox3.fsf@localhost> <87iljra2lw.fsf@localhost> <87v8nq10qg.fsf@localhost> <87zgd0adod.fsf@localhost> <87pmdvk054.fsf@localhost> <87leof8os1.fsf@localhost> Date: Sun, 13 Nov 2022 21:52:10 +0100 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Proofpoint-GUID: jDYVxufUhbmkHdF7-sCduSL93zMVBK2F X-Proofpoint-ORIG-GUID: jDYVxufUhbmkHdF7-sCduSL93zMVBK2F X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.816,17.11.62.513.0000000_definitions?= =?UTF-8?Q?=3D2022-01-18=5F01:2022-01-14=5F01,2022-01-18=5F01,2021-12-02?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 clxscore=1015 mlxscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2211130145 Received-SPF: pass client-ip=17.58.23.195; envelope-from=salutis@me.com; helo=mr85p00im-ztdg06021801.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1668372784; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=z+Zx2LkuoVr8ffYbgKAIjNB1xyhPu+kasvVGsAw1tT0=; b=hK9XxCcdNCn3+EkLSADxu8NErNjqhXljK4ZGkL296o4SdbETVZ9Vojso7KrtouF7EcHNxn Y0L9vcevw4rnOPBEIxOOfeiHCXEbxvuC/CEqor0J2fuAH8x2rswIuVsfLrznFEdhietoFV i30XjurAn0qodmZLI5zKib9Q2Cu7ZmaTmGWs5CzwK9J2IhO/eLAGYwVU3abR8v2Yi58/uT NmtxQa2TcvKJsI4XyxYPTwboev5FTD96lXGYSeQ2xdYku/DxPVjmfEtE9kVAWnSptm1TCi GtJokGgeHIRFtvyTbU0iGELKMOEgdtDFtPdHGf5Bd8qy4qV92IfXWxFrK+ag/g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1668372784; a=rsa-sha256; cv=none; b=DYNuO8rC3x5CQ0lRnO4eHsnJhLUFKLEe0Om1fX9PMFfqwO9t7nhRBN+Rv3OsnrlyXJQGqo tL7kJKkgK8Qu3O0tuK7WI2xwGP87mxq2AgBfyH/pgaKFwDArdRSSpJOOhEQdFwlwkVgUZV JpjWJ22KjwB9M9wLKIX3J2W716qMqpFymZ4YYaaOmLYq8swSQkfwoFgtehzoJv2BrMPGAX aq5ODHBIPIYjBMoHEprhJHUOGZn+gaBtzCth/ixbgC3ShGnPh3gwIbY8HeE+SzT+mg3Wti 8XS5eaLm091ru4JMv5GRS3PO3DSupYONrwYn40nvneFccmNZcvOW9VEofAMlMA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=me.com header.s=1a1hai header.b=Tf+UFxIE; dmarc=fail reason="SPF not aligned (relaxed)" header.from=me.com (policy=quarantine); 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: 6.00 X-Spam: Yes Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=me.com header.s=1a1hai header.b=Tf+UFxIE; dmarc=fail reason="SPF not aligned (relaxed)" header.from=me.com (policy=quarantine); 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: 2447626968 X-Spam-Score: 6.00 X-Migadu-Spam: Yes X-Migadu-Scanner: scn0.migadu.com X-TUID: 8Uh53YlCbCTf --=-=-= Content-Type: text/plain Ihor Radchenko writes: > I note that you did not mention in the news that MathJax 2 support is > dropped. This is a very important thing we must highlight and ring all > the bells about. Fixed. See the 8th revision of the patch attached below. Better? > Consider that someone has customized path option to a local copy of > MathJax version 2. Then, things will get broken after the update! Correct, and we spell it out in the manual, in the "... and breaking changes" section. Digression [no comment needed; just venting]: This confirms, again, that we should focus on LaTeX, the strength of Org, instead of defaulting to the unstable world of JavaScript, copying popular Markdown editors that have to use MathJax do due to their lack of integration with LaTeX. > However, it could be at least a good idea to warn the users who are > trying to use MathJax 2. Would it be possible? As far as I know, we have no reliable way of knowing the version of MathJax without actually reading the JavaScript file, locally and remotely. Rudy --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-ox-html-Update-from-MathJax-2-to-MathJax-3.patch Content-Transfer-Encoding: quoted-printable >From b886755450e052c3584e793fe0960914b0733001 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Rudolf=3D20Adamkovi=3DC4=3D8D?=3D Date: Fri, 7 Oct 2022 15:03:48 +0200 Subject: [PATCH] ox-html: Update from MathJax 2 to MathJax 3+ * lisp/ox-html.el ( org-html-mathjax-options, org-html-mathjax-template, org-html--build-mathjax-config ): Update from MathJax 2 to 3 while maintaining compatibility. All legacy options should continue to work, except for the 'path' option which must now point to MathJax 3 or later. * testing/lisp/test-ox-html.el ( ox-html/mathjax-path-none, ox-html/mathjax-path-default, ox-html/mathjax-path-custom, ox-html/mathjax-path-in-buffer, ox-html/mathjax-options-default, ox-html/mathjax-options-custom, ox-html/mathjax-options-in-buffer, ox-html/mathjax-legacy-scale-default, ox-html/mathjax-legacy-scale-custom, ox-html/mathjax-legacy-scale-in-buffer, ox-html/mathjax-legacy-scale-message, ox-html/mathjax-legacy-scale-message-in-buffer, ox-html/mathjax-legacy-scale-ignore, ox-html/mathjax-legacy-autonumber-ams, ox-html/mathjax-legacy-autonumber-ams-in-buffer, ox-html/mathjax-legacy-autonumber-none, ox-html/mathjax-legacy-autonumber-none-in-buffer, ox-html/mathjax-legacy-autonumber-all, ox-html/mathjax-legacy-autonumber-all-in-buffer, ox-html/mathjax-legacy-autonumber-message, ox-html/mathjax-legacy-autonumber-message-in-buffer, ox-html/mathjax-legacy-font-tex, ox-html/mathjax-legacy-font-tex-in-buffer, ox-html/mathjax-legacy-font-stix-web, ox-html/mathjax-legacy-font-stix-web-in-buffer, ox-html/mathjax-legacy-font-asana-math, ox-html/mathjax-legacy-font-asana-math-in-buffer, ox-html/mathjax-legacy-font-neo-euler, ox-html/mathjax-legacy-font-neo-euler-in-buffer, ox-html/mathjax-legacy-font-gyre-pagella, ox-html/mathjax-legacy-font-gyre-pagella-in-buffer, ox-html/mathjax-legacy-font-gyre-termes, ox-html/mathjax-legacy-font-gyre-termes-in-buffer, ox-html/mathjax-legacy-font-latin-modern, ox-html/mathjax-legacy-font-latin-modern-in-buffer, ox-html/mathjax-legacy-line-breaks-true, ox-html/mathjax-legacy-line-breaks-true-in-buffer, ox-html/mathjax-legacy-line-breaks-false, ox-html/mathjax-legacy-line-breaks-false-in-buffer, ox-html/mathjax-legacy-line-breaks-message, ox-html/mathjax-legacy-line-breaks-message-in-buffer): Test MathJax in general and also the conversion of legacy options from MathJax 2 to 3. * testing/org-test.el (org-test-capture-messages): Add a new macro useful for testing the messages put in the echo area. * etc/ORG-NEWS: Document MathJax 2 to 3 upgrade, highlighting the benefits of the new version but also mentioning the fact that the user may need to update the `path' option in `org-html-mathjax-options'. * doc/org-manual.org (Math formatting in HTML export): Update the link to the MathJax CDN and the example of how to use `+HTML_MATHJAX' with MathJax 3. Also, remove the note on MathJax extensions, as they did not work (and do not work) as documented. Link: https://list.orgmode.org/orgmode/m2a667n4ax.fsf@me.com/ --- doc/org-manual.org | 20 +- etc/ORG-NEWS | 38 ++ lisp/ox-html.el | 257 ++++++++--- testing/lisp/test-ox-html.el | 818 +++++++++++++++++++++++++++++++++++ testing/org-test.el | 11 + 5 files changed, 1063 insertions(+), 81 deletions(-) create mode 100644 testing/lisp/test-ox-html.el diff --git a/doc/org-manual.org b/doc/org-manual.org index dc2fc57cd..3514f84e4 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -13228,24 +13228,20 @@ as-is. LaTeX math snippets (see [[*LaTeX fragments]]) can be displayed in two different ways on HTML pages. The default is to use the [[https://www.mathjax.org][MathJax]], which should work out of the box -with Org[fn:: By default Org loads MathJax from -[[https://cdnjs.com][cdnjs.com]] as recommended by -[[https://www.mathjax.org][MathJax]].][fn:46]. Some MathJax display -options can be configured via ~org-html-mathjax-options~, or in the -buffer. For example, with the following settings, +with Org[fn:: By default, Org loads MathJax from +[[https://www.jsdelivr.com/][jsDelivr]], as recommended in +[[https://docs.mathjax.org/en/latest/web/start.html][Getting Started +with MathJax Components]].][fn:46]. Some MathJax display options can +be configured via ~org-html-mathjax-options~, or in the buffer. For +example, with the following settings, =20 #+begin_example -,#+HTML_MATHJAX: align: left indent: 5em tagside: left font: Neo-Euler -,#+HTML_MATHJAX: cancel.js noErrors.js +,#+HTML_MATHJAX: align: left indent: 5em tagside: left #+end_example =20 #+texinfo: @noindent equation labels are displayed on the left margin and equations are -five em from the left margin. In addition, it loads the two MathJax -extensions =3Dcancel.js=3D and =3DnoErrors.js=3D[fn:: See -[[https://docs.mathjax.org/en/latest/input/tex/extensions.html#tex-and-lat= ex-extensions][TeX -and LaTeX extensions]] in the [[https://docs.mathjax.org][MathJax -manual]] to learn about extensions.]. +five em from the left margin. =20 #+vindex: org-html-mathjax-template See the docstring of ~org-html-mathjax-options~ for all supported diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index b542da34b..404a907c6 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -139,6 +139,44 @@ rely on the details of visibility state implementation= in backend. From now on, using =3Doutline-*=3D functions is strongly discouraged when working with Org files. =20 +*** HTML export uses MathJax 3+ instead of MathJax 2 + +Org now uses MathJax 3 by default instead of MathJax 2. During HTML +exports, Org automatically converts all legacy MathJax 2 options to +the corresponding MathJax 3+ options, except for the ~path~ option in +which now /must/ point to a file containing MathJax version 3 or +later. The new Org does /not/ work with the legacy MathJax 2. + +Further, if you need to use a non-default ~font~ or ~linebreaks~ (now +~overflow~), then the ~path~ must point to MathJax 4 or later. + +See the updated ~org-html-mathjax-options~ for more details. + +MathJax 3, a ground-up rewrite of MathJax 2 came out in 2019. The new +version brings modularity, better and faster rendering, improved LaTeX +support, and more. + +For more information about new features, see: + +https://docs.mathjax.org/en/latest/upgrading/whats-new-3.0.html +https://docs.mathjax.org/en/latest/upgrading/whats-new-3.1.html +https://docs.mathjax.org/en/latest/upgrading/whats-new-3.2.html + +MathJax 3 comes with useful extensions. For instance, you can typeset +calculus with the ~physics~ extension or chemistry with the ~mhchem~ +extension, like in LaTeX. + +Note that the Org manual does not discuss loading of MathJax +extensions via ~+HTML_MATHJAX~ anymore. It has never worked anyway. +To actually load extensions, consult the official documentation: + +https://docs.mathjax.org/en/latest/input/tex/extensions.html + +Lastly, MathJax 3 changed the default JavaScript content delivery +network (CDN) provider from CloudFlare to jsDelivr. You can find the +new terms of service, including the privacy policy, at +https://www.jsdelivr.com/terms. + ** New features *** Clock table can now produce quarterly reports =20 diff --git a/lisp/ox-html.el b/lisp/ox-html.el index cad06aebf..443ae4ebe 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1166,72 +1166,116 @@ See `format-time-string' for more information on i= ts components." ;;;; Template :: Mathjax =20 (defcustom org-html-mathjax-options - '((path "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js= ?config=3DTeX-AMS_HTML" ) - (scale "100") + '((path "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js") + (scale 1.0) (align "center") - (font "TeX") - (linebreaks "false") - (autonumber "AMS") + (font "mathjax-modern") + (overflow "overflow") + (tags "ams") (indent "0em") (multlinewidth "85%") (tagindent ".8em") (tagside "right")) "Options for MathJax setup. =20 -Alist of the following elements. All values are strings. +Alist of the following elements. =20 -path The path to MathJax. +path The path to MathJax version 3 or later. scale Scaling with HTML-CSS, MathML and SVG output engines. align How to align display math: left, center, or right. -font The font to use with HTML-CSS and SVG output. As of MathJax= 2.5 - the following values are understood: \"TeX\", \"STIX-Web\", - \"Asana-Math\", \"Neo-Euler\", \"Gyre-Pagella\", - \"Gyre-Termes\", and \"Latin-Modern\". +font The font to use with HTML-CSS and SVG output. Needs + MathJax version 4+. MathJax 4 provides 11 fonts: + \"mathjax-modern\" Latin-Modern font, default in MathJax 4+ + \"mathjax-asana\" Asana-Math font + \"mathjax-bonum\" Gyre Bonum font + \"mathjax-dejavu\" Gyre DejaVu font + \"mathjax-pagella\" Gyre Pagella font + \"mathjax-schola\" Gyre Schola font + \"mathjax-termes\" Gyre Termes font + \"mathjax-stix2\" STIX2 font + \"mathjax-fira\" Fira and Fira-Math fonts + \"mathjax-euler\" Neo Euler font that extends Latin-Modern + \"mathjax-tex\" The original MathJax TeX font +overflow How to break displayed equations when too large. Needs + MathJax 4 or newer. Supported options include + \"overflow\", \"scale\", \"scroll\", \"truncate\", + \"linebreak\", and \"elide\". linebreaks Let MathJax perform automatic linebreaks. Valid values are \"true\" and \"false\". indent If align is not center, how far from the left/right side? F= or example, \"1em\". multlinewidth The width of the multline environment. -autonumber How to number equations. Valid values are \"none\", - \"all\" and \"AMS\". +tags How to number equations. Valid values are \"none\", + \"all\" and \"ams\". tagindent The amount tags are indented. tagside Which side to show tags/labels on. Valid values are \"left\" and \"right\" =20 -You can also customize this for each buffer, using something like +You can also customize this for some buffer, using something like =20 -#+HTML_MATHJAX: align: left indent: 5em tagside: left font: Neo-Euler +#+HTML_MATHJAX: align: left indent: 5em tagside: left =20 For further information about MathJax options, see the MathJax documentati= on: =20 - https://docs.mathjax.org/" + https://docs.mathjax.org/ + +To maintain compatibility with pre-9.6 Org that used MathJax 2, +the following conversions take place. + +The legacy \"autonumber\" option, with the value \"AMS\", +\"None\", or \"All\", becomes the \"tags\" option set to the +value \"ams\", \"none\", or \"all\", respectively. + +Any legacy values of the \"scale\" option, specified as +percentage strings, become converted to unit-interval numbers. +For example, a legacy scale of \"150\" becomes a scale of 1.5. + +The legacy \"linebreaks\" option, with the value \"true\" or +\"false\", becomes the \"overflow\" option set to the value +\"linebreak\" or \"overflow\", respectively. + +The legacy values of the \"font\" option, namely \"TeX\", +\"STIX-Web\", \"Asana-Math\", \"Neo-Euler\", \"Gyre-Pagella\", +\"Gyre-Termes\", \"Latin-Modern\", become converted to the +corresponding MathJax 4+ font names. + +Legacy options and values always take precedence. +" :group 'org-export-html - :package-version '(Org . "8.3") + :package-version '(Org . "9.6") :type '(list :greedy t (list :tag "path (the path from where to load MathJax.js)" (const :format " " path) (string)) (list :tag "scale (scaling for the displayed math)" - (const :format " " scale) (string)) + (const :format " " scale) (float)) (list :tag "align (alignment of displayed equations)" (const :format " " align) (string)) - (list :tag "font (used to display math)" - (const :format " " font) - (choice (const "TeX") - (const "STIX-Web") - (const "Asana-Math") - (const "Neo-Euler") - (const "Gyre-Pagella") - (const "Gyre-Termes") - (const "Latin-Modern"))) - (list :tag "linebreaks (automatic line-breaking)" - (const :format " " linebreaks) - (choice (const "true") - (const "false"))) - (list :tag "autonumber (when should equations be numbered)" - (const :format " " autonumber) - (choice (const "AMS") - (const "None") - (const "All"))) + (list :tag "font (used to typeset math)" + (const :format " " font) + (choice (const "mathjax-modern") + (const "mathjax-asana") + (const "mathjax-bonum") + (const "mathjax-dejavu") + (const "mathjax-pagella") + (const "mathjax-schola") + (const "mathjax-termes") + (const "mathjax-stix2") + (const "mathjax-fira") + (const "mathjax-euler") + (const "mathjax-tex"))) + (list :tag "overflow (how to break displayed math)" + (const :format " " overflow) + (choice (const "overflow") + (const "scale") + (const "scroll") + (const "truncate") + (const "linebreak") + (const "elide"))) + (list :tag "tags (whether equations are numbered and how)" + (const :format " " tags) + (choice (const "ams") + (const "none") + (const "all"))) (list :tag "indent (indentation with left or right alignment)" (const :format " " indent) (string)) (list :tag "multlinewidth (width to use for the multline environme= nt)" @@ -1244,27 +1288,38 @@ For further information about MathJax options, see = the MathJax documentation: (const "right"))))) =20 (defcustom org-html-mathjax-template - " -" + +" "The MathJax template. See also `org-html-mathjax-options'." :group 'org-export-html :type 'string) @@ -1945,21 +2000,85 @@ INFO is a plist used as a communication channel." "Insert the user setup into the mathjax template. INFO is a plist used as a communication channel." (when (and (memq (plist-get info :with-latex) '(mathjax t)) - (org-element-map (plist-get info :parse-tree) - '(latex-fragment latex-environment) #'identity info t nil t)) + (org-element-map (plist-get info :parse-tree) + '(latex-fragment latex-environment) #'identity info t nil= t)) (let ((template (plist-get info :html-mathjax-template)) - (options (plist-get info :html-mathjax-options)) - (in-buffer (or (plist-get info :html-mathjax) ""))) + (options (let ((options (plist-get info :html-mathjax-options))) + ;; If the user customized some legacy option, set + ;; the corresponding new option to nil, so that + ;; the legacy user choice overrides the default. + ;; Otherwise, the user did not set the legacy + ;; option, in which case still set the legacy + ;; option but to no value, so that the code can + ;; find its in-buffer value, if set. + `((,(if (plist-member options 'autonumber) + 'tags 'autonumber) + nil) + (,(if (plist-member options 'linebreaks) + 'overflow 'linebreaks) + nil) + ,@options))) + (in-buffer (or (plist-get info :html-mathjax) ""))) (dolist (e options (org-element-normalize-string template)) - (let ((name (car e)) - (val (nth 1 e))) - (when (string-match (concat "\\<" (symbol-name name) ":") in-buffer) - (setq val - (car (read-from-string (substring in-buffer (match-end 0)))))) - (unless (stringp val) (setq val (format "%s" val))) - (while (string-match (concat "%" (upcase (symbol-name name))) - template) - (setq template (replace-match val t t template)))))))) + (let ((symbol (car e)) + (value (nth 1 e))) + (when (string-match (concat "\\<" (symbol-name symbol) ":") + in-buffer) + (setq value + (car (split-string (substring in-buffer + (match-end 0)))))) + (when value + (pcase symbol + (`font + (when-let + ((value-new + (pcase value + ("TeX" "mathjax-tex") + ("STIX-Web" "mathjax-stix2") + ("Asana-Math" "mathjax-asana") + ("Neo-Euler" "mathjax-euler") + ("Gyre-Pagella" "mathjax-pagella") + ("Gyre-Termes" "mathjax-termes") + ("Latin-Modern" "mathjax-modern")))) + (setq value value-new))) + (`linebreaks + (org-display-warning + "Converting legacy MathJax option: linebreaks") + (setq symbol 'overflow + value (if (string=3D value "true") + "linebreak" + "overflow"))) + (`scale + (when (stringp value) + (let ((value-maybe (string-to-number value))) + (setq value + (if (=3D value-maybe 0) + (progn + (org-display-warning + (format "Non-numerical MathJax scale: %s" + value)) + 1.0) + value-maybe)))) + (when (>=3D value 10) + (setq value + (let ((value-new (/ (float value) 100))) + (org-display-warning + (format "Converting legacy MathJax scale: %s to = %s" + value + value-new)) + value-new)))) + (`autonumber + (org-display-warning + "Converting legacy MathJax option: autonumber") + (setq symbol 'tags + value (downcase value)))) + (while (string-match (format "\\(%%%s\\)[^A-Z]" + (upcase (symbol-name symbol))) + template) + (setq template + (replace-match (format "%s" value) + t + t template 1))))))))) =20 (defun org-html-format-spec (info) "Return format specification for preamble and postamble. diff --git a/testing/lisp/test-ox-html.el b/testing/lisp/test-ox-html.el new file mode 100644 index 000000000..e1b492733 --- /dev/null +++ b/testing/lisp/test-ox-html.el @@ -0,0 +1,818 @@ +;;; test-ox-html.el --- Tests for ox-html.el + +;; Copyright (C) 2022 Rudolf Adamkovi=C4=8D + +;; Author: Rudolf Adamkovi=C4=8D + +;; This file is 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 . + +;;; Code: + +(require 'ox-html) + + +;;; Loading MathJax + +(ert-deftest ox-html/mathjax-path-none () + "Test that MathJax does not load when not needed." + (should-not + (org-test-with-temp-text "No LaTeX here." + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (let ((case-fold-search t)) + (search-forward "MathJax" nil t))))))) + +(ert-deftest ox-html/mathjax-path-default () + "Test the default path from which MathJax loads." + (should + (=3D 1 (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx "")))))))) + +(ert-deftest ox-html/mathjax-path-custom () + "Test a customized path from which MathJax loads." + (should + (=3D 1 (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + '((path "./mathjax/es5/tex-mml-chtml.js")))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx "")))))))) + +(ert-deftest ox-html/mathjax-path-in-buffer () + "Test a in-buffer customized path from which MathJax loads." + (should + (=3D 1 (org-test-with-temp-text " +#+HTML_MATHJAX: path: ./mathjax/es5/tex-mml-chtml.js +$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx "")))))))) + + +;;; Configuring MathJax with options + +(ert-deftest ox-html/mathjax-options-default () + "Test the default MathJax options." + (should + (=3D 1 (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx "")))))))) + +(ert-deftest ox-html/mathjax-options-custom () + "Test customized MathJax options." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + '((path "") ; tested elsewhere + (scale 0.5) + (align "right") + (font "mathjax-euler") + (overflow "scale") + (tags "all") + (indent "1em") + (multlinewidth "100%") + (tagindent "2em") + (tagside "left")))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx "")))))))) + +(ert-deftest ox-html/mathjax-options-in-buffer () + "Test in-buffer customized MathJax options." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: scale: 0.5 +#+HTML_MATHJAX: align: right +#+HTML_MATHJAX: font: mathjax-euler +#+HTML_MATHJAX: overflow: scale +#+HTML_MATHJAX: tags: all +#+HTML_MATHJAX: indent: 1em +#+HTML_MATHJAX: multlinewidth: 100% +#+HTML_MATHJAX: tagindent: 2em +#+HTML_MATHJAX: tagside: left" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx "")))))))) + + +;;; Converting legacy MathJax scales + +;; Define a legacy scale as any scale given as a percentage string, +;; such as "150", instead of a unit-interval float, such as 1.5. + +(ert-deftest ox-html/mathjax-legacy-scale-default () + "Test the legacy scale conversion with the old default value." + (should + (=3D 2 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(scale "100") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "scale: 1.0" (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-scale-custom () + "Test the legacy scale conversion with a non-default value." + (should + (=3D 2 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(scale "10") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "scale: 0.1" (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-scale-in-buffer () + "Test the legacy scale conversion with an in-buffer value." + (should + (=3D 2 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: scale: 10" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "scale: 0.1" (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-scale-message () + "Test the legacy scale conversion message." + (should + (=3D 1 + (seq-count + (lambda (message) + (string=3D "Converting legacy MathJax scale: 20 to 0.2" + message)) + (org-test-capture-warnings + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(scale "20") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode)))))))) + +(ert-deftest ox-html/mathjax-legacy-scale-message-in-buffer () + "Test the legacy scale conversion message for an in-buffer value." + (should + (seq-count + (lambda (message) + (string=3D "Converting legacy MathJax scale: 20 to 0.2" + message)) + (org-test-capture-warnings + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: scale: 20" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode))))))) + +(ert-deftest ox-html/mathjax-legacy-scale-ignore () + "Test the legacy scale conversion ignores small values." + (should + (=3D 2 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options '((scale "9")))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "scale: 9" (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-scale-invalid () + "Test the legacy scale conversion with an invalid value." + (should + (=3D 2 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(scale "xxx") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "scale: 1.0" (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-scale-invalid-message () + "Test the invalid legacy scale conversion message." + (should + (=3D 1 + (seq-count + (lambda (message) + (string=3D "Non-numerical MathJax scale: xxx" + message)) + (org-test-capture-warnings + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(scale "xxx") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode)))))))) + + +;;; Converting legacy MathJax auto-numbering + +;; NOTE: AMS stands for American Mathematical Society. + +(ert-deftest ox-html/mathjax-legacy-autonumber-ams () + "Test legacy auto-numbering, when AMS." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(autonumber "AMS") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "tags: 'ams'" (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-autonumber-ams-in-buffer () + "Test legacy auto-numbering, when AMS in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: autonumber: AMS" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "tags: 'ams'" (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-autonumber-none () + "Test legacy auto-numbering, when disabled." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(autonumber "None") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "tags: 'none'" (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-autonumber-none-in-buffer () + "Test legacy auto-numbering, when disabled in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: autonumber: None" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "tags: 'none'" (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-autonumber-all () + "Test legacy auto-numbering, when enabled." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(autonumber "All") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "tags: 'all'" (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-autonumber-all-in-buffer () + "Test legacy auto-numbering, when enabled in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: autonumber: All" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "tags: 'all'" (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-autonumber-message () + "Test legacy auto-numbering conversion message." + (should + (=3D 1 + (seq-count + (lambda (message) + (string=3D "Converting legacy MathJax option: autonumber" + message)) + (org-test-capture-warnings + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(autonumber "AMS") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode)))))))) + +(ert-deftest ox-html/mathjax-legacy-autonumber-message-in-buffer () + "Test legacy auto-numbering conversion message." + (should + (=3D 1 + (seq-count + (lambda (message) + (string=3D "Converting legacy MathJax option: autonumber" + message)) + (org-test-capture-warnings + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: autonumber: AMS" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode)))))))) + + +;;; Converting legacy MathJax fonts + +(ert-deftest ox-html/mathjax-legacy-font-tex () + "Test legacy font, when TeX." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(font "TeX") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-tex'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-tex-in-buffer () + "Test legacy font, when TeX in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: font: TeX" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-tex'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-stix-web () + "Test legacy font, when STIX-Web." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(font "STIX-Web") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-stix2'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-stix-web-in-buffer () + "Test legacy font, when STIX-Web in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: font: STIX-Web" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-stix2'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-asana-math () + "Test legacy font, when Asana-Math." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(font "Asana-Math") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-asana'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-asana-math-in-buffer () + "Test legacy font, when Asana-Math in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: font: Asana-Math" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-asana'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-neo-euler () + "Test legacy font, when Neo-Euler." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(font "Neo-Euler") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-euler'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-neo-euler-in-buffer () + "Test legacy font, when Neo-Euler in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: font: Neo-Euler" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-euler'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-gyre-pagella () + "Test legacy font, when Gyre-Pagella." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(font "Gyre-Pagella") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-pagella'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-gyre-pagella-in-buffer () + "Test legacy font, when Gyre-Pagella in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: font: Gyre-Pagella" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-pagella'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-gyre-termes () + "Test legacy font, when Gyre-Termes." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(font "Gyre-Termes") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-termes'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-gyre-termes-in-buffer () + "Test legacy font, when Gyre-Termes in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: font: Gyre-Termes" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-termes'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-latin-modern () + "Test legacy font, when Latin-Modern." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(font "Latin-Modern") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-modern'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-font-latin-modern-in-buffer () + "Test legacy font, when Latin-Modern in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: font: Latin-Modern" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "font: 'mathjax-modern'" + (or "," "\n")))))))))) + + +;;; Converting legacy MathJax line breaks + +(ert-deftest ox-html/mathjax-legacy-line-breaks-true () + "Test legacy line breaks, when true." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (append '((linebreaks "true") + (overflow "overflow")) + org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "displayOverflow: 'linebreak'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-line-breaks-true-in-buffer () + "Test legacy line breaks, when true in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: linebreaks: true" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(overflow "overflow") org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "displayOverflow: 'linebreak'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-line-breaks-false () + "Test legacy line breaks, when false." + (should + (=3D 1 + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (append '((linebreaks "false") + (overflow "linebreak")) + org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "displayOverflow: 'overflow'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-line-breaks-false-in-buffer () + "Test legacy line breaks, when true in-buffer." + (should + (=3D 1 + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: linebreaks: false" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options + (cons '(overflow "linebreak") + org-html-mathjax-options))) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode) + (with-current-buffer export-buffer + (how-many (rx (seq "displayOverflow: 'overflow'" + (or "," "\n")))))))))) + +(ert-deftest ox-html/mathjax-legacy-line-breaks-message () + "Test the legacy line breaks conversion message." + (should + (=3D 1 + (seq-count + (lambda (message) + (string=3D "Converting legacy MathJax option: linebreaks" + message)) + (org-test-capture-warnings + (org-test-with-temp-text "$x$" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil) + (org-html-mathjax-options (cons '(linebreaks "true") + org-html-mathjax-options)= )) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode)))))))) + +(ert-deftest ox-html/mathjax-legacy-line-breaks-message-in-buffer () + "Test the legacy scale conversion message for an in-buffer value." + (should + (=3D 1 + (seq-count + (lambda (message) + (string=3D "Converting legacy MathJax option: linebreaks" + message)) + (org-test-capture-warnings + (org-test-with-temp-text "$x$ +#+HTML_MATHJAX: linebreaks: true" + (let ((export-buffer "*Test HTML Export*") + (org-export-show-temporary-export-buffer nil)) + (org-export-to-buffer 'html export-buffer + nil nil nil nil nil + #'html-mode)))))))) + +(provide 'test-ox-html) +;;; test-ox-html.el ends here diff --git a/testing/org-test.el b/testing/org-test.el index 9f7bab9ea..880d9e845 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -33,6 +33,7 @@ =20 (require 'org) (require 'org-id) +(require 'org-macs) =20 ;;; Ob constants =20 @@ -531,6 +532,16 @@ TIME can be a non-nil Lisp time value, or a string spe= cifying a date and time." (or a ,at) (or b ,at))))) ,@body)))) =20 +(defmacro org-test-capture-warnings (&rest body) + "Capture all warnings passed to `org-display-warning' within BODY." + (declare (indent 0) (debug t)) + `(let ((messages (list))) + (cl-letf (((symbol-function 'org-display-warning) + (lambda (message) + (setq messages (cons message messages))))) + ,@body) + (nreverse messages))) + (provide 'org-test) =20 ;;; org-test.el ends here --=20 2.38.1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 "Programming reliably -- must be an activity of an undeniably mathematical nature [=E2=80=A6] You see, mathematics is about thinking, and doing mathematics is always trying to think as well as possible." -- Edsger W. Dijkstra, 1981 Rudolf Adamkovi=C4=8D [he/him] Studenohorsk=C3=A1 25 84103 Bratislava Slovakia --=-=-=--