Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This is a combination of hacks, and only of interest for those who want hacks down to the detail.

It is actually a two part question. I was going through some listings setups and hacks: Firstly Listings line numbers that match the linerange specification, secondly Styling a lstlisting caption using caption package and Visual separation when using linerange in listings. Which can provide me with: https://dl.dropboxusercontent.com/u/271521/Stackoverflow%20Question/StackTex/Tex.pdf

With the first hack there seem to be a problem that it does not increment when empty lines is supplied. It would be cool if someone could figure it out. Another way have solved this was to make two different listing of the same file but since I want the same caption and reference to the listing this represents a hard hacking.

Furthermore I wanted to get some indication of the linerange, like the third hack, some \vdots or something. Instead of making two distinct listings. Any idears?

% The memoir documentclass is setup to danish on a twosided a4 paper, with font-size 11pt.
\documentclass[english,a4paper,twoside,article,11pt]{memoir}

% Input and output character encoding: http://tex.stackexchange.com/questions/44694/fontenc-vs-inputenc
\usepackage{iftex}
\ifPDFTeX
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\else
\ifXeTeX
\usepackage{xltxtra}
\else 
\usepackage{luatextra}
\fi
\defaultfontfeatures{Ligatures=TeX}
\fi

% Use fixme to note things that shall be changed:
\usepackage[draft,english]{fixme}    % Skriv rette noter i margin

% Subcaptions in figure:
\usepackage[subrefformat=parens]{subcaption}

% Listing package: ftp://ftp.tex.ac.uk/tex-archive/macros/latex/contrib/listings/listings.pdf
\usepackage{listings}                % Listingspakke til at importere kode

% References (no abbrevation of words, ex. fig. instead of figure):
\usepackage[noabbrev]{cleveref}


% Ruled caption header: http://tex.stackexchange.com/questions/117531/styling-a-lstlisting-caption-using-caption-package
\DeclareCaptionFormat{listing}{\rule{\dimexpr\columnwidth}{1pt}\par\vskip1pt#1#2#3}
\captionsetup[lstlisting]{format=listing,singlelinecheck=false, margin=0pt, font={sf},labelsep=space,labelfont=bf}

% Linerange skips linenumbers hack: http://tex.stackexchange.com/questions/110187/listings-line-numbers-that-match-the-linerange-specification
\makeatletter
\lst@Key{numbers}{none}{%
  \let\lst@PlaceNumber\@empty
  \lstKV@SwitchCases{#1}%
  {none&\\%
    left&\def\lst@PlaceNumber{\llap{\normalfont
        \lst@numberstyle{\thelstnumber}\kern\lst@numbersep}}\\%
    leftliteral&\def\lst@PlaceNumber{\llap{\normalfont
        \lst@numberstyle{\the\lst@lineno}\kern\lst@numbersep}}\\%
    right&\def\lst@PlaceNumber{\rlap{\normalfont
        \kern\linewidth \kern\lst@numbersep
        \lst@numberstyle{\thelstnumber}}}%
  }{\PackageError{Listings}{Numbers #1 unknown}\@ehc}}
\makeatother

\lstset{
  language=C++,                 % Programming language
  escapeinside={//@}{@},        % Escape inside code to make e.g. labels possible with //@\label{lst:test}@
  basicstyle=\footnotesize,     % The size of the fonts that are used for the code
  numbers=left,                 % Position of linenumbers
  numberstyle=\footnotesize,    % Size of linenumbers
  stepnumber=1,                 % Stepsize until next 
  numbersep=5pt,                % Distance between linenumber and code
  showspaces=false,             % show spaces adding particular underscores
  showstringspaces=false,       % underline spaces within strings
  showtabs=false,               % show tabs within strings adding particular underscores
  frame=single,                 % adds a frame around the code
  tabsize=2,                    % sets default tabsize to 2 spaces
  captionpos=t,                 % sets the caption-position to bottom
  breaklines=true,              % sets automatic line breaking
  breakatwhitespace=false,      % sets if automatic breaks should only happen at whitespace
  title=\lstname,               % show the filename of files included with \lstinputlisting;
  firstnumber=last,             % Linienummer skal være det samme som i original fil
  caption=\space,               % Default space caption i no caption is supplied
  % also try caption instead of title
  morekeywords={*,...},         % if you want to add more keywords to the set
  frame = TB,                   % Double frame on top and bottom of code
}


\usepackage{filecontents}

\begin{filecontents*}{mycode.txt}
  > AD9914.exe -help //@\label{lst:test}@
  -backup <filepath> writes a file at destination <filepath> with the values of the registers in integers, these can be reprogrammed to the DDS by using -setup <filepath>.

  -backuphex <filepath> writes a file at destination <filepath> with the values of the DDS registers in hexidecimals, this cannot be reprogrammed to the DDS using -setup.

  -setup <filepath> takes the file at destination <filepath> and programmes this to the DDS-chip. These has to be in integers, see an example by generating an file using the command: -backup <filepath>

  -uut is a unit-under-test mode, where everything interpreted from the file, which should be programmed to the DDS is instead printed to the console (can be used with the DDS unconnected).


  Besides this the 'labSetup.txt' file has the initial setup of the DDS-chip which is programmed every time.

\end{filecontents*}

\begin{document}

\lstinputlisting[language={},linerange={1-2,4-6}, numbers=leftliteral, label={lst}]{mycode.txt}

Cool internal line refernce here: \cref{lst:test} in \cref{lst}.

\end{document}
share|improve this question

closed as unclear what you're asking by Jubobs, Martin Schröder, Jesse, Peter Jansson, Stefan Kottwitz Feb 27 at 13:53

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
I don't understand what you want to achieve. Your post actually doesn't ask any question. I suggest you edit your question to make it more self-contained instead of just pointing to other questions. Also, your code seems far from minimal. If you made it more concise, you'd stand a better chance of getting answers. –  Jubobs Feb 27 at 12:20

Browse other questions tagged or ask your own question.