正式出版物: typst vs markdown(pandoc) vs latex

当时typst还不成熟,所以采用了 pandoc模板 的方案。

折腾这个pandoc方案还需要维护一个比较复杂的模板框架与年久失修的filter插件。

目前也在学习typst,感觉适合有编程基础的学,毕竟 #开头 的都是代码/命令。

希望typst能变成pandoc的替代品,pandoc的ppt转译器或其架构不太好调整了,也比较久没维护了,没有新功能。

需求

先总结

  • pandoc虽然支持格式广泛,但如果要做到正式出版物的程度,要折腾,消耗很多精力,找各种第三方插件,还有各种坑。可能会出现,我明明在写文章,但我得先去修复插件的bug 😂。如果一定需要支持可编辑的doc/ppt ,再考虑pandoc+markdown吧。
    • slidev支持从markdown生成网页交互式ppt,也可以折腾一个slidev模板。
  • latex 尾大不掉,我没用过所以无法深入评价。
  • typst,性能新星,官方云服务支持多人编辑,排版够用,但对中文支持欠缺。相对markdown要学更多,是一种可编程的文章格式(mdx: 有人说我吗)。
    • 仍然需要用pandoc从typst转doc
    • 插件导出的ppt是烘焙图片的只读形式,缺乏动态的交互。

导出doc&ppt:pandoc胜出

楼主用过pandoc折腾过毕业论文,所以必须要支持导出到docx给老师看,如果支持ppt方便答辩展示则是一个加分项。

  • pandoc: 双向转换,支持最多的格式,生成可编辑的pptx与docx
  • typst: 官方支持 PDF, PNG, SVG, HTML. 插件支持 图片烘焙的静态只读PPT, DOC
  • latex: 貌似官方只能导出pdf,latex与其他格式互转需要借助pandoc

TOC目录生成

TODO: 不知道 自定义目录样式 谁的上限高,不过应该都挺折腾的,不评价。

pandoc导出的 docx 还需要进 word 二次编辑。

  • pandoc: 比较鸡肋, 见issue: 目录无法单开一页

    yaml 复制代码
    # pandoc --defaults=conf.yaml
    toc: true
    toc-depth: 4
  • typst

    typst 复制代码
    #outline()
  • latex

    latex 复制代码
    \tableofcontents

引用:typst胜出

联动生成参考文献

typst和latex很方便,pandoc折腾好了还行

  • pandoc, 需2个独立文件

    markdown 复制代码
    这里引用AClon的文献。 [@ref_2026]
    
    <!-- 参考文献 -->
    
    ::: {#refs}
    :::
  • typst, 参考文献

    typst 复制代码
    这里引用AClon的文献。@ref_2026 @cite_id.
    你也可以显式地调用`cite`命令: #cite(<ref_2026>)
    
    #bibliography("ref.bib")
  • latex

    latex 复制代码
    这里引用AClon的文献。\citet{ref_2026}

脚注

语法上都各有所好,有的长点,有的短点,不评价。

  • pandoc

    markdown 复制代码
    Here is a footnote reference,[^1] and another.[^longnote]
    [^1]: Here is the footnote.
    [^longnote]: Here's one with multiple blocks.
  • typst

    typst 复制代码
    You can edit Typst documents online.
    #footnote[https://typst.app/app] <fn>
    Checkout Typst's website. @fn
    And the online app. #footnote(<fn>)
  • latex

    latex 复制代码
    \footnote[number]{text for footnote}

图表&自动标注:typst胜出

pandoc这里完全依赖第三方插件,不推荐,很折腾。

latex语法太冗长了。

typst的表格没有markdown的表格语法直观,但typst的表格排版更好控制。

  • 第三方插件 pandoc-crossref

    如果要将 mermaid, plantuml 的代码块变成标号图,就需要自己折腾。

    我的方法是convert.py里的正则替换来自动给 区分开,自动编号。需配合pandoc-figure-caption-patch

    markdown 复制代码
    ---
    ## pandoc-figure-caption-patch
    autoFigLabels: true
    
    ## crossref
    chapters: true
    chaptersDepth: 1
    figureTitle: "图"
    tableTitle: "表"
    titleDelim: " "
    chapDelim: "-"
    figPrefix: [""]
    tblPrefix: [""]
    ---
    
    ```mermaid
    graph LR
    A --> B
    ```
    
    : mermaid's caption {#fig:mermaid}
    
    ```plantuml
    A -> B
    ```
    
    : uml's caption {#fig:uml}
  • typst

    typst 复制代码
    @glacier shows a glacier. Glaciers are complex systems.
    
    #figure(
      image("glacier.jpg", width: 80%),
      caption: [A curious figure.],
    ) <glacier>
    
    #figure(
    table(
      columns: 4,
      [t], [1], [2], [3],
      [y], [0.3s], [0.4s], [0.8s],
    ),
    caption: [Timing results],
    )
  • latex

    latex 复制代码
    \begin{figure}[ht]        % [ht] 控制图片位置 (here, top)
    \centering              % 图片居中
    \includegraphics[width=0.5\textwidth]{example.jpg}
    
    \caption{这是标题内容}   % 自动生成 "Figure 1: 这是标题内容"
    \label{fig:my_image}    % 用于文中引用的标签
    \end{figure}

