Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
It is possible in restricted circumstances but really it's better to mark up each word that needs highlighting (as you would have to do in CSS or in the wiki markup on this site) –  David Carlisle Oct 11 '12 at 18:20
2  
Related/duplicate(?): tex.stackexchange.com/questions/16996/… –  Torbjørn T. Oct 11 '12 at 18:26
    
If you can use LuaLaTeX, it's easy to programm a script which replaces the word with \textbf{word} on the fly. –  Juri Robl Oct 11 '12 at 19:00
    
Another Related Question: Highlight language keywords in a paragraph?. –  Peter Grill Oct 11 '12 at 19:50
add comment

3 Answers 3

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

share|improve this answer
3  
To use mere mortals this seems to work great, so not sure about your opening remark? –  Peter Grill Oct 11 '12 at 21:12
    
@PeterGrill I'd never apply something like this in my documents. ;-) However xesearch might have some real uses. –  egreg Oct 11 '12 at 21:15
add comment

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}
share|improve this answer
add comment

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}
share|improve this answer
    
I think you want \protected@edef not \xdef there or bad things will happen. –  David Carlisle Oct 11 '12 at 19:16
add comment

Your Answer

 
discard

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.