How to display mathematical formulas and flowcharts with Markdown in AnQiCMS?

Calendar 👁️ 80

In content operation, sometimes we need to display complex mathematical formulas or clear flow charts, especially in technical articles, data reports, or educational content.AnQiCMS with its powerful Markdown editor provides us with the convenience to meet this requirement.By simple configuration and introducing the necessary library files, you can perfectly present these professional contents on the website front-end.

Enable AnQiCMS Markdown Editor

Firstly, you need to make AnQiCMS recognize and handle Markdown format content, and you need to make corresponding settings in the background.Please go to the "Global Settings" in the AnQiCMS admin panel, find the "Content Settings" option.Here, you will see an option to "enable Markdown editor", check it and save the changes.After enabling this feature, you can choose Markdown format to write content when creating or editing documents.

Insert mathematical formulas and flowcharts in the content

Enable Markdown editor after, in the document content area, you can directly use Markdown syntax to write mathematical formulas and flowcharts.

Fora mathematical formulaThis is usually done in the following way:

  • Inline formula:Using a single$symbol enclosed, for example$E=mc^2$.
  • Inline formula:Using double$$Symbols enclosed, formulas will be displayed on separate lines and centered, for example$$ \sum_{i=1}^n i = \frac{n(n+1)}{2} $$.

ForFlowchartYou can use Mermaid syntax to place it in a special Markdown code block:

```mermaid
graph TD;
    A[开始] --> B{决策};
    B -- 是 --> C[执行操作];
    C --> D[结束];
    B -- 否 --> D;
```

These syntaxes will be recognized in the Markdown editor, but to ensure they are displayed correctly on the front-end page, further steps are required.

Add basic styles to Markdown content

To make your Markdown content look tidy and professional on your website, we can introduce a universal Markdown stylesheet.This is like putting on a beautiful dress for text content. You need to place it in the public header file of the website (usuallybase.html, located/templateIn the folder of the template you are using under the directory<head>Area, add the following CDN links:

<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" />

This stylesheet provides a set of default styles for the HTML elements rendered by Markdown, significantly enhancing the visual appeal and readability of the content.

Ensure the correct display of mathematical formulas

The rendering of mathematical formulas requires a dedicated JavaScript library to convert Markdown-formatted formulas into browser-displayable mathematical symbols.MathJax is a very popular choice, it can convert formulas in LaTeX and other formats into high-quality layouts.Likewise, inbase.htmlthe file<head>The area, following the Markdown style sheet, add MathJax CDN reference:

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

This script will asynchronously load the MathJax library and automatically scan and render mathematical formulas on the page after it is loaded.

Implement the dynamic rendering of flowcharts.

The display of flowcharts can be achieved with the Mermaid library.Mermaid allows you to create various types of diagrams using simple text syntax.To enable it, pleasebase.htmlthe file<head>or<body>Add the following code before the end tag:

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

This code imports the Mermaid library and initializes it to automatically recognize and render the flowchart definitions in Markdown code blocks after the page has loaded.

Template content rendering settings

After completing the reference to all the external libraries, the most critical step is to ensure that your AnQiCMS template can correctly render Markdown content into HTML. In obtaining the template tags for document content (such as those commonly used in document detail pages, for example, in the document detail page),archiveDetailIn the tag),you need to handle it specially.

AnQiCMS template system provides convenience for rendering Markdown content. You are usingarchiveDetailLabel can be added when fetching contentrender=trueThe parameter tells the system to automatically convert Markdown formatted text to HTML. Moreover, to avoid the HTML code being doubly escaped by the browser and causing display exceptions, it is necessary to use it in conjunction with|safefilter.

Therefore, the fragment of the document body that you retrieve and display in your template may look like this:

{% archiveDetail articleContent with name="Content" render=true %}
{{ articleContent|safe }}

With such settings, you can use the Markdown editor in AnQiCMS backend to write content containing mathematical formulas and flowcharts, which can be correctly parsed, rendered, and beautifully presented on the front-end page.


Frequently Asked Questions (FAQ)

  1. Q: Why did the mathematical formulas and flowcharts still not display after I added the CDN and template code according to the steps?

    • A:When encountering this situation, please check the following key points first:
      • Is the Markdown syntax correct?Confirm the mathematical formula you entered in the background (for example$$...$$) and the flowchart (for examplemermaid ...The syntax complies with Markdown and MathJax/Mermaid standards. Any minor grammar error can lead to rendering failure.
      • Are the template rendering parameters and filters applied correctly?Ensure that your template uses it to get content when{% archiveDetail ... render=true %}and adds it when outputting{{ variable|safe }}. If missingrender=true, Markdown will not be converted to HTML by AnQiCMS; if missing|safeThe converted HTML may be escaped again by the browser, causing MathJax and Mermaid to fail to recognize and process.
      • Is the CDN link valid and accessible?Use the browser developer tools' Network tab to check if the CDN files of MathJax and Mermaid are loaded successfully, without any 404 or other network errors.
      • Is there a JavaScript error in the browser console?In the browser developer tool's Console tab, check if there are any JavaScript error reports related to MathJax or Mermaid, which will help locate the problem.
  2. Q: Can I download the MathJax and Mermaid library files to the local server instead of using CDN?

    • A:Absolutely. If you have special considerations for the loading speed, stability, or reliance on CDN of the website, you can download these JavaScript library files to your server.Then, willbase.htmlReplace the CDN link with the relative paths of these local files. For example, you can store the files in/public/static/js/directory, thensrcThe property to/static/js/mathjax.jsor/static/js/mermaid.esm.min.mjsThe specific path depends on the actual storage location of your file.
  3. Q: Does AnQiCMS support other mathematical formula or flowchart rendering libraries besides MathJax and Mermaid?

    • A:AnQiCMS itself provides a powerful Markdown editor and the core capability to render Markdown content to HTML.This means theoretically, as long as any third-party library that can be rendered on the front-end through JavaScript, you can try to integrate it into your AnQiCMS website.You just need to find the CDN link or local file of the corresponding library, add it to your template according to its official documentation, and ensure that the content is output in the correct HTML structure so that these libraries can recognize and process it further.

Related articles

How to display the complete article content on the article detail page, including lazy-loaded images?

How to elegantly display full content and lazy loading images on article detail pages in AnQi CMS In website content operations, the article detail page is an important touchpoint for users to obtain information and gain a deeper understanding of brands and products.A well-designed, fast-loading, and comprehensive article detail page that can greatly enhance user experience and effectively assist in SEO optimization.For users who use Anqi CMS, taking full advantage of its powerful template tag system can easily realize the complete presentation of article content, and combine modern web technologies to implement lazy loading of images, making your website both beautiful and efficient.###

2025-11-08

How to display a document list based on different conditions (such as categories, recommended properties)?

In Anqi CMS, flexibly displaying website content is the key to improving user experience and meeting operational needs.Whether based on the category of the article or the recommended attributes of the content, the system provides powerful and easy-to-use template tags that allow you to easily customize the display of the document list. ### Core Tool: `archiveList` Document List Tag The core tool used in AnQi CMS to control the display of document lists is the `archiveList` tag.It allows you to filter, sort, and limit the number of displayed documents based on multiple conditions

2025-11-08

How to get and display all the content and associated images of a specific single page?

In Anqi CMS, a single page is an important part of the website content structure, such as "About Us", "Contact Information", and so on.Effectively acquire and display all the content of these single pages and associated images, which is crucial for the communication and visual expression of the website.Aanqi CMS provides an intuitive backend management and flexible template tags, making this process very convenient. ### Easily set up single page content and images in the background First, we need to create and edit single page content in the Anqi CMS backend management system. This is usually performed under the 'Page Resources' section in the 'Page Management' module

2025-11-08

How to display all or part of a single-page list on a website?

In website operations, we often need to display some independent, fixed-content pages, such as 'About Us', 'Contact Information', or some policy descriptions, etc.In Anqi CMS, these are called "single pages". Effective management and presentation of these single pages not only makes the website structure clearer but also enhances the user experience.Next, we will discuss how to flexibly display all or part of a single-page list on a website.### **Understanding the Creation and Management of Single Pages (Backend Operations)** Before Starting the Frontend Display

2025-11-08

How to display the links to the previous and next articles on the document detail page?

When browsing website content, users often want to be able to navigate easily between related articles.For example, after reading a news article or tutorial, you can quickly click to go to the "previous" or "next" article to maintain the continuity of reading.This not only improves user experience and reduces the bounce rate, but also has a positive effect on the internal link structure of the website and search engine optimization (SEO).AnQiCMS (AnQiCMS) is an efficient content management system that provides a very simple and intuitive way to implement this function.We do not need complex backend programming

2025-11-08

How to display a list of related articles below the article detail page?

In website operation, the list of "related articles" at the bottom of the article detail page is an important function to enhance user experience, increase page views (PV), and prolong the time users stay on the site.It can guide users to discover more interesting content, thereby enhancing the overall stickiness of the website, and also has a positive effect on search engine optimization (SEO).To implement this feature in AnQi CMS, it benefits from its flexible template system and powerful tag functions, making the entire process intuitive and efficient.### One, understand the call mechanism of "related articles" The template tags of AnQi CMS are the core of realizing various functions

2025-11-08

How to display custom parameters on an article or product detail page?

In website operation, adding personalized information to articles or product detail pages is the key to improving content professionalism and user experience.AnQiCMS (AnQiCMS) fully understands this need and provides powerful customizable parameter functions, allowing us to flexibly add and display the required information according to different content types. Imagine you publish a technical article, in addition to the title and content, you also want to display unique attributes such as "author", "publish date", "technology stack", and so on; Or maybe, you are selling a product, in addition to the usual name, price, and description, you also want to highlight the "color"

2025-11-08

How to implement filtering conditions based on document parameters and display the filtering results?

In AnQiCMS (AnQiCMS), using document parameters to build flexible filtering conditions and display the filtering results is a key factor in improving website user experience and content management efficiency.This not only helps users find the information they need faster, but also makes the website's content structure clearer.This article will introduce you to how to implement this feature in AnQi CMS, from the initial parameter definition to the final filtering and display, helping you easily master content management.## Make content smarter: How to cleverly use document parameters to implement filtering function in Anqi CMS As the content of the website continues to enrich

2025-11-08