# RTL 与 MathJax

**URL:** <https://meta.discourse.org/t/rtl-and-mathjax/127512>\
**Category:** Support\
**Tags:** math\
**Created:** [2019年九月3日 18:30 UTC](https://meta.discourse.org/t/rtl-and-mathjax/127512 "2019-09-03T18:30:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![verilog15](https://avatars.discourse-cdn.com/v4/letter/v/9f8e36/32.png) [@verilog15](https://meta.discourse.org/u/verilog15)\
**Post date:** [2019年九月3日 18:30 UTC](https://meta.discourse.org/t/rtl-and-mathjax/127512/1 "2019-09-03T18:30:59Z")

</div>

大家好 🙂  
我有个关于如何混合使用英语和从右向左（RTL）语言（如希伯来语）主题的小问题，特别是当这些主题使用 MathJax 插件时。在我们的 Discourse 论坛中，效果如下：

 ![image](https://global.discourse-cdn.com/meta/original/3X/4/1/414027e3e04106c58fdb95d64c20ddcfb9ca9b3a.png)

最终结果非常棒！唯一的问题是编写这些公式。如果要写较长的公式，可能会非常困难。我理解混合使用 RTL 和 LTR 可能会引发问题，但我想确认这是否可行？是否有办法解决？

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2019年九月3日 21:47 UTC](https://meta.discourse.org/t/rtl-and-mathjax/127512/2 "2019-09-03T21:47:02Z")

</div>

> [@verilog15](#):
>
> 编写长公式可能会变得非常困难。

你可以尝试启用“支持混合文本方向”站点设置。有关该设置的详细信息，请参阅 [https://meta.discourse.org/t/what-does-the-support-mixed-text-direction-setting-do/91247。](https://meta.discourse.org/t/what-does-the-support-mixed-text-direction-setting-do/91247%E3%80%82)

启用后，该设置会在编辑器中添加一个“切换方向”按钮：

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/f/bffcd62628eef29d607313960340e3aaddbbe3e0.png)

我尚未在 MathJax 插件上测试此功能，但它应该能让编写长公式变得容易得多。如果你尝试该设置后遇到任何问题，请告诉我们。

---

<div class="post-metadata">

**Author:** ![verilog15](https://avatars.discourse-cdn.com/v4/letter/v/9f8e36/32.png) [@verilog15](https://meta.discourse.org/u/verilog15)\
**Post date:** [2019年九月3日 23:43 UTC](https://meta.discourse.org/t/rtl-and-mathjax/127512/3 "2019-09-03T23:43:10Z")

</div>

感谢您的回复！  
我其实在发帖前就已经尝试过了，只是忘了提及。它确实有助于改善用 $$-$$ 分隔的公式的显示效果，但对单行公式没有帮助。此外，它还会将 RTL 语言转换为 LTR（因为无法为单行切换方向），这也导致显示效果混乱。您还有其他建议吗？  
再次感谢您的回复 🙂

---

<div class="post-metadata">

**Author:** ![verilog15](https://avatars.discourse-cdn.com/v4/letter/v/9f8e36/32.png) [@verilog15](https://meta.discourse.org/u/verilog15)\
**Post date:** [2019年十月1日 21:26 UTC](https://meta.discourse.org/t/rtl-and-mathjax/127512/4 "2019-10-01T21:26:30Z")

</div>

大家好 🙂  
再次尝试一下。有没有办法在代码块和 MathJax 块之间实现从左到右（LTR）的排版？在从右到左（RTL）的论坛中编写代码或公式感觉很不自然：

 ![image](https://global.discourse-cdn.com/meta/original/3X/e/2/e2fd526209282450816edc7bc65ca575ef417b9a.png)

理想效果应该是这样的：

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/e/5e17583705c22b2d9a7cc24eae06ff13f64365c2.png)

有什么方法可以实现吗？

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2019年十月1日 23:12 UTC](https://meta.discourse.org/t/rtl-and-mathjax/127512/5 "2019-10-01T23:12:39Z")

</div>

> [@verilog15](#):
>
> 在从右向左（RTL）的论坛中编写代码或公式感觉很别扭：

是的，这确实会很困难。这不是一个完美的解决方案，但你可以通过主题组件为编辑器添加一个方向切换按钮。这样，当你编写代码时，可以将整个编辑器编辑区域的方向切换为从左向右（LTR）。下面的代码是从启用 `支持混合文本方向` 站点设置时所使用的代码中提取的。如果你的站点默认方向是 RTL，请保持代码不变。如果默认方向是 LTR，请将三元运算符中的 `'rtl'` 替换为 `'ltr'`，以避免首次使用切换按钮时需要双击。

```javascript
<script type="text/discourse-plugin" version="0.8.32">
    api.onToolbarCreate(toolbar => {
        toolbar.addButton({
            id: "toggle-direction",
            group: "extras",
            icon: "exchange-alt",
            shortcut: "Shift+6",
            title: "切换方向",
            perform: () => {
                const $textArea = $(".d-editor-input");
                let currentDir = $textArea.attr("dir") ? $textArea.attr("dir") : 'rtl', // 将默认值设置为你站点的默认文本方向。
                    newDir = currentDir === "ltr" ? "rtl" : "ltr";
                $textArea.attr("dir", newDir).focus();
            }
        });
    });
</script>

```

点击“切换方向”图标以更改编辑器的方向：

 ![image](https://global.discourse-cdn.com/meta/original/3X/8/d/8d6eeaacea4774d46b8879dff63361eb1c6cc1ca.png)

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [2023年五月30日 09:41 UTC](https://meta.discourse.org/t/rtl-and-mathjax/127512/6 "2023-05-30T09:41:09Z")

</div>



---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [2023年五月30日 10:11 UTC](https://meta.discourse.org/t/rtl-and-mathjax/127512/7 "2023-05-30T10:11:19Z")

</div>


