How to place labels correctly and use cross-reference in latex to be able to convert to html(5) using pandoc?

白昼怎懂夜的黑 提交于 2020-01-05 04:32:07

问题


Introduction

I'd like to create source code in latex in order to produce pdf via pdflatex and html page(s) via pandoc. I use the following source

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

This can be compiled with pdflatex without any error or warning.

Problem

I create the html page via pandoc using the following code:

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

but it creates unsatisfactory results around the label and the reference:

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

Question

What shall I modify in the latex source code in order to get something like this:

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

回答1:


What shall I modify in the latex source code [...]

Pandoc does currently not support parsing and processing of \label{...} or \ref{...} from LaTeX files, so there is no easy solution to your problem.




回答2:


Why not go an alternative way?

Instead of writing your sources in LaTeX, write them in Markdown.

That way it will me much easier to convert the sources to HTML as well as to LaTeX and PDF.

As a bonus, you also get top-notch support to convert the sources to EPUB, DOCX, ODT and much more....



来源:https://stackoverflow.com/questions/29086880/how-to-place-labels-correctly-and-use-cross-reference-in-latex-to-be-able-to-con

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!