$\LaTeX$ Syntax
The following section describes how to add equations written using $\LaTeX$ to your documentation.
Escaping Characters in Docstrings
Since some characters used in $\LaTeX$ syntax are treated differently in docstrings they need to be escaped using a \ character as in the following example:
"""
Here's some inline maths: \$\\sqrt[n]{1 + x + x^2 + \\ldots}\$.
Here's an equation:
\$\\frac{n!}{k!(n - k)!} = \\binom{n}{k}\$
This is the binomial coefficient.
"""
func(x) = # ...To avoid needing to escape the special characters the doc"" string macro can be used:
doc"""
Here's some inline maths: $\sqrt[n]{1 + x + x^2 + \ldots}$.
Here's an equation:
$\frac{n!}{k!(n - k)!} = \binom{n}{k}$
This is the binomial coefficient.
"""
func(x) = # ...A related issue is how to add dollar signs to a docstring. They need to be double-escaped as follows:
"""
The cost was \\\$1.
"""Inline Equations
Here's some inline maths: ``\sqrt[n]{1 + x + x^2 + \ldots}``.which will be displayed as
Here's some inline maths: $\sqrt[n]{1 + x + x^2 + \ldots}$.
Display Equations
Here's an equation:
```math
\frac{n!}{k!(n - k)!} = \binom{n}{k}
```
This is the binomial coefficient.which will be displayed as
Here's an equation:
\[\frac{n!}{k!(n - k)!} = \binom{n}{k}\]
This is the binomial coefficient.