4

Below is how the code listing looks like now: enter image description here

I want to change line number 8 to blank, and line number 9 to 10. Reason is that they are actually two lines at ... (at line 8), how should I do that?

Below is the preamble

\usepackage{upquote}
\usepackage{listings}
\usepackage{pxfonts}
\makeatletter
\lstdefinelanguage{HTML5}{
    sensitive=true,
    keywords={%
    % JavaScript
    typeof, new, true, false, catch, function, return, null, catch, switch, var, if, in, while, do, else, case, break,
    % HTML
    html, title, meta, style, head, body, script, canvas,
    % CSS
    border:, transform:, -moz-transform:, transition-duration:, transition-property:,
    transition-timing-function:
    },
    % http://texblog.org/tag/otherkeywords/
    otherkeywords={<, >, \/},
    %ndkeywords={class, export, boolean, throw, implements, import, this},
    comment=[l]{//},
    % morecomment=[s][keywordstyle]{<}{>},
    morecomment=[s]{/*}{*/},
    morecomment=[s]{<!}{>},
    morestring=[b]',
    morestring=[b]",
    alsoletter={-},
    alsodigit={:}
}
\lstset{%
    % Basic design
    %backgroundcolor=\color{white},
    basicstyle={\ttfamily},
    frame=l,
    % Line numbers
    xleftmargin={0.75cm},
    numbers=left,
    stepnumber=1,
    firstnumber=1,
    numberfirstline=true,
    % Code design
    identifierstyle=\color{black},
    keywordstyle=\bfseries,
    ndkeywordstyle=\color{blue}\bfseries,
    stringstyle=\color{black}\ttfamily,
    commentstyle=\color{darkgray}\ttfamily,
    % Code
    language={HTML5},
    tabsize=2,
    showtabs=false,
    showspaces=false,
    showstringspaces=false,
    extendedchars=true,
    breaklines=true
}
\makeatother

Below is the code listing

\begin{lstlisting}
(function (__global) {
     var tmp0, tmp1,....;
     tmp13 = function (a) {
         var tmp14;
         tmp14 = a;
         return tmp14;
     };
     ...
     tmp16 = function (flag) {
        ...
        tmp20 = tmp21 == tmp22;
        if (tmp20) {
             tmp26 = 'x';
             tmp24 = __global[tmp26];
             tmp25 = 1;
             tmp23 = tmp24 * tmp25;
             return tmp23;
         }
     ...
     tmp7 = tmp16(tmp10, tmp11);
     ...
}(typeof global === 'undefined' ? this : global));
  \end{lstlisting}
  • I think you need to end the listing on line 8, put the ... on it's own, then start a new listing with [firstnumber=10]... – Thruston Apr 21 '16 at 14:09
  • Can you post a minimal-but-complete compilable example please? – Thruston Apr 21 '16 at 14:11
4

Well, perhaps would it be easier to expand line 8 to two lines 8 and 9, containing each of them ....

Package listings offers some options you can use to change line numbers. With options firstline and lastline you can define the showed lines in the printed listing, with firstnumber and lastnumber you can define the showed line numbers ...

MWE:

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.c}
(function (__global) {
     var tmp0, tmp1,....;
     tmp13 = function (a) {
         var tmp14;
         tmp14 = a;
         return tmp14;
     };
     ...
     tmp16 = function (flag) {
        ...
        tmp20 = tmp21 == tmp22;
        if (tmp20) {
             tmp26 = 'x';
             tmp24 = __global[tmp26];
             tmp25 = 1;
             tmp23 = tmp24 * tmp25;
             return tmp23;
         }
     ...
     tmp7 = tmp16(tmp10, tmp11);
     ...
}(typeof global === 'undefined' ? this : global));
\end{filecontents*}


\documentclass{scrartcl}

\usepackage{listings}
\usepackage{xcolor}


\lstdefinelanguage{HTML5}{
    sensitive=true,
    keywords={%
    % JavaScript
    typeof, new, true, false, catch, function, return, null, catch, switch, var, if, in, while, do, else, case, break,
    % HTML
    html, title, meta, style, head, body, script, canvas,
    % CSS
    border:, transform:, -moz-transform:, transition-duration:, transition-property:,
    transition-timing-function:
    },
    % http://texblog.org/tag/otherkeywords/
    otherkeywords={<, >, \/},
    %ndkeywords={class, export, boolean, throw, implements, import, this},
    comment=[l]{//},
    % morecomment=[s][keywordstyle]{<}{>},
    morecomment=[s]{/*}{*/},
    morecomment=[s]{<!}{>},
    morestring=[b]',
    morestring=[b]",
    alsoletter={-},
    alsodigit={:}
}
\lstset{%
    % Basic design
    %backgroundcolor=\color{white},
    basicstyle={\ttfamily},
    frame=l,
    % Line numbers
    xleftmargin={0.75cm},
    numbers=left,
    stepnumber=1,
    firstnumber=1,
    numberfirstline=true,
    % Code design
    identifierstyle=\color{black},
    keywordstyle=\bfseries,
    ndkeywordstyle=\color{blue}\bfseries,
    stringstyle=\color{black}\ttfamily,
    commentstyle=\color{darkgray}\ttfamily,
    % Code
    language={HTML5},
    tabsize=2,
    showtabs=false,
    showspaces=false,
    showstringspaces=false,
    extendedchars=true,
    breaklines=true
}


\begin{document}

Complete listing:
\lstinputlisting{\jobname.c}
\clearpage
The following lines lines shows how to~\dots
\lstinputlisting[firstline=1,lastline=7]{\jobname.c}
The following lines shows that \dots
\lstinputlisting[firstline=9,firstnumber=10]{\jobname.c}
\end{document}

and result:

page two of mwe

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.