0

I've built a command that combines minted with tcolorbox, but I'm having issues with SASS syntax. Here's a minimum reproducable example:

\documentclass[a4paper,headinclude=on,footinclude=on,12pt,oneside]{scrbook}
\usepackage[dvipsnames]{xcolor}
\usepackage{color}
\usepackage{fontawesome}
\usepackage{minted}
\usepackage[most,minted]{tcolorbox}
\tcbuselibrary{listings,minted,breakable}

% custom colors
\definecolor{codebackground}{HTML}{F2F2F2}

% for fancy spacing of code snippet title bars 
\usepackage{tabularx}
\newcolumntype{\CeX}{>{\centering\let\newline\\\arraybackslash}X}%
\newcommand{\TwoSymbolsAndText}[3]{%
  \begin{tabularx}{\textwidth}{c\CeX c}%
    #1 & #2 & #3
  \end{tabularx}%
}

\AtBeginDocument{
\newtcblisting[blend into=listings]{codeInput}[3]{
  listing engine=minted,
  minted language=#1,
  minted options={breaklines,breaksymbolleft=,breaksymbolright=,fontsize=\footnotesize},
  listing only,
  listing remove caption=true,
  size=title,
  arc=1.5mm,
  breakable,
  enhanced jigsaw,
  colframe=Black,
  coltitle=White,
  boxrule=0.5mm,
  colback=codebackground,
  coltext=Black,
  title=\TwoSymbolsAndText{\faCode}{%
    \footnotesize{\texttt{#2}}
  }{\faCode},
  list text=#3
}
}

\begin{document}

\begin{codeInput}{sass}{\_toasts.scss}{A small SASS file.}
.Toastify__progress-bar--default {
  background: \$primary !important;
}
\end{codeInput}


\end{document}

Produces the following PDF output:

Strange character formatting

Note that the brackets, dollar sign, and semicolon point are all marked with a red border around them - however this is correct SASS syntax. (Apart from the slash in front of the dollar sign which I needed for LaTeX not to complain - I suppose a sub question is how I can escape a $ within the source code here as well!)

How can I fix this syntax highlighting issue?

1
  • This is the default as you can see on pygment's website. pygments.org/demo
    – DG'
    Commented May 4, 2023 at 11:43

1 Answer 1

1

You can redefine the \PYG@tok@err:

\AddToHook{cmd/minted@addcachefile/after}{%
\@namedef{PYG@tok@err}{\def\PYG@bc##1{##1}}}

In your code:

\documentclass[a4paper,headinclude=on,footinclude=on,12pt,oneside]{scrbook}
\usepackage[dvipsnames]{xcolor}
\usepackage{color}
\usepackage{fontawesome}
\usepackage{minted}
\usepackage[most,minted]{tcolorbox}
\tcbuselibrary{listings,minted,breakable}

% custom colors
\definecolor{codebackground}{HTML}{F2F2F2}

% for fancy spacing of code snippet title bars 
\usepackage{tabularx}
\newcolumntype{\CeX}{>{\centering\let\newline\\\arraybackslash}X}%
\newcommand{\TwoSymbolsAndText}[3]{%
  \begin{tabularx}{\textwidth}{c\CeX c}%
    #1 & #2 & #3
  \end{tabularx}%
}

\AtBeginDocument{
\newtcblisting[blend into=listings]{codeInput}[3]{
  listing engine=minted,
  minted language=#1,
  minted options={breaklines,breaksymbolleft=,breaksymbolright=,fontsize=\footnotesize},
  listing only,
  listing remove caption=true,
  size=title,
  arc=1.5mm,
  breakable,
  enhanced jigsaw,
  colframe=Black,
  coltitle=White,
  boxrule=0.5mm,
  colback=codebackground,
  coltext=Black,
  title=\TwoSymbolsAndText{\faCode}{%
    \footnotesize{\texttt{#2}}
  }{\faCode},
  list text=#3
}
}

\makeatletter
\AddToHook{cmd/minted@addcachefile/after}{%
\@namedef{PYG@tok@err}{\def\PYG@bc##1{##1}}}
\makeatother

\begin{document}

\begin{codeInput}{sass}{\_toasts.scss}{A small SASS file.}
.Toastify__progress-bar--default {
  background: $primary !important;
}
\end{codeInput}

\end{document}

enter image description here

Note: You need $ instead of \$.

2
  • Hey fantastic! Thanks a lot! Do you know if I might encounter this highlighting issue with other languages? I noticed it for sass, but I wonder if there might be more... Commented May 4, 2023 at 13:35
  • @fullStackChris Unfortunately I don't know, I'm not Pygments expert. Commented May 4, 2023 at 14:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .