Leo
Leo

Reputation: 509

How to refer to an equation in Sphinx

I have an equation written in a rst file as:

.. math::
   F=\begin{bmatrix} \lambda_1 & 0 & 0\\0 & \lambda_2 & 0\\0 & 0 & \lambda_3\end{bmatrix}
  :label: eq:6

It is shown perfectly as:

enter image description here

Now I want to refer to this equation in the same rst file. I tried somwthing like:

I need to refer to this :ref:`Link title < eq:6>`

However it did not work. How can I link (e.g. refer) to this equation?

Upvotes: 1

Views: 1438

Answers (1)

Steve Piercy
Steve Piercy

Reputation: 15065

You have mismatched indentation for your math role, an incorrect role option of label instead of name, incorrect ordering of role and its content, and an extra space after the < in your link reference.

The following works for me.

.. math::
    :name: eq:6

    F=\begin{bmatrix} \lambda_1 & 0 & 0\\0 & \lambda_2 & 0\\0 & 0 & \lambda_3\end{bmatrix}

I need to refer to this :ref:`Link title <eq:6>`

There is another reference to :math:numref:, but I do not think that is what you want. There is also the use of ref where one can use a label as the target of the ref.

Upvotes: 1

Related Questions