TransWikia.com

Using listings package, can I display line numberings in paretheses?

TeX - LaTeX Asked by mac501 on July 19, 2021

I want to achieve the following effect for line numbers using lstlisting:

(1)  public constructor(value?: number) {
(2)    if (value > 0xff) {
(3)      throw new Error('Value should not be greater than 0xff');
(4)    }
(5)    this._intValue = value ? value & 0xff : 0;
(6)  }

Is it even possible?

One Answer

Welcome to TeX.SX! This is possible by redefining the thelstnumber macro:

documentclass{article}
usepackage{listings}

renewcommand*thelstnumber{(thevalue{lstnumber})} % <- add this to preamble

lstset{numbers=left, numberstyle=footnotesize, numbersep=5pt}

begin{document}

begin{lstlisting}
public constructor(value?: number) {
 if (value > 0xff) {
  throw new Error('Value should not be greater than 0xff');
 }
 this._intValue = value ? value & 0xff : 0;
}
end{lstlisting}

end{document}

enter image description here

Correct answer by Jasper Habicht on July 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP