【问题标题】:How can make math equation left-aligned instead of center-aligned in reStructuredText?如何使数学方程左对齐而不是 reStructuredText 中的中心对齐?
【发布时间】:2022-01-16 06:16:08
【问题描述】:

以下文本可以在 reStructuredText 中创建一个简单的数学方程:

.. math::

   \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =
   1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
   {1+\frac{e^{-8\pi}} {1+\ldots} } } }

make html 将文本设置为 html 时默认居中对齐,我要设置格式:

  1. 使其左对齐
  2. 左对齐并在行首添加 4 个空白

我几乎用一种简单的方法解决了这个问题,即在raw html 中添加一个math

vim   "source/ebed equation in div.rst"
ebed equation in raw html
==================================
normal equation

.. math::

   \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =
   1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
   {1+\frac{e^{-8\pi}} {1+\ldots} } } } 

equation ebeded in div

.. raw:: html

   <div style="margin-left:20px;width:300px;height:120px;">
.. math::

   \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =
   1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
   {1+\frac{e^{-8\pi}} {1+\ldots} } } } 

width:300px;height:450px; 的样式比以前更小了,它使方程左对齐,即使方程在 div 中仍然居中对齐。
样式margin-left:20px;在开头添加一个空白。
make html编译,在浏览器中打开:

有个小bug,元素div没有关闭!
如果我以这种方式关闭 div 标签:

vim   "source/ebed equation in div.rst"
ebed equation in raw html
==================================
normal equation

.. math::

   \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =
   1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
   {1+\frac{e^{-8\pi}} {1+\ldots} } } } 

equation ebeded in div

.. raw:: html

   <div style="margin-left:20px;width:300px;height:120px;">
.. math::

   \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =
   1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
   {1+\frac{e^{-8\pi}} {1+\ldots} } } } 

   </div>

编译后如下图:

html 标签&lt;/div&gt; 将显示为新的等式。
怎样才能以合乎逻辑的方式谨慎地关闭div标签?

【问题讨论】:

  • make html 将其制作为 html 文件。
  • 你使用 MathJax 吗?您希望所有方程式都左对齐,还是只有一个?
  • 让它变得简单,让它变得愚蠢,只是.. math::,使math中的方程左对齐。
  • 没有 MathJax,只是指定了 .. math:: 中的方程。

标签: python-sphinx restructuredtext


【解决方案1】:

第一个.. raw:: html表示html的开始,第二个.. raw:: html包含&lt;/div&gt;表示html的停止,类似php。

.. raw:: html

   <div style="margin-left:20px;width:300px;height:120px;">
.. math::

   \frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =
   1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
   {1+\frac{e^{-8\pi}} {1+\ldots} } } } 

.. raw:: html

   </div>

【讨论】:

    猜你喜欢
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 2017-10-30
    • 2017-02-16
    • 2013-11-27
    • 2012-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多