# LaTeX: is it possible to create a macro to add words to index (using TexMaker)?

I'm just finishing my first document (a book), and I have to create an index (\makeindex, \printindex, \index{WORD}, ...).

I am using TexMaker on Linux.

I was wondering if it's possible to define something like a "macro", to be able to avoid adding \index{WORD} before each word to be indexed (my document will have very many words to be indexed... :-).

I mean, I'd like to be able to define a command which would allow me - clicking a keyboard short-cut, for example [Ctrl][F9] - to insert \index{WORD} just before the WORD the cursor is on...

Skimming through TexMaker docs, I couldn't find anything useful to that intent...

UPDATE I am following the suggestions in the comments, but I can't yet fully understand how to solve my problem... Feel quite dumb right now... :-(

So: I add the command \iindex in my book heading, as Sigur suggested:

\newcommand\iindex[1]{#1\index{#1}}


So far so good. Now I would like to associate a keyboard shortcut to it. As suggested (always by Sigur) I look for a macros menu, but I can't find it (I use Texmaker 4.0.3).

• User Tags
• User Commands
• Customize Completion

Both Tags, Commands can be customized, but I suppose:
- Commands are for external commands (not my case).
- Tags are more promising, but what do I write in tag's LaTeX content? I mean, how do I refer to the word under cursor, which I want to index?
- Customize completion lists items already defined (which include for example \index{•}), and I can add new commands; but, I can't understand how to associate it with a shortcut... :-).

Any more literal suggestion for a LaTeX newbe...?
If anybody solves and answers, I will accept the answer, of course... :-)

-
First, I suggest you to define a new command \newcommand\iindex[1]{#1\index{#1}}. then you can add a shortcut to this command and then you double click a word and press the shortcut. I guess that this should work. – Sigur Dec 26 '13 at 14:56
Thanks! I suppose you added an excess "i"...: "\newcommand\index[1]{#1\index{#1}}", right? And, sorry (I told I was new to LaTeX? :-), how do I add a shortcut to a command? – MarcoS Dec 26 '13 at 14:59
No! \index already exists. So I defined a new command, so you can not use the same name. The new command makes use of the old one. – Sigur Dec 26 '13 at 15:00
I use TeXstudio. It is similar. First, insert the new command in your preamble. Then, use the Macros menu to add a new macro. You can call it as you wish and use the new command on the macro, that is, the result of the macro will be \iindex{foo}. After this you can access the macro in the same menu or you can use the shortcut. In my editor, shift+F1. Then, select the word and press it. – Sigur Dec 26 '13 at 15:14
Hi @MarcoS is very easy to create shortcuts and customize things in TeXmaker as in TeXStudio as @Sigur says (in fact, TeXStudio is a fork from TeXMaker). In the user menu you can add and custom tags, commands or improve the autocompletation. For me is the easiest way to do what you want. – Aradnix Dec 26 '13 at 17:42

Having added the suggested \newcommand to the preamble, you can add a user tag with

\iindex{@}


as 'LaTeX Content'. Using the default shortcut, e.g. Shift + F1 if the first tag was chosen, will insert \iindex{•}, or if a word was selected, it will replace word with \iindex{word}.

I don't know if it is possible to change these shortcuts, I didn't see anything in Options --> Configure Texmaker --> Shortcuts.

-
Thanks! I could add my first item to index with a key! Is there some way to change the shortcut (from default [shift][F1]) to something else? – MarcoS Dec 28 '13 at 13:02
@MarcoS As I said, I don't know. Some shortcuts can be modified in the options, but these are not listed. – Torbjørn T. Dec 28 '13 at 13:36
Anybody? Really Texmaker doesn't allow to change tags shortcuts??? I can even change some config file, if GUI does not allow it... – MarcoS Dec 28 '13 at 14:40
@MarcoS Texmaker isn't the most configurable editor I think. TeXstudio, mentioned in the comments to your question, does let you change these. – Torbjørn T. Dec 28 '13 at 15:11
I will try TeXstudio ASAP... :-) – MarcoS Dec 28 '13 at 22:58