[Feature Request] Math & UML #423

Open
opened 2026-02-04 19:47:28 +03:00 by OVERLORD · 47 comments
Owner

Originally created by @Zottelchen on GitHub (Sep 5, 2017).

Desired Feature: Math & UML

I would really like a simple way to write down Math and UML. There are enough libaries which support Markdown and WYSIWYG (at least Math, not sure about UML). Also if Math is going to be included please don't forget an easy way to paste special symbols.

Originally created by @Zottelchen on GitHub (Sep 5, 2017). Desired Feature: Math & UML I would really like a simple way to write down Math and UML. There are enough libaries which support Markdown and WYSIWYG (at least Math, not sure about UML). Also if Math is going to be included please don't forget an easy way to paste special symbols.
OVERLORD added the 🔨 Feature Request label 2026-02-04 19:47:28 +03:00
Author
Owner

@noxify commented on GitHub (Sep 5, 2017):

For the UML part, do you mean something like this?

@noxify commented on GitHub (Sep 5, 2017): For the UML part, do you mean something like this? * https://github.com/plantuml/plantuml / http://plantuml.com/tinymce * https://github.com/knsv/mermaid
Author
Owner

@Zottelchen commented on GitHub (Sep 11, 2017):

Yes, exactly. Both seem to give enough options to explain a process visually.

@Zottelchen commented on GitHub (Sep 11, 2017): Yes, exactly. Both seem to give enough options to explain a process visually.
Author
Owner

@TBK commented on GitHub (Jan 19, 2018):

For the math part of your feature request would https://www.mathjax.org/ suffice?

@TBK commented on GitHub (Jan 19, 2018): For the math part of your feature request would https://www.mathjax.org/ suffice?
Author
Owner

@noxify commented on GitHub (Jan 19, 2018):

For Mathjax, here the MD / TinyMCE implementation:

@noxify commented on GitHub (Jan 19, 2018): For Mathjax, here the MD / TinyMCE implementation: * https://hiltmon.com/blog/2017/01/28/mathjax-in-markdown/ * https://github.com/SoftwareMansion/tinymceMathjax
Author
Owner

@DagW commented on GitHub (Jan 24, 2018):

+1 for Mermaid!

@DagW commented on GitHub (Jan 24, 2018): +1 for Mermaid!
Author
Owner

@TBK commented on GitHub (Mar 18, 2019):

@ssddanbrown could this be a v0.27.0 target? 🙏

@TBK commented on GitHub (Mar 18, 2019): @ssddanbrown could this be a v0.27.0 target? 🙏
Author
Owner

@JHenneberg commented on GitHub (Apr 15, 2019):

I also would appreciate this very much :)

@JHenneberg commented on GitHub (Apr 15, 2019): I also would appreciate this very much :)
Author
Owner

@nicobbg commented on GitHub (Apr 15, 2019):

Mermaid is available in Gitlab and is easy to use. It would be great to have this feature in Bookstack as well.

@nicobbg commented on GitHub (Apr 15, 2019): Mermaid is available in Gitlab and is easy to use. It would be great to have this feature in Bookstack as well.
Author
Owner

@ltDan79 commented on GitHub (May 9, 2019):

+1 :)

@ltDan79 commented on GitHub (May 9, 2019): +1 :)
Author
Owner

@schuepp commented on GitHub (May 23, 2019):

+1 mermaid looks super dope

@schuepp commented on GitHub (May 23, 2019): +1 mermaid looks super dope
Author
Owner

@ThomasF34 commented on GitHub (Aug 18, 2019):

+1 for Mermaid features :)

@ThomasF34 commented on GitHub (Aug 18, 2019): +1 for Mermaid features :)
Author
Owner

@eceforge commented on GitHub (Nov 25, 2019):

For the math side of this might I recommend KaTeX https://katex.org/ instead of mathjax -- it's significantly faster and has no dependencies. I've had partial success in fact simply adding the required javascript include to the customer header section of bookstack. The problem comes when attempting to bind the auto-rendering to a javascript event as it seems to break the image insertion as described in #1588

