1

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?

5

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

Moreover, it doesn't matter whether

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

  • 1
    \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 May 20 '17 at 8:14
7

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}

enter image description here

  • 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
5

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}

enter image description here

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}

enter image description here

2

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.