LaTeX forum ⇒ MakeIndex, Nomenclature, Glossaries and AcronymsMarking 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?

Postby thowi » Thu Aug 15, 2013 10:15 pm

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

Tags:

User avatar
Johannes_B
Site Moderator
Posts: 4044
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Fri Aug 16, 2013 7:27 am

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: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Fri Aug 16, 2013 5:16 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

Postby thowi » Fri Aug 16, 2013 6:50 pm

Hi together

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

  1. \begin{document}
  2. Dies ist ein neues Dokument\index{Dokument: Dies ist ein Stichwort.}.
  3. \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

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Fri Aug 16, 2013 7:04 pm

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

  1. \documentclass{article}
  2.  
  3. % preamble code:
  4. \usepackage{imakeidx}
  5. \makeindex
  6.  
  7. \newcommand*\Index[2][]{%
  8. $\rightarrow$~#2%
  9. % use the mandatory argument for indexing if no optional argument is given
  10. \if\relax\detokenize{#1}\relax
  11. \index{#2}%
  12. \else
  13. % otherwise use the optional argument:
  14. \index{#1}%
  15. \fi
  16. }
  17.  
  18. \begin{document}
  19.  
  20. Dies ist ein neues \Index[Dokument: Dies ist ein Stichwort.]{Dokument}.
  21.  
  22. Hier ist ein weiteres \Index{Beispiel} ohne optionales \Index{Argument}.
  23.  
  24. \printindex
  25.  
  26. \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

Postby thowi » Fri Aug 16, 2013 7:21 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 :D

Thanks for your kind help!

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Fri Aug 16, 2013 7:29 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

Postby thowi » Fri Aug 16, 2013 7:51 pm

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 212 times


  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
  2. \newcommand*\Index[2][]
  3. {%
  4. $\rightarrow$~#2%
  5. % use the mandatory argument for indexing if no optional argument is given
  6. \if\relax\detokenize{#1}\relax
  7. \index{#2}%
  8. \else
  9. % otherwise use the optional argument:
  10. \index{#1}%
  11. \fi
  12. }
  13.  
  14. \makeatother
  15.  
  16. \begin{document}
  17. Text
  18.  
  19. test\index{test: blablablablbalblba}
  20.  
  21. text
  22.  
  23. blabla
  24.  
  25. \printindex{}
  26. \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

Postby thowi » Fri Aug 16, 2013 8:00 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.

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Fri Aug 16, 2013 8:05 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:

  1. \makeatletter
  2. \let\original@index\index
  3. \renewcommand*\index[2][]{%
  4. $\rightarrow$~#2%
  5. % use the mandatory argument for indexing if no optional argument is given
  6. \if\relax\detokenize{#1}\relax
  7. \original@index{#2}%
  8. \else
  9. % otherwise use the optional argument:
  10. \original@index{#1}%
  11. \fi
  12. }
  13. \makeatother



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


Return to “MakeIndex, Nomenclature, Glossaries and Acronyms”

Who is online

Users browsing this forum: No registered users and 2 guests