@eceforge commented on GitHub (Nov 25, 2019): For the math side of this might I recommend KaTeX [https://katex.org/](https://katex.org/) instead of mathjax -- it's significantly faster and has no dependencies. I've had partial success in fact simply adding the required javascript include to the customer header section of bookstack. The problem comes when attempting to bind the auto-rendering to a javascript event as it seems to break the image insertion as described in #1588
Author
Owner

@Lerke commented on GitHub (Dec 9, 2019):

Another +1 from me. Having embedded UML support via Mermaid or PlantUML instead of having to render it locally and upload would be a great feature!

@Lerke commented on GitHub (Dec 9, 2019): Another +1 from me. Having embedded UML support via Mermaid or PlantUML instead of having to render it locally and upload would be a great feature!
Author
Owner

@gkostkowski commented on GitHub (Jan 20, 2020):

+1 for Mathjax or KaTeX

@gkostkowski commented on GitHub (Jan 20, 2020): +1 for Mathjax or KaTeX
Author
Owner

@Zeigren commented on GitHub (Jan 22, 2020):

Another +1 from me. Having embedded UML support via Mermaid or PlantUML instead of having to render it locally and upload would be a great feature!

The included draw.io has support for PlantUML

@Zeigren commented on GitHub (Jan 22, 2020): > Another +1 from me. Having embedded UML support via Mermaid or PlantUML instead of having to render it locally and upload would be a great feature! The included draw.io has support for [PlantUML](https://about.draw.io/use-plantuml-in-draw-io/)
Author
Owner

@kwm1800 commented on GitHub (Apr 5, 2020):

+1 Seriously need this support. A lot of stuffs cannot be written well without math equations.

@kwm1800 commented on GitHub (Apr 5, 2020): +1 Seriously need this support. A lot of stuffs cannot be written well without math equations.
Author
Owner

@ssddanbrown commented on GitHub (Apr 5, 2020):

I'll probably consider Math as part of the "Editor Alignment & Review" on the roadmap.

If you need something to get by for now, it is possible to insert math via the draw.io integration as described in my comment here:
https://github.com/BookStackApp/BookStack/issues/639#issuecomment-597112337

For markdown editor users, markdown is converted to HTML on the front-end using markdown-it. Looks like there's a few math based markdown-it plugins out there. We fire some events for the editors for people to "hook" into. Details of this can be found here:
https://www.bookstackapp.com/docs/admin/hacking-bookstack/#bookstack-editor-events

You may be able to use a plugin and the above editor hooks to implement this for your own system. An example of doing this for a different markdown-it plugin can be seen here:
https://github.com/BookStackApp/BookStack/issues/1671#issuecomment-607480496

Note, any custmomizations like this are out-of-support so could get broken in future updates.

@ssddanbrown commented on GitHub (Apr 5, 2020): I'll probably consider Math as part of the "Editor Alignment & Review" on the roadmap. If you need something to get by for now, it is possible to insert math via the draw.io integration as described in my comment here: https://github.com/BookStackApp/BookStack/issues/639#issuecomment-597112337 For markdown editor users, markdown is converted to HTML on the front-end using markdown-it. Looks like there's a few math based markdown-it plugins out there. We fire some events for the editors for people to "hook" into. Details of this can be found here: https://www.bookstackapp.com/docs/admin/hacking-bookstack/#bookstack-editor-events You may be able to use a plugin and the above editor hooks to implement this for your own system. An example of doing this for a different markdown-it plugin can be seen here: https://github.com/BookStackApp/BookStack/issues/1671#issuecomment-607480496 Note, any custmomizations like this are out-of-support so could get broken in future updates.
Author
Owner

@eceforge commented on GitHub (Apr 12, 2020):

So I have been successful in adding KaTeX rendering with just a simple addition to the custom header. This code snippet works only on the main content of an entry so it won't work in the editor or in page titles etc. I did that on purpose because the KaTeX auto-render plugin has some unintended effects when run on the parts of the DOM that include the add-image icon in the editor.

I'm no javscript expert -- feel free to suggest changes, I just couldn't stand not having math in my wiki pages.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous">

<!-- The loading of KaTeX is deferred to speed up page rendering -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script>

<!-- To automatically render math in text elements, include the auto-render extension: -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous"></script>
<script>
        var katexRenderFilter = function katexRenderFilter () {
	var content = document.body.getElementsByClassName("page-content");
	if (content.length > 0) {
	    renderMathInElement(content[0], 
		{
		    delimiters: 
		    [
			{left: "$$", right: "$$", display: true},
			{left: "$", right: "$", display: false},
			{left: "\\(", right: "\\)", display: false},
			{left: "\\[", right: "\\]", display: true}
		    ]
		}
	    );
	}
    }
    document.addEventListener("DOMContentLoaded", katexRenderFilter);
</script>

The process of writing math would be a lot easier I think if we included the "preview" plugin for the tinyMCE GUI editor, I haven't gotten around to re-building the assets for bookstack to include that plugin though. So as of now you have to write the math in latex, and save the page to get it to render. The primary problem with just enabling it in editor is if you enable it then proceed to save the rendered math you get issues in the finished page. So either we need a button to "un-render" the math before the save or the preview function. Maybe a good use of the the new editor hooks?

@eceforge commented on GitHub (Apr 12, 2020): So I have been successful in adding KaTeX rendering with just a simple addition to the custom header. This code snippet works only on the main content of an entry so it won't work in the editor or in page titles etc. I did that on purpose because the KaTeX auto-render plugin has some unintended effects when run on the parts of the DOM that include the add-image icon in the editor. I'm no javscript expert -- feel free to suggest changes, I just couldn't stand not having math in my wiki pages. ```javascript <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous"> <!-- The loading of KaTeX is deferred to speed up page rendering --> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script> <!-- To automatically render math in text elements, include the auto-render extension: --> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous"></script> <script> var katexRenderFilter = function katexRenderFilter () { var content = document.body.getElementsByClassName("page-content"); if (content.length > 0) { renderMathInElement(content[0], { delimiters: [ {left: "$$", right: "$$", display: true}, {left: "$", right: "$", display: false}, {left: "\\(", right: "\\)", display: false}, {left: "\\[", right: "\\]", display: true} ] } ); } } document.addEventListener("DOMContentLoaded", katexRenderFilter); </script> ``` The process of writing math would be a lot easier I think if we included the "preview" plugin for the tinyMCE GUI editor, I haven't gotten around to re-building the assets for bookstack to include that plugin though. So as of now you have to write the math in latex, and save the page to get it to render. The primary problem with just enabling it in editor is if you enable it then proceed to save the rendered math you get issues in the finished page. So either we need a button to "un-render" the math before the save or the preview function. Maybe a good use of the the new editor hooks?
Author
Owner

@coffeepenbit commented on GitHub (Apr 28, 2020):

+1 I would really appreciate this feature. Right now I'm resorting to writing an equation and taking a screenshot of it.

@coffeepenbit commented on GitHub (Apr 28, 2020): +1 I would _really_ appreciate this feature. Right now I'm resorting to writing an equation and taking a screenshot of it.
Author
Owner

@Bart-van-Ingen commented on GitHub (May 14, 2020):

+1 this would make bookstack an even better contender to confluence for example! the work around with draw.io, just isnt great ...

@Bart-van-Ingen commented on GitHub (May 14, 2020): +1 this would make bookstack an even better contender to confluence for example! the work around with draw.io, just isnt great ...
Author
Owner

@ssddanbrown commented on GitHub (May 15, 2020):

Just had a quick review/think about this, Putting down some thoughts so I don't forget them:

  • Mermaid and KaTeX seem to be the most requested and both look well supported.
  • Both libraries are of considerable size. Mermaid's dist min.js file is at 1.3MB, KaTeX min.css & min.js being around 280kB excluding required fonts. Would need to be considerate in how these are built/loaded.
  • Due to the custom syntax and output we won't really be able to revert or use a different library down the line unless they offered great compatibility. That's a pretty harsh one.
  • Also due to the custom syntax and output, user content becomes more "Proprietary" to BookStack which is something I've been adamant I want to specifically avoid. Another harsh one.
  • Content would really need to be pre-rendered when saved into storage to provide the best experience, so content loads instantly on view (No loading jolt/jank) and so it at least has a chance of rendering on exports, although unlikely via the default DomPDF renderer.
    • Pre-rendering could be done without too much trouble via the WYSWIYG Editor.
    • Pre-rendering or even just previewing will be trouble in the Markdown editor, Re-rendering live on change will be janky unless we selectively update but that'd take some work.
    • Pre-rendering requirement prevents causes stronger dependency on browser-side, and means we can't move final MD rendering to server side. Not even sure how we could support this via the API without some node requirement. That's a pain.
    • Pre-rendering will make jumping between the editors way more of a painful/confusing/tricky experience.
    • On seconds thoughts, I don't think we're going to be able to pre-render.
  • Will require effort in updating the editors, as we draw closer to a time we'd be reviewing options to replace the current editors.
  • The use-case for math is fairly strong, since it is often used in documentation for certain fields and the alternative option is not math-focused.
  • The current use-case for UML/Mermaid is weaker since we now have draw.io which has a lot of overlap and is well-suited to the use-case of multi-ability environments. I can see why those technically inclined may like UML/Mermaid, kind of want to use it myself tbh, but it's focusing on a narrow audience with a custom text syntax, which kind of opposes the idea/spirit of the project.
@ssddanbrown commented on GitHub (May 15, 2020): Just had a quick review/think about this, Putting down some thoughts so I don't forget them: * Mermaid and KaTeX seem to be the most requested and both look well supported. * Both libraries are of considerable size. Mermaid's dist min.js file is at 1.3MB, KaTeX min.css & min.js being around 280kB excluding required fonts. Would need to be considerate in how these are built/loaded. * Due to the custom syntax and output we won't really be able to revert or use a different library down the line unless they offered great compatibility. That's a pretty harsh one. * Also due to the custom syntax and output, user content becomes more "Proprietary" to BookStack which is something I've been adamant I want to specifically avoid. Another harsh one. * Content would really need to be pre-rendered when saved into storage to provide the best experience, so content loads instantly on view (No loading jolt/jank) and so it at least has a chance of rendering on exports, although unlikely via the default DomPDF renderer. * Pre-rendering could be done without too much trouble via the WYSWIYG Editor. * Pre-rendering or even just previewing will be trouble in the Markdown editor, Re-rendering live on change will be janky unless we selectively update but that'd take some work. * Pre-rendering requirement prevents causes stronger dependency on browser-side, and means we can't move final MD rendering to server side. Not even sure how we could support this via the API without some node requirement. That's a pain. * Pre-rendering will make jumping between the editors way more of a painful/confusing/tricky experience. * _On seconds thoughts, I don't think we're going to be able to pre-render._ * Will require effort in updating the editors, as we draw closer to a time we'd be reviewing options to replace the current editors. * The use-case for math is fairly strong, since it is often used in documentation for certain fields and the alternative option is not math-focused. * The current use-case for UML/Mermaid is weaker since we now have draw.io which has a lot of overlap and is well-suited to the use-case of multi-ability environments. I can see why those technically inclined may like UML/Mermaid, kind of want to use it myself tbh, but it's focusing on a narrow audience with a custom text syntax, which kind of opposes the idea/spirit of the project.
Author
Owner

@ascii78 commented on GitHub (May 17, 2020):

Would be nice if we could get some content like drawio from: https://www.mathcha.io. I do not think they are opensource though so that would be a problem, maybe you could get some ideas from it.

Some other nice graphical things would be:

But tbh. only a little bit of latex like it is in most markdown processors would be enough for me.

@ascii78 commented on GitHub (May 17, 2020): Would be nice if we could get some content like drawio from: https://www.mathcha.io. I do not think they are opensource though so that would be a problem, maybe you could get some ideas from it. Some other nice graphical things would be: - https://www.geogebra.org/classic - https://jsxgraph.uni-bayreuth.de/wp/index.html But tbh. only a little bit of latex like it is in most markdown processors would be enough for me.
Author
Owner

@ascii78 commented on GitHub (Jul 13, 2020):

Just noticed that the embedded draw.io app now features math support, even in the bookstack demo. It's under extra's -> mathematical typesetting. It's mathjax and works great:

"Not available in offline versions of draw.io", not sure how that would impact bookstack.

@ascii78 commented on GitHub (Jul 13, 2020): Just noticed that the embedded draw.io app now features math support, even in the bookstack demo. It's under extra's -> mathematical typesetting. It's mathjax and works great: - https://desk.draw.io/support/solutions/articles/16000032875 (How to use mathematical typesetting?) - https://app.diagrams.net/#Uhttps%3A%2F%2Fraw.githubusercontent.com%2Fjgraph%2Fdrawio-diagrams%2Fmaster%2Fdiagrams%2Fmath.xml (example) _"Not available in offline versions of draw.io"_, not sure how that would impact bookstack.
Author
Owner

@davidjgraph commented on GitHub (Jul 31, 2020):

Not available offline is incorrect. Previously, draw didn't have a way to generate client-side PNG if Math was included, but now does.

@davidjgraph commented on GitHub (Jul 31, 2020): Not available offline is incorrect. Previously, draw didn't have a way to generate client-side PNG if Math was included, but now does.
Author
Owner

@noahlove commented on GitHub (Sep 6, 2020):

+1 this would be an amazing feature

@noahlove commented on GitHub (Sep 6, 2020): +1 this would be an amazing feature
Author
Owner

@dean-mrack commented on GitHub (Nov 11, 2020):

Mermaid or PlantUML is very amazing in Markdown editor +1

@dean-mrack commented on GitHub (Nov 11, 2020): Mermaid or PlantUML is very amazing in Markdown editor +1
Author
Owner

@MFYDev commented on GitHub (Dec 28, 2020):

+1 Really need this feature.

@MFYDev commented on GitHub (Dec 28, 2020): +1 Really need this feature.
Author
Owner

@dopoljak commented on GitHub (Jan 6, 2021):

+1

@dopoljak commented on GitHub (Jan 6, 2021): +1
Author
Owner

@Bruno4l commented on GitHub (Feb 3, 2021):

+1

@Bruno4l commented on GitHub (Feb 3, 2021): +1
Author
Owner

@cadavre commented on GitHub (Mar 8, 2021):

Currently I'm using BookStack in such a way I create Mermaid graph in Live Editor which gives me PNG and I use it as a image. But below I paste source Markdown for future edit purposes. Having it built-in would be wonderful.

PS Having it in such a way with draw.io would albo be wonderful. ;) Currently draw.io once saved is not editable – it hurst, but it's different story. :)

@cadavre commented on GitHub (Mar 8, 2021): Currently I'm using BookStack in such a way I create Mermaid graph in Live Editor which gives me PNG and I use it as a image. But below I paste source Markdown for future edit purposes. Having it built-in would be wonderful. PS Having it in such a way with draw.io would albo be wonderful. ;) Currently draw.io once saved is not editable – it hurst, but it's different story. :)
Author
Owner

