How to embed mathematical formulas and flowcharts in content and ensure correct rendering?

Calendar 👁️ 97

In modern web content creation, illustrations are a basic requirement, and for websites in technical, educational, or scientific research fields, mere images and text are often not enough to clearly express complex concepts.At this time, how to flexibly embed mathematical formulas and flowcharts in the content, and ensure that they are rendered correctly and beautifully on the page, has become a focus of content operators.AnQiCMS, with its powerful functions, provides us with an effective way to achieve this goal.

The AnQi CMS built-in Markdown editor greatly facilitates us in writing content with complex structures.It not only supports the syntax features of Markdown, but more importantly, it can seamlessly integrate with third-party rendering libraries through simple configuration, allowing mathematical formulas and flowcharts to be vividly displayed on the front-end page.


Step 1: Turn on the Markdown editor feature

The first step to enable the math formula and flowchart rendering capability in AnQi CMS is to ensure that our content editor supports Markdown format.This setting is very intuitive, just go to the background management interface.

Please log in to the AnQi CMS backend and navigate toGlobal Settingsand then clickContent settings. On this page, you will find a name called “Enable Markdown editorThe options.Please make sure to check this option and save the settings.Turning on the Markdown editor is the foundation for using mathematical formulas and flowcharts, as it allows us to write these special contents using a specific Markdown syntax.


Second step: Introduce the MathJax rendering library

Mathematical formulas are usually written in LaTeX syntax, and browsers themselves cannot directly parse this syntax.To display complex mathematical expressions correctly on the web, we need to use third-party JavaScript libraries like MathJax to render them in real time.

The Anqi CMS template system allows us to flexibly introduce external resources on the page. In the default template structure, there is usually a namedbase.htmlA basic template file named (or similar name), which includes the common header and footer content of the web page. We need to do this in the file<head>Add a line of code in the area to include the MathJax library:

<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

This code will asynchronously load the MathJax core script, once loaded, it will automatically scan the page content, find, and render mathematical formulas that conform to LaTeX syntax. For example, in a Markdown editor, you can use$$...$$Enclose an independent formula display (such as$$E=mc^2$$), or use$...$Enclose an inline formula (such as爱因斯坦的质能方程是$E=mc^2$)


Third step: Introduce the flowchart rendering library (Mermaid.js)

Similar to mathematical formulas, flowcharts also require specialized libraries to parse and render their concise text descriptions.Mermaid.js is a very popular flowchart drawing tool that allows us to define various charts using simple text syntax, including flowcharts, sequence diagrams, Gantt charts, and so on.

Likewise, in order to make Mermaid.js work on the front-end page, we need to add its script inbase.htmltemplate file<head>the area:

<script type="module">
    import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
    mermaid.initialize({ startOnLoad: true });
</script>

This script imports the Mermaid library and initializes it, so that it automatically searches and renders charts that conform to the Mermaid syntax when the page is loaded.In the Markdown editor, you can use a specific Mermaid code block to create a flowchart.

```mermaid
graph TD;
    A[开始] --> B{决策};
    B -- 是 --> C[行动1];
    B -- 否 --> D[行动2];
    C --> E[结束];
    D --> E;

请注意,`mermaid`代码块的开头和结尾需要使用三个反引号(```)标记,并在开头指定语言为`mermaid`。

---

### 第四步:优化Markdown内容显示样式(可选)

虽然上述步骤已经能够正确渲染公式和流程图,但为了让Markdown内容在页面上拥有更好的视觉效果和一致性,您可以选择引入一个预设的Markdown样式表,例如GitHub风格的Markdown CSS。

这同样是在`base.html`模板文件的`<head>`区域内添加一行`link`标签:

