Вопрос

I've been trying to figure out what's wrong with this expression in my docstring. I'm using the sphinx.ext.mathjax extension in python sphinx v1.2b. The docstring:

.. math::

    w_k^* = \min_{w_k} \ell_k(w_k) + \lambda\left(\alpha||w_k||_1 
    + \frac{1}{2}(1-\alpha) ||w_k||^2\right)

This is what appears: enter image description here

But it continues to generate this strange warning and not render the expression at all:

WARNING: Block quote ends without a blank line; unexpected unindent.

Strangely enough, if I remove \alpha, \left, \right, \frac symbols, the expression renders fine without warnings. Not sure why \lambda would be supported and not \alpha.

Это было полезно?

Решение

From the Sphinx documentation:

Keep in mind that when you put math markup in Python docstrings read by autodoc, you either have to double all backslashes, or use Python raw strings (r"raw").

This is needed so that LaTeX commands, such as \alpha, are interpreted correctly (\a and a few other sequences have special meaning in a string literal).

This is the raw version of the docstring in the question, with triple quotes, prepended by r:

r"""
.. math::
 
    w_k^* = \min_{w_k} \ell_k(w_k) + \lambda\left(\alpha||w_k||_1 
    + \frac{1}{2}(1-\alpha) ||w_k||^2\right)
"""
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top