@nightsparc commented on GitHub (Mar 8, 2021):

Would also love to have Mermaid around :)

PS Having it in such a way with draw.io would albo be wonderful. ;) Currently draw.io once saved is not editable – it hurst, but it's different story. :)

That's not true...you can re-edit any draw.io diagram by just double-clicking on the image in the preview :)

@nightsparc commented on GitHub (Mar 8, 2021): Would also love to have Mermaid around :) > PS Having it in such a way with draw.io would albo be wonderful. ;) Currently draw.io once saved is not editable – it hurst, but it's different story. :) That's not true...you can re-edit any draw.io diagram by just double-clicking on the image in the preview :)
Author
Owner

@cadavre commented on GitHub (Mar 8, 2021):

That's not true...you can re-edit any draw.io diagram by just double-clicking on the image in the preview :)

Oh my... 😅 You just changed my life to better! Thank you! :)

@cadavre commented on GitHub (Mar 8, 2021): > That's not true...you can re-edit any draw.io diagram by just double-clicking on the image in the preview :) Oh my... 😅 You just changed my life to better! Thank you! :)
Author
Owner

@nightsparc commented on GitHub (Mar 8, 2021):

Oh my... sweat_smile You just changed my life to better! Thank you! :)

You're welcome :)

@nightsparc commented on GitHub (Mar 8, 2021): > Oh my... sweat_smile You just changed my life to better! Thank you! :) You're welcome :)
Author
Owner

