TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a variable that contains a long list of keywords, e.g.:

\keywords{computers, business, biology, fine art, literature, zoology}

I need to make an if-then statement that checks for the presence of a particular keyword, e.g.:

IF "zoology" IN keywords

How can I check if a variable contains a particular keyword in plain TeX?

  • I can change the format of \keywords, e.g. \keywords{computers biology fine_art}, if that will be easier to implement.
share|improve this question

The following example uses package kvsetkeys to get a parser for lists with comma separated entries:

\input kvsetkeys.sty % parser for comma separated lists
\input ltxcmds.sty % helper macros

\catcode`\@=11 % \makeatletter

% \testkeywordinlist{keyword}{keyword list}{true}{false}
\catcode`\@=12 % \makeatother

\def\keywords{computers, business, biology, fine art, literature, zoology}

  \immediate\write16{* "zoology" found.}%
  \immediate\write16{* "zoology" not found.}%



  • "zoology" found.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.