Mattermost-server: TeX code cannot be highlighted when LaTeX rendering is enabled

Created on 28 May 2020  路  16Comments  路  Source: mattermost/mattermost-server

Summary

When the Enable Latex Rendering option is enabled to allow rendering of math formulas, TeX source code cannot be highlighted anymore.

in order to allow users to use codehighlighting when sharing la/tex code, we are decided to add two new codeblock suffixes:

  • texcode
  • latexcode
    which won't get pickup by the latex renderer, and can be used to show highlighted code.

Jira Ticket

Original ticket

Steps to reproduce

Set the Enable Latex Rendering to true, then try to post something like
````text

\documentclass{article}

\begin{document}

Hello World!

\end{document}

````

Expected behavior

Of the language names tex and latex, only tex is mentioned in the text formatting documentation section on syntax highlighting, while only latex is mentioned in the section on rendering math. Thus, the code should be highlighted as TeX code, like this:

\documentclass{article}

\begin{document}

Hello World!

\end{document}

Observed behavior (that appears unintentional)

The code is interpreted as MathJax input and thus marked as incorrect by printing it back in red.
In practice this means that teams that want to talk about TeX code cannot render LaTeX formulas and vice versa.

Possible fixes

I can imagine two ways to fix this.

  • One could distinguish between the language identifiers tex and latex to make one of them render math formulas and one of them highlight source code.
  • More in line with the integration of MathJax into Markdown in other services (e.g. Stackexchange), one could switch to a syntax based on $ for rendering math. A syntax of single dollar signs ($a + b = c$) for inline math and double dollar signs ($$a + b = c$$) for display math would also be more in line with TeX syntax.

Since rendering math is something totally different from code blocks, a separate syntax would probably be more appropriate anyways. It would break backwards compatibility somewhat, though.

Easy Help Wanted PR Exists TecReactJS

All 16 comments

@schtandard This was determined to be a feature request, would you be open to creating a feature request issue for this here https://mattermost.uservoice.com/forums/306457-general?

@amyblais I created a feature request for the dollar sign syntax.

However, I would still consider the conflict between displaying TeX source code and parsing MathJax input a bug which should

  • either be fixed by making ```tex still highlighting source code while ```latex is interpreted as MathJax input, as documented
  • or be documented as intended behavior by adding latex to the list of supported languages for code highlighting and adding tex to the documentation of the Enable Latex Rendering option. A warning that enabling this option removes the ability to highlight TeX source code should also be added.

Obviously, I would prefer the first option, though the second one would certainly be realized more easily.

@hmhealey Can you help confirm that I should open a bug ticket for above ^

Yeah, it sounds like a bug. Back when Latex rendering was added, I'm pretty sure it was supposed to use tex to print the source code and latex to render it properly. That must've changed at some point.

Actually, I was wrong about that. They both rendered the latex from the beginning.

after grooming we came to the conclussion to fix it by adding two new suffixes for codeblocs:
'''texcode and '''latexcode that displays codehighlight but doesn't trigger the renderer.

For anyone interested in working on this, if you have any questions, feel free to message me here or on our community server where I'm @harrison.

Hey team, I am not able to reproduce the above issue. can I get more context n this?

@14Richa Basically, there's no way to post raw Latex or Tex code and have it appear with proper syntax highlighting currently. Back when Latex support was added, we added it by replacing the tex and latex languages in the code block with the rendered latex, so there's no way to actually use syntax highlighting with latex.

For example, posting
~~~

\sqrt{x * y + 2}

~~~
on GitHub looks like

\sqrt{x * y + 2}

but in Mattermost, it looks like
Screen Shot 2020-07-16 at 10 38 04 AM
and there's no way to have it post the raw code like GitHub.

We want to make it so that
~~~

\sqrt{x * y + 2}

~~~
posts a syntax-highlighted code block in Mattermost.

Got it @hmhealey. Thanks! :)

Actually, I was wrong about that. They both rendered the latex from the beginning.

Hey @hmhealey, I was working on this issue, but was not able to find markdown.jsx file in web app codebase. Can you please help?

I think it moved to the webapp repo in a different form

Cool. @Willyfrog Thanks! :)

Yeah, that's right. It's renderer.tsx in the linked folder. The original PR that I linked is really old, and we've moved stuff around a lot since then.

Hey @hmhealey, I have created a PR for the above issue. As it is my first contribution it would be great if I can get a feed back. :)

Was this page helpful?
0 / 5 - 0 ratings