TransWikia.com

tex4ht: problem with Index compilation

TeX - LaTeX Asked by Yulia Spryn on March 1, 2021

I have problems with index section.

I use tex4ht to compile my manual to html file.

In case if makeindex and begin{document}/end{document} commands are located in included file, compilation if failed.

Simple example

manual.tex file:

documentclass{article}
usepackage{makeidx}

include{index}

index.tex

makeindex
title{A Title}
author{An Author}
date{July 19, 2004}

begin{document}
maketitle  tableofcontents
section{First Section}
    Some text.
    index{first}
section{Second Section}
subsection{A Subsection}
    Some text 2
    index{Second}
printindex
end{document}

Compilation Error:

! Argument of idx:extI has an extra }.
par l.11
section{Second Section} ?

!!! However in case if contents of file is located in one file, compilation is successfull.

Separate text into two files is obligatory condition in my case.

Could someone help me?

One Answer

Edit:

This answer is obsolete. make4ht has built-in indexing support now. See this answer for an example.

Original answer:

The problem is with name of your included file, because tex4ht tries to include .4ht file for every file which is included. In your case this causes problem, because file index.4ht exists, which should be included for index.sty. An obvious fix is to rename included file to some safe name, like text-index.tex, or something.

Now you only have to compile the index in form usable for tex4ht. It is easy using make4ht build file, manual.mk4:

Make:add("makeindex", function(arg)
  os.execute("tex '\def\filename{{${input}}{${sext}}{${iext}}{${dext}}} \input idxmake.4ht'" % arg) 
  os.execute("makeindex -o ${input}.${dext} ${input}.${iext}" % arg)
end,{sext = "idx", iext ="4dx", dext = "ind"} )

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

compile the file with

make4ht -u manual.tex

Interesting part of the build file is:

Make:add("makeindex", function(arg)
  os.execute("tex '\def\filename{{${input}}{${sext}}{${iext}}{${dext}}}  \input idxmake.4ht'" % arg) 
   os.execute("makeindex -o ${input}.${dext} ${input}.${iext}" % arg)
 end,{sext = "idx", iext ="4dx", dext = "ind"} )

Make:add creates new command which can be used in a build file. For using makeindex with tex4ht, it is first necessary to post-process the idx file with idxmake.4ht, and it needs to have defined used extensions in filename command. It creates intermediate file which is then processed by makeindex. the extensions of processed files are given in

{sext = "idx", iext ="4dx", dext = "ind"}

The result:

enter image description here

Correct answer by michal.h21 on March 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP