1

I'm trying to create a tcolorbox listing for a command that includes the percent sign. However, somehow that percent sign always switches the font to italics, and I have no idea why.

Minimum example:

\documentclass[a4paper,11pt,oneside,final,extrafontsizes]{memoir}
\usepackage[most]{tcolorbox}
\newtcblisting{commandbox}{breakable, enhanced,%
  left=5pt, top=3pt, bottom=2pt,
  before skip=6pt, after skip=11pt,
  arc=0mm, grow to left by=0.5cm, grow to right by=2cm,
  borderline={0.5pt}{0pt}{black,dashed},
  listing only, colback=black!10!white, colframe=black!10!white,
  listing options={style=tcblatex,inputencoding=utf8,basicstyle=\ttfamily\small}}
\begin{document}
Testbox:
\begin{commandbox}
foo bar baz --option foo --option bar% --option baz
\end{commandbox}
\end{document}  

Running this through xelatex or xeluatex results in the following output: italics

note the italics text starting from the percent sign on. If I remove the percent sign, this does not happen. If I escape the percent sign with a \, I get the \ also in the output (no escaping in verbatim environments).

Does anyone have a workaround for this behavior?

Note that it also happens with a standard \begin{tcblisting}{} block...

  • 1
    Listings use latex syntax by default (and the percent sign starts comment, hence italic). You could add language=sh to the listings option list to switch language. – Sergei Golovan Jul 23 '18 at 13:30
  • ah I see, this is what I was missing. However, changing it to language=sh makes other words appear bold instead of normal (like hash). Changing it to language={} worked though – Michael D. Jul 23 '18 at 14:04
1

The language can be set with the option language=..., and setting the option to {} will clear all highlights.

So, adding language={} to the listing options={...} line fixes the issue for me

Thanks @sergei for the hint!

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.