TransWikia.com

How to highlight the word "base" as code with the listings package, e. g. lstinline{base}?

TeX - LaTeX Asked by stackprotector on June 16, 2021

When I use the word base inside lstinline{} to highlight it as inline code, I get an error, followed by warnings that are not there, if the error is not there:

Package xcolor Error: Undefined color `yac'. lstinline{base}
Usage of package `parskip' together(scrreprt) with a KOMA-Script class is not recommended.
float@addtolists detected!(scrreprt) Implementation of float@addtolist became(scrreprt) deprecated in KOMA-Script v3.01 2008/11/14 and(scrreprt) has been replaced by several more flexible(scrreprt) features of package `tocbasic`.
Overfull hbox (0.64577pt too wide) in paragraph
float@listhead detected!(scrreprt) Implementation of float@listhead became(scrreprt) deprecated in KOMA-Script v3.01 2008/11/14 and(scrreprt) has been replaced by several more flexible(scrreprt) features of package `tocbasic`.

I get this error when I use lstinline{base}, lstinline{<base>} or lstinline{a base}, but not with lstinline{Base} or lstinline{abase}. So I’m whondering, is base a reserved word? How can I highlight it with the listings package? Btw. base is an HTML element.

MCRE:

documentclass{scrreprt}

usepackage[dvipsnames]{xcolor}
usepackage{listings}

lstset{
    emph={square}, 
    emphstyle=color{blue}texttt,
    emph={[2]root,base},
    emphstyle={[2]color{yac}texttt}
}

begin{document}
    No error: lstinline{Base} 
    
    Error: lstinline{base}
end{document}

One Answer

It his what you are looking for?

documentclass{scrreprt}

usepackage[dvipsnames]{xcolor}
usepackage{listings}

lstset{
    emph={square}, 
    emphstyle=color{blue}texttt,
    emph={[2]root,base},
    emphstyle={[2]color{red}texttt},
}

begin{document}
    No error: lstinline{square} 
    
    Error: lstinline{base}
end{document}

Result:

enter image description here

Correct answer by scd on June 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP