【问题标题】:How to place labels correctly and use cross-reference in latex to be able to convert to html(5) using pandoc?如何正确放置标签并在乳胶中使用交叉引用以便能够使用 pandoc 转换为 html(5)?
【发布时间】:2015-05-19 03:51:36
【问题描述】:

简介

我想在 Latex 中创建源代码,以便通过 pdflatex 生成 pdf 并通过 pandoc 生成 html 页面。我使用以下来源

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[magyar]{babel}
\usepackage{hyperref}

\begin{document}
\begin{enumerate}
\item \label{itm:thefirst}
First example point
\end{enumerate}

This is an example to demonstrate how \textbackslash label\{\} and \textbackslash ref\{\} are not working with pandoc. Here should be a reference to the first example: \ref{itm:thefirst}
\end{document}

这可以用 pdflatex 编译,没有任何错误或警告。

问题

我使用以下代码通过 pandoc 创建 html 页面:

pandoc -f latex sample.tex -t html5 -o sample.html -S --toc -s

但它会在标签和引用周围产生不令人满意的结果:

<body>
<ol>
<li><p>[itm:thefirst] First example point</p></li>
</ol>
<p>This is an example to demonstrate how \label{} and \ref{} are not working with pandoc. Here should be a reference to the first example: [itm:thefirst]</p>
</body>

问题

为了得到这样的东西,我应该在乳胶源代码中修改什么:

<body>
<ol>
<li><p id="itm:thefirst">First example point</p></li>
</ol>
<p>This is an example to demonstrate how \label{} and \ref{} are not working with pandoc. Here should be a reference to the first example: <a href="#itm:thefirst">(1)</a></p>
</body>

【问题讨论】:

标签: html latex pandoc cross-reference


【解决方案1】:

我应该在乳胶源代码中修改什么[...]

Pandoc 目前不支持从 LaTeX 文件中解析和处理 \label{...}\ref{...},因此没有简单的解决方案来解决您的问题。

【讨论】:

  • 有不简单的解决办法吗?
  • 我不知道解决方法,抱歉。我发布答案是为了明确说明您尝试使用的功能实际上并不存在。
【解决方案2】:

为什么不另辟蹊径?

不要用 LaTeX 编写源代码,而是用 Markdown 编写它们。

这样我可以更轻松地将源代码转换为 HTML 以及 LaTeX 和 PDF。

作为奖励,您还可以获得一流的支持,将源文件转换为 EPUB、DOCX、ODT 等等......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-22
    • 2020-01-31
    • 2019-05-12
    • 1970-01-01
    相关资源
    最近更新 更多