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