5

I'm trying to make a document with an index. I have two issues with that (probably both caused by the first. I use the package imakeidx since that should run makeindex automatically, but it does not. I set an output-directory which seems to be the culprit.

have this mwe:

\documentclass[10pt, a4paper]{article}

\usepackage{imakeidx}
\makeindex

\begin{document}
add something to the index \index{something}
add something else to the index \index{somethin else}
add item to the index \index{item}

\printindex

\end{document}

when I then run

pdflatex --shell-escape main.tex
pdflatex --shell-escape main.tex

This results in a document containing no index, just:

enter image description here

Now, when I run makeindex separately, like so:

pdflatex --shell-escape --output-directory=build main.tex
cd build
makeindex main.idx
cd ../
pdflatex --shell-escape --output-directory=build main.tex

I do get an index in the PDF. However, going this route things fail when I try to name the indices (which is needed because I will need multiple indices in the final document), so this would fail:

\documentclass[10pt, a4paper]{article}

\usepackage{imakeidx}
\makeindex[name=references,title=References used]

\begin{document}
add something to the index \index[references]{something}
add something else to the index \index[references]{else}
add item to the index \index[references]{item}

\printindex[references]

\end{document}

From reading the manual and other answers here on SO, using imakeid and run pdflatex with shell-escape should be all. What am I missing? I run an up to date version of miktex on windows with all packages up to date.

6
  • You shouldn't need shell escape. Use \printindex[references] for the named index.
    – egreg
    Jun 8, 2020 at 12:37
  • Hi egreg, thanks. I've updated the example, because I did in fact use \printindex[references], just didn't copy that right. I have in fact found out that something else may cause the issues and that is that I use an output directory. Jun 8, 2020 at 12:49
  • 1
    That's not supported, sorry.
    – egreg
    Jun 8, 2020 at 12:50
  • well, ok then. Definitely not the answer I was hoping for. Thanks anyway Jun 8, 2020 at 13:01
  • 1
    makeindex doesn't support --output-directory, so you would need some script. But I would simply not use --output-directory, imho it is more pain than gain. Jun 8, 2020 at 13:09

2 Answers 2

1

As unfortunate as it is, output-directory is simply not supported with makeindex as you can see in the comments to my question. I could solve this with some intermediate scrips and whatnot, but let's bend instead of break and just lose the output directory, and now it all works fine.

1
  • A small patch of imakeidx could help you as well. See my answer above. Sep 26, 2020 at 12:28
1

I have a similar problem and solve it using a small patch of imakeidx.

Actually, the only issue is that we have to cd into the build directory before calling the respective makeindex(or similar) program.

My patch is

\usepackage{etoolbox}
\makeatletter
\patchcmd\imki@putindex
  {\imki@exec{\imki@program \imki@options #1.idx}}          %% OLD CODE
  {\imki@exec{cd build;\imki@program\imki@options#1.idx}}   %% NEW CODE: cd to build directory first
  {\message{Patch succeeded in imki@putindex}}
  {\errmessage{Patch failed in imki@putindex}}
\makeatother

and when I insert it immediately after the \usepackage{imakeidx} line of your two examples, both work out nicely for me.

3
  • Should build be replaced by the name of the directory? Does it works with several indexes? Can options like program=xindy, options= -C utf8 -M my_style.xdy be passed to makeindexas usual?
    – AlMa
    May 11, 2021 at 8:28
  • build is my build directory, so yes. I never worked with xindy of with several indices but I would expect it to work. May 11, 2021 at 10:06
  • Thank you! This helped me. For anyone else interested, this script requires that pdflatex is run with the flag -shell-escape.
    – Seub
    Jun 13, 2021 at 14:55

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.