# How to automatically color a string that starts by a specific character (@)?

Using the memoir class, I'm looking for a way to automatically color any string that starts whith an @ character, whether it be in the main text or in a footnote. Any idea how to do that?

Update : I also use bibtex, and i don't want link box or color to my citation, that explain the hidelink option.

With a minimal example :

\documentclass[a4paper, 12pt,twoside, openright]{memoir}
\usepackage{polyglossia}
\setdefaultlanguage{french}
\usepackage{fontspec}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[autostyle=true,french=guillemets,maxlevel=3]{csquotes}
\usepackage{xparse}
\usepackage{graphicx}
\usepackage[protrusion=true]{microtype}

\makeatletter

\renewcommand\@makefnmark{\hbox{\@textsuperscript{\normalfont\color{BurntOrange}\@thefnmark}}}
\renewcommand\@makefntext[1]{%
\parindent 1em\noindent
\hb@xt@1.8em{%
\hss\@textsuperscript{\normalfont\@thefnmark}}#1}
\makeatother

\begin{document}

\chapterstyle{bringhurst}

\end{document}


• Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – jub0bs Mar 15 '14 at 14:36
• The two words in the example that start with @ are the link texts of \href. But you have specified the hyperref option hidelinks, which removes all visible markup of links. – Heiko Oberdiek Mar 15 '14 at 14:52
• Because i have also citation link using bibtex, and i don't want colored link on it :/ – reyman64 Mar 15 '14 at 15:14

REVISION with general solution to problem of coloring all words beginning with a particular symbol, @. RE-EDITED to handle situation of lone @ character. It is done by making @ active, and then defining it to turn on red and print the saved copy of @. The key to this revision is the macro \tilblank that uses recursion to print out the next word (still in red). When it encounters a space, it reverts to black. If it encounters an end-of-group, it exits (and also reverts to black).

\documentclass{article}
\usepackage{ifnextok}
\usepackage{xcolor}
\makeatletter
\def\tilblank#1{#1\IfNextToken\@sptoken{ \color{black}}{%
\IfNextToken\egroup{}{\tilblank}}}
\def\atend{\IfNextToken\@sptoken{ \color{black}}\tilblank}
\let\svat @
\makeatother
\catcode@=\active
\def@{\color{red}\svat\atend}
\begin{document}
This tests @the use of @midstream or in its own {@group}.
Also testing @ by itself and at the end of a @paragraph.

This follows in black, as @it should.
\end{document}


ORIGINAL SOLUTION

I'm not sure if this approach breaks anything else. I make @ active. Also, this only works because your @ words are in their own group. That means if you wanted to use @ in text, it would have to be enclosed in {}.

\documentclass[a4paper, 12pt,twoside, openright]{memoir}
\usepackage{polyglossia}
\setdefaultlanguage{french}
\usepackage{fontspec}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[autostyle=true,french=guillemets,maxlevel=3]{csquotes}
\usepackage{xparse}
\usepackage{graphicx}
\usepackage[protrusion=true]{microtype}

\makeatletter

\renewcommand\@makefnmark{\hbox{\@textsuperscript{\normalfont\color{BurntOrange}\@thefnmark}}}
\renewcommand\@makefntext[1]{%
\parindent 1em\noindent
\hb@xt@1.8em{%
\hss\@textsuperscript{\normalfont\@thefnmark}}#1}
\makeatother

\begin{document}
\let\svat @
\catcode@=\active
\def@{\color{red}\svat}

\chapterstyle{bringhurst}

\end{document}

\documentclass{article}
\usepackage{xcolor}
\let\svat @
\catcode@=\active
\def@{\textcolor{red}{\svat}}
\begin{document}
xy@z
\end{document}
`

• @reyman64 I improved the solution, making it general. – Steven B. Segletes Mar 16 '14 at 1:58