1

subfiles is designed to both work as \input, but also allow to compile a subfile individually in order to save compile time.

I have a big multi-file project and I want to test my index style while having lots of references, but for tweaking small detail, I'm required to wait much longer for the whole document to compile.

main.tex

\documentclass{article}
\usepackage{imakeidx}
\makeindex

\usepackage{subfiles}

\begin{document}

foo\index{foo}

bar\index{bar}

\subfile{indexfile}

\end{document}

indexfile.tex

\documentclass[main]{subfiles}

\begin{document}

\printindex

\end{document}

Everything works fine when compiling the root main.tex file, but indexfile.tex doesn't produce a pdf standalone.

It should definitely be possible to achieve what I need since formatted index is generated in main.ind, so it's a matter of calling makeindex and inserting the content, which should be automatic since subfiles appends whole preamble of root, thus the changes in style should be reflected upon indexfile.tex compilation

6
  • When you say you're working on the index style, do you mean you're working on a custom .ist? Or ...?
    – cfr
    Commented May 9 at 0:40
  • @cfr exactly, just didn't want to complicate MWE.
    – antshar
    Commented May 9 at 3:23
  • So, in that case, can't you just \input the formatted file without remaking the index? You can keep regenerating the index as you change the .ist and literally just compile that inside a document environment. Just don't use \makeindex and the rest of it. This is the kind of case where subfile handling is probably more hindrance than help.
    – cfr
    Commented May 9 at 4:19
  • Failing that, make the \makeindex invocation conditional.
    – cfr
    Commented May 9 at 4:24
  • @cfr so the proposition is to use \input{main.ind} instead of \printindex?
    – antshar
    Commented May 9 at 5:16

1 Answer 1

1

\makeindex is not what you want here. What you want is to simply input the formatted .ind file, so that you can regenerate that and see the results without remaking the .idx.

\makeindex tells LaTeX to write the entries to the .idx. Traditionally, you would then process this file separately to produce the .ind. Because you are using imakeidx, this processing is done as part of compilation.

When you compile the subfile, LaTeX indeed reads the preamble and writes the index to file. Since no entries are created during this compilation, the .idx is empty. Nonetheless, imakeidx causes it to be processed, producing an equally empty .ind. This is the file \printindex then inputs. Since it is empty and the subfile has no other content, no pages are produced and there is no PDF.

What you want, I think, is to simply input the main .ind. When you tweak the .ist, you want to regenerate this file from the existing .idx for the main file. You do not want LaTeX to use the subfile's .idx or .ind at all.

This is straightforward, although it may mean the use of the subfile mechanism is somewhat pointless in this case. All you need is that your subfile \input the main .ind file. When you wish to regenerate it, you can simply run the processing step by hand.

\begin{filecontents*}[overwrite]{\jobname-i.tex}
\documentclass[main]{subfiles}

\begin{document}

\input{main.ind}% or whatever - this should be the name of the main file

\end{document}
\end{filecontents*}
\documentclass{article}
\usepackage{imakeidx}
\makeindex

\usepackage{subfiles}

\begin{document}

foo\index{foo}

bar\index{bar}

\subfile{\jobname-i}

\end{document}

You can leave imakeidx and \makeindex as-is or you can comment them out or make them conditional. The only difference they make is that a few empty files are written to disk. If that bothers you, use a conditional so they aren't used when compiling the subfile.

When you have adjusted the .ist and want to see the effect, run

makeindex -s <custom>.ist main

and recompile the subfile to observe the result.

9
  • I'm using imakeidx specifically to avoid running makeindex executable manually, especially because in a real document I have several indices with different styles and options (encoding in particular) set as optional argument to \makeindex, so I'd prefer to delegate it to compilation process. I tried to utilize \ifSubfilesClassLoaded from subfiles to avoid .idx recreation by \makeindex as suggested and even (ab)use imakeidx internals, but didn't succeed.
    – antshar
    Commented May 10 at 5:56
  • @antshar It's the wrong file anyway. When you load imakeidx when compiling the subfile, it processes the .idx just file. It's just the wrong .idx file. I don't know the subfiles package, but you'd need some way of telling imakeidx to (1) not generate the .idx but (2) process the .idx to produce the .ind using a jobname other than the current one.
    – cfr
    Commented May 10 at 6:18
  • @antshar What options exactly are you giving \makeindex? At least some will be written to the .idx file(s), so you can forget about those. You only need those when compiling the main file. They're just irrelevant when compiling the subfile. If, on the other hand, they alter the arguments passed to makeindex or change the name of the .ist, that's a different matter.
    – cfr
    Commented May 10 at 6:21
  • I understand that precisely, so that's why I'm asking for help. I tried to trick by replacing \imki@jobname with main file name, but it didn't work. I found a line that calls makeindex process \imki@exec{\imki@program\imki@options#1.idx}, but for some reason it erases .idx when run from subfile.
    – antshar
    Commented May 10 at 6:49
  • One index uses only -s style.ist, while another specifies program=texindy and passes -C utf8 additionally. So I doubt I can combine all that to a single makeindex call with no arguments.
    – antshar
    Commented May 10 at 6:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .