0

I am writing a template for my lecture notes and I wanted to have a different color as my highlighted text.

\usepackage{soul}
\usepackage[dvipsnames]{xcolor}    
\definecolor{delectricblue}{RGB}{93, 117, 131}
\newcommand{\hldb}[1]{\sethlcolor{delectricblue!30}\hl{#1}}

But the code doesn't look correctly as if there's a bug or sth. if I don't use the !30 part. the code highlights everything, otherwise it only highlights white spaces. What should I do?

enter image description here enter image description here

Kid A
  • 3
  • 2

1 Answers1

1

Welcome to TeX.SX! You can only use pure color names with the macro \sethlcolor, but not the ! notation known from the xcolor package.

However, you can use the \colorlet macro to define a lighter version of your previously defined color and then use this color for highlighting.

Note that you should also enclose the definition of your macro by another pair of curly braces in order to set the highlighting color only for the relevant \hldb command. Otherwise the changed color will also be used in all following \hl commands.

\documentclass{article}
\usepackage{soul}
\usepackage[dvipsnames]{xcolor}

\definecolor{delectricblue}{RGB}{93, 117, 131} \colorlet{lightdelectricblue}{delectricblue!30}

\newcommand{\hldb}[1]{% {% \sethlcolor{lightdelectricblue}% \hl{#1}% }% }

\begin{document}

\hl{Foo}

\hldb{Some random text.}

\hl{Bar}

\end{document}

enter image description here