How to correctly display mathematical formulas and flowcharts in the template of AnQiCMS?

Calendar 👁️ 88

On the day when content management is becoming increasingly refined, websites not only carry text and images but also need to present complex information in a professional and easy-to-understand way, such as mathematical formulas and flowcharts.AnQiCMS is dedicated to providing efficient and flexible content management solutions. When we handle technical articles, academic content, or business process diagrams on our websites, how to ensure that these special elements are displayed correctly and beautifully becomes a topic worth discussing.

AnQiCMS itself provides good support for Markdown editors, which means we can write formulas and flowcharts using concise Markdown syntax.However, to make the browser correctly parse and render these special Markdown syntaxes, some mature front-end libraries are needed.This article will introduce in detail how to introduce these libraries in the AnQiCMS template and ensure that mathematical formulas and flowcharts are perfectly presented.

Preparation: Enable Markdown Editor

Firstly, we need to enable the Markdown editor in the AnQiCMS backend so that we can use the relevant syntax when editing content.

Please log in to your AnQiCMS backend and navigate toGlobal Settings-u003eContent settings. On this page, you will find an option named "Enable Markdown Editor". Be sure to set it to "Is. Enable it to use Markdown syntax when publishing or editing document content.

Core steps: Introduce the frontend support library into the template.

AnQiCMS uses a template engine syntax similar to Django, which means that website templates usually have abase.htmlA file that serves as the skeleton for all pages, carrying common page headers, footers, and so on. In order for mathematical formulas and flowcharts to be displayed normally throughout the site, we need to introduce the required frontend libraries into thisbase.htmlthe file<head>area.

Your template file is located in/templatethe directory, each template package has its own directory. Find the directory of the template package you are currently using.base.htmlFile (or similar public header file), then add the code according to the following steps.

1. Markdown content styling (optional, but highly recommended)

Although this is not necessary for the display of formulas and flowcharts, introducing a set of beautiful Markdown styles can make your content more readable.We recommend using GitHub-style Markdown CSS.

Inbase.htmlthe file<head>Add the following code inside the tag:

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

2. Implement the correct display of mathematical formulas

The rendering of mathematical formulas usually depends on libraries like MathJax, which can convert formulas written in LaTeX, AsciiMath, or MathML syntax into clear and beautiful mathematical symbols.

Continue inbase.htmlthe file<head>Add the CDN script for MathJax inside the tag:

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

3. Implement the correct display of flowcharts

The rendering of flowcharts can be assisted by the Mermaid library, which allows you to generate various charts, including flowcharts, sequence diagrams, Gantt charts, and so on, through simple text descriptions.

Similarly, inbase.htmlthe file<head>Add Mermaid's CDN script and initialization code inside the tag:

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

Render Markdown fields in the content template:

Completed the back-end setup and front-end library integration, and the final step is very critical: make sure that your content template can correctly parse and render Markdown-formatted document content.

In AnQiCMS, when we usearchiveDetailorpageDetailtags to call documents or pagesContentWhen a field needs to be explicitly told to the system to perform Markdown to HTML conversion, this is done by adding in the tag.render=trueParameters to implement. At the same time, since the rendered HTML code may contain tags, we need to use|safea filter to prevent HTML entity escaping.

For example, assuming you are on a document detail pagearticle/detail.htmlor a similar document template, your code might look like this:

<article class="markdown-body"> {# 配合上一步的github-markdown-css样式 #}
    <h1>{% archiveDetail with name="Title" %}</h1>
    <div class="article-content">
        {%- archiveDetail articleContent with name="Content" render=true %}
        {{ articleContent|safe }}
    </div>
</article>

Here:

  • {%- archiveDetail articleContent with name="Content" render=true %}This line of code tells AnQiCMS to get the current document'sContentcontent and render it as Markdown.articleContentIt is the temporary variable we define for rendering results.
  • {{ articleContent|safe }}: Outputs the rendered HTML content safely to the page, preventing the browser from displaying it as plain text.

If you are displaying content in a single page, the calling method is similar:

<div class="page-content markdown-body">
    {%- pageDetail pageContent with name="Content" render=true %}
    {{ pageContent|safe }}
</div>

Test and verify

After completing all the above steps, you can proceed to the test:

  1. Create or edit a document/page in the AnQiCMS backend.
  2. In the content editor, try inserting Markdown syntax for mathematical formulas and flowcharts.
    • Example of mathematical formula (LaTeX syntax):
      
      行内公式:$E=mc^2$
      块级公式:
      $$
      \sum_{i=1}^{n} i = \frac{n(n+1)}{2}
      $$
      
    • Example of flowchart (Mermaid syntax):
      graph TD;
          A[Start] --> B{Decision};
          B -- Yes --> C[Perform Action 1];
          B -- No --> D[Perform Action 2];
          C --> E[End];
          D --> E;
  3. Save and publish the document/page.
  4. Visit the website's front end, view this document/page. If everything is configured correctly, you should be able to see beautifully rendered mathematical formulas and clear flowcharts.

If the display is not normal, please check if there are any JavaScript errors in the browser console and carefully check itbase.htmlcode introduced in CDN and content template inrender=trueand|safeIs the use of the filter correct.

By these simple configurations, your AnQiCMS website can perfectly present complex mathematical formulas and clear flowcharts, greatly enhancing the professionalism and readability of the content, bringing your visitors a better reading experience.


Frequently Asked Questions (FAQ)

Q1: I have enabled the Markdown editor and also configured CDN, but the mathematical formulas and flow charts still do not display, or display as raw Markdown text. Why is that? A1: This is likely because you are in the content template (for examplearticle/detail.htmlorpage/detail.htmlWhen calling article or page content, did not correctly inform AnQiCMS to render Markdown. Make sure you have added inarchiveDetailorpageDetailtags.render=trueParameter, and the content output has been used|safea filter. For example:{% archiveDetail articleContent with name="Content" render=true %}{{ articleContent|safe }}.

Q2: Can I customize the style of the formulas and flowcharts rendered by MathJax or Mermaid? A2: Of course you can. MathJax and Mermaid both offer a rich set of configuration options, allowing you to customize fonts, colors, layouts, etc. You can modifymermaid.initialize()Configuration parameters, or defined before the MathJax script is loadedMathJax = { ... }objects to customize their behavior and style. In addition,

Related articles

How to insert Markdown formatted text in website content and render it correctly as HTML?

In AnQiCMS, inserting Markdown formatted text and rendering it correctly to HTML is an important way for content operators to improve efficiency and produce high-quality pages.AnQiCMS has built-in support for Markdown editing and rendering, allowing you to enjoy the simplicity and efficiency of Markdown while ensuring that the final page output is beautiful and structured HTML.### Enable Markdown Editor To start using Markdown in AnQiCMS, you first need to ensure that the editor feature is enabled

2025-11-07

How to dynamically display the website's logo image in the template of AnQiCMS?

The website's logo is the core of the brand image, it not only enhances the professionalism of the website, but also facilitates users in quickly identifying and remembering your brand.For AnQiCMS users, dynamically displaying the logo image in the website template is a basic and important operation.Luckyly, AnQiCMS provides a very convenient way to achieve this, allowing you to easily manage and display the website logo without writing complex code.### Website Logo Management: Backend settings are crucial Display the Logo on your AnQiCMS website

2025-11-07

How to display a user comment list on the front end and support review status display?

User comments are an important manifestation of website vitality, they not only enhance the interactivity of content but also provide valuable reference for other visitors.AnQi CMS understands the importance of comment management, providing simple and powerful features that allow you to flexibly display comment lists on the website front end and clearly identify the review status of comments.The core of displaying the comment list on the front-end: `commentList` tag To display user comments on your website's front-end page, you need to use the `commentList` template tag provided by AnQiCMS

2025-11-07

How to display a list of website friend links in the front-end template?

In website operation, friendship links are not only a bridge between websites, but also an important strategy to enhance website authority, increase external traffic, and optimize search engine rankings.Reasonably configure and display friendship links, which can effectively improve the website's SEO performance and provide users with more valuable external resources.AnQiCMS as an efficient content management system, fully considers this need, and provides a simple and intuitive way to manage and display friend links in the front-end template.### Backend Management: Setting and Maintaining Friend Links Display Friend Links on the Front-end Page

2025-11-07

Enhance interactive security: A practical guide to integrating captcha in the Anqi CMS frontend comments or messages

The website's comment section and message board are important channels for user interaction with the website.However, these interactive areas are often plagued by spam and automated programs, which not only affect the cleanliness of the website but also reduce the reading and communication experience of users.(CAPTCHA) is the effective barrier against such problems, it distinguishes between human users and malicious robots by requiring users to complete a task that is easy for humans but difficult for computers.For a website built with Anqi CMS, integrating captcha is not a complex matter.The Anqi CMS system provides a simple and clear path

2025-11-07

How to automatically parse URL addresses into clickable links in article content for AnQiCMS?

When using AnQiCMS for website content operation, we often hope that URLs in articles, product descriptions, or other text content can be automatically identified and converted into clickable links. This not only improves user experience but also helps in the dissemination of content and is friendly to search engines.AnQiCMS as a content management system focusing on efficiency and SEO optimization has of course considered this requirement and provided a very convenient implementation method.This is mainly due to its flexible template engine and built-in filter functions.To implement automatic URL parsing in article content

2025-11-07

How to display website traffic statistics and spider crawling information on the front end?

We often care about the number of visits to our website, and which search engine spiders have crawled our content.This data can not only help us understand the health status of the website, optimize the content strategy, but also improve user trust.The Anqi CMS provides detailed traffic statistics and crawler monitoring functions in the background, allowing us to have a thorough understanding of the website's operational status.If you want to present valuable data such as today's visitor count and yesterday's spider visit count directly on the website front end, how can you achieve this?### AnQi CMS data statistics capability First

2025-11-07

How to control the style of each element within a loop in AnQiCMS templates (such as odd and even rows differently)?

In website content display, we often need to present data in a list form, such as article lists, product lists, or category navigation.To make the page more attractive or to better organize information, we often hope that each element in the list has a different style, such as the common even-odd row background **split.AnQiCMS provides a powerful and flexible template system, making it very simple to implement these fine style controls.AnQiCMS's template system borrows the syntax of the Django template engine, which is characterized by the use of double curly braces for variables

2025-11-07