2

I have an elaborate workflow for producing academic articles that produced latex wit references processed using Biblatex-chicago. The text is mainly in English, but occasionally I need to include excerpts in other languages, including Chinese.

I use htlatex because I usually need to provide drafts in word format. I use make4ht to create odt files, then open them in word and save in docx format, which is what editors and readers require.

When it comes to Chinese characters, it all works fine for pdf, and I have now also got htlatex/make4ht to produce Chinese properly for html files, by following the instructions in the answer to this question:

How to create multilingual (English, Japanese) html document with htlatex

However, I can't get the process to work for odt format. When I process the files everything is fine except the Chinese characters are completely absent. As far as I can tell they are not producing any output that is not being displayed, they are just absent.

Here is my MWE:

\documentclass{article}
\usepackage{alternative4ht}
\altusepackage{fontspec}
\altusepackage{xeCJK}
\setCJKmainfont{STFangsong}
\setCJKsansfont{STFangsong}
\setCJKmonofont{STFangsong}
\setCJKmathfont{STFangsong}
\altusepackage{xunicode}
\begin{document}
中文\\
This section is in english.
\end{document}

I don't really care about formatting for this purpose, so I just used a single font for simplicity. This is the command I've been using to compile:

make4ht -f odt -m draft -ue mybuild.mk4 test.tex

I'll be very grateful if anyone can help me to work out how to make this work! I'm very much a dabbler so may well be overlooking something obvious. Thanks!

2

You can try this:

\documentclass{article}
\usepackage{fontspec}
\ifdefined\HCode\else
\usepackage{xeCJK}
\setCJKmainfont{STFangsong}
\setCJKsansfont{STFangsong}
\setCJKmonofont{STFangsong}
\setCJKmathfont{STFangsong}
\altusepackage{xunicode}
\fi
\begin{document}
中文\\
This section is in english.
\end{document}

I've used \ifdefined\HCode to suppress loading of xeCJK and xunicode packages when you compile the document with make4ht. They are not needed.

This document can be compiled using

make4ht -lm draft -e mybuild.mk4 test.tex

Note that the recent versions of make4ht use utf-8 output by default, so it is not necessary to use the -e option. What is necessary though is to use the -l option to require compilation with LuaTeX. This enables the support for full Unicode.

This is the result:

enter image description here

15
  • As usual excellent suggestion....
    – MadyYuvi
    May 16 '20 at 12:52
  • Thanks so much for the quick reply!
    – Jon Mair
    May 16 '20 at 14:13
  • This works for my MWE, but I'm having problems with my actual files. The process I'm using creates a main file with the text and stitches a whole tex file together with \input. That is not compiling using the method above. However, when I manually copy all the pieces into one file, so that \input is not required, then it works fine. Is it that ht4latex can't work with included files? If so do you know if there is a workaround for this?
    – Jon Mair
    May 16 '20 at 14:17
  • sorry I mean 'tex4ht'!
    – Jon Mair
    May 16 '20 at 14:22
  • PS - it might be that some of the included files are in texmf instead of in the working directory, but when compiling to html, it works no problem.
    – Jon Mair
    May 16 '20 at 14:45

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.