Skip to content

Instantly share code, notes, and snippets.

@shanehh
Created June 7, 2022 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanehh/3ba1112315e574687b32f468219cc0f2 to your computer and use it in GitHub Desktop.
Save shanehh/3ba1112315e574687b32f468219cc0f2 to your computer and use it in GitHub Desktop.
python scripts
"""
change `$` delimiter to `\(` and `\)` pair, at mathjax
"""
import itertools
delimiters = iter(itertools.cycle(["\(", "\)"]))
# from https://math.stackexchange.com/questions/3307627
original = r"""The point is that all rational numbers can be expressed in lowest terms. They don't have to be. Yes, $\frac 24$ is a perfectly good rational number, but the same number can be expressed as $\frac 12$. When we prove $\sqrt 2$ is irrational, we assume it is rational, then say to express that rational in lowest terms as $\frac ab$. The reason to do that is that we then show both $a$ and $b$ are even, so $\frac ab$ is not in lowest terms. If we had not assumed it was in lowest terms we would not have the contradiction we are seeking."""
new = ""
for char in original:
if char == "$":
new += next(delimiters)
else:
new += char
print(new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment