# Discourse Chat（ベータ版）のご紹介

**URL:** https://meta.discourse.org/t/introducing-discourse-chat-beta/210734
**Category:** Announcements
**Tags:** chat, new-feature
**Created:** [2021 年 12 月 1 日午後 6:18 UTC](https://meta.discourse.org/t/introducing-discourse-chat-beta/210734 "2021-12-01T18:18:21Z")
**Posts on this page:** 1
**Showing post:** 58

<div class="post-metadata">

### Author: ![panic](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@panic](https://meta.discourse.org/u/panic)
#### Post date: [2021 年 12 月 30 日午前 9:34 UTC](https://meta.discourse.org/t/introducing-discourse-chat-beta/210734/58 "2021-12-30T09:34:59Z")

</div>

チャットで discourse-math が壊れているようです。少なくとも KaTeX では、このスクリプトで修正できます。

> **スクリプト**
>
> ```js
> ;(function () {
>     
> var loadScript = require("discourse/lib/load-script").default;
> 
> function ensureKaTeX() {
> return loadScript("/plugins/discourse-math/katex/katex.min.js").then(function () {
> return loadScript("/plugins/discourse-math/katex/katex.min.css", {
> css: true,
> }).then(function () {
> return loadScript("/plugins/discourse-math/katex/mhchem.min.js");
> });
> });
> }
> 
> function decorate(elem) {
> var $elem = $(elem);
> var displayMode = elem.tagName === "DIV";
> 
> if ($elem.data("applied-katex")) {
> return;
> }
> $elem.data("applied-katex", true);
> 
> if ($elem.hasClass("math")) {
> var tag = elem.tagName === "DIV" ? "div" : "span";
> var displayClass = tag === "div" ? "block-math" : "inline-math";
> var text = $elem.text();
> $elem.addClass(`math-container ${displayClass} katex-math`).text("");
> window.katex.render(text, elem, { displayMode });
> }
> }
> 
> function katex($elem) {
> if (!$elem || !$elem.find) {
> return;
> }
> 
> const mathElems = $elem.find(".math");
> 
> if (mathElems.length > 0) {
> ensureKaTeX().then(function () {
> mathElems.each(function (idx, elem) { decorate(elem) });
> });
> }
> }
> 
> setInterval(function () {
> Array.from(document.querySelectorAll('.tc-message-container')).forEach(function (el) { katex(Discourse.$(el)) })
> }, 1000)
> 
> })()
> 
> ```

---

_[View the full topic](https://meta.discourse.org/t/introducing-discourse-chat-beta/210734)._
