Typst-Algorithms 项目教程
typst-algorithms 项目地址: https://gitcode.com/gh_mirrors/ty/typst-algorithms
1. 项目目录结构及介绍
Typst-Algorithms 项目的目录结构如下:
typst-algorithms/
├── examples/
│ ├── examples.typ
│ └── test.typ
├── .gitignore
├── LICENSE
├── README.md
├── algo.typ
├── typst.toml
目录结构介绍
-
examples/: 包含项目的示例文件,展示了如何使用
algo
和code
函数编写伪代码和代码块。examples.typ
: 示例文件,展示了不同风格的伪代码和代码块。test.typ
: 测试文件,用于验证代码的正确性。
-
.gitignore: Git 忽略文件,指定哪些文件和目录不需要被 Git 跟踪。
-
LICENSE: 项目的许可证文件,本项目使用 MIT 许可证。
-
README.md: 项目的说明文件,包含项目的基本介绍、使用方法和示例。
-
algo.typ: 核心文件,定义了
algo
和code
函数,用于编写伪代码和代码块。 -
typst.toml: 项目的配置文件,包含项目的元数据和依赖项。
2. 项目启动文件介绍
项目的启动文件是 algo.typ
,该文件定义了 algo
和 code
函数,用于在 Typst 中编写伪代码和代码块。
algo.typ
文件内容
#import "@preview/algo:0.3.3": algo, i, d, comment, code
// 使用 algo 函数编写伪代码
#algo(
title: "Fib",
parameters: ("n"),
)[
if $n < 0$:
return null
if $n = 0$ or $n = 1$:
return $n$
return #smallcaps("Fib")$(n-1) +$ #smallcaps("Fib")$(n-2)$
]
// 使用 code 函数编写代码块
#code()[
```py
def fib(n):
if n < 0:
return None
if n == 0 or n == 1:
return n
return fib(n-1) + fib(n-2)
]
### 启动文件介绍
- **`algo` 函数**: 用于编写伪代码,支持自定义标题、参数、行号、关键字强调等功能。
- **`code` 函数**: 用于编写代码块,支持行号、缩进指南、填充颜色等样式选项。
## 3. 项目的配置文件介绍
项目的配置文件是 `typst.toml`,该文件包含了项目的元数据和依赖项。
### `typst.toml` 文件内容
```toml
[package]
name = "typst-algorithms"
version = "0.3.3"
description = "A Typst library for writing algorithms"
license = "MIT"
[dependencies]
typst = "0.6.0"
配置文件介绍
-
[package]
: 定义了项目的名称、版本、描述和许可证。name
: 项目名称,typst-algorithms
。version
: 项目版本,0.3.3
。description
: 项目描述,A Typst library for writing algorithms
。license
: 项目许可证,MIT
。
-
[dependencies]
: 定义了项目的依赖项。typst
: 依赖的 Typst 版本,0.6.0
。
通过以上配置文件,Typst 可以正确识别项目的依赖关系,并确保项目在正确的环境中运行。
typst-algorithms 项目地址: https://gitcode.com/gh_mirrors/ty/typst-algorithms