2

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

  • 2
    Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – DG' Oct 14 '19 at 20:10
  • 1
    There seems to be a JSX lexer available for Pygments, so you could use the minted package instead of listings – siracusa Oct 15 '19 at 0:42
1

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

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.