Discussion:
[Docutils-users] Questions on using equations in rst
Ксения Лукашевичус
2013-10-27 18:18:13 UTC
Permalink
Hello everyone!
I have some questions about equatuons:
1) I want to get from rst source latex code like this: How can I do this?
Would it be ok just to use two math:: directives each with :label: option?
The question is on alignment.

\begin{eqnarray}

m_1\ddot{x}_1+(k_1+k_2)x_1-k_2x_2 & = & u_1, \label{spmass1}\\

m_2\ddot{x}_2-k_2x_1+(k_1+k_2)x_2 & = & u_2 . \label{spmass2}

\end{eqnarray}


2) Is it possible to get labels for equations like these:

\begin{equation}

\dot{x}(t) = f(t, x, u),

\label{ctds1}

\end{equation}


\begin{equation}

x(t+1) = f(t, x, u),

\tag*{(\ref{ctds1}d)}

\label{dtds1}

\end{equation} ?

I mean I want labels to look like (1) and (1d), for example.


3) What about referencing equation from another file (chapter)? Is it possible?


Lukashevichus Ksenia.
Guenter Milde
2013-10-28 09:01:20 UTC
Permalink
Post by Ксения Лукашевичус
1) I want to get from rst source latex code like this: How can I do this?
Would it be ok just to use two math:: directives each with :label: option?
The answer depends on whether you are using Sphinx with a "math"
extension or the "math" directive provided by Docutils.

The follwing all holds for Docutils (and Sphinx without using any math extension, i.e. using the
Docutils math directive).

There is no :label: option. You can specify a label with :name:, but
currently equation numbering is not supported.
http://docutils.sourceforge.net/docs/ref/rst/directives.html#math
Post by Ксения Лукашевичус
The question is on alignment.
There is no alignment between separate "math" directives.

Empty lines in the content of a "math" directive start a new "equation*"
environment. For aligned equations, Docutils uses align* if a line-break
(\\) is detected outside of an envinronment (like "matrix").

I.e.

.. math::

m_1\ddot{x}_1+(k_1+k_2)x_1-k_2x_2 & = & u_1, \label{spmass1}\\
m_2\ddot{x}_2-k_2x_1+(k_1+k_2)x_2 & = & u_2 . \label{spmass2}

becomes

\begin{align*}
m_1\ddot{x}_1+(k_1+k_2)x_1-k_2x_2 & = & u_1, \label{spmass1}\\
m_2\ddot{x}_2-k_2x_1+(k_1+k_2)x_2 & = & u_2 . \label{spmass2}
\end{align*}

This works in LaTeX if you remove the stars and fails in HTML because of the
\label.
You can try

.. math::
:name: ctds1

\dot{x}(t) = f(t, x, u),

.. math::

x(t+1) = f(t, x, u),
\tag*{(\ref{ctds1}d)}
\label{dtds1}
Post by Ксения Лукашевичус
I mean I want labels to look like (1) and (1d), for example.
Again, you need to remove the *-s in the environment names in the latex
output.
Post by Ксения Лукашевичус
3) What about referencing equation from another file (chapter)? Is it
possible?
In docutils, referencing by number is not supported (how could it when
equation numbering is usupported). You can use (at your own risk) raw LaTeX
or a derived role. As raw is not controlled by Docutils, there is no limit
regarding the file but also no support whatsoever. You need to make sure
that LaTeX finds the reference.

Günter

Loading...