代码引用自动更新:typst胜出

typst原生支持代码同步!

  • 我自研的第三方插件 pandoc-code-include

    markdown 复制代码
    ```{.py include=convert.py snippet=main .numberLines}
    
    ```
  • typst

    typst 复制代码
    #let text = read("code.py")
    #raw(text, block: true, lang: "python")
  • latex

    latex 复制代码
    \usepackage{listings}
    
    \begin{lstlisting}[caption={我的 Python 代码}, label={lst:example}, language=Python]
    print("Hello World")
    \end{lstlisting}
    
    % 文中引用
    如代码 \ref{lst:example} 所示...

语法

markdown

markdown 复制代码
## 必读文档 Must Read

[👍 draw.io 流程图后期编辑](https://app.diagrams.net/): 支持导入 mermaid plantuml sql csv

[default table style 默认表格样式,✅MS-Word,❌WPS](https://github.com/jgm/pandoc/issues/3275#issuecomment-369198726)

[markdown转markdown:\$toc\$自定义目录位置](https://github.com/jgm/pandoc/wiki/Pandoc-Tricks#using-markdown-templates)

[用markdown写论文@geChunYu](https://ge-chunyu.github.io/posts/2019-11-pandoc-large-document/)

[用markdown写论文@st1020](https://st1020.com/write-thesis-with-markdown-part1/)

**关键词:** Markdown; Pandoc

\newpage

<div custom-style="Title">
Based on pandoc word template
</div><div custom-style="Abstract Title">
Abstract
</div>

Write abstract here.

**Key Words:** Markdown; Pandoc

</div>

<br section>

# Heading 1

## Heading 2

### Heading 3

#### Heading 4

##### Heading 5

###### Heading 6

首段落 First Paragraph.
正文Normal, 正文字体Body Text. `Verbatim Char代码字体` [超链接Hyperlink](https://github.com/AClon314 "mouse-over-hint") 脚注Footnote [^1]

[^1]: footnote.

**Bold** _Italic_ ~~Delete~~

1. 有序列表
   1. 11
      1. 111
         1. 1111
            1. 11111
               1. 111111
   1. 12
1. 2

- 无序列表
  - 11
    - 111
      - 1111
        - 11111
          - 111111
  - 12
- 2

如表[@tbl:table]。如图[@fig:ID]。

| Compact |  b  |
| :-----: | :-: |
|    1    |  2  |

: simple_tables see https://pandoc.org/chunkedhtml-demo/8.9-tables.html {#tbl:table}

::: {custom-style="Figure"}
| a | b |
| :---: | :---: |
| 1 | 2 |
表{} 表名
:::

![invert](https://images7.memedroid.com/images/UPLOADED819/64a1d3e2c44ae.jpeg){#fig:ID}

```dot
digraph G {
    rankdir=TB;
    subgraph L {
        rank = same;
        b -> a [dir=back];  // b ← a
    }
    subgraph R {
        rank = same;
        c -> d;  // c → d
    }
    b -> c
}
```

```plantuml
@startuml
Bob->Alice: Hi Alice
@enduml
```

```{.py include=convert.py snippet=main .numberLines}

```

> quote

```python {.numberLines}
#!/bin/env python
if __name__ == "__main__":
    print("👻")
```

\newpage

# 参考文献

::: {#refs}
:::

typst

typst 复制代码
== 必读文档 Must Read

- #link("https://app.diagrams.net/")[👍 draw.io 流程图后期编辑]: 支持导入 mermaid plantuml sql csv
- #link("https://github.com/jgm/pandoc/issues/3275#issuecomment-369198726")[default table style 默认表格样式,✅MS-Word,❌WPS]
- #link("https://github.com/jgm/pandoc/wiki/Pandoc-Tricks#using-markdown-templates")[markdown转markdown:$toc$自定义目录位置]
- #link("https://ge-chunyu.github.io/posts/2019-11-pandoc-large-document/")[用markdown写论文@geChunYu]
- #link("https://st1020.com/write-thesis-with-markdown-part1/")[用markdown写论文@st1020]

*关键词:* Markdown; Pandoc

#pagebreak()

#align(center)[
  #text(size: 18pt, weight: "bold")[Based on pandoc word template]
]

#align(center)[
  #text(size: 14pt, weight: "bold")[Abstract]
]

Write abstract here.

*Key Words:* Markdown; Pandoc

// Pandoc 的 <br section> 通常需要模板层处理,这里略去

= Heading 1
== Heading 2
=== Heading 3
==== Heading 4
===== Heading 5
====== Heading 6

首段落 First Paragraph.

正文Normal, 正文字体Body Text. `Verbatim Char代码字体` #link("https://github.com/AClon314")[超链接Hyperlink] 脚注Footnote#footnote[footnote.]

*Bold* _Italic_ #strike[Delete]

+ 有序列表
  + 11
    + 111
      + 1111
        + 11111
          + 111111
  + 12
+ 2

- 无序列表
  - 11
    - 111
      - 1111
        - 11111
          - 111111
  - 12
- 2

如表 @tbl:table。 如图 @fig:ID。

#figure(
  table(
    columns: 2,
    align: center,
    table.header([Compact], [b]),
    [1], [2],
  ),
  caption: [simple_tables see https://pandoc.org/chunkedhtml-demo/8.9-tables.html],
) <tbl:table>

#figure(
  table(
    columns: 2,
    align: center,
    table.header([a], [b]),
    [1], [2],
  ),
  caption: [表名],
)

#figure(
  image("https://images7.memedroid.com/images/UPLOADED819/64a1d3e2c44ae.jpeg"),
  caption: [invert],
) <fig:ID>

#raw(
  "digraph G {\n    rankdir=TB;\n    subgraph L {\n        rank = same;\n        b -> a [dir=back];  // b ← a\n    }\n    subgraph R {\n        rank = same;\n        c -> d;  // c → d\n    }\n    b -> c\n}",
  block: true,
  lang: "dot",
)

#raw(
  "@startuml\nBob->Alice: Hi Alice\n@enduml",
  block: true,
  lang: "plantuml",
)

// Pandoc 的 include/snippet 属性没有直接等价物,通常改为手动读取或预处理
#let text = read("code.py")
#raw(text, block: true, lang: "py")

#quote[
  quote
]

#raw(
  "#!/bin/env python\nif __name__ == \"__main__\":\n    print(\"👻\")",
  block: true,
  lang: "python",
)

