3

I need to create an index for a fully-written book. Going through the entire text and manually inserting \index commands would be extremely time-consuming, and would also be difficult in terms of RSI.

It occurs to me that the following way of adding index entries would result in a huge speed up: in an editor, highlight some material and press a certain key (e.g. F2) to have that material copied into an \index entry.

So, for example, if my text says

analogous to Geach's donkey sentences

I want to be able to highlight `donkey sentences', press the relevant key and have the text changed to

analogous to Geach's donkey sentences\index{donkey sentences}.

Does anyone know of a Windows TeX editor that would support this? (Not emacs, please! Something a little more accessible -- any TeX IDE would be fine.)

4
  • So are the answers below sufficient (in which case you should accept one), or do you have still something different in mind? If you found a different solution yourself, please share it with us. Self-answers are welcome in our community and you may then accept those as well.
    – bodo
    Sep 14, 2012 at 5:43
  • The WinEdt answer looks very promising, which is why I upvoted it. I hadn't accepted it yet because a) I haven't actually had time to install WinEdt and test it yet, and b) I hope there will be a alternative involving non-commercial software. I will accept that answer now if you feel I ought to... please let me know.
    – Mohan
    Sep 14, 2012 at 16:05
  • Please don't understand me wrong. It is completely ok if you are not ready to decide yet. (Although you can of course always change which answer you accepted.) It just happens, that one forgets about the question here. In particular I had that feeling because you didn't react to my answer. But maybe you just don't like vi to start with.
    – bodo
    Sep 15, 2012 at 5:10
  • I didn't realise I could change my answer! (Thanks.) emacs/vi seem rather overwhelming/intimidating and not very user-friendly, which is why I specifically asked for a lightweight editor...
    – Mohan
    Sep 15, 2012 at 9:36

3 Answers 3

1

In WinEdt7 it is very easy to create small macros, menu items and shortcuts. For your problem you can define a macro in the MainMenu.ini (WinEdt-->Options-->Options Interfacae...). Create an new ITEM in one of the menus or submenus with:

 ITEM="Index"
  CAPTION="&Index"
  IMAGE="Citation"
  MACRO="IfSel(2,'>',!'SetSel(0);');[Copy;]InsLabel('\index','{','}');[Paste;]"
  SHORTCUT="113::F2"
  REQ_DOCUMENT=1      

Edit: A cleaner macro would be:

MACRO="IfSel(2,'>',!'SetSel(0);');GetSel(0,1);InsLabel('%!1\index','{','}');"

The important thing is the shortcut! With this shortcut you are able just to double click the word and press F2 to copy, paste and surround the selected word with the \index command. So donkey sentences becomes donkey sentences\index{donkey sentences}.

enter image description here

1
  • Tested and works nicely -- thank you!
    – Mohan
    Sep 14, 2012 at 20:29
8

Firstly I wasn't aware that there were editors other than emacs...

To get from

donkey sentences.

to

donkey sentences\index{donkey sentences}.

using a mouse to highlight and a key to insert the text sounds like a lot of hand movement in any editor. I would just set things up so that a spare character (say | but anything would do, such as £ if it is unused elsewhere)

Then all you need is two keystrokes to get to

|donkey sentences|.

if | is defined as

\catcode`|=\active
\def|#1|{#1\index{#1}}
4
  • 2
    Surely you know about vi! Sep 6, 2012 at 16:02
  • That's a very neat solution. I think I still do have a reason for preferring insertion of \index ... in many cases I will want to edit the entry slightly to get rid of morphological variation (i.e. plurals, etc.). For example, I might want to change "donkey sentences" to "donkey sentence".
    – Mohan
    Sep 6, 2012 at 16:08
  • It may also be worth saying that (at least in my case) most index entries will be for a single word. In that situation, double-clicking on the word would highlight it, so it shouldn't take much in the way of hand movement.
    – Mohan
    Sep 6, 2012 at 16:10
  • OK, well in that case I'm out (unless you want a bit of emacs lisp:-) Sep 6, 2012 at 16:19
1

If you use GVim and latex-suite, you can put the following key mapping in your .vimrc:

vmap <F6> <C-\><C-N>:call Tex_PutCommand('index', 'yes')<CR>

and then mark any word/phrase you want to alter, press F6 and voilà, instead of donkey you have \index{donkey}.

You must log in to answer this question.

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