I'm using TexLive 2011 on Ubuntu 11.10. Take this for example:


Then I run htlatex test.tex to convert it to html, but after conversion, the Chinese characters are not displayed in the browser. Then I checked the html source, it's like this:

<!--l. 3--><p class="noindent" ><span 

Seems like it's converting the characters in the weirdest way.

So how do I configure it to let it produce readable Chinese? If tex4ht isn't able to do this, what other tools should I look into?

  • It is mainly because of the wrongly produced .htf files. (htf 文件没做好,以前是不同人做的,不匹配。这是已知的问题,ctex-kit 上很早的 issue 了,不过都觉得应用很少没人处理。) – Leo Liu Mar 15 '12 at 12:45
  • You can find more information at code.google.com/p/ctex-kit/issues/detail?id=46 – Leo Liu Mar 15 '12 at 12:48
  • @LeoLiu I'm translating a book written in Latex. It uses tex4ht to produce an HTML version. Guess it leaves me no choice :\ – Wang Dingwei Mar 17 '12 at 14:43

The reason is because tex4ht can't find the htf font files, i.e. unisong51.htf etc. However, tex4ht does come with utf8song*.htf files in %TEX4HT%/ht-fonts/unicode/cjk/utf8/, so you could just create copies of those. (%TEX4HT% is likely to be %TEXMF%/tex4ht on your system.)

Here's what I did.

  • Create a copy of each utf8song*.htf to unisong*.htf, and modify the first and last lines of the file contents to unisong* accordingly.
  • In my case, I had to also edit %TEX4HT%/tex4ht/base/unix/tex4ht.env. (Or in win32 if you're on Windows). Change all the ~/tex4ht.dir/texmf in that file to the actual path where my TEXMF tree really is, especially the ones under the heading <unihtf>.
  • Then run the following command:

    htlatex test.tex "xhtml,charset=utf-8,NoFonts" " -cunihtf -utf8"

I was then able to get a readable webpage in Chinese.

  • Personally I don't think tex4ht is a proper tool to produce HTML pages. pandoc is a better choice, I think. – Leo Liu Mar 15 '12 at 12:58
  • 2
    @LeoLiu +1 for pandoc, I use it for writing my "first drafts". But IMHO tex4ht wins hands-down on most "real-life" LaTeX documents. pandoc can't handle beyond a few common LaTeX packages, while tex4ht can almost handle any packages you throw at it. So it really depends on how complicated your LaTeX document is, especially w.r.t. the kinds of macros and packages you're using. – LianTze Lim Mar 15 '12 at 13:20
  • @Lim: Well, I would just use markdown for pandoc to produce both HTML and PDF (via LaTeX). – Leo Liu Mar 15 '12 at 14:40
  • @LianTzeLim I think this only solves font issues for simsun or 新宋体. How do I make it work for all Chinese fonts, like simhei, simkai, and those Wenquanyi fonts? – Wang Dingwei Mar 18 '12 at 3:22
  • I tried to find a way to direct tex4ht to just look at utf8song* for all CJK, since the metrics and encodings should be the same anyway (as long as we're still talking about UTF8), but I haven't found it yet (assuming it does exist). If you need a solution urgently, the best bet might be to write a script to create copies of appropriately renamed utf8song*.htf files, by looking at the errors you'll know what to rename them to. Really ugly and dirty, I know, so hopefully I (or someone else!) will be able to find the correct parameter soon. >_< – LianTze Lim Mar 18 '12 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.