2

How do I have to change the arara commands in the following so that the index of names will also be printed? As it stands, I get just the main index.

% arara: pdflatex
% arara: bibtex
% arara: pdflatex
% arara: pdflatex
% arara: nomencl
% arara: makeindex
% arara: pdflatex
% arara: pdflatex
% !arara: indent: { overwrite: false, output: outputfile.tex, trace: true }

\documentclass{memoir}
\usepackage[backend=bibtex,style=numeric]{biblatex}
\addbibresource{mybib.bib}
\usepackage{nomencl}
\makenomenclature
\makeindex
\makeindex[names]

\begin{document}

\chapter{Area} \label{chap:area}
\section{Area of a circle} \label{sec:circle-area}

Consult \textcite{Archimedes200} and \textcite{EulerE1776}.
\index[names]{Archimedes}
\index[names]{Euler, Leonhard}

The area $A$ 
\nomenclature{$A$}{area}%
of a circle with radius $r$
\nomenclature{$r$}{radius of circle}%
is defined as
\begin{equation}
    A = \pi r^{2}.
\end{equation}
\index{area!of circle}
\index{area}
\index{circle!area of}

\printbibliography

\printnomenclature

\renewcommand{\indexname}{Index of Names}
\printindex[names]

\renewcommand{\indexname}{Index}
\printindex

\end{document}

Here is the file mybib.bib:

@article{Archimedes200,
  author = {Archimedes},
  title = {Pi's the limit},
  journal = {Syracuse J. Gastronom.\ Math.}, 
  year = {200BCE},
  volume = {10},
  pages={\textsc{CCCXV}--\textsc{CCCXIV}}
}
@article{EulerE1776,
  author = {Euler, Leonhard},
  title = {All about E},
  journal = {Math.\ Psychol.},
  year = {1776},
  volume = {4},
  pages={1--2718}
}
murray
  • 7,944
  • Somebody had posted an answer, involving a modification of makeindex.yaml, that seems to work. But for reasons unknown to me, that answer has been deleted. – murray Aug 23 '19 at 19:08
  • Phelype has written a very interesting approach! I mentioned to him that arara has a built-in way of doing this task, and for some reason, he decided to delete it. I will poke him to undelete the answer and add an addendum to the quick way of doing it. :) – Paulo Cereda Aug 23 '19 at 20:52
  • By the way, add % arara: makeindex: { files: [ names ] } and have fun. :) – Paulo Cereda Aug 23 '19 at 20:53

1 Answers1

3

Credits to Paulo, for showing me this: all arara rules have an implicit parameter called files, which takes a (comma-separated) list of file names. arara will then iterate in this list and apply that directive to each item in the list.

Another point is that you don't need the two pdfLaTeX runs between BibTeX and MakeIndex: the first run of pdfLaTeX is enough to generate the auxiliary files for the external tools. The final two runs of pdfLaTeX are necessary to include the generated bibliographies/indexes and sort out cross references.

Your list of directives could be changed to:

% arara: pdflatex
% arara: bibtex
% arara: makeindex
% arara: makeindex: { files: [ names ] }
% arara: pdflatex
% arara: pdflatex

and perhaps replace the two makeindex lines by only one (supposing your main .tex file is main.tex): % arara: makeindex: { files: [ main, names ] }.

Or, if you want arara to be clever and skip unnecessary steps (explanation here):

% arara: pdflatex: { draft: yes }
% arara: bibtex if changed (toFile('mybib.bib'))
% arara: --> || found ('log', 'Warning: Citation')
% arara: makeindex: { files: [ main, names ] } if changed ('idx')
% arara: pdflatex until !found('log', '\\(?(R|r)e\\)?run (to get|LaTeX)')

Another option, as barbarabeeton mentioned in the comment, is the imakeidx package, which runs makeindex from within pdfLaTeX. Since makeindex is a trusted program, it is allowed to run in restricted shell-escape, which is usually enabled. The imakeidx package already takes care of multiple indexes and everything.

To use it you would just need to load it with \usepackage{makeindex}, and repalce \makeindex[names] by \makeindex[name=names].

However the repeatindex package you use seems to be incompatible with imakeidx... I'll try to figure out why.


Or, if you prefer to look like the cool kid (like me, who did all this before being told of the files parameter :-) and do it the hard way, you can make a small modification to the makeindex.yaml file and add a basename option which takes the base name of the index file (names, in your case) and works on it instead of the current file name.

First, below the arguments: line in makeindex.yaml you add the option itself:

- identifier: basename
  flag: >
    @{
      parameters.basename
    }

