Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docstring for split_dollars() function #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions sphinx_math_dollar/math_dollar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}$
Expand Down