nomenclature horror

In retrospective, I don't even know why I am still using [nomenclature](, but with my current fixes it seems to work just fine. I am using the nomencl package to create a list of symbols for mathematical texts. The options are as follows,
% ... 
because I think it is extremely practical to have a page reference to the definition of a mathematical symbol. However, page referencing does not seem to be a very popular feature of this *rich* package, so it is clear that more effort was put into developing other features. In fact, problems do not occur if you only use the nomenclature command once for each symbol. However, I sometimes want to add the same command in two places in order to reference two different pages. This usually happens when I define a symbol for a special case first, then extend the definition to a larger scope. For reasons I do not fully comprehend, nomencl will sometimes handle this very competently, and sometimes screw up cataclysmically. Every once in a while, it will write
\nompageref{12} \nompageref{17} 
instead of
\nompageref{12, 17} 
Now the nompageref macro contains an \endgroup command, so two of them following each other will cause the latex compilation to fail. I have no idea what causes this bug, but it is quite easy to fix. But don't worry, there's more. The nomenclature creation
makeindex %2.nlo -s -o %2.nls
does write \nomeqrefs commands to the nls-file, which is completely unnecessary considering my options - but it *did* make me realize another bug: Even if two entries are completely identical, if they have a different equation preceeding them, nomencl will create one separate entry for each of them. That is quity silly considering that I explicitly forbade it to ever display equation references anyway. To make a long story short, I wrote a little script to fix all the horrible things that nomencl does wrong. For the time being, it might be of use to someone.
import re
from sys import argv, stdout

stdout.write('Removing nomeqrefs ...')
contents = open(argv[1],'r').read()
contents = re.sub('\\\\nomeqref\s?\{[\d.]*\}\s*','',contents)
stdout.write(' done.\n')

stdout.write('Merging nompagerefs ...')
contents = contents.replace('}, \\nompageref{',', ')
stdout.write(' done.\n')

stdout.write('Combining ...')
flip = True
count = 0
while flip:
  pattern = '\\\\item\s\\\x5B\{\$([^\$]*)\$\}\\\x5D' + \
  matched_items = [ match for match in re.finditer(pattern,contents) ]
  flip = False  
  for m in matched_items:
    if flip: break
    for n in matched_items:
      if n is m: continue
      elif flip: break
      if ==
        flip = True
        count += 1
        number =
        contents = contents[:m.start()]+contents[m.end():]
        contents = contents[:n.end(3)]+', '+number+contents[n.end(3):]

stdout.write(' %d combined.\n' % count)
In [LED]( (which is, by the way, the worst editor with the best preview function) I can now do all the jobs at once in the following user1.bat:
@echo off
cd %1
makeindex %2
makeindex %2.nlo -s -o %2.nls
python %2.nls
Here's a minimal example for those who really just want a working nomenclature:





\section{First Section}
I will call $\Gamma$ something nice
\nomenclature[G]{$\Gamma$}{something nice}
and also, $\Delta$ will be something bad.
\nomenclature[D]{$\Delta$}{something bad}

\section{Second Section}
In a completely different context, let $\Gamma$ again be something rather nice.
\nomenclature[G]{$\Gamma$}{something nice}
that's it!


Tags: - -

Leave a Reply

Your email address will not be published. Required fields are marked *