(apparently Java doesn't like if you use only base, for some reason, so I used the more verbose basename.) We set this option without a default value, so that when it's empty we use getBasename(file).

Now we modify the command: section to use that option:

  command: >
    @{
        if (isEmpty(basename))
          { basename = getBasename(file); }
        infile = basename.concat('.').concat(input);
        outfile = [ '-o', basename.concat('.').concat(output) ];
        logfile = [ '-t', basename.concat('.').concat(log) ];
        return getCommand('makeindex', german, style, order, options,
                          logfile, infile, outfile);
    }

first we check if basename is empty; if it is, use the current file name from getBasename(file). Then proceed normally adding the extensions of the input, output, and log files, and then calling the makeindex executable.

(complete modified version of makeindex.yaml file at the bottom of this answer, for your convenience)

After that, you can change your directives to:

% arara: pdflatex
% arara: bibtex
% arara: makeindex
% arara: makeindex: { basename: names }
% arara: pdflatex
% arara: pdflatex

(note that I removed the two pdflatex rules before makeindex: you don't need those.)

And you should now have the index compiled correctly.


If you didn't make the change in the original copy of makeindex.yaml (which you should really not), then you need to save the new makeindex.yaml file in some folder, and then create a .araraconfig.yaml file which contains:

paths:
- '/path/to/the/folder/'

and put this .araraconfig.yaml in the current working directory or in your USER_HOME folder (see the arara manual, chapter 4 for more on that). If the makeindex.yaml file is also in the current working directory you can use - './' in the second line of the config file.


Full makeindex.yaml file:

!config
# Arara, the cool TeX automation tool
# Copyright (c) 2018, Paulo Roberto Massa Cereda 
# All rights reserved.
#
# This rule is part of arara.
identifier: nmakeindex
name: MakeIndex
authors:
- Marco Daniel
- Paulo Cereda
commands:
- name: The MakeIndex software
  command: >
    @{
        if (isEmpty(basename))
          { basename = getBasename(file); }
        infile = basename.concat('.').concat(input);
        outfile = [ '-o', basename.concat('.').concat(output) ];
        logfile = [ '-t', basename.concat('.').concat(log) ];
        return getCommand('makeindex', german, style, order, options,
                          logfile, infile, outfile);
    }
arguments:
- identifier: basename
  flag: >
    @{
      parameters.basename
    }
- identifier: input
  flag: >
    @{
      parameters.input
    }
  default: idx
- identifier: output
  flag: >
    @{
      parameters.output
    }
  default: ind
- identifier: log
  flag: >
    @{
      parameters.log
    }
  default: ilg
- identifier: german
  flag: >
    @{
        isTrue(parameters.german, '-g')
    }
- identifier: order
  flag: >
    @{
        if ([ 'letter', 'word' ].contains(parameters.order)) {
            return isTrue(parameters.order == 'letter', '-l', '');
        }
        else {
            throwError('The provided order is invalid.');
        }
    }
- identifier: style
  flag: "@{ [ '-s', parameters.style ] }"
- identifier: options
  flag: >
    @{
        if (isList(parameters.options)) {
            return parameters.options;
        }
        else {
            throwError('I was expecting a list of options.');
        }
    }
Paulo Cereda
  • 44,220
  • Is there a reason that imakeindex won't work? – barbara beeton Aug 23 '19 at 01:00
  • @barbarabeeton Two, actually. First, I didn't know about it (so thanks for mentioning it :-). Second, it seems to have some issue with the repeatindex package OP uses: when both packages are loaded the indexes aren't printed. I'll investigate further and update the answer once I find a work around. Anyhow, I mentioned imakeidx in the answer. – Phelype Oleinik Aug 23 '19 at 22:58
  • And i didn't know about repeatindex, so we're even! (Good luck finding the incompatibility.) – barbara beeton Aug 24 '19 at 01:49
  • Re: imakeindex: Notice that my example used memoir, which had built-in indexing support, for multiple indexes if desired. – murray Aug 24 '19 at 14:31
  • My memoir document uses two separate .bib files, for two bibliographies. In the "clever", 5-step arara sequence, how should one modify the directive % arara: bibtex if changed (toFile('mybib.bib')) || found ('log', 'Warning: Citation') (which was spread over 2 lines as shown in the answer) so as to accommodate having two bibliographies? – murray Aug 24 '19 at 14:34
  • @murray % arara: bibtex if changed (toFile('first_bib.bib')) || changed (toFile('second_bib.bib')) || found ('log', 'Warning: Citation') should do. This line runs bibtex only when either one of the .bib files changed or an undefined citation was spotted by LaTeX. This was originally written for biber, which is a bit slower. BibTeX is so fast it's almost not worth the hassle of checking :-) – Phelype Oleinik Aug 24 '19 at 16:42
  • @PhelypeOleinik: that bibtex directive works like a charm, thank you! I had wondered whether there was something similar to the files construction of arara: makeindex: { files: [ first_index, second_index ] } if changed ('idx'). – murray Aug 24 '19 at 18:43
  • @murray You're welcome! BibTeX already catches multiple .bib files in a single run, so the files parameter isn't of much use here. – Phelype Oleinik Aug 24 '19 at 18:50