## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ How to split long C/C++ code line on two lines without inserting new line number?

Information and discussion about graphics, figures & tables in LaTeX documents.
DryRun
Posts: 8
Joined: Sun May 19, 2019 7:08 pm

### How to split long C/C++ code line on two lines without inserting new line number?

I am using the following snippet to insert C/C++ code into my LaTeX document but the problem is that the code on one line is too long and it goes over the right side of the document page. How to split this on two lines? I tried to simply move part of the line to another line but then it also introduces a new line number on the side. I would like to keep the same line number but i'm not sure how to do that.

\begin{listing}[H]    \begin{minted}    [    frame=lines,    framesep=2mm,    baselinestretch=1.2,    linenos    ]    {cpp}    void angle_PD()    {      anglePWM = kp_angle * (angleSetpoint - angle) + kd_angle * (angularSpeed0 - angular_speed);    }    \end{minted}    \caption{PD controller}    %\label{code:3}    \end{listing}

I tried to split the single long line into two lines but the problem as shown in the screenshot below is that the next line now has a different line number (4) and i would like to keep them both on a single line (3).
pdcontroller.png (13.18 KiB) Viewed 103 times

kaiserkarl13
Posts: 636
Joined: Tue Mar 25, 2008 5:02 pm
You want "breaklines=true" inside lstset.

DryRun
Posts: 8
Joined: Sun May 19, 2019 7:08 pm
kaiserkarl13 wrote:You want "breaklines=true" inside lstset.

I'm not sure where to find lstset. I looked inside macros.tex and preamble.tex but i couldn't find it.

baselinestretch=1.2,linenosbreaklines=true

But it gives an error.

Ijon Tichy
Posts: 120
Joined: Mon Dec 24, 2018 10:12 am
The comma after option linenos is missing. For more information about options like breaklines see section “5.3 Available options” in the manual of package minted.

BTW: \lstset is a listings command. For minted you can setup the options either with \setminted or as optional argument of the minted environment. See the manual for more information.

BTW: If you have a problem, instead of a screenshot and a code snippet a minimal working example that makes it possible to reproduce this problem and to test a suggestions would be useful. And error messages should be quoted. Something like “gives an error” is far away from being enough information. It is more like, “my dishwasher does not wash”. Not enough information, neither to describe the symptom nor for a proper remote diagnostic.