# Math and AI workarounds

**URL:** https://meta.discourse.org/t/math-and-ai-workarounds/393642
**Category:** Support
**Tags:** math
**Created:** [December 13, 2024, 9:12am UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642 "2024-12-13T09:12:43Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![ozkn](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ozkn/32/196013_2.png) [@ozkn](https://meta.discourse.org/u/ozkn)
#### Post date: [December 13, 2024, 9:12am UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/1 "2024-12-13T09:12:43Z")

</div>

> [@Add support for Latex style blocks and inlines for Math](https://meta.discourse.org/t/add-support-for-latex-style-blocks-and-inlines-for-math/393638/1):
>
> artificial intelligence gives answers in latex format. I wrote a prompt to convert this latex format to mathjax format, but the prompt is not always implemented and responds in latex format. When I wrote my problem to the openai community, the following suggestion came.
> 
> "I decided it wasn’t even worth the effort of cluttering up a system prompt, when I could just do the following on my end with the results:

There are new suggestions from the openai community regarding the problems I am experiencing. Are you planning to make an update about this? suggestions are as follows.

Suggestion 1;

```plaintext
def parse_stream_to_katex(stream: Stream):
    """
    Takes an OpenAI Stream and replaces ChatGPT LaTeX delimiters
    with KateX ones.
    Yields text, not chunks
    """
    last_text = ""
    for chunk in stream:
        text = chunk.choices[0].delta.content
        if text:
            # Sometimes delimiters like \( can be split over two chunks.
            # If the previous chunk ended in \, prepend that to this chunk
            if last_text.endswith("\\"):
                text = last_text + text

            text = (
                text.replace(r"\[", "$$")
                .replace(r"\]", "$$")
                .replace(r"\(", "$")
                .replace(r"\)", "$")
            )
            last_text = text

            # If the text ends in \, we don't return it, we'll get include it in the next chunk
            if not text.endswith("\\"):
                yield text

```

**Suggestion 2:**

```plaintext
// MarkdownLaTeXRenderer.js
import React from 'react';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';
import rehypeRaw from 'rehype-raw';
import rehypeKatex from 'rehype-katex';

const MarkdownLaTeXRenderer = ({ content }) => {
    // Replace \[with $$ and \] with $$ to ensure compatibility
    const processedText = content 
      .replace(/\\\[/g, '$$$') // Replace all occurrences of \[ with $$
      .replace(/\\\]/g, '$$$') // Replace all occurrences of \] with $$
      .replace(/\\\(/g, '$$$') // Replace all occurrences of \( with $$
      .replace(/\\\)/g, '$$$'); // Replace all occurrences of \) with $$

    const remarkMathOptions = {
        singleDollarTextMath: false,

```

```
};

return (
    <ReactMarkdown
        className="markdown-content"
        children={processedText}
        remarkPlugins={[[remarkMath, remarkMathOptions], remarkGfm]} // Pass options as the second element of the array
        rehypePlugins={[rehypeRaw, rehypeKatex]} // Include rehypeRaw for HTML, rehypeKatex for LaTeX
    />
);

```

};

export default MarkdownLaTeXRenderer;  
’

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [December 13, 2024, 9:21am UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/2 "2024-12-13T09:21:44Z")

</div>

And as an end user… I’m using system prompt for that (OpenAI).

When math is in own line or chapter, change `\(` and `\)` → at own lines, before and after, `$$` is quite reliable.

But when same should do inline with single `$`… that fails almost every time.

If that could happen automatic… even better.

---

<div class="post-metadata">

### Author: ![CAX.DO](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@CAX.DO](https://meta.discourse.org/u/CAX.DO)
#### Post date: [December 21, 2024, 1:57pm UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/3 "2024-12-21T13:57:46Z")

</div>

When I view mathematical formulas on my mobile device, I cannot see the entire formula correctly (the formula is too long). Does anyone know how to solve this issue?  
 ![image](https://global.discourse-cdn.com/meta/original/4X/7/3/9/739a35897096fdc5715344535b1e3b2efce9eec1.png)  
Below is the correct display on the PC .  
 ![image](https://global.discourse-cdn.com/meta/original/4X/9/8/3/98321be85fe0de54c5719510582532e57dbd26be.png)

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [December 21, 2024, 3:16pm UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/4 "2024-12-21T15:16:02Z")

</div>

Turning phone horizontally? But why it is quoted, and can that be the issue?

Otherwise. I asked from AI of my forum and it answered this (no idea if it is helpful or pure crap).

> **Solutions for Aligning Long Equations Using MathJax
AI**
>
> **Jagster:**
> 
> The forum utilizes MathJax for mathematics and equations. Occasionally, an equation is so long that it does not fit on a mobile screen. Is there a way to somehow break the equation into multiple lines?
> 
> **Asiavastaaja:**
> 
> MathJax does not directly support automatic line breaking for equations, but you can use some techniques to make long equations fit better on mobile screens. Here are a few tips:
> 
> 1. **Use the `align` environment** : You can split the equation into multiple lines using the `align` environment. This allows you to align and distribute parts of the equation across several lines. For example:
> 
> 2. **Use the `split` environment** : This is another way to break an equation into multiple lines. It is particularly useful when you want to split the equation into parts without needing alignment. For example:
> 
> 3. **Use the `multline` environment** : This environment is designed for long equations that do not fit on a single line. It breaks the equation into multiple lines without alignment. For example:
> 
> These environments allow you to control the presentation of equations and ensure they are readable even on smaller screens. Remember that MathJax environments often require the `amsmath` package, which is usually enabled by default in MathJax.

---

<div class="post-metadata">

### Author: ![CAX.DO](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@CAX.DO](https://meta.discourse.org/u/CAX.DO)
#### Post date: [December 22, 2024, 2:54am UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/5 "2024-12-22T02:54:35Z")

</div>

@Jagster These should be good solutions. I originally wanted to set a horizontal scrollbar for the formula, but it was not successful.

```plaintext
.math-tex {
    overflow-x: auto;
    max-width: 100%;
    padding: 5px 0;
    display: block;
}

```

---

<div class="post-metadata">

### Author: ![thaidb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thaidb/32/68488_2.png) [@thaidb](https://meta.discourse.org/u/thaidb)
#### Post date: [February 1, 2025, 12:34am UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/6 "2025-02-01T00:34:39Z")

</div>

I’m having trouble copying math formulas from Google Sheets into Meta Discourse. Don’t the formulas seem to be rendering correctly?

NPV=CFt \* [1-1(1+r)Tr]- CFo= 84,000 \* [1-1(1+13%)713%]- 385,000 = $-13,500

PI = 1 + NPVCFo = 1+ n=1784,000(1,13)n - 385,000385,000 ~ 0,965

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [February 1, 2025, 12:41am UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/7 "2025-02-01T00:41:42Z")

</div>

I think you need to escape `$` and `%` with `\`.  
`NPV=CFt * [1-1(1+r)Tr]- CFo= 84,000 * [1-1(1+13\%)713\%]- 385,000 = \$-13,500`

Let’s see here:

NPV=CFt \* [1-1(1+r)Tr]- CFo= 84,000 \* [1-1(1+13\%)713\%]- 385,000 = \$-13,500  
PI = 1 + NPVCFo = 1+ n=1784,000(1,13)n - 385,000385,000 ~ 0,965

* * *

It renders OK, but there is no scrollbar to see the whole math. There is, in the preview, though.  
In the post, you can only see the other part if you zoom:

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/7/9/d7902ffea055b0c57d2db5ba565a60bf06099512.png)

---

<div class="post-metadata">

### Author: ![Ethsim2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethsim2/32/522255_2.png) [@Ethsim2](https://meta.discourse.org/u/Ethsim2)
#### Post date: [March 6, 2025, 1:42pm UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/8 "2025-03-06T13:42:44Z")

</div>

In the preview plane whilst drafting a post, when the SVG gets rendered the preview plane scrolls up. Is there a setting that can be changed so the scrolling returns to lowest position?

Having to scroll down every time i edit math annoys my lecturers, but i have been coping

---

<div class="post-metadata">

### Author: ![Ethsim2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethsim2/32/522255_2.png) [@Ethsim2](https://meta.discourse.org/u/Ethsim2)
#### Post date: [July 15, 2025, 8:08pm UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/9 "2025-07-15T20:08:39Z")

</div>

I’ve notice a couple of “deprecate” in the activity.

If someone could please explain what this means for an instance with a large databases of math that renders ok

---

<div class="post-metadata">

### Author: ![Ethsim2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethsim2/32/522255_2.png) [@Ethsim2](https://meta.discourse.org/u/Ethsim2)
#### Post date: [July 16, 2025, 8:13am UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/10 "2025-07-16T08:13:35Z")

</div>

after a full update/rebuild, the math seems to be rendering fine

For those that haven’t heard, this plugin is now bundled with core. Please see rebuild/revision 2 of 3 of [this post](https://meta.discourse.org/t/what-happens-next/374404/7) to show this.

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [July 16, 2025, 9:24pm UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/11 "2025-07-16T21:24:41Z")

</div>

> [@Ethsim2](#):
>
> For those that haven’t heard, this plugin is now bundled with core. Please see rebuild/revision 2 of 3 of [this post](https://meta.discourse.org/t/what-happens-next/374404/7) to show this.

In the deed! 👍 Sorry for causing concern. You should be good to go now.

🥳 This plugin is now bundled with Discourse core as part of [Bundling more popular plugins with Discourse core](https://meta.discourse.org/t/bundling-more-popular-plugins-with-discourse-core/373574). If you are self-hosting and use the plugin, you need to remove it from your `app.yml` before your next upgrade.

---

<div class="post-metadata">

### Author: ![ozkn](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ozkn/32/196013_2.png) [@ozkn](https://meta.discourse.org/u/ozkn)
#### Post date: [August 29, 2025, 3:35pm UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/12 "2025-08-29T15:35:43Z")

</div>

I have a math character problem in the AI answers. It gives me answers in latex format even though I have typed the required prompt. This creates an image as if there are broken characters. Can you solve this problem. Example;

\( A = \begin{pmatrix} x & -1 \\ z & 2y \end{pmatrix} \)

\[  
\boxed{  
x = 0, \quad y = 4, \quad z = 4  
}  
\]

\[  
\begin{cases}  
A\_{11} = B^T\_{11} \Rightarrow x = y - z \\  
A\_{12} = B^T\_{12} \Rightarrow -1 = -1 \quad (\text{benar otomatis}) \\  
A\_{21} = B^T\_{21} \Rightarrow z = y \\  
A\_{22} = B^T\_{22} \Rightarrow 2y = 8 \\  
\end{cases}  
\]

I have previously shared solutions from the openai community

---

<div class="post-metadata">

### Author: ![Ethsim2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethsim2/32/522255_2.png) [@Ethsim2](https://meta.discourse.org/u/Ethsim2)
#### Post date: [August 30, 2025, 7:43am UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/13 "2025-08-30T07:43:53Z")

</div>

Hi @ozkn

I too have this problem. My recommendation would be

- sign up for an account with the AI provider
- tell the AI account to

> remember for future answers that Discourse is compatible with MathJax/Katex `$…$` `$$…$$` inline or multi-line centric formatting.

- you should find your output more copy-paste’able when logged into your AI account

> **you may need to keep pushing for the best memory**
>
> ![image](https://global.discourse-cdn.com/meta/original/4X/9/4/6/9466d86b2ad45ab475fb0fd965e5148e3c757008.png)  
> ![image](https://global.discourse-cdn.com/meta/original/4X/1/9/f/19f4215138a428d1441f48b167245ac416093b5f.png)

---

<div class="post-metadata">

### Author: ![Ethsim2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethsim2/32/522255_2.png) [@Ethsim2](https://meta.discourse.org/u/Ethsim2)
#### Post date: [August 30, 2025, 7:49am UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/14 "2025-08-30T07:49:44Z")

</div>

Just to add to the last point — if you’re mixing **math** and **currency** , remember:

- `$...$` = math
- `\$` = literal dollar sign

So:  
`$x+1$ costs \$5.` → renders math for x+1 and shows the price as $5.

That’s really all you need: math with `$`, money with `\$`.

---

<div class="post-metadata">

### Author: ![Ethsim2](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ethsim2/32/522255_2.png) [@Ethsim2](https://meta.discourse.org/u/Ethsim2)
#### Post date: [August 30, 2025, 1:59pm UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/15 "2025-08-30T13:59:39Z")

</div>

another good one to encourage chatGPT to remember is that you can’t render math in details pane titles

 ![image](https://global.discourse-cdn.com/meta/original/4X/4/a/e/4ae3e59ef35c2b3cbe52d499fddc8858b3578961.png)

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [January 16, 2026, 5:55am UTC](https://meta.discourse.org/t/math-and-ai-workarounds/393642/16 "2026-01-16T05:55:13Z")

</div>

none of these hacks are needed anymore, we support this natively.