```html
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />

After introducing this stylesheet, your Markdown content (including plain text, headings, lists, etc.) will be presented to the user in a more professional and readable GitHub style.


Summary of actual operation procedure

  1. Turn on Markdown editor in the background:Log in to the Anqi CMS backend -> Global settings -> Content settings -> Check 'Enable Markdown editor'.
  2. Modify the template file:Edit the website template directory underbase.htmlfiles (usually located in/template/{您的模板名称}/base.html) at<head>Inside the tag, add the reference code for MathJax, Mermaid, and GitHub Markdown CSS.
  3. Clear the system cache:After modifying the template file, be sure to click the "Update Cache" button on the Anqi CMS backend to clear the front-end template cache in order to ensure that the changes take effect.
  4. Write in the content:When writing article or page content, use the Markdown editor and write your mathematical formulas and flowcharts according to the specifications of MathJax (LaTeX syntax) and Mermaid.js (Mermaid syntax).

By following these steps, you can create high-quality content in AnQi CMS that includes rich mathematical formulas and clear flowcharts, greatly enhancing the professionalism and readability of the content.


Frequently Asked Questions (FAQ)

1. I followed the steps, but the mathematical formula or flowchart still does not display, why is that?

  • Check the cache:First, please confirm whether you have cleared the system cache on the Anqi CMS backend. The modification of template files requires clearing the cache to take effect on the front end.
  • Check the code inclusion location:Ensure MathJax and Mermaid's<script>The label is placed atbase.htmlthe file<head>Inside the tag.
  • Check the network connection:These rendering libraries are loaded through CDN, please make sure that your server and visitors can access the CDN address normallycdn.jsdelivr.netandcdnjs.cloudflare.com)
  • Check Markdown syntax:Please carefully check the LaTeX and Mermaid syntax you have written in the content for correctness.A small spelling error or incorrect formatting can lead to rendering failure.
  • Check browser console:Press F12 to open the browser developer tools, check if there are any JavaScript error messages in the console, this usually helps you locate the problem.

2. Can I download these libraries to my local server if I don't want to use a CDN?Of course you can. You can download the corresponding versions of MathJax and Mermaid.js to your website's static resource directory (such as/public/static/js/),then modifybase.htmlIntroduce these scriptssrcThe path should point to your local resource path. This can reduce the dependency on external CDNs, but you are responsible for updating and maintaining the library files.

**3. Markdown

Related articles

Can I design a dedicated display style for a single page (such as 'About Us')?

In website operation, we all hope that each page can perfectly present its unique content and brand image.For single pages such as 'About Us' and 'Contact Information' that carry corporate culture, core values, or important service information, having a dedicated display style undoubtedly enhances the page's attractiveness and user experience.So, can we design exclusive display styles for these single-page designs in AnQiCMS (AnQiCMS)?The answer is affirmative, and it is more flexible and convenient than you imagined.The Aanqi CMS understands the personalized needs of content display

2025-11-09

How to set the recommended attributes of the article to affect the front-end content sorting and display?

In content operation, how to make meticulously crafted articles seen by more readers and presented in the most prominent position on the website is the core concern of every operator.AnQiCMS provides a set of intuitive and powerful article recommendation attribute settings, helping us easily achieve fine-grained content management and front-end display optimization.This article will elaborate on how to use these properties to cleverly affect the sorting and display of the content on your website's front end.What are article recommendation attributes?

2025-11-09

What methods does AnQiCMS support to display images and thumbnails?

When building and operating a website, displaying images and thumbnails is an indispensable element in attracting users and conveying information.An excellent content management system (CMS) should provide powerful and flexible image processing capabilities.AnQiCMS performs well in this aspect, it not only simplifies the image management process, but also provides a variety of intelligent display methods, helping us easily create websites with outstanding visual effects and fast loading speed.### Core Image Management Capability: Say goodbye to chaos Firstly, AnQiCMS provides a centralized "Image Resource Management" function

2025-11-09

How can I apply a unique document display template under a specific category?

When managing the content of our website, we often encounter such situations: We want articles under a specific category to be presented in a unique layout or style, distinct from the standard display of other parts of the website.For example, product showcase articles may need to include detailed parameter tables and multi-image carousels, while blog articles focus on smooth reading experience and comment sections.AnQi CMS fully understands the importance of this personalized need and provides a very flexible and intuitive way to achieve this, that is to apply a unique document display template for specific categories.

2025-11-09

Does AnQiCMS support showing or hiding specific content based on user group permissions?

In website operation, displaying or hiding specific content based on different user groups is a key link in achieving personalized services and content monetization.Many operators are looking for a content management system that can flexibly support this kind of permission control.Whether does AnQiCMS (AnQiCMS) support displaying or hiding specific content based on user group permissions?The answer is affirmative. AnQiCMS was designed from the beginning with flexibility and diversity in content operations in mind.The built-in "user group management and VIP system" as well as the "flexible permission control mechanism"

2025-11-09

How to ensure accurate switching and display of multilingual content on different user interfaces?

Today, with the increasing closeness of globalization, it is crucial for website content to be accurately presented in multiple languages to users in different regions, which has become a key factor for many enterprises to expand their markets and improve user experience.AnQiCMS (AnQiCMS) took full consideration of the need for multilingual promotion from the very beginning, making it a core feature to help us efficiently manage and display multilingual content.How can we ensure that these multilingual contents are accurately switched and displayed on different user interfaces?This requires us to carefully plan and operate at multiple levels from content preparation, system configuration to front-end display.

2025-11-09

How does AnQiCMS's pseudo-static feature affect the display of content URLs?

How does AnQiCMS's pseudostatic feature affect the display of content URLs?In modern website operations, the structure of the URL (Uniform Resource Locator) is crucial for the website's search engine optimization (SEO) and user experience (UX).A clear, concise, and descriptive URL that not only helps search engines better understand the page content, but also gives users a preliminary understanding of the page information when they see the link.AnQiCMS is a content management system that focuses on SEO optimization, and its powerful static feature is designed to achieve this goal. Static

2025-11-09

How to configure 301 redirects to avoid traffic loss after content adjustments?

In website operation, content adjustment, page revision, or website structure optimization is a common thing.However, every adjustment may come with risks, the most common and far-reaching of which is traffic loss.When the old page address is no longer available and not properly handled, search engines may encounter dead links, and users will see a 404 error page, which undoubtedly seriously damages the SEO performance and user experience of the website.This is when the 301 redirect becomes particularly important, as it is the key tool to ensure seamless connection of the website after content adjustment and avoid traffic loss

2025-11-09