5

I have this simple example of jsx code. How can I change the settings so that the indention of the code snippet gets right? Btw in case somebody has a decent link or example of listings which support syntax hightlighting for newer languages like golang please let me know!

\usepackage{listings}
\usepackage{xcolor} 
\definecolor{hellgelb}{rgb}{1,1,0.9}
\lstset{
  float=hbp,
  basicstyle=\ttfamily\color{black}\small\smaller,
  identifierstyle=\color{black},
  keywordstyle=\color{black},
  stringstyle=\color{black},
  commentstyle=\color{black},
  columns=false,
  tabsize=2,
  frame=single,
  extendedchars=true,
  showspaces=false,
  showstringspaces=false,
  numbers=left,
  numberstyle=\tiny,
  breaklines=true,
  backgroundcolor=\color{hellgelb},
  breakautoindent=false
}

enter image description here

thiloilg
  • 153

1 Answers1

2

Like it was suggested in the comments to the questions, there is a JSX lexer available that can help, if you use minted.

In order to use minted you need to install an additional package (usually called pygments or python-pygments).

To install the JSX lexer, you need to run as administrator:

pip install jsx-lexer

After that, the "jsx" language should be recognized by minted:

\documentclass{article}

\usepackage{minted}

\begin{document}

\begin{listing}[H]
  \centering
  \begin{minted}{jsx}
class HelloMessage extends React.Component {
  render() {
    return (
      <div>
        Hello {this.props.name}
      </div>
    );
  }
}

ReactDOM.render(
  <HelloMessage name="Taylor" />,
  document.getElementById('hello-example')
);
  \end{minted}

  \caption{Example of JSX code}
\end{listing}

\end{document}

Remember that you need to pass the -shell-escape flag to pdflatex in order to use minted.

This should be the result:

Example JSX code in Latex

William
  • 168