@paolobasso99 commented on GitHub (Dec 27, 2021):

Since I really wanted Latex support I developed a little hack that correctly display math both while viewing and editing a page (using markdown).

Firstly I include Katex in the head:

<!-- KaTeX -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css" integrity="sha384-R4558gYOUz8mP9YWpZJjofhk+zx0AS11p36HnD2ZKj/6JR5z27gSSULCNHIRReVs" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js" integrity="sha384-z1fJDqw8ZApjGO3/unPWUPsIymfsJmyrDVWC8Tv/a1HeOtGmkwNd/7xUS0Xcnvsx" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"></script>

Then the following script add the event listeners to correctly displaying latex:

<script>
function renderMath (pageContent) {
	renderMathInElement(pageContent,{
		delimiters: [
			{left: '$$', right: '$$', display: true},
			{left: '$', right: '$', display: false},
			{left: '\\(', right: '\\)', display: false},
			{left: '\\[', right: '\\]', display: true}
		],
                // It is important to disable throwing errors which causes loops in the editing view
                throwOnError : false
	});
}

// View
document.addEventListener("DOMContentLoaded", () => {
	const pageContent = document.body.getElementsByClassName("page-content");
	if (pageContent.length > 0) {
		renderMath(pageContent[0]);
	}
});

// Markdown edit
document.addEventListener('editor-markdown::setup', () => {
	const markdownDisplay = document.getElementsByClassName("markdown-display")[0];
	
	markdownDisplay.addEventListener('load', () => {
		const pageContent = markdownDisplay.contentWindow.document.getElementsByClassName("page-content")[0];
		renderMath(pageContent);
		
		const observer = new MutationObserver((mutationsList, observer) => {
			renderMath(pageContent);
		});
		observer.observe(pageContent, {
			attributes: false,
			childList: true,
			subtree: true
		});
	});
});
</script>

