MakeIndex, Nomenclature, Glossaries and AcronymsMarking the keywords in the text?

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?

Post by thowi »

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?

Thanks for your time!

cheers,
Thowi

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Marking the keywords in the text?

Post by Johannes_B »

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.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Marking the keywords in the text?

Post by cgnieder »

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
site moderator & package author
thowi
Posts: 22
Joined: Sun Aug 11, 2013 3:31 pm

Marking the keywords in the text?

Post by thowi »

Hi together

Thank you for your answers so far.
A document could look like this:

Code: Select all

\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.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Marking the keywords in the text?

Post by cgnieder »

You could define a custom command for this. Maybe something along the following lines:

Code: Select all

\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
site moderator & package author
thowi
Posts: 22
Joined: Sun Aug 11, 2013 3:31 pm

Marking the keywords in the text?

Post by thowi »

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 :D

Thanks for your kind help!
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Marking the keywords in the text?

Post by cgnieder »

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
site moderator & package author
thowi
Posts: 22
Joined: Sun Aug 11, 2013 3:31 pm

Marking the keywords in the text?

Post by thowi »

Mh maybe I did something wrong? I just added your code into the Preamble and the appearance doesn't change:
Neues_Dokument1.tex
(1.11 KiB) Downloaded 433 times

Code: Select all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 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.
thowi
Posts: 22
Joined: Sun Aug 11, 2013 3:31 pm

Marking the keywords in the text?

Post by thowi »

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.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Marking the keywords in the text?

Post by cgnieder »

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:

Code: Select all

\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
site moderator & package author
Post Reply