latex - 从 Latex .toc 文件中生成用于 Markdown 的目录

标签 latex markdown pandoc github-flavored-markdown

我有一个 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/

相关文章:

latex - 用 LaTeX 中的列表包编号最后一行

r - 生成没有重复值的 pandoc 表

latex - ``\nabla'' 符号错误地显示为黑色光盘

markdown - Jekyll:如何使用 Kramdown 在 block 内进行 Markdown 解析?

html - 在 octopress post 中添加一个 anchor

python - 将 Mkdocs 部署到 Azure Web 应用

r - knitcitations 给出了 pandoc-citeproc 错误

syntax - Pandoc,Markdown to Doc,如何使用变量?

Rmarkdown删除引用超链接

latex - 如何在 Latex 中定位图形?