如何正确放置标签并在latex中使用交叉引用以便能够使用pandoc转换为html(5)?

时间:2015-03-16 21:02:43

标签: html latex pandoc cross-reference

简介

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

\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>

2 个答案:

答案 0 :(得分:2)

  

我应该在乳胶源代码[...]

中修改什么

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

答案 1 :(得分:0)

为什么不采取其他方式?

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

这样,将源转换为HTML以及LaTeX和PDF将更容易。

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

相关问题