5

Hi I am doing a project for my 10th grade Graphic design class and we have to make up an inspirational type thing with the emotion words Bold, in a bigger size and capitalized and I was wondering if there is a way in TeX to Make a predetermined list of words to have effects on them sort of like CSS for HTML were I make that list and tell it to have those effects and Whenever I type them they will output to the effects I told it to do. here is an example

HI how was YOUR day I hope it was GREAT.

Torbjørn T.
  • 206,688

3 Answers3

7

This is just a joke, of course. Requires XeLaTeX.

\documentclass{article}
\usepackage{fontspec}

\usepackage{xesearch}
\SearchList{upper}{\textbf{\MakeUppercase{#1}}}{hi,your,great,I}

\begin{document}

Hi, how was your day? I hope it was great.

\StopList{upper}

Hi, how was your day? I hope it was great.

\end{document}

enter image description here

egreg
  • 1,121,712
6

Here is a totally different approach that does allow you to apply formatting to each of the words, and that is to use literate from the listings package:

enter image description here

Notes:

  • This solution as other issues in that a verbatim environment is used.

Further Enhancements:

  • I used a trailing space to check that words are matched and not parts of words. However, this requires a separate check for a trailing punctuation. Some sort of regex matching here would be helpful.

Code:

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

\lstdefinestyle{FormattedNumber}{% literate={great }{\textcolor{blue}{GREAT }}{1}% {great.}{\textcolor{blue}{GREAT}.}{1}% {hi }{\textcolor{red}{HI }}{1}% {I }{\textcolor{orange}{I }}{1}% {your }{\textbf{YOUR }}{1}% , } \newcommand{\CSS}[1]{% \lstinline[style=FormattedNumber]{#1}% }

\begin{document} \CSS{hi how was your day I hope it was great.} \end{document}

Peter Grill
  • 223,288
3

Well, here is one way to approach it: place the desired text in an environment and pre-process it before typesetting. However, I am not sure that this qualifies as an answer yet, as I think it really needs some sort of expansion magic to be able to apply macros such as \textbf{} to the desired words -- I could not get that to work. But for now this can do some simple text substitution:

enter image description here

Notes:

  • I used the environ package which provides an environment where you can access the complete body of the environment via \BODY.
  • This version needs to have ONLY plain text in the body of the environment.
  • The \protected@edef below is used to prevent "bad things from happening" as per David Carlisle's comment.

Further Enhancements:

  • Figure out how to apply macros to the selected words.
  • Have a list of words and a specific macro to be applied to each word, and use a \foreach type of loop to process. Not sure if this is simpler or not.
  • I used a trailing space to check that words are matched and not parts of words. However, this requires a separate check for a trailing punctuation. Some sort of regex matching here would be helpful.

Code:

\documentclass{article}
\usepackage{xstring}
\usepackage{environ}

\makeatletter \newcommand{\AlteredBody}{} \NewEnviron{CSS}{ \protected@edef\AlteredBody{\BODY} \StrSubstitute{\AlteredBody}{great }{GREAT }[\AlteredBody] \StrSubstitute{\AlteredBody}{great.}{GREAT.}[\AlteredBody] \StrSubstitute{\AlteredBody}{hi }{HI }[\AlteredBody] \StrSubstitute{\AlteredBody}{your }{YOUR }[\AlteredBody] \AlteredBody } \makeatother

\newcommand{\Text}{hi how was your day I hope it was great.}%

\begin{document}

\Text

\medskip \begin{CSS} \Text \end{CSS} \end{document}

Peter Grill
  • 223,288