从 latex .toc 文件中生成 table 的降价内容
generate table of contents for markdown out of latex .toc-file
我有一个 latex 生成的 .toc 文件,其中 table 是一个大型文档的内容。我想将 TOC 提取到 (github-)markdown 列表中,例如与潘多克。
例如我有
\contentsline {chapter}{\numberline {1}Introduction}{1}{chapter.1}
\contentsline {section}{\numberline {1.1}Aim and Motivation}{1}{section.1.1}
\contentsline {section}{\numberline {1.2}State of the art}{1}{section.1.2}
\contentsline {section}{\numberline {1.3}Outline}{1}{section.1.3}
\contentsline {chapter}{\numberline {2}Fundamentals}{2}{chapter.2}
...
在我的 .toc 文件中。
并且想得到这样的东西
1. Introduction
1.1. Aim and Motivation
1.2. State-of-the-art
1.3. Outline
2. Fundamentals
另一种方法是直接从 tex 文件中提取此信息(不含内容)。但是,我无法让它工作,我也认为它更容易出错。
有什么建议吗?
Another alternative would be to extract this information out of the tex-file directly.
Pandoc 可以做到这一点:
$ pandoc -s --toc input.tex -o output.md
要排除文档正文内容,您必须使用自定义 pandoc markdown 模板:
$ pandoc -D markdown > mytemplate.md
修改 mytemplate.md
以保留 $toc$
并删除 $body$
,然后与 pandoc --template mytemplate.md ...
一起使用
如果你想更多地自定义它我建议输出到 html (pandoc -t html
) 而不是 markdown,然后写一个遍历 html [=28= 的小脚本] 并进行编号等
不幸的是,Pandoc 在我的案例中创建了一个空的降价文件。我创建了一个开源 cli 工具,用于执行该转换:
https://github.com/MaaxGr/latex-toc-markdown
下载二进制文件(参见 GitHub 页的自述文件)并执行以下命令:
./latex-toc-markdown Input.toc Output.toc
输出文件如下所示:
* 1 Introduction
* 1.1 Aim and Motivation
* 1.2 State of the art
* 1.3 Outline
* 2 Fundamentals
我有一个 latex 生成的 .toc 文件,其中 table 是一个大型文档的内容。我想将 TOC 提取到 (github-)markdown 列表中,例如与潘多克。
例如我有
\contentsline {chapter}{\numberline {1}Introduction}{1}{chapter.1}
\contentsline {section}{\numberline {1.1}Aim and Motivation}{1}{section.1.1}
\contentsline {section}{\numberline {1.2}State of the art}{1}{section.1.2}
\contentsline {section}{\numberline {1.3}Outline}{1}{section.1.3}
\contentsline {chapter}{\numberline {2}Fundamentals}{2}{chapter.2}
...
在我的 .toc 文件中。
并且想得到这样的东西
1. Introduction
1.1. Aim and Motivation
1.2. State-of-the-art
1.3. Outline
2. Fundamentals
另一种方法是直接从 tex 文件中提取此信息(不含内容)。但是,我无法让它工作,我也认为它更容易出错。
有什么建议吗?
Another alternative would be to extract this information out of the tex-file directly.
Pandoc 可以做到这一点:
$ pandoc -s --toc input.tex -o output.md
要排除文档正文内容,您必须使用自定义 pandoc markdown 模板:
$ pandoc -D markdown > mytemplate.md
修改 mytemplate.md
以保留 $toc$
并删除 $body$
,然后与 pandoc --template mytemplate.md ...
如果你想更多地自定义它我建议输出到 html (pandoc -t html
) 而不是 markdown,然后写一个遍历 html [=28= 的小脚本] 并进行编号等
不幸的是,Pandoc 在我的案例中创建了一个空的降价文件。我创建了一个开源 cli 工具,用于执行该转换: https://github.com/MaaxGr/latex-toc-markdown
下载二进制文件(参见 GitHub 页的自述文件)并执行以下命令:
./latex-toc-markdown Input.toc Output.toc
输出文件如下所示:
* 1 Introduction
* 1.1 Aim and Motivation
* 1.2 State of the art
* 1.3 Outline
* 2 Fundamentals