As you can see I use a MutationObserver.

I only use the markdown editor so I have implemented a solution only for that one but using MutationObserver and the editor-tinymce::setup event it should be easy to port this solution to tinymce.

If you ever need to export as pdf or html you could export a markdown file and then convert it using, for example, pandoc which supports the KaTeX syntax.

@paolobasso99 commented on GitHub (Dec 27, 2021): Since I really wanted Latex support I developed a little hack that correctly display math both while viewing and editing a page (using markdown). Firstly I include [Katex ](https://katex.org/)in the head: ``` <!-- KaTeX --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css" integrity="sha384-R4558gYOUz8mP9YWpZJjofhk+zx0AS11p36HnD2ZKj/6JR5z27gSSULCNHIRReVs" crossorigin="anonymous"> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js" integrity="sha384-z1fJDqw8ZApjGO3/unPWUPsIymfsJmyrDVWC8Tv/a1HeOtGmkwNd/7xUS0Xcnvsx" crossorigin="anonymous"></script> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"></script> ``` Then the following script add the event listeners to correctly displaying latex: ``` <script> function renderMath (pageContent) { renderMathInElement(pageContent,{ delimiters: [ {left: '$$', right: '$$', display: true}, {left: '$', right: '$', display: false}, {left: '\\(', right: '\\)', display: false}, {left: '\\[', right: '\\]', display: true} ], // It is important to disable throwing errors which causes loops in the editing view throwOnError : false }); } // View document.addEventListener("DOMContentLoaded", () => { const pageContent = document.body.getElementsByClassName("page-content"); if (pageContent.length > 0) { renderMath(pageContent[0]); } }); // Markdown edit document.addEventListener('editor-markdown::setup', () => { const markdownDisplay = document.getElementsByClassName("markdown-display")[0]; markdownDisplay.addEventListener('load', () => { const pageContent = markdownDisplay.contentWindow.document.getElementsByClassName("page-content")[0]; renderMath(pageContent); const observer = new MutationObserver((mutationsList, observer) => { renderMath(pageContent); }); observer.observe(pageContent, { attributes: false, childList: true, subtree: true }); }); }); </script> ``` As you can see I use a [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver). I only use the markdown editor so I have implemented a solution only for that one but using MutationObserver and the `editor-tinymce::setup` event it should be easy to port this solution to tinymce. If you ever need to export as pdf or html you could export a markdown file and then convert it using, for example, [pandoc](https://pandoc.org/) which supports the KaTeX syntax.
Author
Owner

@paolobasso99 commented on GitHub (May 1, 2022):

Apparently, the little hack I developed does not work anymore on the edit screen.

In particular const pageContent = markdownDisplay.contentWindow.document.getElementsByClassName("page-content")[0]; does not works and the iframe appears to have no source when using the developers tools (I do not understand why that is).

The load element of the iframe is not fired anymore too.

@paolobasso99 commented on GitHub (May 1, 2022): Apparently, the little hack I developed does not work anymore on the edit screen. In particular `const pageContent = markdownDisplay.contentWindow.document.getElementsByClassName("page-content")[0];` does not works and the `iframe` appears to have no source when using the developers tools (I do not understand why that is). The `load` element of the `iframe` is not fired anymore too.
Author
Owner

@cdrfun commented on GitHub (May 6, 2022):

Mermaid syntax is supported via diagrams.net https://www.diagrams.net/blog/mermaid-diagrams

@cdrfun commented on GitHub (May 6, 2022): Mermaid syntax is supported via diagrams.net https://www.diagrams.net/blog/mermaid-diagrams
Author
Owner

@dean-mrack commented on GitHub (May 6, 2022):

awesome, thank you )

