Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TeXmacs/packages/standard/std-math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@

<assign|stack|<macro|x|<tformat|<twith|table-valign|C>|<cwith|1|-1|1|-1|cell-halign|c>|<cwith|1|-1|1|1|cell-lsep|0spc>|<cwith|1|-1|-1|-1|cell-rsep|0spc>|<cwith|1|-1|1|-1|cell-bsep|0.5sep>|<cwith|1|-1|1|-1|cell-tsep|0.5sep>|<cwith|1|1|1|-1|cell-tsep|0sep>|<cwith|-1|-1|1|-1|cell-bsep|0sep>|<arg|x>>>>

<assign|subarray|<macro|x|<stack|<arg|x>>>>>

<assign|to|<macro|\<rightarrow\>>>
<assign|varOmega|<macro|\<varOmega\>>>
</body>
Expand Down
16 changes: 16 additions & 0 deletions TeXmacs/tests/tmu/0308.tmu

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions devel/0308.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# [0308] 添加 subarray 宏支持

## 1 相关文档
- [dddd.md](dddd.md) - 任务文档模板

## 2 任务相关的代码文件
- `TeXmacs/packages/standard/std-math.ts`
- `src/Plugins/Tex/fromtex_post.cpp`

## 3 如何测试

### 3.1 确定性测试(单元测试)
```
# 无新增单元测试
```

### 3.2 非确定性测试(文档验证)
```bash
xmake b stem
```
在 Mogan 中测试:
1. 输入 <subarray|a\\b> 验证渲染效果与 <stack|a\\b> 一致
2. 导入包含 \begin{subarray}{l}...\end{subarray} 的 LaTeX 文档,验证正确转换为 stack 环境

在 Liii 中测试:
打开 TeXmacs/tests/tmu/0308.tmu,对文中的图片进行 OCR 识别,验证识别结果不会出现未正常显示的 subarray 结构。


## 4 如何提交

提交前执行以下最少步骤:

```bash
xmake b stem
```

## 5 What

添加 subarray 宏支持,在 Mogan 内部将 subarray 重定义为 stack 环境,并支持从 LaTeX 导入 subarray 环境。

1. 在 `std-math.ts` 中定义 `subarray` 宏,展开为 `stack`
2. 在 `fromtex_post.cpp` 的 `finalize_pmatrix` 中添加 `subarray` 环境解析,转换为 `stack` 环境

## 6 Why

LaTeX `amsmath` 宏包提供 `subarray` 环境用于多行下标/上标,Mogan 此前没有对应支持。通过将 `subarray` 重定义为 `stack` 环境,可以复用现有排版逻辑,同时兼容 LaTeX 导入。

## 7 How

- 宏层面:在 `std-math.ts` 中通过 `<assign|subarray|<macro|x|<stack|<arg|x>>>>>` 实现,内部使用时自动展开为 `stack`
- 导入层面:LaTeX 的 `\begin{subarray}{l}...\end{subarray}` 在 `fromtex.cpp` 中已被通用环境解析为 `BEGIN "subarray" "l" ...`,只需在 `finalize_pmatrix` 中增加一行 `parse_pmatrix` 调用,将其目标格式设为 `"stack"`,即可复用现有的矩阵/环境解析逻辑(对齐参数也会由 `parse_matrix_params` 自动处理)
2 changes: 2 additions & 0 deletions src/Plugins/Tex/fromtex_post.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ finalize_pmatrix (tree t) {
else if (u[i][0] == "aligned")
parse_pmatrix (r, u, i, "", "", "tabular*");
else if (u[i][0] == "stack") parse_pmatrix (r, u, i, "", "", "stack");
else if (u[i][0] == "subarray")
parse_pmatrix (r, u, i, "", "", "stack");
else if (u[i][0] == "matrix")
parse_pmatrix (r, u, i, "", "", "tabular*");
else if (u[i][0] == "pmatrix")
Expand Down
Loading