如何在MathJax中左对齐某些方程式 [英] How to left align certain equations in MathJax

查看:575
本文介绍了如何在MathJax中左对齐某些方程式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,默认情况下,MathJax方程居中,但我想使某些方程左对齐.我知道如何使所有方程式与MathJax.Hub.Config对齐,但这不是我想要的.

So, by default MathJax equations are centered, but I want to left align certain equations. I know how to make ALL equations left aligned with MathJax.Hub.Config, but this is not what I want.

我尝试了在网络上找到的其他代码,例如:

I've tried other code found on the web, such as the following:

<script type="text/javascript">
  MathJax.Hub.Queue(function () {
      MathJax.Hub.Config({displayAlign:"left"});
      MathJax.Hub.Typeset(["leqn"]);
    });
 </script>

然后将id为leqn的div包裹在等式周围,如下所示:

then wrapped a div around the equation with an id of leqn, like so:

<div id="leqn">$$e^{\pi i} - 1 = 0$$</div>

这不起作用,而且我对MathJax甚至JS的了解还不足以对我做错了什么有任何想法.有什么想法吗?

This does not work and I don't know enough about MathJax or even JS to have any idea as to what I'm doing wrong. Any ideas?

推荐答案

没有使用TeX输入执行此操作的优雅方法.该方法将随用例而变化.在这里,您似乎可以将HTML环绕在要向左对齐的方程式周围.为此,您通常处于正确的轨道上.这是需要修复的地方:

There's no elegant way for doing this using TeX input. The approach will vary with the use cases. Here you seem to be able to wrap HTML around those equations you want to align to the left. For this you are generally on the right track. Here's what would need fixing:

  • 使用正确的方法连接MathJax的内部结构
  • 让MathJax在第一轮排版中通过添加class="tex2jax_ignore"
  • 来忽略相关方程式
  • 删除该类,更改配置,并让MathJax排版其余的
  • use the correct way of hooking into MathJax's internals
  • have MathJax ignore the relevant equations on the first round of typesetting by adding class="tex2jax_ignore"
  • remove that class, change the configuration, and have MathJax typeset the rest

以下是实现此目的的一种方法.

Below is one way of doing that.

  • 您可以配置其他类名称,请参阅文档.
  • 由于SO对摘要中的外部资源有限制(不允许查询字符串,所以我要手动"注入它),这有点复杂-在您的页面中,只需使用window.MathJax部分并在加载前将其加载即可加载MathJax.js.
  • You can configure other class names, see the docs.
  • It's a bit more complicated because of SO's restrictions on external resources in snippets (no query strings allowed so I'm injecting it "manually") -- in your page, just use the window.MathJax part and load it before you load MathJax.js.

      window.MathJax = {
        AuthorInit: function() {
          MathJax.Hub.Register.StartupHook("Begin", function() {
            MathJax.Hub.Queue(function() {
              var elements = document.getElementsByClassName('tex2jax_ignore');
              for (var i = 0; i < elements.length; i++) {
                elements[i].classList.remove('tex2jax_ignore');
              }
              MathJax.Hub.Config({
                displayAlign: "left"
              });
              MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
            });
          });
        }
      };

      (function(d, script) {
        script = d.createElement('script');
        script.type = 'text/javascript';
        script.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML-full';
        d.getElementsByTagName('head')[0].appendChild(script);
      }(document));

$$e^{\pi i} - 1 = 0$$
<span class="tex2jax_ignore">$$e^{\pi i} - 1 = 0$$</span>
$$e^{\pi i} - 1 = 0$$

这篇关于如何在MathJax中左对齐某些方程式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