As a professional who deeply understands the operation of AnQiCMS (AnQiCMS), I will detail how to correctly display mathematical formulas and flowcharts in AnQiCMS.The AnQi CMS has added support for Markdown editors in the new version, which greatly enriches the expression forms of content creation, making it possible to insert complex mathematical formulas and intuitive flowcharts into articles.However, to perfectly present these special contents on the frontend page, some additional configuration steps are required, mainly using external JavaScript libraries for rendering.
In order to be able to use the Markdown editor to create mathematical formulas and flowcharts, you first need to enable the Markdown editor feature in the Anqi CMS backend.You can navigate to the 'Global Settings' under the 'Content Settings' option, where you can find and enable the Markdown editor.After enabling, you can choose to use Markdown format for content creation when creating or editing documents.
Mathematical formulas and flowcharts inserted in Markdown editors, although they can be recognized as specific syntax, browsers themselves cannot directly render these complex structures.Therefore, we need to introduce the corresponding third-party JavaScript library to parse and beautify these contents.These libraries are typically provided through content delivery networks (CDN) for fast loading and stable operation.base.htmlfile, and include these scripts in the header area of the page.
For the correct display of mathematical formulas, we recommend using the MathJax library.MathJax can render mathematical expressions in LaTeX, MathML, or AsciiMath format into high-quality images or HTML elements, ensuring that formulas are presented clearly and accurately across various devices and browsers.base.htmlAdd the following script reference to the header area of the file:
<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 find and render the mathematical formulas you have written in Markdown content after the page has finished loading. In Markdown, you can use$$...$$or$...$Write a mathematical formula, for example: $$E=mc^2$$.
Similarly, for the drawing and display of flowcharts, Mermaid is a very powerful JavaScript library.Mermaid allows you to define various charts using simple text syntax, including flowcharts, sequence diagrams, Gantt charts, and more.It can convert these text definitions into SVG graphics, thus achieving cross-platform and responsive chart display.base.htmlAdd the following JavaScript code to the header area of the file:
<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 will import the Mermaid library in a modular way and initialize it to automatically search and render diagrams when the page loads. In Markdown, you can use a specific Mermaid syntax block to define diagrams, such as:
```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
此外,为了让您的Markdown内容拥有更一致和美观的样式,尤其是在显示代码块和表格时,您可以考虑引入GitHub风格的Markdown CSS。这并非强制,但能显著提升阅读体验。您可以在`base.html`文件的头部添加如下样式表链接:
```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" />
Common Questions and Answers (FAQ)
1. Why does the mathematical formula and flow chart still not display even though I have configured it according to the steps?
Firstly, please ensure that you have enabled the Markdown editor in the 'Global Settings' -> 'Content Settings' of the AnQiCMS backend. Secondly, check carefully.base.htmlWhether the CDN link included in the file is complete and correct, and is located in the correct position (usually in the<head>Tag inside.Network connection issues may also cause CDN resource loading to fail. You can try changing your network environment or check the browser console for error messages.graph TDstandard.
2. Can I deploy MathJax and Mermaid libraries on my own server instead of using a CDN?
Yes, you can choose to download the files of MathJax and Mermaid libraries to your server and modify thembase.htmlThe script reference path points to your local file. For example, set the scriptsrcattribute to/public/static/js/mathjax/tex-mml-chtml.js.The benefits of doing so include avoiding dependence on external CDNs, improving the website's autonomy and control, and possibly providing faster loading speeds in certain network environments.However, you need to manage the updates and maintenance of these libraries yourself.
3. What are some recommended syntaxes for writing mathematical formulas and flowcharts in Markdown?
For mathematical formulas, the most commonly used is LaTeX syntax. Inline formulas can be enclosed using$your formula$, and standalone formula blocks can be enclosed using$$your formula$$. For example:$a^2 + b^2 = c^2$and$$x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}$$.
For flowcharts, Mermaid has its specific text syntax. It starts withmermaid `开始,以`end. For example, a simple flowchart can be defined as follows:
```mermaid
graph LR
A[开始] --> B{决策?};
B -- 是 --> C[执行操作];
B -- 否 --> D[结束];
C --> D;
[en] You can refer to the official documentation of MathJax and Mermaid for more detailed and complex syntax examples.