7

I am not a native English speaker and there are some grammar mistakes I do a lot, especially have/has in conjunction with each/every, and so on.

Q: Is there some way to highlight all occurrences of some words (from a list I specify) in a document automatically?

  • The new question at https://tex.stackexchange.com/q/242279/7883 is perhaps relevant. – Thérèse May 05 '15 at 16:59
  • Yes, it is similar; however, all solutions presented there require extra software or that one manually mark all instances where one wants to do some highlightning – Per Alexandersson May 05 '15 at 17:44

2 Answers2

4

You can use the listings package to do this, although it is not ideal because the text won't be typeset "normally" and most comments are disabled inside a lstlisting environment. If you are happy with these constraints then this might be OK, at least for drafts.

Here's what is does to your question:

enter image description here

and here is the latex code:

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}

\lstset{morekeywords={have,has,each,every},  % define the words to be highlighted
        keywordstyle=\color{blue},           % define how they are highlighted
}


\begin{document}
  \begin{lstlisting}% wrap your text inside a listings environment
    I am not a native English speaker and there are some grammar mistakes
    I do a lot, especially have/has in conjunction with each/every, and so
    on.

    Q: Is there some way to highlight all occurrences of some words (from
    a list I specify) in a document automatically?
  \end{lstlisting}
\end{document}
4

With luatex, you can use the package chickenize, somewhat like this:

\documentclass{article}
\usepackage{chickenize}
\addtosubstitutions{have}{HAVE}
\addtosubstitutions{has}{HAS}
\addtosubstitutions{each}{EACH}
\addtosubstitutions{every}{EVERY}
\begin{document}
\substitutewords
I am not a native English speaker and there are some grammar mistakes
I do a lot, especially have/has in conjunction with each/every, and so
on.

Is there some way to highlight all occurrences of some words (from a
list I specify) in a document automatically?
\end{document}

Once you’ve checked all occurrences of the problematic words, simply comment out \substitutewords, and they’ll go back to being lowercase instead of all caps.

Thérèse
  • 12,679