#pagebreak()

= 参考文献

// 例如:#bibliography("refs.bib")

latex

latex 复制代码
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{listings}
\usepackage[normalem]{ulem} % \sout

\section{必读文档 Must Read}

\begin{itemize}
  \item \href{https://app.diagrams.net/}{👍 draw.io 流程图后期编辑}: 支持导入 mermaid plantuml sql csv
  \item \href{https://github.com/jgm/pandoc/issues/3275#issuecomment-369198726}{default table style 默认表格样式,✅MS-Word,❌WPS}
  \item \href{https://github.com/jgm/pandoc/wiki/Pandoc-Tricks#using-markdown-templates}{markdown转markdown:\$toc\$自定义目录位置}
  \item \href{https://ge-chunyu.github.io/posts/2019-11-pandoc-large-document/}{用markdown写论文@geChunYu}
  \item \href{https://st1020.com/write-thesis-with-markdown-part1/}{用markdown写论文@st1020}
\end{itemize}

\textbf{关键词:} Markdown; Pandoc

\newpage

\begin{center}
  {\LARGE\bfseries Based on pandoc word template\par}
  \vspace{1em}
  {\large\bfseries Abstract\par}
\end{center}

Write abstract here.

\textbf{Key Words:} Markdown; Pandoc

% Pandoc 的 <br section> 通常需要文档类或模板层处理

\section{Heading 1}
\subsection{Heading 2}
\subsubsection{Heading 3}
\paragraph{Heading 4}
\subparagraph{Heading 5}
\textbf{Heading 6}

首段落 First Paragraph.

正文Normal, 正文字体Body Text. \texttt{Verbatim Char代码字体} \href{https://github.com/AClon314}{超链接Hyperlink} 脚注Footnote\footnote{footnote.}

\textbf{Bold} \textit{Italic} \sout{Delete}

\begin{enumerate}
  \item 有序列表
  \begin{enumerate}
    \item 11
    \begin{enumerate}
      \item 111
      \begin{enumerate}
        \item 1111
        \begin{enumerate}
          \item 11111
          \begin{enumerate}
            \item 111111
          \end{enumerate}
        \end{enumerate}
      \end{enumerate}
    \end{enumerate}
    \item 12
  \end{enumerate}
  \item 2
\end{enumerate}

\begin{itemize}
  \item 无序列表
  \begin{itemize}
    \item 11
    \begin{itemize}
      \item 111
      \begin{itemize}
        \item 1111
        \begin{itemize}
          \item 11111
          \begin{itemize}
            \item 111111
          \end{itemize}
        \end{itemize}
      \end{itemize}
    \end{itemize}
    \item 12
  \end{itemize}
  \item 2
\end{itemize}

如表~\ref{tbl:table}。如图~\ref{fig:ID}。

\begin{table}[htbp]
  \centering
  \begin{tabular}{cc}
    \toprule
    Compact & b \\
    \midrule
    1 & 2 \\
    \bottomrule
  \end{tabular}
  \caption{simple\_tables see \url{https://pandoc.org/chunkedhtml-demo/8.9-tables.html}}
  \label{tbl:table}
\end{table}

\begin{table}[htbp]
  \centering
  \begin{tabular}{cc}
    \toprule
    a & b \\
    \midrule
    1 & 2 \\
    \bottomrule
  \end{tabular}
  \caption{表名}
\end{table}

\begin{figure}[htbp]
  \centering
  % 远程图片通常需要先下载到本地再插入
  \includegraphics[width=.6\linewidth]{invert.jpeg}
  \caption{invert}
  \label{fig:ID}
\end{figure}

\begin{lstlisting}[caption={Graphviz DOT}, language={}]
digraph G {
    rankdir=TB;
    subgraph L {
        rank = same;
        b -> a [dir=back];  % b <- a
    }
    subgraph R {
        rank = same;
        c -> d;  % c -> d
    }
    b -> c
}
\end{lstlisting}

\begin{lstlisting}[caption={PlantUML}, language={}]
@startuml
Bob->Alice: Hi Alice
@enduml
\end{lstlisting}

% Pandoc 的 include/snippet 属性通常要改成预处理或 \lstinputlisting
\lstinputlisting[language=Python]{convert.py}

\begin{quote}
quote
\end{quote}

\begin{lstlisting}[language=Python, numbers=left]
#!/bin/env python
if __name__ == "__main__":
    print("👻")
\end{lstlisting}

\newpage

\section{参考文献}

% 例如:\bibliographystyle{plain}
% \bibliography{refs}