despite my precarious knowledge of the environment, I have been able to style listings to my taste (which is nothing fancy) for modern JavaScript.
The show-stopper is that I need to syntax-highlight React.js, which isn't properly rendered via listing. I like very much how I've been able to zebra/alternate the lines' background color, line numbers, fonts, etc. but the jsx language isn't recognized. I've searched extensively for ways to make it work, and apparently the recommendation is to switch to the Minted package altogether, and install a separate third-party jsx lexer.
It works, but I haven't found a way to alternate the background color of each line in the zebra fashion.
Any suggestion on how to turn the Minted output to something closer to the listing example (both in terms of line highlighting and, if possible, to line numbers, etc) would be greatly appreciated.
MWE (requires --shell-escape and jsx-lexer):
\documentclass[]{scrbook}
\usepackage{xcolor}
\usepackage[]{cleveref}
\usepackage{listings}
\definecolor{listing-background}{HTML}{FFFFFF}
\definecolor{listing-background-alternate}{HTML}{F8F8F8}
\definecolor{listing-rule}{HTML}{B3B2B3}
\definecolor{listing-numbers}{HTML}{B3B2B3}
\definecolor{listing-text-color}{HTML}{000000}
\definecolor{listing-keyword}{HTML}{007F00}
\definecolor{listing-keyword-2}{HTML}{1284CA}
\definecolor{listing-keyword-3}{HTML}{9137CB}
\definecolor{listing-keyword-4}{HTML}{407F7F}
\definecolor{listing-identifier}{HTML}{000000}
\definecolor{listing-identifier}{HTML}{435489}
\definecolor{listing-string}{HTML}{BA2121}
\definecolor{listing-comment}{HTML}{8E8E8E}
\lstdefinelanguage{es6}{
morekeywords=[1]{break, continue, delete, else, for, function, if, in,
new, return, this, typeof, var, void, while, with, await, async, case, catch, class, const, default, do, enum, export, extends, finally, from, implements, import, instanceof, let, static, super, switch, throw, try },
morekeywords=[2]{false, null, true, boolean, number, undefined,
Array, Boolean, Date, Math, Number, String, Object },
morekeywords=[3]{eval, parseInt, parseFloat, escape, unescape },
otherkeywords = {+,-},
sensitive,
morecomment=[s]{/}{/},
morecomment=[l]//,
morecomment=[s]{/*}{/},
morestring=[b]',
morestring=[b]"
}[keywords, comments, strings]
\makeatletter
\let\old@lstKV@SwitchCases\lstKV@SwitchCases
\def\lstKV@SwitchCases#1#2#3{}
\makeatother
\usepackage{lstlinebgrd}
\makeatletter
\let\lstKV@SwitchCases\old@lstKV@SwitchCases
\lst@Key{numbers}{none}{%
\def\lst@PlaceNumber{\lst@linebgrd}%
\lstKV@SwitchCases{#1}%
{none:\%
left:\def\lst@PlaceNumber{\llap{\normalfont
\lst@numberstyle{\thelstnumber}\kern\lst@numbersep}\lst@linebgrd}\%
right:\def\lst@PlaceNumber{\rlap{\normalfont
\kern\linewidth \kern\lst@numbersep
\lst@numberstyle{\thelstnumber}}\lst@linebgrd}%
}{\PackageError{Listings}{Numbers #1 unknown}@ehc}}
\makeatother
\lstdefinestyle{fancylisting}{
basicstyle=\ttfamily\linespread{1.0}\color{listing-text-color}\small,
numbers = left,
xleftmargin = 2.7em,
framexleftmargin = 2.5em,
backgroundcolor = \color{listing-background},
breaklines = true,
frame = single,
framesep = 0.19em,
rulecolor = \color{listing-rule},
frameround = ffff,
tabsize = 4,
numberstyle = \color{listing-numbers}\footnotesize\ttfamily{},
linebackgroundcolor={\ifodd\value{lstnumber}\color{listing-background-alternate}\fi},
aboveskip = 1.2em,
belowskip = 1em,
abovecaptionskip = 0em,
belowcaptionskip = 1.0em,
keywordstyle = {\color{listing-keyword}\bfseries},
keywordstyle = {[2]\color{listing-keyword-2}},
keywordstyle = {[3]\color{listing-keyword-3}\bfseries\itshape},
keywordstyle = {[4]\color{listing-keyword-4}},
sensitive = true,
identifierstyle = \color{listing-identifier},
commentstyle = \color{listing-comment},
stringstyle = \color{listing-string},
showstringspaces = false,
escapeinside = {/@}{@/} }
\lstset{style=fancylisting}
\lstnewenvironment{es6}[1][]
{\lstset{
language=es6,
morekeywords=[4]{+,<,>,-,=},
#1
}}
{}
\lstnewenvironment{bash}[1][]
{\lstset{
language=bash,
linebackgroundcolor=\color{white},
backgroundcolor=\color{white},
numbers=none,
frame=l,
framerule=0.5pt,
rulecolor = \color{listing-rule},
#1
}}
{}
\crefname{lstlisting}{listing}{listings}
\Crefname{lstlisting}{Listing}{Listings}
\crefname{lstinputlisting}{listing}{listings}
\Crefname{lstinputlisting}{Listing}{Listings}
\usepackage{fancyvrb}
\usepackage[cache=false,outputdir=.texpadtmp]{minted}
\begin{document}
Minted (syntax recognized, ugly formatting)
\begin{minted}{jsx}
const BlogTitle = ({ children }) => (
<h3>{children}</h3>
);
// class component
class BlogPost extends React.Component {
renderTitle(title) {
return <BlogTitle>{title}</BlogTitle>
};
render() {
return (
<div className="blog-body">
{this.renderTitle(this.props.title)}
<p>{this.props.body}</p>
</div>
);
}
}
\end{minted}
Listing (syntax not recognized, desired formatting):
\begin{es6}
const BlogTitle = ({ children }) => (
<h3>{children}</h3>
);
// class component
class BlogPost extends React.Component {
renderTitle(title) {
return <BlogTitle>{title}</BlogTitle>
};
render() {
return (
<div className="blog-body">
{this.renderTitle(this.props.title)}
<p>{this.props.body}</p>
</div>
);
}
}
\end{es6}
\end{document}
Thank you!


