[Tex/LaTex] Underlining a coloured DNA sequence

colorformattingverbatim

In the posts to the question of Timtico (here) several ways have been proposed to colour the As,Ts,Cs and Gs differently within a DNA sequence. What I want is also to be able to underline some nucleotides to emphasise them, e.g.: \dna{ATACAG$\underbar{AG}$CATA} but I didn't manage to do so.
Does anyone have suggestions to this problem?
Thank you very much!

Best Answer

I added a delimiter to the code from my answer at typesetting different characters with different colors in a DNA sequence

\documentclass{article}
\usepackage{listings,xcolor}
\lstdefinestyle{dna}{%
    literate={A}{\textcolor{green}{A}}{1}
        {B}{\textcolor{blue}{B}}{1}
        {C}{\textcolor{red}{C}}{1}
        {a}{\textcolor{green}{A}}{1}
        {b}{\textcolor{blue}{B}}{1}
        {c}{\textcolor{red}{C}}{1},
    basicstyle=\ttfamily,
    moredelim=[is][\underline]{_}{_}
}
\newcommand{\DNA}[1]{%
    \lstinline[style=dna]{#1}%
}
\begin{document}
\DNA{AA_CAAAD_A}
\end{document}

The result is
result of the above code

I think, this should work for you.

Related Question