Let me make just a little remark. The Mermaid diagram has a clear advantage over PlantULM, that allows you to select a text or search for it on page with diagram. In the implementation diagrams.net an image is formed, as well as silt at PlantUML. That's great, but Mermaid is better in its search capability.
But there is also a great https://kroki.io which in my opinion is even more interesting than Mermaid.

@dean-mrack commented on GitHub (May 6, 2022): awesome, thank you ) Let me make just a little remark. The Mermaid diagram has a clear advantage over PlantULM, that allows you to select a text or search for it on page with diagram. In the implementation diagrams.net an image is formed, as well as silt at PlantUML. That's great, but Mermaid is better in its search capability. But there is also a great https://kroki.io which in my opinion is even more interesting than Mermaid.
Author
Owner

@cdrfun commented on GitHub (May 6, 2022):

Yeah, this is a good point and also an issue with the current diagrams implementation apart from using mermaid. Maybe it would be an option to extract all text from the diagram and add it somehow to the document?

@cdrfun commented on GitHub (May 6, 2022): Yeah, this is a good point and also an issue with the current diagrams implementation apart from using mermaid. Maybe it would be an option to extract all text from the diagram and add it somehow to the document?
Author
Owner

@tacerus commented on GitHub (Oct 2, 2022):

@Zeigren

The included draw.io has support for PlantUML

Is there any information on how to use this? The provided link unfortunately returns a 404. We run PlantUML ourselves and it would be great to integrate it with our BookStack instance.

