2

This question already has an answer here:

enter image description hereHello I have the following code:

\documentclass[12pt]{article}
\usepackage[top=0.3in, bottom=1.5in, left=0.8in, right=0.8in]{geometry}

\usepackage[utf8]{inputenc}

\usepackage{setspace}
\setlength{\parindent}{0cm}

\usepackage{amsmath}
\usepackage{unicode-math}

\usepackage{listings}

\begin{document}

\begin{lstlisting}[frame=single,title={Blinking both LEDs},breaklines=true]

#include  <msp430g2553.h>

 unsigned int i = 0;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;

  P1DIR |= 0x01;
  P1DIR |= 0x40;

  for(;;)

  {
        //Both LEDs blink simultaneously

        P1OUT ^= 0x01;
        P1OUT ^= 0x40;

        //Or alternative P1OUT ^= 0x01|0x40

        for(i=0;i<30000;i++);

        //If I place P1OUT ^= 0x40; here then one LED blink and then the other
  };

}


\end{lstlisting}

\end{document}

In the last comment why doesn't the new line starts from the beggining (meaning under the //) but instead starts with a little left margin? And also why the first comment is far more left than the rest of the code in its block?

I have uploaded an image also with tabs on. There is something wrong. When I experiment with tabs odd things happen and the document doesn't appear as it should be. The second image is based on the code I wrote in that post and I haven't experiment on that one.

enter image description here

marked as duplicate by jub0bs, Jesse, Thorsten, Guido, Peter Jansson Mar 20 '14 at 12:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    You must have a tab, versus actual spaces which are being treated differently. You can try adjusting tabsize=<number>. Cutting and pasting your MWE works fine for me so the tabbing must be getting lost in the pasting here. – Peter Grill Mar 19 '14 at 19:09
  • 1
    @PeterGrill The site replaces all tabs by 4 spaces. – jub0bs Mar 19 '14 at 19:15
  • 1
    For debugging this you could add showtabs=true to your listing – Andrew Swann Mar 19 '14 at 21:02
  • There is something wrong...Even though I press tab in the first comment it doesn't appear... – Adam Mar 19 '14 at 21:06
  • 1
    @Adam Try to copy the code you posted in your question, paste it back into your editor/IDE, and compile. Do you get the same output? – jub0bs Mar 19 '14 at 21:21

Browse other questions tagged or ask your own question.