# How to use color and symbol at the same time?

How can I write in LaTeX, for example: \sanela{} but in red color? I typed \verb|\sanela|\{\} but it seems like a lot to type? How to add color red here?

This could you be your choice by using the xcolor package to get the colored text:

\documentclass[10pt,a4paper]{article}
\usepackage{xcolor}
\begin{document}
{\color{red}\textbackslash \texttt{sanela}\{\}}
\end{document}


to get

you are using symbol or not, when you use colors just create your closed environment by enclosing whatever you need in the desired colors within {\color{yourcolor}.....your data.....that can also span multiple lines....or even equations......}

All the immediately available colors are listed in this link

• \color{red}\textbackslash \texttt{sanela}\{\} is more similar to \verb|\sanela|\{\} – CarLaTeX May 20 '17 at 8:12
• @CarLaTeX I didn't know that before, I shall play with that as well. Also, updated my answer by including the \texttt{.} – Raaja_is_at_topanswers.xyz May 20 '17 at 8:14

To me it looks like two questions. The first is how to write \sanela{}, and then the basic \verb|\sanela{}| is probably the simplest form. The second is how to get it colored, and then things get more complicated. \verb is a bit special as command and it connat be used as argument to other commands. One idea is to use tcolorbox where you can define your own (inline) verbatim command. If you have non-white background you might want to change colframe and colback.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{listings}
\DeclareTotalTCBox{\myTestVerb}{O{black}v}{%
verbatim,
top=0pt,bottom=0pt,left=0mm,right=0mm,
boxsep=0pt,
leftrule=0pt,rightrule=0pt,toprule=0pt,bottomrule=0pt,
colframe=white,colback=white,
}{\color{#1}#2}
%%%%%%%%%%
\begin{document}
Text \myTestVerb{\sanela{}} \myTestVerb[red]{\sanela{}} Text
\end{document}


• I upvote your answer (+1). It is very nice. I have undestood thath the user want to write \sanela{} not in verbatim. – Sebastiano May 20 '17 at 9:57
• @Sebastiano, Yes you might be rigth that is not about colored verbatim, even though \verb is mentioned. The question is not entirely clear to me. – StefanH May 20 '17 at 10:12

You can use newverbs:

\documentclass{article}
\usepackage{newverbs,xcolor}

\newverbcommand{\redverb}{\leavevmode\begingroup\color{red}}{\endgroup}

\begin{document}

Normal \verb|\sanela{}| and red \redverb|\sanela{}|

\end{document}


A more customizable version:

\documentclass{article}
\usepackage{newverbs,xcolor}

\newverbcommand{\colorverbgeneric}{}{\endgroup}
\newcommand{\colorverb}[1][red]{%
\leavevmode
\begingroup
\color{#1}%
\colorverbgeneric
}

\begin{document}

Normal \verb|\sanela{}| and red \colorverb|\sanela{}|
and also green \colorverb[green]|\sanela{}|

\end{document}


\documentclass[10pt,a4paper]{article}
\usepackage{xcolor}
\begin{document}
\textcolor{red}{\textbackslash sanela\{\}}
\end{document}