0

I am using the solution from How can I write line numbers inside boxed code. Its code with slightly changes:

\begin{filecontents*}{\jobname.sol}
    function hello_world(uint a, uint b, uint c, uint d, uint e, uint f) public returns bool {
            uint256 amount = 100
            return amount * 100
            return true;
        }
\end{filecontents*}

\documentclass[10pt,journal,compsoc]{IEEEtran}

\usepackage[english]{babel} \usepackage{pgfplots} \usepackage{booktabs} \usepackage{listings} \usepackage[many]{tcolorbox} \tcbuselibrary{listings}

\ifCLASSOPTIONcompsoc \usepackage[nocompress]{cite} \else \usepackage{cite} \fi

\pgfplotsset{compat=1.18} \hyphenation{op-tical net-works semi-conduc-tor}

\newtcbinputlisting{\inputlisting}[2][]{% listing file={#2}, top=0pt, left=16pt, bottom=0pt, right=8pt, colback=verylightgray, colframe=black, listing only, breakable, sharp corners, boxrule=0.2pt, listing options={#1}, }

\lstdefinelanguage{Solidity}{ keywords=[1]{% generic keywords including crypto operations anonymous, assembly, assert, balance, break, call, callcode, case, catch, class, constant, continue, constructor, contract, debugger, default, delegatecall, delete, do, else, emit, event, experimental, export, external, false, finally, for, function, gas, if, implements, import, in, indexed, instanceof, interface, internal, is, length, library, log0, log1, log2, log3, log4, memory, modifier, new, payable, pragma, private, protected, public, pure, push, require, return, returns, revert, selfdestruct, send, solidity, storage, struct, suicide, super, switch, then, this, throw, transfer, true, try, typeof, using, value, view, while, with, addmod, ecrecover, keccak256, mulmod, ripemd160, sha256, sha3 }, keywordstyle=[1]\color{blue}\bfseries, keywords=[2]{% types; money and time units address, bool, byte, bytes, bytes1, bytes2, bytes3, bytes4, bytes5, bytes6, bytes7, bytes8, bytes9, bytes10, bytes11, bytes12, bytes13, bytes14, bytes15, bytes16, bytes17, bytes18, bytes19, bytes20, bytes21, bytes22, bytes23, bytes24, bytes25, bytes26, bytes27, bytes28, bytes29, bytes30, bytes31, bytes32, enum, int, int8, int16, int24, int32, int40, int48, int56, int64, int72, int80, int88, int96, int104, int112, int120, int128, int136, int144, int152, int160, int168, int176, int184, int192, int200, int208, int216, int224, int232, int240, int248, int256, mapping, string, uint, uint8, uint16, uint24, uint32, uint40, uint48, uint56, uint64, uint72, uint80, uint88, uint96, uint104, uint112, uint120, uint128, uint136, uint144, uint152, uint160, uint168, uint176, uint184, uint192, uint200, uint208, uint216, uint224, uint232, uint240, uint248, uint256, var, void, ether, finney, szabo, wei, days, hours, minutes, seconds, weeks, years}, keywordstyle=[2]\color{teal}\bfseries, keywords=[3]{% environment variables block, blockhash, coinbase, difficulty, gaslimit, number, timestamp, msg, data, gas, sender, sig, value, now, tx, gasprice, origin }, keywordstyle=[3]\color{violet}\bfseries, identifierstyle=\color{black}, sensitive=false, comment=[l]{//}, morecomment=[s]{/}{/}, commentstyle=\color{gray}\ttfamily, stringstyle=\color{red}\ttfamily, morestring=[b]', morestring=[b]" }

\lstset{ language=Solidity, extendedchars=true, basicstyle=\footnotesize\ttfamily, showstringspaces=false, showspaces=false, numbers=none, numberstyle=\footnotesize, numbersep=9pt, tabsize=1, breaklines=true, showtabs=false, captionpos=b }

\begin{document}

\section{Introduction}

\inputlisting{\jobname.sol}

\end{document}

enter image description here

Seems like broken lines have four spaces.

Is it possible to have the linebreak tab size as two space? Please note that I have changed tabsize=1 to smaller values but it did not have any effect.

As an example, see where there are two spaces before uint d and bool {:

function hello_world(uint a, uint b, uint c, 
  uint d, uint e, uint f) public returns bool {
  uint256 amount = 100
  return amount * 100
  return true;
}

Related:

Ingmar
  • 6,690
  • 5
  • 26
  • 47
alper
  • 1,389

1 Answers1

1

Use breakindent.

\documentclass[11pt]{article}

\usepackage{amsmath,amssymb} \usepackage{listings} \usepackage{lstautogobble}

\lstdefinestyle{mystyle} { basicstyle=\ttfamily, frame=single, breaklines, basewidth=0.6em, breakindent=1.2em, breakatwhitespace }

\begin{document}

\begin{lstlisting}[style=mystyle,autogobble] function hello_world(uint a, uint b, uint c, uint d, uint e, uint f) public returns bool { uint256 amount = 100 return amount * 100 return true; } \end{lstlisting}

\begin{lstlisting}[style=mystyle,autogobble,postbreak=\hbox{$\hookrightarrow$\space}] function hello_world(uint a, uint b, uint c, uint d, uint e, uint f) public returns bool { uint256 amount = 100 return amount * 100 return true; } \end{lstlisting}

\end{document}

I have set basewidth (which is the width of a character) explicitly so that breakindent can be set exactly to 2 characters wide. In case you wish to use, the second version prints a hook to distinguish a line break.

Output:

enter image description here

Zxcvasdf
  • 1,735
  • I can apply [language=Solidity] to appyly language colors right? – alper Jun 22 '22 at 09:52
  • Yes, definitely! I have just given the bare settings required to achieve the two space indentation you asked for. – Zxcvasdf Jun 22 '22 at 09:54
  • Thanks! it was exactly what I was looking for. In case for 4 space I just have to change 1.2em to 2.4em right? – alper Jun 22 '22 at 10:04
  • Yes, that is correct! – Zxcvasdf Jun 22 '22 at 11:08
  • Sorry for the late comment, can the width size to breakline increased? – alper Jul 03 '22 at 20:37
  • It can be done. I had set it to 1.2em since the question asks for two-space indent. – Zxcvasdf Jul 04 '22 at 04:04
  • I had changed 1.2em to a larger value like 1.5em or more but it did not helped to increase the width per line like I want d, on the first line since there is more space at the end of the first line – alper Jul 04 '22 at 08:15
  • @alper, I couldn't understand what you said. Perhaps an image of your desired output would help. – Zxcvasdf Jul 04 '22 at 10:26