我有一个 latex 生成的 .toc 文件,其中包含一个大文档的目录。我想将 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 DOM 并进行编号等。
关于latex - 从 Latex .toc 文件中生成用于 Markdown 的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45215470/