@tacerus commented on GitHub (Oct 2, 2022): @Zeigren > The included draw.io has support for [PlantUML](https://about.draw.io/use-plantuml-in-draw-io/) Is there any information on how to use this? The provided link unfortunately returns a 404. We run PlantUML ourselves and it would be great to integrate it with our BookStack instance.
Author
Owner

@sceptri commented on GitHub (Dec 22, 2022):

Since I really wanted Latex support I developed a little hack that correctly display math both while viewing and editing a page (using markdown).

Firstly I include Katex in the head:

<!-- KaTeX -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css" integrity="sha384-R4558gYOUz8mP9YWpZJjofhk+zx0AS11p36HnD2ZKj/6JR5z27gSSULCNHIRReVs" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js" integrity="sha384-z1fJDqw8ZApjGO3/unPWUPsIymfsJmyrDVWC8Tv/a1HeOtGmkwNd/7xUS0Xcnvsx" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"></script>

Then the following script add the event listeners to correctly displaying latex:

<script>
function renderMath (pageContent) {
	renderMathInElement(pageContent,{
		delimiters: [
			{left: '$$', right: '$$', display: true},
			{left: '$', right: '$', display: false},
			{left: '\\(', right: '\\)', display: false},
			{left: '\\[', right: '\\]', display: true}
		],
                // It is important to disable throwing errors which causes loops in the editing view
                throwOnError : false
	});
}

// View
document.addEventListener("DOMContentLoaded", () => {
	const pageContent = document.body.getElementsByClassName("page-content");
	if (pageContent.length > 0) {
		renderMath(pageContent[0]);
	}
});

// Markdown edit
document.addEventListener('editor-markdown::setup', () => {
	const markdownDisplay = document.getElementsByClassName("markdown-display")[0];
	
	markdownDisplay.addEventListener('load', () => {
		const pageContent = markdownDisplay.contentWindow.document.getElementsByClassName("page-content")[0];
		renderMath(pageContent);
		
		const observer = new MutationObserver((mutationsList, observer) => {
			renderMath(pageContent);
		});
		observer.observe(pageContent, {
			attributes: false,
			childList: true,
			subtree: true
		});
	});
});
</script>

As you can see I use a MutationObserver.

I only use the markdown editor so I have implemented a solution only for that one but using MutationObserver and the editor-tinymce::setup event it should be easy to port this solution to tinymce.

If you ever need to export as pdf or html you could export a markdown file and then convert it using, for example, pandoc which supports the KaTeX syntax.

As @paolobasso99 mentioned later, this unfortunately doesn't work. But today I played around with it a lot and it seems I got it working like so:

<!-- KaTeX -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css" integrity="sha384-vKruj+a13U8yHIkAyGgK1J3ArTLzrFGBbBc0tDp4ad/EyewESeXE/Iv67Aj8gKZ0" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js" integrity="sha384-PwRUT/YqbnEjkZO0zZxNqcxACrXe+j766U2amXcgMg5457rve2Y7I6ZJSm2A0mS4" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"
    onload="renderMathInElement(document.body);"></script>
<script>
function renderMath (pageContent) {
	renderMathInElement(pageContent,{
		delimiters: [
			{left: '$$', right: '$$', display: true},
			{left: '$', right: '$', display: false},
			{left: '\\(', right: '\\)', display: false},
			{left: '\\[', right: '\\]', display: true}
		],
                // It is important to disable throwing errors which causes loops in the editing view
                throwOnError : false
	});
}

// View
document.addEventListener("DOMContentLoaded", () => {
	const pageContent = document.body.getElementsByClassName("page-content");
	if (pageContent.length > 0) {
		renderMath(pageContent[0]);
	}
    const snippet = document.body.getElementsByClassName("entity-item-snippet");
  	if (snippet.length > 0) {
      	snippet.forEach(element => renderMath(element));
    }
});
  
async function asyncRenderMath(pageContent) {
  	const result = await renderMath(pageContent);
}
  
window.addEventListener('load', () => {   
  	const markdownDisplay = document.getElementsByClassName("markdown-display")[0];
	const pageContent = markdownDisplay.contentWindow.document.getElementsByClassName("page-content")[0];
  
	renderMath(pageContent);
  
  	pageContent.addEventListener("DOMSubtreeModified", () => {
      	setTimeout(() => {
           asyncRenderMath(pageContent);
        }, 500);
    });
});
</script>

I know it is not the best solution, but it (kinda) works. Hopefully someone finds it useful 😄

@sceptri commented on GitHub (Dec 22, 2022): > Since I really wanted Latex support I developed a little hack that correctly display math both while viewing and editing a page (using markdown). > > Firstly I include [Katex ](https://katex.org/)in the head: > > ``` > <!-- KaTeX --> > <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css" integrity="sha384-R4558gYOUz8mP9YWpZJjofhk+zx0AS11p36HnD2ZKj/6JR5z27gSSULCNHIRReVs" crossorigin="anonymous"> > <script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js" integrity="sha384-z1fJDqw8ZApjGO3/unPWUPsIymfsJmyrDVWC8Tv/a1HeOtGmkwNd/7xUS0Xcnvsx" crossorigin="anonymous"></script> > <script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/contrib/auto-render.min.js" integrity="sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR" crossorigin="anonymous"></script> > ``` > > Then the following script add the event listeners to correctly displaying latex: > > ``` > <script> > function renderMath (pageContent) { > renderMathInElement(pageContent,{ > delimiters: [ > {left: '$$', right: '$$', display: true}, > {left: '$', right: '$', display: false}, > {left: '\\(', right: '\\)', display: false}, > {left: '\\[', right: '\\]', display: true} > ], > // It is important to disable throwing errors which causes loops in the editing view > throwOnError : false > }); > } > > // View > document.addEventListener("DOMContentLoaded", () => { > const pageContent = document.body.getElementsByClassName("page-content"); > if (pageContent.length > 0) { > renderMath(pageContent[0]); > } > }); > > // Markdown edit > document.addEventListener('editor-markdown::setup', () => { > const markdownDisplay = document.getElementsByClassName("markdown-display")[0]; > > markdownDisplay.addEventListener('load', () => { > const pageContent = markdownDisplay.contentWindow.document.getElementsByClassName("page-content")[0]; > renderMath(pageContent); > > const observer = new MutationObserver((mutationsList, observer) => { > renderMath(pageContent); > }); > observer.observe(pageContent, { > attributes: false, > childList: true, > subtree: true > }); > }); > }); > </script> > ``` > > As you can see I use a [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver). > > I only use the markdown editor so I have implemented a solution only for that one but using MutationObserver and the `editor-tinymce::setup` event it should be easy to port this solution to tinymce. > > If you ever need to export as pdf or html you could export a markdown file and then convert it using, for example, [pandoc](https://pandoc.org/) which supports the KaTeX syntax. As @paolobasso99 mentioned later, this unfortunately doesn't work. But today I played around with it a lot and it seems I got it working like so: ``` <!-- KaTeX --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css" integrity="sha384-vKruj+a13U8yHIkAyGgK1J3ArTLzrFGBbBc0tDp4ad/EyewESeXE/Iv67Aj8gKZ0" crossorigin="anonymous"> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js" integrity="sha384-PwRUT/YqbnEjkZO0zZxNqcxACrXe+j766U2amXcgMg5457rve2Y7I6ZJSm2A0mS4" crossorigin="anonymous"></script> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script> <script> function renderMath (pageContent) { renderMathInElement(pageContent,{ delimiters: [ {left: '$$', right: '$$', display: true}, {left: '$', right: '$', display: false}, {left: '\\(', right: '\\)', display: false}, {left: '\\[', right: '\\]', display: true} ], // It is important to disable throwing errors which causes loops in the editing view throwOnError : false }); } // View document.addEventListener("DOMContentLoaded", () => { const pageContent = document.body.getElementsByClassName("page-content"); if (pageContent.length > 0) { renderMath(pageContent[0]); } const snippet = document.body.getElementsByClassName("entity-item-snippet"); if (snippet.length > 0) { snippet.forEach(element => renderMath(element)); } }); async function asyncRenderMath(pageContent) { const result = await renderMath(pageContent); } window.addEventListener('load', () => { const markdownDisplay = document.getElementsByClassName("markdown-display")[0]; const pageContent = markdownDisplay.contentWindow.document.getElementsByClassName("page-content")[0]; renderMath(pageContent); pageContent.addEventListener("DOMSubtreeModified", () => { setTimeout(() => { asyncRenderMath(pageContent); }, 500); }); }); </script> ``` I know it is not the best solution, but it (kinda) works. Hopefully someone finds it useful :smile:
Author
Owner

@vfosnar commented on GitHub (Aug 29, 2023):

+1 for kroki

@vfosnar commented on GitHub (Aug 29, 2023): +1 for kroki
Author
Owner

@pada57 commented on GitHub (Jan 12, 2024):

+1 for support of UMl as text based

This solution will be much better for developers as can maintain only one place in git their designs and push to bookstack as is without any picture convertion.

Plant or mermaid or both support will be a killer feature

Seems support is available at least on draw.io

https://www.drawio.com/blog/plantuml

@pada57 commented on GitHub (Jan 12, 2024): +1 for support of UMl as text based This solution will be much better for developers as can maintain only one place in git their designs and push to bookstack as is without any picture convertion. Plant or mermaid or both support will be a killer feature Seems support is available at least on draw.io https://www.drawio.com/blog/plantuml
Author
Owner

@end-user commented on GitHub (Feb 10, 2025):

I'm still not clear on what the resistance is to mermaid support, and it doesn't seem to be a low-demand issue. Using diagram.net is a poor substitute because the diagram is just imported as an image, but the source of that is lost. We really need to keep the source of the diagram in the document so that it can be edited.

@end-user commented on GitHub (Feb 10, 2025): I'm still not clear on what the resistance is to mermaid support, and it doesn't seem to be a low-demand issue. Using diagram.net is a poor substitute because the diagram is just imported as an image, but the source of that is lost. We really need to keep the source of the diagram _in_ the document so that it can be edited.
Author
Owner

@ssddanbrown commented on GitHub (Feb 10, 2025):

We really need to keep the source of the diagram in the document so that it can be edited.

@end-user Just to confirm, the drawing source is retained in the rendered diagram.net PNG files for re-editing, which is why you can re-edit diagrams you create via the editor. You can also import/drag-in these PNG files to other diagrams.net instances/windows for full drawing editing.

@ssddanbrown commented on GitHub (Feb 10, 2025): > We really need to keep the source of the diagram in the document so that it can be edited. @end-user Just to confirm, the drawing source is retained in the rendered diagram.net PNG files for re-editing, which is why you can re-edit diagrams you create via the editor. You can also import/drag-in these PNG files to other diagrams.net instances/windows for full drawing editing.
Author
Owner

@end-user commented on GitHub (Feb 11, 2025):

@ssddanbrown Ah, I was not aware. It should be noted somewhere that this functionality is not available if the user is editing in markdown mode; images can only be re-edited through the WYSIWYG editor.

--I guess my remaining complaint about draw.io is: I'm not a designer, don't want to do all the layout. What I like about mermaid is that I can just feed it all the pieces of the flow/graph/diagram and it will do the layout. I don't see that to be the case on draw.io.--

Nevermind, I found where I can put the mermaid code (under "+", advanced).

@end-user commented on GitHub (Feb 11, 2025): @ssddanbrown Ah, I was not aware. It should be noted somewhere that this functionality is not available if the user is editing in markdown mode; images can only be re-edited through the WYSIWYG editor. --I guess my remaining complaint about draw.io is: I'm not a designer, don't want to do all the layout. What I like about mermaid is that I can just feed it all the pieces of the flow/graph/diagram and it will do the layout. I don't see that to be the case on draw.io.-- Nevermind, I found where I can put the mermaid code (under "+", advanced).
Author
Owner

@AstonishingStone commented on GitHub (May 28, 2025):

I made a PR to integrate Mermaid into BookStack, can you give it visibility please ?

https://github.com/BookStackApp/BookStack/pull/5630

@AstonishingStone commented on GitHub (May 28, 2025): I made a PR to integrate Mermaid into BookStack, can you give it visibility please ? https://github.com/BookStackApp/BookStack/pull/5630
Author
Owner

@mallewski commented on GitHub (Nov 12, 2025):

+1 for PlantUML.

It’s more powerful and expressive than Mermaid or draw.io, especially for modeling complex systems, organizational processes, and software architectures. Native support would make BookStack far more versatile for technical and business documentation.

@mallewski commented on GitHub (Nov 12, 2025): +1 for PlantUML. It’s more powerful and expressive than Mermaid or draw.io, especially for modeling complex systems, organizational processes, and software architectures. Native support would make BookStack far more versatile for technical and business documentation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#423