TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I spent most of yesterday trying to get LaTeX to create a list of abbreviations using the {nomencl} package , and after a lot of research managed to succeed using latexmk and creating a customised rule in a latexmkrc file. (This was by copying examples, I have no idea what I'm actually doing!). However, it only works if I put the latexmkrc file in the current document folder. The code in the latexmkrc file, which was cloned from a post on another board by John Collins, is as follows:

add_cus_dep('nlo', 'nls', 0, 'makenlo2nls');
sub makenlo2nls {
my $cwd = cwd();
my $base = $_[0];
# Normalize the filenames to use / to separate the directory
# components, since both \ and / are allowed under MSWin:
$base =~ s(\\)(/)g;
$cwd =~ s(\\)(/)g;
# Remove any initial string equal to the name of current
# working directory (and the following separator):
$base =~ s(^$cwd/)();
# Normalize the filename back to standard MSWin:
$base =~ s(/)(\\)g;
# Quote the filenames in the command line
# (to give safety against special characters):
system("makeindex \"$base.nlo\" -s nomencl.ist -o \"$base.nls\"");

Is there a central location where I can put the latexmkrc file so that it is available to all my documents? I have tried the obvious locations such as C:\Users\*username*.

share|improve this question
up vote 9 down vote accepted

Try to name the file LatexMK and put it in C:\latexmk.

EDIT: Quoting the latexmk manual, section "Configuration/initialization (RC) files", p. 9--10:

Latexmk can be customized using initialization files, which are read at startup in the following order:

1) The system RC file, if it exists.


On a MS-WINDOWS system it looks for "C:\latexmk\LatexMk".


2) The user’s RC file, "$HOME/.latexmkrc", if it exists. Here $HOME is the value of the environment variable HOME. [...] [O]n MS-Windows, the user may choose to set it.

3) The RC file in the current working directory. This file can be named either "latexmkrc" or ".latexmkrc", and the first of these to be found is used, if any.

4) Any RC file(s) specified on the command line with the -r option.

share|improve this answer
Yeh @lockstep, option 1 works! I feel a bit of a fool, because I read the latexmk documentation yesterday and ignored option 1 – (a) because there wasn't a C:\latexmk folder on my computer, and (b) because option 2 was more appealing as the file would have been backed up automatically from my home directory. However, I was struggling with the '$HOME' environment variable – my version of Windows only seems to have '%HOMEPATH%', '%HOMEDRIVE%' and '%HOMESHARE%' user environment variables. Anyway, I can add C:\latexmkto my backup tree, so problem solved. Many thanks! – Mark Birtwistle Jan 1 '12 at 14:37
Actually latexmk's documentation is incomplete in explaining its notion of the location of a user's home folder. If the environment variable HOME exists, that is used (which normally works on UNIX-like systems). If not, then the value of USERPROFILE is used (which should work on a Windows system). – John Collins Jan 2 '12 at 18:25
@JohnCollins Could you elaborate on this in a separate answer to this question? – lockstep Jan 2 '12 at 18:26
@lockstep Yes, I'll make a separate answer. – John Collins Jan 2 '12 at 18:32

Actually latexmk's documentation is incomplete in explaining its notion of the location of a user's home folder.

If the environment variable HOME exists, that is used (which normally works on UNIX-like systems, or if the user defines this variable). If not, then the value of USERPROFILE is used (which should work on a Windows system). The fall back is just to use the current directory, but that shouldn't matter here

On a Windows 7 system, the default for USERPROFILE is supposed to be C:\Users\*username*. So it should work to put the initialization file there, but the question says that doesn't work. However, the name of the file in the home directory should be .latexmkrc, with a period in front of it (in accordance with UNIX conventions for treating such files as hidden). Perhaps the period was missing in the filename, or perhaps (less likely) the userprofile is not in its default location.

share|improve this answer
Many thanks for that @JohnCollins. You are quite correct in inferring that I had used the incorrect filename in my USERPROFILE directory. However, Windows 7 won't easily allow me to change the filename to .latexmkrc. I get the error message 'You must type a filename'! The problem, I think, is that Windows treats everything after the final '.' as a file extension, and therefore thinks that the name part of the filename is missing. I can open latexmkrc and save it as .latexmkrc.txt, but as soon as I try to remove the final .txt, I get the same error message. – Mark Birtwistle Jan 3 '12 at 10:35
This is a feature/limitation of Windows Explorer. The easiest solution is to do the rename from the command prompt. You could also open the file in Notepad (or another editor) and save with the correct name, taking care to avoid the automatic addition of an extension. (That can be done in Notepad under Windows XP, so it may also work with Notepad under Windows 7.) – John Collins Jan 3 '12 at 15:47
Thanks @JohnCollins, I've managed to successfully change the file name with Notepad – and it now works from my USERPROFILE folder (I've deleted the C:\latexmk folder). I normally use Wordpad as my general text editor (as it tends to format some files better than Notepad), but oddly it doesn't have the 'All files' *.* save option and you have to save files with one of several given extensions. Anyway, the problem is now solved – so many thanks again for your help. – Mark Birtwistle Jan 3 '12 at 16:25

I guess, something like the following would allow more suitable option than putting the setting file in the working folder every time:

  1. Create a variable HOME with an appropriate value

  2. Create file .latexmkrc in the corresponding folder from 1.

  3. Put the following into it:

    # Custom dependency and function for nomencl package 
    add_cus_dep( 'nlo', 'nls', 0, 'makenlo2nls' );
    sub makenlo2nls {
    system( "makeindex -s nomencl.ist -o \"$_[0].nls\" \"$_[0].nlo\"" );
  4. Assuming, Perl is installed, install PAR packer:

    cpan -i PAR::Packer
  5. Change latexmk.pl as follows:

    # Note that each rc file may unset $auto_rc_use to
    # prevent lower-level rc files from being read.
    # So test on $auto_rc_use in each case.
    if ( $auto_rc_use ) {
        # System rc file:
        read_first_rc_file_in_list( @rc_system_files );
    if ( $auto_rc_use ) {
        # User rc file:
    # Give Perl access to the windows HOME environment variable
     my $HOME = $ENV{HOME}; 
    read_first_rc_file_in_list( "$HOME/.latexmkrc" );
    if ( $auto_rc_use ) { 
    # Rc file in current directory:
    read_first_rc_file_in_list( "latexmkrc", ".latexmkrc" );
  6. Now, compile it:

    pp -o latexmk latexmk.pl
  7. Done. Latexmk should now compile with nomenclature using %HOME%/.latexmkrc

Unfortunately, I couldn't test it since after many trials, I gave up installing pp on my Windows x64 platform.

share|improve this answer

Your Answer


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.