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.
2 Answers
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}
-
I tried this with latex on Ubuntu and just got two regular a's with no accent or color. Jan 12, 2015 at 4:58
-
@JosephGarvin Sounds like a encoding issue. Instead of
â
, try writing\^a
. Also, it could be a font problem; you can try using\usepackage{lmodern}
instead of\usepackage[T1]{fontenc}
– JLDiazJan 12, 2015 at 8:50
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}