How to correctly insert mathematical formulas and flowcharts in a Markdown editor and ensure they display normally on the web?

Calendar 👁️ 93

In content creation, especially in fields involving technology, science, or complex concepts, we often need to insert mathematical formulas or draw flowcharts to assist in explanation.The Markdown editor of AnQiCMS (AnQiCMS) provides us with great convenience, allowing these complex elements to be input in a concise text format and presented elegantly on the web.How can we specifically operate to ensure that the content is displayed correctly?

Firstly, make sure that your CMS system has enabled the Markdown editor.You can go to the Anqi CMS backend, find the corresponding option under "Global Settings" and "Content Settings", and set it to enabled.This is the foundation for all subsequent steps.

Insert mathematical formula and ensure its correct display

In the Markdown editor, mathematical formulas are usually written using LaTeX syntax.AnQi CMS integrates MathJax or a similar library to parse these formulas.When writing, you can choose between two forms: inline formula and block-level formula.

  • Inline formula: If you want to insert a short mathematical expression in a paragraph of text, you can use a single dollar sign$Wrap the formula. For example,$E=mc^2$It will display Einstein's mass-energy equation in the text stream.
  • Block formula: For formulas that need to be displayed independently, centered, and may contain multiple lines or complex structures, you can use double dollar signs.$$Enclose it. For example:
    
    $$
    \int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
    $$
    
    This format causes the formula to be displayed on a new line and is usually centered.

It is not enough to enter formulas in the editor, a special JavaScript library is needed in the web browser to render these LaTeX syntaxes into recognizable mathematical symbols.We usually rely on CDN resources like MathJax./templateUnder the directorybase.htmlfile, and in its<head>the tag the followingscriptcode:

<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 library, which will automatically scan and render mathematical formulas on the page after it is loaded.

Insert a flowchart and ensure it is displayed correctly.

Flowcharts play an indispensable role in explaining business logic and program algorithms.The Anqi CMS Markdown editor supports Mermaid syntax for drawing flowcharts.Mermaid is a text-based chart tool that can convert concise text descriptions into beautiful charts.

In the Markdown editor, you need to use special code blocksmermaidto enclose your flowchart description. For example, a simple flowchart can be written like this:

graph TD
    A[Start] --> B{Do you meet the condition?};
    B -- Yes --> C[Perform action];
    B -- No --> D[End];
    C --> D;

This code will describe a simple judgment process from 'beginning' to 'end'.

Similar to mathematical formulas, Mermaid flowcharts also require a JavaScript library to be rendered in the browser. You also need to editbase.htmlfile, and in its<head>the tag the followingscriptcode:

<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 will import the Mermaid library and initialize it to be able to recognize and render Markdown inmermaidcode blocks defined by flowcharts. Please notetype="module"It is the syntax of ES module, ensuring that the browser can load it correctly.

Integrate styles with the final presentation

To make your Markdown content, including formulas and flowcharts, visually more coordinated and professional, you can also consider introducing a default Markdown stylesheet. For example, you canbase.htmlof<head>Add:

<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 Markdown rendering effects similar to GitHub, making your content more unified and beautiful.

After completing these steps, save your template file and ensure that the article content has used LaTeX and Mermaid syntax correctly.When visiting a webpage, these formulas and flowcharts are automatically parsed and rendered by the JavaScript library loaded in the browser, clearly presented to the reader.If you encounter display issues, please check the browser console (F12) for any error messages and confirm that all CDN links are accessible and error-free.


Frequently Asked Questions (FAQ)

  1. Why is the formula or flowchart I inserted in the background Markdown editor not displayed on the front page?This is usually because you have not included the template file for the website (such asbase.html) Properly introduce the corresponding rendering library script. MathJax (for mathematical formulas) and Mermaid (for flowcharts) both need to pass throughscriptThe tag needs to be loaded from the CDN and initialized before it can be parsed and displayed in the browser for the special Markdown syntax. Please check yourbase.htmlfile to ensure that the mentioned above is correctscriptThe code has been added correctly.

  2. If my website already has custom CSS styles, introducinggithub-markdown-cssWill it cause style conflicts? github-markdown-cssIt is a general Markdown rendering stylesheet that provides default styles for common Markdown elements (such as headings, paragraphs, lists, code blocks, etc.).If your website already has very detailed custom CSS, there is indeed a possibility of some style conflicts.github-markdown-cssPlace the reference after your custom CSS so that your custom styles can override it; or, you can optionally only include a part of itgithub-markdown-cssThe rule, or simply not to introduce, but to write exclusive styles for Markdown content according to your own design style.

  3. Can I use multiple mathematical formula rendering libraries or flowchart libraries at the same time?In technical terms, it is feasible to load multiple libraries simultaneously, but it is usually not recommended.This may lead to resource redundancy, increase page load time, and there may be compatibility issues or conflicts between different libraries, leading to incorrect rendering.To ensure **'s performance and stability, it is recommended that you choose a rendering library that meets your needs (such as MathJax and Mermaid) and maintain consistency throughout the entire website.If you indeed have special requirements, be sure to perform thorough testing to ensure that all content is displayed normally.

