博客项目演示网站

代码和数学公式编写

代码和数学公式编写

avatarManfredMT

目录:

代码块使用

本项目的markdown处理器支持代码块的语法高亮和行高亮.

基本写法

编写行内代码可参考markdown的代码基本语法.使用单反引号或者双反引号包裹行内代码.示例如下:

markdown语法显示效果
文字`let x = 1`文字文字let x = 1文字
文字``let s = `string text` ``文字文字let s = `string text` 文字

代码块可以通过缩进的方式或者围栏的方式来创建.

  • 使用缩进方式要在代码块的每一行至少缩进一个制表符或者四个空格.
  • 使用围栏代码块要在代码块的之前和之后加上三个反引号```或者三个波浪号~~~.如果要使用四个五个六个也是可以的.但代码前后要一致.

语法高亮

要显示出代码语法高亮的效果需要使用围栏代码块.在上围栏的三个反引号或者三个波浪号之后加上代码的语言.

markdown写法:

1```js 2let addr = ""; 3for(let i = 0; i < 4; i++) { 4 addr += customer[`address${i}`] + "\n"; 5} 6```

显示为:

1let addr = ""; 2for(let i = 0; i < 4; i++) { 3 addr += customer[`address${i}`] + "\n"; 4}

行高亮

要使用行高亮的功能需要在代码语言后空格再加上大括号包裹的行号,如{3-5,8}代表3,4,5,8行.

代码块中的行高亮示例:

markdown写法:

1```js {3-7,11,15,19,26} 2const videoSchema = mongoose.Schema( 3 { 4 videoId: { 5 type: String, 6 required: [true, "Please add a video id"], 7 unique: true, 8 }, 9 videoSrc: { 10 type: String, 11 required: true, 12 unique: true, 13 }, 14 kind: { 15 type: String, 16 required: true, 17 }, 18 title: { 19 type: String, 20 required: true, 21 }, 22 description: { 23 type: String, 24 }, 25 thumbnail: { 26 type: String, 27 required: true, 28 } 29 }, 30 { 31 timestamps: true, 32 } 33); 34```

显示为:

1const videoSchema = mongoose.Schema( 2 { 3 videoId: { 4 type: String, 5 required: [true, "Please add a video id"], 6 unique: true, 7 }, 8 videoSrc: { 9 type: String, 10 required: true, 11 unique: true, 12 }, 13 kind: { 14 type: String, 15 required: true, 16 }, 17 title: { 18 type: String, 19 required: true, 20 }, 21 description: { 22 type: String, 23 }, 24 thumbnail: { 25 type: String, 26 required: true, 27 } 28 }, 29 { 30 timestamps: true, 31 } 32);

编写数学公式

项目使用KaTex来编写数学公式,因为KaTex具有很好的性能,并且功能足以满足绝大部分需求.要了解KaTex语法可以查看官方文档.在markdown中写KaTex代码需要用$包裹起来.

  • 行内公式用单个$包裹
  • 一段数学公式在之前和之后使用两个$$

示例:

markdown语法显示效果
文字$x\in\mathbb{R}^{p}$文字文字xRpx\in\mathbb{R}^{p}文字

markdown写法:

1$$ 2\eta =\argmax_{\eta;\left \| \eta \right \|_{\infty}\leqslant \epsilon } L[f(x,\theta),f(x+\eta,\theta)] 3$$

显示为:

η=arg maxη;ηϵL[f(x,θ),f(x+η,θ)]\eta =\argmax_{\eta;\left \| \eta \right \|_{\infty}\leqslant \epsilon } L[f(x,\theta),f(x+\eta,\theta)]
上一篇

本网站仅作为项目的演示网站!

下一篇

markdown示例

loading