Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a way to make Latexmk invoke makeglossaries (part of the glossaries package)?

Specifically I want to use latexmk to compile a LaTeX document that uses the glossaries package to produce a glossary. Currently I'm using this rather clumsy sequence of commands:

makeglossaries document
latexmk -pdf document.tex
makeglossaries document
latexmk -pdf document.tex

The first run of makeglossaries is required to produce files that the glossaries package needs, or otherwise causes latexmk to fail, but there's still no data in the (non-existant) .aux file, so that first makeglossaries invocation produces nothing (except for an empty file).

So, how to do this using latexmk alone (and let that deal with invoking makeglossaries at the right time)?

share|improve this question
add comment

5 Answers

up vote 25 down vote accepted

You need to write a configuration file that tells latexmk which files are interesting for the glossary and how to handle them. Fortunately, the author provides some sample rc files.

Putting

add_cus_dep('glo', 'gls', 0, 'makeglo2gls');
sub makeglo2gls {
    system("makeindex -s '$_[0]'.ist -t '$_[0]'.glg -o '$_[0]'.gls '$_[0]'.glo");
}

in ~/.latexmkrc (globally in your home directory) or ./latexmkrc (locally in your document directory) should do the trick.

share|improve this answer
    
Do you have to add something to your build command? –  drozzy Jun 7 '12 at 19:05
    
Also, why does it go into directory .latexmkrc/latexmkrc? I thought it was simply the .latexmkrc or latexmkrc file? –  drozzy Jun 7 '12 at 19:14
    
@drozzy: It’s the file .latexmkrc or latexmkrc in the directory where the LaTeX master file you are working on resides. –  mhp Jun 17 '12 at 5:25
add comment

At Hans-Peter E. Kristiansen’s request, I provide another answer, extending the one given by kay102.

Add the following lines to some latexmk initialization file (e.g., on Linux systems, ~/.latexmkrc):

add_cus_dep('glo', 'gls', 0, 'run_makeglossaries');
add_cus_dep('acn', 'acr', 0, 'run_makeglossaries');

sub run_makeglossaries {
  if ( $silent ) {
    system "makeglossaries -q '$_[0]'";
  }
  else {
    system "makeglossaries '$_[0]'";
  };
}

As a consequence, if latexmk is invoked with the -silent option makeglossaries will be silent, too.

Moreover, add

push @generated_exts, 'glo', 'gls', 'glg';
push @generated_exts, 'acn', 'acr', 'alg';
$clean_ext .= ' %R.ist %R.xdy';

to update the cleanup functionality of latexmk appropriately.

share|improve this answer
    
Cool - I am assuming that you find that kay102's answer is the best(however marginal). Can you improve this answer by adding extension from glossaries to remove with the -c or -C option? or is this bad for some reason? –  Hans-Peter E. Kristiansen Feb 12 '12 at 20:32
    
@Hans-Peter E. Kristiansen: I’ve extended my answer accordingly. –  mhp Feb 12 '12 at 21:10
    
Thanks - just what I needed. Bounty coming up when grace period is over. –  Hans-Peter E. Kristiansen Feb 12 '12 at 21:28
    
Now the only file(except .tex) that is not removed by -C option, is the .bbl file. Should I add push @generated_exts, 'bbl'; or $clean_ext .= ' %R.bbl'; to my latexmkrc? –  Hans-Peter E. Kristiansen Feb 12 '12 at 21:58
    
@Hans-Peter E. Kristiansen: The .bbl file isn’t related to the glossaries package. So it could be worth posing your comment as a regular question. (Most probably, you need $bibtex_use = 2;.) –  mhp Feb 12 '12 at 22:16
show 1 more comment

You can also let latexmk call makeglossaries directly by adding the following to your latexmkrc file (in my case I had to add it to $HOME/.latexmkrc):

add_cus_dep('glo', 'gls', 0, 'makeglossaries');
add_cus_dep('acn', 'acr', 0, 'makeglossaries');

sub makeglossaries {
    system "makeglossaries $_[0]";
    if ( -z "$_[0].glo" ) {
        open GLS, ">$_[0].gls";
        close GLS;
    }
    return 0;
}
share|improve this answer
    
With the current version of the makeglossaries program, testing for empty .glo and .acn files isn’t necessary any longer. –  mhp Jan 10 '12 at 19:34
add comment

A lightweight solution is adding

add_cus_dep('glo', 'gls', 0, 'makeglo2gls');
add_cus_dep('acn', 'acr', 0, 'makeglo2gls');
sub makeglo2gls {
        system("makeglossaries $_[0]");
}

to your .latexmk file.

share|improve this answer
    
You still need the add_cus_dep('acn', 'acr', 0, 'makeglo2gls') line for acronyms. –  wcmatthysen Jun 24 '11 at 8:57
    
You are right. I have added the line. –  kay102 Jun 26 '11 at 16:30
2  
Slight improvement to the makeglo2gls subroutine: Call makeglossaries with/without the -q option, depending on whether $silent is true/false. –  mhp Jan 10 '12 at 19:30
    
I'm trying to use this to make a list of acronyms but it is not working? Any ideas? –  Darling Jan 15 '12 at 11:31
    
@kay102: Is your solution better than the others? –  Hans-Peter E. Kristiansen Feb 12 '12 at 16:37
show 2 more comments

mhp's code didn't work out for me on my windows 8 machine, so i changed his code to:

add_cus_dep('glo', 'gls', 0, 'run_makeglossaries');
add_cus_dep('acn', 'acr', 0, 'run_makeglossaries');

sub run_makeglossaries {
  if ( $silent ) {
    system "makeglossaries -q $_[0]";
  }
  else {
    system "makeglossaries $_[0]";
  };
}

push @generated_exts, 'glo', 'gls', 'glg';
push @generated_exts, 'acn', 'acr', 'alg';
$clean_ext .= ' %R.ist %R.xdy';

primarily i just removed the single quotes around $_[0]. otherwise makeglossaries wasn't able to find the filename.aux file properly.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.