## LaTeX forum ⇒ MakeIndex, Nomenclature, Glossaries and Acronyms ⇒ Marking the keywords in the text? Topic is solved

Information and discussion about MakeIndex - the tool to generate subject indices for LaTeX documents.
thowi
Posts: 22
Joined: Sun Aug 11, 2013 3:31 pm

### Marking the keywords in the text?

Hey all together,

using the keywords is working pretty well, but I think it's a good thing that the used kewords can be identified in the text itself so I know "ah, I can lookup this word". Are there any possibilities to mark all the keywords in a special style, maybe via definition in the preamble? Can you recomment something?

cheers,
Thowi

Tags:

Johannes_B
Site Moderator
Posts: 4044
Joined: Thu Nov 01, 2012 4:08 pm
It would be very helpful if you could state your question in form of some code. A minimal working example would be perfect (please follow the link). That means your code is immediately compilable and we can test posibble solutions. You can state your wishes directly in the code, either as text, or asa simple comment (the %-sign in front).

Best regards
Johannes
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm
Hi Thowi,

Welcome to the LaTeX community!

thowi wrote:using the keywords is working pretty well,/quote]
Using which keywords where? And to do what? I have no idea what you're talking about. The only hint I have is that this question is somehow related to generating an index since it is posted in the “makeindex” forum...

thowi wrote:Are there any possibilities to mark all the keywords in a special style, maybe via definition in the preamble? Can you recomment something?

Please try to clarify what you're talking about. Do you want to mark the indexed words in the text? (And if so, why? The only books where I knows this kind of markup are encyclopedias and the like).

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

thowi
Posts: 22
Joined: Sun Aug 11, 2013 3:31 pm
Hi together

A document could look like this:

\begin{document}Dies ist ein neues Dokument\index{Dokument: Dies ist ein Stichwort.}.\end{document}

cgnieder wrote:Do you want to mark the indexed words in the text?

Yes, that's it! I would like to mark the indexed words in the text, so in the above mentioned example I would like to mark the word "Dokument". I'm using LyX and already looked up the manuals but couldn't find any information about this topic.

cheers,
thowi
Last edited by cgnieder on Fri Aug 16, 2013 6:52 pm, edited 1 time in total.
Reason: changed code markup from inline to block

cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm
You could define a custom command for this. Maybe something along the following lines:

\documentclass{article} % preamble code:\usepackage{imakeidx}\makeindex \newcommand*\Index[2][]{%   $\rightarrow$~#2%   % use the mandatory argument for indexing if no optional argument is given   \if\relax\detokenize{#1}\relax     \index{#2}%   \else     % otherwise use the optional argument:     \index{#1}%   \fi} \begin{document} Dies ist ein neues \Index[Dokument: Dies ist ein Stichwort.]{Dokument}. Hier ist ein weiteres \Index{Beispiel} ohne optionales \Index{Argument}. \printindex \end{document}

I am not familiar with LyX, though, so I don't know what the best way to do this in LyX would be. You could just insert the preamble code to the LaTeX preamble and use \Index{<mandatory>} or \Index[<optional>]{<mandatory>} as ERT.

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

thowi
Posts: 22
Joined: Sun Aug 11, 2013 3:31 pm
Hi Clemens

Yes exactly, this looks like a solution for my question, thank you very much!
I think it doesn't work with LyX but I'm not exactly sure why. Normally LyX uses makeindex for generating the index. Maybe the package loading of imakeidx is restricted - strange. I will try a few things and when I got it working, I will come back to you guys

cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm
The package imakeidx is not necessary for the solution: it just simplifies the index generation for us LaTeX users since it saves us a separate makeindex run. Just leave it out and generate your index as usual and all should be fine.

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

thowi
Posts: 22
Joined: Sun Aug 11, 2013 3:31 pm
Mh maybe I did something wrong? I just added your code into the Preamble and the appearance doesn't change:
Neues_Dokument1.tex

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.\newcommand*\Index[2][]{%   $\rightarrow$~#2%   % use the mandatory argument for indexing if no optional argument is given   \if\relax\detokenize{#1}\relax     \index{#2}%   \else     % otherwise use the optional argument:     \index{#1}%   \fi} \makeatother \begin{document}Text test\index{test: blablablablbalblba} text blabla \printindex{}\end{document}
Last edited by cgnieder on Fri Aug 16, 2013 8:01 pm, edited 1 time in total.
Reason: changed code markup from inline to block

thowi
Posts: 22
Joined: Sun Aug 11, 2013 3:31 pm
Ah okay, I got it!
My test\index{... needs to be test\Index{....
It's case sensitive. And changing your Preamble to "i" doesn't work because "index" is already defined... mh. Ok, I could use the normal TeX Code with capital "Index", which would solve the problem.

cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm
thowi wrote:Ah okay, I got it!
My test\index{... needs to be test\Index{....
It's case sensitive. And changing your Preamble to "i" doesn't work because "\index" is already defined.

That's true. One can however redefine \index to have the new definition. We need to save the old definition, though, as it is used in the new one:

\makeatletter\let\original@index\index\renewcommand*\index[2][]{%   $\rightarrow$~#2%   % use the mandatory argument for indexing if no optional argument is given   \if\relax\detokenize{#1}\relax     \original@index{#2}%   \else     % otherwise use the optional argument:     \original@index{#1}%   \fi}\makeatother

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim