This question is similar to many others posted on these forums, but the answers I have seen have not solved my problem (e.g. at Converting Latex to MsWord .doc or .rtf). Please forgive me if this is repetitive, and point me in the direction of its solution. I will be deeply indebted to anyone who has ideas.
In brief, I wrote my dissertation in XeLaTeX largely because of the flexibility of biblatex. I work in a field wherein I have to cite a lot of East Asian source materials, and getting other reference managers to output these sorts of references correctly has been difficult. Biblatex works beautifully, and I'd be sorry to give it up.
However, now that I am on the other side of my dissertation, I need to submit papers (and manuscripts) for publication. In my backwards field, such papers very often need to be submitted as a Word document.
I need now to consider whether I can keep Xelatex, biblatex, and the large bibliography file I created during my dissertation as part of my workflow–even if the end product sometimes has to be a Word-readable and Word-editable document. I know of several programs that can convert an uncompiled Xelatex document to other formats (pandoc, etc.). And I know that tex4ht can convert some LaTeX documents to html or odt after running biber. But for reasons I can't understand (that may have to do with incompatibilities between Tex4ht and xelatex?), it does not seem to work on my stuff. (I am working on Windows 10 with MikTex.)
The documents I need to be able to produce are fairly simple (although cjk bibliography requires some definitions to be able to work). I don't have graphs, charts, or images to include: just Chinese and Japanese texts.
Here is an extremely minimal example that I cannot get to work. This is the latex file:
\documentclass{article}
\usepackage{xeCJK}
\setmainfont[Ligatures={Common, TeX}]{Times New Roman}
\setCJKmainfont[Scale=1]{SimSun}
\begin{document}
Zhupo shihua 竹坡詩話
\end{document}
Of course, this extremely minimal code compiles perfectly into a pdf with Xelatex. When I then go to run htlatex on it (i.e. in the command prompt, I type: htlatex test.tex), I get the following error message:
C:\Users\lbxxx>latex \makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\g@addto@macro\@documentclasshook{\RequirePackage[#1,html]{tex4ht}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode .a.b.c.\input "C:\Users\lbxxx\Desktop\Tex Testing\onlinetest.tex"
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (MiKTeX 2.9.6300 64-bit)
entering extended mode
LaTeX2e <2017-04-15>
Babel <3.9r> and hyphenation patterns for 72 language(s) loaded.
! Undefined control sequence.
<*> ...}\makeatother\HCode .a.b.c.\input C:\Users
\lbxxx\Desktop\Tex Testing...
?
I can hit r several times and nothing at all comes out. Same basic thing for htxelatex.
Of course, the actual files I would like to be able to convert this way are much more complicated. Here would be a minimal example, this time including footnotes and bibliography (many thanks to moewe for much of this code):
\documentclass{article}
\usepackage{xltxtra}
\usepackage[fallback]{xeCJK}
\usepackage{xunicode-addon}
\setmainfont[Ligatures={Common, TeX}]{Times New Roman}
\setCJKmainfont[Scale=1]{SimSun}
\makeatletter
\newcommand\blx@unitmark{23sp}
\makeatother
\usepackage{filecontents}
\begin{filecontents*}{chicago-notes.dbx}
\ProvidesFile{chicago-notes.dbx}[2016/07/24 extended name format for biblatex]
\DeclareDatamodelConstant[type=list]{nameparts}{prefix,family,suffix,given,cjk}
\end{filecontents*}
\begin{filecontents*}{\jobname.bib}
@book{zhaos,
title={A Nation-State by Construction: Dynamics of Modern Chinese Nationalism},
author={given=Suisheng, family=Zhao, cjk=趙歲升},
isbn={9780804750011},
year={2011},
address = {Stanford},
publisher={Stanford University Press}}
@book{ZhupoShihua,
author = {family=Zhou, cjk=周紫芝, given=Zizhi},
title = {Zhupo shihua},
titleaddon = {竹坡詩話},
series = {Yinying Wenyuange Siku quanshu edition},
year = {1985},
address = {Taibei},
publisher = {Taiwan shangwu yinshu guan}
}
@book{jim,
title={Lorem},
author={Smith, Junior, Jim},
year={2009},
address = {Stanford},
publisher={Stanford University Press}}
\end{filecontents*}
\usepackage[notes,strict,annotation,cmsdate=both,isbn=false, backend=biber]{biblatex-chicago}
\addbibresource{\jobname.bib}
% Based on definitions from biblatex.def
\newbibmacro*{name:cjk}[3]{%
\usebibmacro{name:delim}{#2#3#1}%
\usebibmacro{name:hook}{#2#3#1}%
\mkbibnamefamily{#1}%
\ifdefvoid{#2}{}{\bibnamedelimd\mkbibnamegiven{#2}}%
\ifdefvoid{#3}{}{\bibnamedelimd\mkbibnamecjk{#3}}}
\DeclareNameFormat{given-family}{%
\ifdefvoid{\namepartcjk}
{\iffirstinits
{\usebibmacro{name:given-family}
{\namepartfamily}
{\namepartgiveni}
{\namepartprefix}
{\namepartsuffix}}
{\usebibmacro{name:given-family}
{\namepartfamily}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}}}
{\usebibmacro{name:cjk}{\namepartfamily}{\namepartgiven}{\namepartcjk}}%
\usebibmacro{name:andothers}}
\DeclareNameFormat{family-given}{%
\ifdefvoid{\namepartcjk}
{\iffirstinits
{\usebibmacro{name:family-given}
{\namepartfamily}
{\namepartgiveni}
{\namepartprefix}
{\namepartsuffix}}
{\usebibmacro{name:family-given}
{\namepartfamily}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}}}
{\usebibmacro{name:cjk}{\namepartfamily}{\namepartgiven}{\namepartcjk}}%
\usebibmacro{name:andothers}}
\DeclareNameFormat{family-given/given-family}{%
\ifdefvoid{\namepartcjk}
{\ifnumequal{\value{listcount}}{1}
{\iffirstinits
{\usebibmacro{name:family-given}
{\namepartfamily}
{\namepartgiveni}
{\namepartprefix}
{\namepartsuffix}}
{\usebibmacro{name:family-given}
{\namepartfamily}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}}
\ifboolexpe{%
test {\ifdefvoid\namepartgiven}
and
test {\ifdefvoid\namepartprefix}}
{}
{\usebibmacro{name:revsdelim}}}
{\iffirstinits
{\usebibmacro{name:given-family}
{\namepartfamily}
{\namepartgiveni}
{\namepartprefix}
{\namepartsuffix}}
{\usebibmacro{name:given-family}
{\namepartfamily}
{\namepartgiven}
{\namepartprefix}
{\namepartsuffix}}}}
{\usebibmacro{name:cjk}{\namepartfamily}{\namepartgiven}{\namepartcjk}}%
\usebibmacro{name:andothers}}
\DeclareFieldFormat[book]{title}{%
\mkbibemph{#1}%
\iffieldundef{titleaddon}{\isdot}{\nopunct}}
\DeclareFieldFormat{booktitle}{%
\mkbibemph{#1}%
\iffieldundef{booktitleaddon}{}{\nopunct}}
\DeclareFieldFormat{maintitle}{%
\mkbibemph{#1}%
\iffieldundef{maintitleaddon}{}{\nopunct}}
\DeclareFieldFormat[article]{title}{%
\iffieldundef{title}{}{\mkbibquote{#1}}%
\iffieldundef{titleaddon}{\isdot}{\nopunct}}
\DeclareFieldFormat{usere}{\mkbibparens{#1}}
\begin{document}
\cite{zhaos,jim,ZhupoShihua}
\cite{zhaos,jim,ZhupoShihua}\footnote{\cite{zhaos,jim,ZhupoShihua}}
\printbibliography
\end{document}
So, in short, is there any way to be able to continue to use biblatex with my cjk-materials but output to .html, .odt, .rtf, or .doc? I am not particular about the formatting of the final document, except that the text needs to be there and footnotes need to be footnotes. Please do not suggest converting the final pdf to word–I'd rather type in all my bibliographic material by hand than have to deal with all the headaches that causes.
Anyone who can solve this will have my eternal gratitude.
Best Answer
Your main issue is that you can't include the TeX file in the compilation. I can't reproduce this issue, I guess that it is some issue with spaces in your file path.
Anyway, once you manage to actually compile your document, you will face some issues. There are some minor issues with
biblatex
package and big issue withxeCJK
package, which causestex4ht
to fail. Both of these issues can be fixed easily with some custom configurations.Save the following files to your document's directory:
and configuration file for
biblatex
,biblatex.4ht
:Now, instead of
htxelatex
, I would usemake4ht
. It is much more flexible. You will need a build file to enablebiber
compilation and to enable bothodt
andhtml
output. Save the following file asmybuild.mk4
:With
make4ht
, you can use--mode
or-m
command line option. This selects which compiling sequence will be used. You will also need to use-u
for Unicode output and-x
for XeLaTeX. Basic compilation would be thus:This will compile the document as HTML and it will run
biber
after first LaTeX compilation. On subsequent compilations, when the bibliography doesn't change and it is thus unnecessary to runbiber
, you can usedraft
mode:To get an ODT document, you can add
odt
to the draft option:This is the resulting HTML:
Edit:
It seems that your distribution is missing some files distributed with
tex4ht
, so you may also need this one,usepackage-fontspec.4ht
. It seems that there is a limit on how many characters post can contain, so I had to upload it to Gist.