add math label and untabify

This commit is contained in:
2026-01-02 14:08:48 +01:00
parent 9824aaa7a5
commit 30b260e097

View File

@@ -98,11 +98,13 @@
(:rst-metadata nil "rst-metadata" org-rst-metadata)
(:rst-metadata-format nil nil org-rst-metadata-format)
(:rst-metadata-timestamp-format nil nil org-rst-metadata-timestamp-format)
(:rst-equation-reference-format "RST_EQUATION_REFERENCE_FORMAT" nil org-rst-equation-reference-format t)
(:rst-inline-images nil nil org-rst-inline-images)
(:rst-inline-image-rules nil nil org-rst-inline-image-rules)
(:rst-link-org-files-as-rst nil nil org-rst-link-org-files-as-rst)
(:rst-link-home "RST_LINK_HOME" nil org-rst-link-home)
(:rst-link-use-ref-role nil nil org-rst-link-use-ref-role)
(:rst-prefer-user-labels nil nil org-rst-prefer-user-labels)
(:rst-extension nil nil org-rst-extension)
(:rst-file-link-use-ref-role nil nil org-rst-file-link-use-ref-role)
(:rst-text-markup-alist nil nil org-rst-text-markup-alist)
@@ -123,6 +125,10 @@
;;; Internal Variables
(defvar org-rst--id-attr-prefix "ID-"
"Prefix to use in ID attributes.
This affects IDs that are determined from the ID property.")
;;; User Configurable Variables
@@ -238,8 +244,7 @@ contain these elements:
%a stands for the author's name.
%e stands for the author's email.
%d stands for the date.
%c will be replaced by `org-html-creator-string'.
%v will be replaced by `org-html-validation-link'.
%c will be replaced by `org-rst-creator-string'.
%T will be replaced by the export time.
%C will be replaced by the last modification time.
@@ -380,6 +385,25 @@ in order to mimic default behaviour:
:group 'org-export-rst
:type 'function)
;;;; RST-specific
(defcustom org-rst-prefer-user-labels nil
"When non-nil use user-defined names and ID over internal ones.
By default, Org generates its own internal ID values during RST
export. This process ensures that these values are unique and
valid, but the keys are not available in advance of the export
process, and not so readable.
When this variable is non-nil, Org will use NAME keyword, or the
real name of the target to create the ID attribute.
Independently of this variable, however, CUSTOM_ID are always
used as a reference."
:group 'org-export-rst
:type 'boolean
:safe #'booleanp)
;;;; Inlinetasks
@@ -399,6 +423,26 @@ The function should return the string to be exported."
:type 'function)
;;;; LaTeX
(defcustom org-rst-equation-reference-format "\\eqref{%s}"
"The MathJax command to use when referencing equations.
This is a format control string that expects a single string argument
specifying the label that is being referenced. The argument is
generated automatically on export.
The default is to wrap equations in parentheses (using \"\\eqref{%s}\)\".
Most common values are:
\\eqref{%s} Wrap the equation in parentheses
\\ref{%s} Do not wrap the equation in parentheses"
:group 'org-export-rst
:type 'string
:safe #'stringp)
;;;; Src blocks
(defcustom org-rst-code-block 'code
@@ -577,11 +621,11 @@ See `org-rst-text-markup-alist' for details."
(defun org-rst--checkbox (item _info)
"Return checkbox string for ITEM or nil.
INFO is a plist used as a communication channel."
;(let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
; (case (org-element-property :checkbox item)
; (on (if utf8p "☑ " "[X] "))
; (off (if utf8p "☐ " "[ ] "))
; (trans (if utf8p "☒ " "[-] ")))))
;; (let ((utf8p (eq (plist-get info :ascii-charset) 'utf-8)))
;; (case (org-element-property :checkbox item)
;; (on (if utf8p "☑ " "[X] "))
;; (off (if utf8p "☐ " "[ ] "))
;; (trans (if utf8p "☒ " "[-] ")))))
(cl-case (org-element-property :checkbox item)
(on "")
(off "")
@@ -594,7 +638,6 @@ INFO is a plist used as a communication channel."
(defun org-rst-format-spec (info)
"Return format specification for metadata.
INFO is a plist used as a communication channel."
;; (timestamp-format (plist-get info :html-metadata-timestamp-format))
;; org-export-date-timestamp-format
(let ((timestamp-format (plist-get info :rst-metadata-timestamp-format)))
`((?t . ,(org-export-data (plist-get info :title) info))
@@ -798,7 +841,8 @@ information."
(defun org-rst-export-block (export-block _contents _info)
"Transcode a EXPORT-BLOCK element from Org to reStructuredText.
CONTENTS is nil. INFO is a plist holding contextual information."
(when (member (org-element-property :type export-block) '("RST" "REST" "RESTRUCTUREDTEXT"))
(when (member (org-element-property :type export-block)
'("RST" "REST" "RESTRUCTUREDTEXT"))
(org-element-property :value export-block)))
@@ -813,13 +857,13 @@ CONTENTS is nil. INFO is a plist holding contextual information."
;;;; Footnote Definition
;(defun org-rst-footnote-definition (footnote-definition contents info)
; "Transcode a FOOTNOTE-DEFINITION element from Org to reStructuredText.
;CONTENTS is nil. INFO is a plist holding contextual information."
; (replace-regexp-in-string
; "^" ".. "
; (org-remove-indentation
; (org-element-property :value footnote-definition))))
;; (defun org-rst-footnote-definition (footnote-definition contents info)
;; "Transcode a FOOTNOTE-DEFINITION element from Org to reStructuredText.
;; CONTENTS is nil. INFO is a plist holding contextual information."
;; (replace-regexp-in-string
;; "^" ".. "
;; (org-remove-indentation
;; (org-element-property :value footnote-definition))))
;;;; Footnote Reference
@@ -1019,12 +1063,11 @@ targets and targets."
(org-element-property :value datum))
(org-element-property :name datum)
(when-let* ((id (org-element-property :ID datum)))
(concat org-html--id-attr-prefix id)))))
(concat org-rst--id-attr-prefix id)))))
(cond
((and user-label
(or ;; (plist-get info :html-prefer-user-labels)
nil
(or (plist-get info :rst-prefer-user-labels)
;; Used CUSTOM_ID property unconditionally.
custom-id))
user-label)
@@ -1044,7 +1087,7 @@ caption and \"id\" attribute."
(if (org-string-nw-p label) (format " :label: %s\n" label) "")
;; Caption.
(if (not (org-string-nw-p caption)) ""
(format " :label:%s\n" caption))
(format " :label: %s\n :nowrap:\n" caption)) ;; todo: flag for nowrap?
;; Contents.
(format "\n%s\n" (org-rst--indent-string
(org-trim contents) org-rst-quote-margin))))
@@ -1054,7 +1097,7 @@ caption and \"id\" attribute."
Math environments match the regular expression defined in
`org-latex-math-environments-re'. This function is meant to be
used as a predicate for `org-export-get-ordinal' or a value to
`org-html-standalone-image-predicate'."
`org-rst-standalone-image-predicate'."
(string-match-p org-latex-math-environments-re
(org-element-property :value element)))
@@ -1068,7 +1111,7 @@ Starred and \"displaymath\" environments are not numbered."
"Transcode a LATEX-ENVIRONMENT element from Org to reStructuredText.
CONTENTS is nil. INFO is a plist holding contextual
information."
(let ((processing-type (plist-get info :with-latex))
(let ((processing-type t) ;; (plist-get info :with-latex)
(latex-frag (org-remove-indentation
(org-element-property :value latex-environment)))
(label (org-rst--reference latex-environment info t))
@@ -1078,8 +1121,8 @@ information."
(org-export-get-ordinal
latex-environment info nil
(lambda (l _)
(and (org-html--math-environment-p l)
(org-html--latex-environment-numbered-p l))))))))
(and (org-rst--math-environment-p l)
(org-rst--latex-environment-numbered-p l))))))))
(when processing-type
;; latex-frag
(org-rst--wrap-latex-environment latex-frag info caption label))))
@@ -1167,8 +1210,8 @@ INFO is a plist holding contextual information."
(link-org-files-as-rst-maybe
(function
(lambda (raw-path info)
"Treat links to `file.org' as links to `file.rst', if needed.
See `org-rst-link-org-files-as-rst'."
;; Treat links to `file.org' as links to `file.rst', if
;; needed. See `org-rst-link-org-files-as-rst'.
(cond
((and (plist-get info :rst-link-org-files-as-rst)
(string= ".org"
@@ -1272,8 +1315,16 @@ INFO is a plist holding contextual information."
(format "`%s`_" (org-rst--build-title destination info nil))))
;; Fuzzy link points to a target.
(otherwise
(if (and destination
(org-element-type-p destination 'latex-environment)
(eq 'math (org-latex--environment-type destination)))
;; Caption and labels are introduced within LaTeX
;; environment. Use "ref" or "eqref" macro, depending on user
;; preference to refer to those in the document.
(format (plist-get info :rst-equation-reference-format)
(org-rst--reference destination info))
(if (not desc) (format "`%s`_" raw-path)
(format "`%s <%s>`_" desc raw-path))))))
(format "`%s <%s>`_" desc raw-path)))))))
;; Coderef: replace link with the reference name or the
;; equivalent line number. It is not supported in ReST.
((string= type "coderef")
@@ -1287,8 +1338,8 @@ INFO is a plist holding contextual information."
(format ":ref:`%s <%s>`" desc ref)
(format ":ref:`%s`" ref))))
;; Link type is handled by a special function.
;((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
; (funcall protocol (org-link-unescape path) desc 'latex))
;; ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
;; (funcall protocol (org-link-unescape path) desc 'latex))
;; External link with a description part.
((and path desc) (format "`%s <%s>`_" desc path))
;; External link without a description part.