2

Main question

Answers to the question Automatically colour previously defined strings of text show how to colour pre-defined strings of text, but all those pre-defined strings are without spaces and punctuation marks.

I would like to ask if it were possible to design a MWE with (more or less, but without specificities such as; I quote; "only the endings of words") analogue function, but which additionally is functional also for strings with spaces and/or punctuation marks.

I am sorry if this is a duplicate. If so, I would be happy to be shown the way (to the duplicate).

Suggested MWE strings, colouring rules and trial text

Since it was suggested (in the comments) for me to propose some strings, colouring rules, and a piece of text to test the MWE, I have created the following poetic piece:

\documentclass{article}

\begin{document}

{\huge Strings to be coloured red} (regardless of how they are formatted, this should e.g. work both for bold and for not bold text) \vspace{3em}

\begin{itemize}
\item \textbf{old, you}
\item \textbf{... and when}
\end{itemize}

\vspace{3em} {\huge Strings to be coloured blue} (regardless of how they are formatted, this should e.g. work both for bold and for not bold text) \vspace{3em}

\begin{itemize}
\item \textbf{you don't}
\end{itemize}

\vspace{3em} {\huge Suggested poem to be automatically coloured (according to text strings and rules predefined above):} \vspace{3em}

\textbf{When you are old, you know that.}\\
When you are old, you know how the story ends without reading.\\
Or maybe you don't know, but you know that the story will end.\\
When you are old, you know what you did wrong.\\
Or maybe you don't know, but you know that you did wrong.\\
You realize that what you have liked is just what you have known.\\
And that you like so much more than you have known.\\

When great surgeons undergo surgeries ...\\
... and when great writers read a book ... \\
... and when great lovers are loved ...\\
Then what?\\

Don't be mistaken: it is not because you are dead\\
that you will not do wrong!\\
People might stumble over your bones and get terribly injured.\\
Getting older never stops.\\
So donate your body to science, and grow old well.

\end{document}
O0123
  • 1,773
  • You're asking two (different) things at the same time –  Apr 19 '16 at 10:50
  • 1
    Should I split up into 2 questions (and perhaps wait with the second until further answers on the first)? P.S.: I have now further clarified that indeed 2 different things are asked. EDIT TO YOUR COMMENT BELOW: Ok, text removed according to your advice. – O0123 Apr 19 '16 at 10:51
  • I would remove the second question from the text, wait until the first one is answered (for which I would use, l3regex, for example, but this depends on the precise structure. –  Apr 19 '16 at 10:54
  • Can you provide an example how such predefined strings look like and how they should be coloured, best with a compilable document, even if the colouring is not done (of course= –  Apr 19 '16 at 11:03
  • @ChristianHupfer I have updated the question according to your advice. – O0123 Apr 19 '16 at 11:49
  • This would be easy to do with something like python. With tex it seems to be...difficult. Perhaps the xstring or listings packages would help? –  Apr 19 '16 at 12:24

0 Answers0