From feefd7ee6463832ef67314bf95b6b9e6c197d8da Mon Sep 17 00:00:00 2001 From: Steve Kieffer Date: Wed, 2 Aug 2023 13:33:37 -0400 Subject: [PATCH] Improve docstring for `split_dollars()` function * Update to mention the 'display math' type, and give an example * Fix typos --- sphinx_math_dollar/math_dollar.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sphinx_math_dollar/math_dollar.py b/sphinx_math_dollar/math_dollar.py index dbec635..c8f3ad7 100644 --- a/sphinx_math_dollar/math_dollar.py +++ b/sphinx_math_dollar/math_dollar.py @@ -5,13 +5,13 @@ def split_dollars(text): Split text into text and math segments. Returns a list of tuples ``(type, text)``, where ``type`` is either - ``"text"`` or ``"math"`` and ``text`` is the text. + ``"text"``, ``"math"``, or ``"display math"``, and ``text`` is the text. Example: - >>> split_dollars(r"The functions $\sin(x)$ and $\cos(x)$.") + >>> split_dollars(r"The functions $\sin(x)$ and $$\cos(x)$$.") [('text', 'The functions '), ('math', '\\sin(x)'), ('text', ' and '), - ('math', '\\cos(x)'), ('text', '.')] + ('display math', '\\cos(x)'), ('text', '.')] More precisely, do a regular expression search. To match as math, the first character after the first $ should not be a space. This is to avoid @@ -23,11 +23,11 @@ def split_dollars(text): Escaped dollars (\$) are also not matched as math delimiters, however all escaped dollars are replaced with normal dollars in the final output. - Math is allowed to be split across multiple lines, as its assumed the + Math is allowed to be split across multiple lines, as it's assumed the dollars will appear in places like docstrings where line wrapping is desired. - This also doesn't replaces dollar signs enclosed in curly braces, + This also doesn't replace dollar signs enclosed in curly braces, to avoid nested math environments, such as :: $f(n) = 0 \text{ if $n$ is prime}$