Function: org-html--build-mathjax-config

org-html--build-mathjax-config is a byte-compiled function defined in ox-html.el.gz.

Signature

(org-html--build-mathjax-config INFO)

Documentation

Insert the user setup into the mathjax template.

INFO is a plist used as a communication channel.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-html.el.gz
(defun org-html--build-mathjax-config (info)
  "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))
    (let ((template (plist-get info :html-mathjax-template))
          (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 ((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= value "true")
                               "linebreak"
                             "overflow")))
              (`scale
               (when (stringp value)
                 (let ((value-maybe (string-to-number value)))
                   (setq value
                         (if (= value-maybe 0)
                             (progn
                               (org-display-warning
                                (format "Non-numerical MathJax scale: %s"
                                        value))
                               1.0)
                           value-maybe))))
               (when (>= 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)))))))))