Typst-Algorithms 项目教程

Typst-Algorithms 项目教程

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/: 包含项目的示例文件,展示了如何使用 algocode 函数编写伪代码和代码块。

    • examples.typ: 示例文件,展示了不同风格的伪代码和代码块。
    • test.typ: 测试文件,用于验证代码的正确性。
  • .gitignore: Git 忽略文件,指定哪些文件和目录不需要被 Git 跟踪。

  • LICENSE: 项目的许可证文件,本项目使用 MIT 许可证。

  • README.md: 项目的说明文件,包含项目的基本介绍、使用方法和示例。

  • algo.typ: 核心文件,定义了 algocode 函数,用于编写伪代码和代码块。

  • typst.toml: 项目的配置文件,包含项目的元数据和依赖项。

2. 项目启动文件介绍

项目的启动文件是 algo.typ,该文件定义了 algocode 函数,用于在 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 typst-algorithms 项目地址: https://gitcode.com/gh_mirrors/ty/typst-algorithms

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凤高崇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值