Related articles

How to define temporary variables with the `with` tag in a template to better control content display logic?

When developing website templates in AnQiCMS, we often need to handle various data and decide the display mode of the content according to these data.With the complexity of website functions, the logic in the templates sometimes becomes difficult to understand and maintain.At this point, mastering some advanced template tag usage is particularly important, and the `with` tag is one of the practical tools that can significantly improve the readability and control of the template.### The `with` tag: A tool for defining temporary variables in templates The `with` tag allows us to define temporary variables within a specific area of the template

2025-11-08

How to use the `stampToDate` tag to format timestamps into a friendly date format to display content publication time?

During the operation of the website, the publication time of the content is an important part of conveying information to visitors.A clear and readable date format not only enhances user experience but also makes the website look more professional and timely.In AnQiCMS, the content publish time is usually stored in the form of a series of numbers (i.e., a timestamp).How can we convert these numbers into the familiar 'year-month-day' or 'month/day time:minute' formats that we are accustomed to?AnQiCMS provides us with a very convenient template tag: `stampToDate`.

2025-11-08

How to use `if` and `for` tags to implement conditional display and loop display of content in AnQiCMS templates?

In the AnQi CMS template world, flexibly controlling the display of content is the key to creating an engaging website.Whether it is to display different information based on specific conditions or to efficiently display a large amount of data, the `if` and `for` tags are indispensable tools for us.AnQiCMS's template engine adopts the syntax of Django, making these operations intuitive and powerful.### Understanding the `if` tag: Implementing conditional display of content The core function of the `if` tag is to decide whether to display a part of the content based on the conditions you set

2025-11-08

How `tdk` tags can dynamically generate and optimize SEO-related Title, Keywords, and Description for each page?

In modern website operation, the importance of Search Engine Optimization (SEO) is self-evident, and the page title (Title), keywords (Keywords), and description (Description), which we commonly refer to as TDK, are the "business card" of the website content on the Search Engine Results Page (SERP).They not only directly affect the click-through rate of the page, but are also key factors for search engines to understand the content of the page and rank it.AnQiCMS (AnQiCMS) fully understands the significance of TDK for SEO, and therefore in the system design

2025-11-08

How does the search engine link push feature help new documents be indexed and displayed in search results quickly?

On the day of content release, how can your meticulously crafted website content be quickly discovered and indexed by search engines, which is a focus for every content operator.A newly released article or product page, if it can appear quickly in the search results, it will undoubtedly seize the initiative and bring valuable early traffic.AnQiCMS (AnQiCMS) fully understands this need and has specially provided a search engine link push feature to help your new document reach the search engine as quickly as possible, thereby speeding up indexing and display.Why is it important to be indexed quickly?

2025-11-08

How to configure custom rewrite rules to create more SEO-friendly content URLs?

The importance of URL structure in website operation is self-evident.A clear, concise, and keyword-rich URL not only improves user experience but also makes it easier for users to remember and share content, and can significantly optimize the crawling and ranking effects of search engines.Aqicms is well aware of this, therefore it provides a flexible and powerful pseudo-static rule configuration function to help users create more SEO-friendly content URL displays.What is the pseudo-static URL and its importance?So-called pseudo-static is not a real static page, but refers to URL rewriting technology through the server

2025-11-08

How to handle images (download remote, Webp, compress large images) to optimize page display speed in content settings?

As website operators, we all know that website loading speed is important for user experience and search engine rankings.Especially on content-rich websites, images are often a key factor affecting page speed.AnQiCMS (AnQiCMS) provides us with several very practical image processing features in the content settings, allowing us to flexibly optimize images and significantly improve the display speed of the website. ### Localizing remote images, controlling image resources During the process of content creation, we sometimes refer to images from other websites. At this time

2025-11-08

How does the navigation settings support creating navigation at different locations to meet the diverse content display needs of the website?

In website operation, the navigation system plays a crucial role, it is not only the map for users to explore the content of the website, but also the key for search engines to understand the structure of the website.A well-designed navigation can significantly improve user experience, guide users to discover more interesting content, thereby extending visit time, and indirectly help the website's SEO performance.AnQiCMS provides a user-friendly and powerful navigation settings feature, allowing you to flexibly build various types of navigation to meet the diverse content display needs of the website.### Core Concept: Flexible Construction of Navigation AnQiCMS

2025-11-08