2

I have this situation

  • a LaTeX file with a macro that is usually translated into a unicode char by tex4ht (e.g. \ldots that became )
  • a citation with non-ascii char in the name of the author (e.g. the í in Albarracín)
  • I would like to generate an xhtml file with htlatex

The procedure works, but the resulting file has one char encoded in utf-8 (the latex macro) and the non-ascii char in the author's name encoded in latin-1. AFAICT, htlatex includes the bbl file reading it as if it was in latin-1.

Is there anything that I could do to fix this behavior? :)
(I'm working on pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022/Arch Linux))

Here is a mwe, and below the commands that I run:

%% File mwe.tex
\documentclass{article}

\usepackage[backend=biber]{biblatex}

\begin{filecontents}{\jobname.bib}
@Article{Albarracin2000,
year = {2000},
volume = {1},
issue = {2},
pages = {3},
author = {Anyone Albarracín},
title = {A beautiful paper.},
journaltitle = {Some Journal}
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

I Am a Scientist\ldots\ Ask Me Anything
\parencite{Albarracin2000}

\printbibliography

\end{document}
htlatex mwe.tex "xhtml" "-cunihtf -utf8" "" ""
biber mwe
htlatex mwe.tex "xhtml" "-cunihtf -utf8" "" ""

and the result

$ file mwe.html
mwe.html: XML 1.0 document, Non-ISO extended-ASCII text
$ grep -a -e 'Anyone Albarra' -e Scientist --color mwe.html 
<!--l. 22--><p class="noindent" >I Am a Scientist… Ask Me Anything [<a 
    <!--l. 26--><p class="noindent" >Anyone Albarrac�n. &#8220;A beautiful paper.&#8221; In: <span 

1 Answer 1

2

The utf8 support is one of the issues that is solved by make4ht. If you compile your file using:

$ make4ht mwe.tex

It will produce utf8 file by default.

If you want to use htlatex, you can use this:

$ htlatex mwe.tex "xhtml,charset=utf-8" " -cunihtf -utf8"

Two significant modifications have been made. Firstly, by including charset=utf-8 in the option list, the encoding of the HTML file has been changed, enabling browsers to display accented characters correctly. Secondly, it is crucial to separate the opening quote and -cunihtf with a space; otherwise, the option is ignored, resulting in a wrongly encoded file.

I still recommend to use make4ht, as it is easier to use, and it fixes other issues too. For example, you can create a build file, build.lua that will compile the bibliography on request:

if mode == "draft" then
  Make:htlatex {}
else
  Make:htlatex {}
  Make:biber {}
  Make:htlatex {}
  Make:htlatex {}
end

Now, you can use it like this:

$ make4ht -e build.lua mwe.tex

It will automatically call biber and then it will run LaTeX twice, to fix all cross-references. If you want to speed up the compilation, you can use the draft option, which will run LaTeX only once, resulting in the much faster compilation:

$ make4ht -e build.lua -m draft  mwe.tex

This is the result:

enter image description here

2
  • A minor clarification for me to remember: I think that charset=utf8 correctly sets the tag <meta ... content="text/html; charset=utf-8" /> in the html file, but the encoding of the file itself is fixed by " -cunihtf -utf8" (with the space in front) :) Mar 6 at 7:40
  • @MatteoGamboz yes, that's correct. Without correct declaration in the <meta> tag, the text could be displayed incorrectly, even if the HTML file itself contained correct characters.
    – michal.h21
    Mar 6 at 8:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .