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

2

1

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>
Wolk answered 16/3, 2015 at 21:2 Comment(1)
It can be a general issue as another SO question ask how to label and ref imagesWolk
T
2

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.

Tiberias answered 17/3, 2015 at 11:25 Comment(2)
Is there a non-easy solution?Wolk
I don't know a work-around, sorry. I posted to answer to make it clear that the feature you're trying to use doesn't actually exist.Tiberias
S
0

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

Spaceport answered 7/5, 2015 at 13:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.