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.

I would like to have the diacritical marks stand out visually by being colored differently. For example, can I have â in which the circumflex is in red, and the 'a' is in black? When I use \textcolor{...} for the diacritical mark, it is not placed correctly over (or under) the letter.

share|improve this question

migrated from stackoverflow.com Feb 7 '13 at 16:03

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 5 down vote accepted

The main problem is when you use a T1 encoded font, in which accented chars are no longer composed by overimposing the diacritic on a "unaccented" char, but instead they are a new glyph which includes the diacritic as part of its design.

For this case, the only solution I can imagine is a hack: first write the accented char in red, then backtrace and draw in black the same char but without accent:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\def\trick#1#2{\textcolor{red}{#1}\llap{#2}}

\begin{document}
a \trick{â}{a} â
\end{document}

Result

share|improve this answer

Perhaps the following:

\documentclass{article}
\usepackage{color}

\newbox\accentboxa
\newbox\accentboxb

\newcommand{\redhat}[1]{\setbox\accentboxa=\hbox{\^#1}%
\setbox\accentboxb=\hbox{\^{}}\leavevmode
\kern\dimexpr(\wd\accentboxa-\wd\accentboxb)/2\relax
{\color{red}%
\raise\dimexpr\ht\accentboxa-\ht\accentboxb\relax\copy\accentboxb}%
\kern-\dimexpr(\wd\accentboxa+\wd\accentboxb)/2\relax #1}

\begin{document}

\^a\redhat{a}\^a

\^A\redhat{A}\^A

\end{document}

enter image description here

share|improve this answer

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.