@ -0,0 +1,61 @@ | |||
The repository includes a great configuration for shown listings in LaTeX with the option to show only a specific range of line numbers. | |||
This is the code in LaTeX, do not forget to include the 'lst-config.tex' file in your folder: | |||
``` | |||
\documentclass{book} | |||
\input{lst-config} | |||
\begin{document} | |||
Here is a code example with showing only specific ranges: | |||
\lstinputlisting[label=ls:figure, caption=Using the configuration., linerange={1-5, 18-23, 39},matchrangestart=t]{code.txt} | |||
\end{document} | |||
``` | |||
This is the source called in LaTeX exmaple: | |||
``` | |||
\documentclass{article} | |||
\usepackage{blindtext} | |||
\usepackage{graphicx} | |||
\begin{document} | |||
\section{Introduction} | |||
\label{sec:intro} | |||
Now I'm using label command to create cross-references, e.g. in section \ref{sec:review} a literature review is presented, in section \ref{sec:method} the methodology is presented, and so on... | |||
\section{Literature review} | |||
\label{sec:review} | |||
\blindtext[1] | |||
\section{Methodology} | |||
\label{sec:method} | |||
In the Fig. \ref{fig:image-a} the methodology is presented. | |||
\begin{figure}[!h] | |||
\centering | |||
\includegraphics[width=3in]{example-image-a} | |||
\caption{The caption of the figure} | |||
\label{fig:image-a} | |||
\end{figure} | |||
\section{Preliminary data} | |||
\label{sec:pre} | |||
\blindtext[1] | |||
\section{Statement of limitations} | |||
\label{sec:limitations} | |||
\blindtext[1] | |||
\section{Conclusions} | |||
\label{sec:conclusions} | |||
\blindtext[1] | |||
\end{document} | |||
``` | |||
This is the output in the PDF file: | |||
![](example.png) | |||
@ -0,0 +1,39 @@ | |||
\documentclass{article} | |||
\usepackage{blindtext} | |||
\usepackage{graphicx} | |||
\begin{document} | |||
\section{Introduction} | |||
\label{sec:intro} | |||
Now I'm using label command to create cross-references, e.g. in section \ref{sec:review} a literature review is presented, in section \ref{sec:method} the methodology is presented, and so on... | |||
\section{Literature review} | |||
\label{sec:review} | |||
\blindtext[1] | |||
\section{Methodology} | |||
\label{sec:method} | |||
In the Fig. \ref{fig:image-a} the methodology is presented. | |||
\begin{figure}[!h] | |||
\centering | |||
\includegraphics[width=3in]{example-image-a} | |||
\caption{The caption of the figure} | |||
\label{fig:image-a} | |||
\end{figure} | |||
\section{Preliminary data} | |||
\label{sec:pre} | |||
\blindtext[1] | |||
\section{Statement of limitations} | |||
\label{sec:limitations} | |||
\blindtext[1] | |||
\section{Conclusions} | |||
\label{sec:conclusions} | |||
\blindtext[1] | |||
\end{document} |
@ -0,0 +1,79 @@ | |||
\usepackage{listings} | |||
\usepackage{courier} | |||
\usepackage{xcolor} | |||
\lstset{ | |||
basicstyle=\footnotesize\ttfamily, % Default font | |||
numbers=left, % Location of line numbers | |||
numberstyle=\tiny, % Style of line numbers | |||
% stepnumber=2, % Margin between line numbers | |||
numbersep=5pt, % Margin between line numbers and text | |||
tabsize=2, % Size of tabs | |||
extendedchars=true, | |||
breaklines=true, % Lines will be wrapped | |||
keywordstyle=\color{red}, | |||
frame=b, | |||
% keywordstyle=[1]\textbf, | |||
% keywordstyle=[2]\textbf, | |||
% keywordstyle=[3]\textbf, | |||
% keywordstyle=[4]\textbf, \sqrt{\sqrt{}} | |||
stringstyle=\color{white}\ttfamily, % Color of strings | |||
showspaces=false, | |||
showtabs=false, | |||
xleftmargin=17pt, | |||
framexleftmargin=17pt, | |||
framexrightmargin=5pt, | |||
framexbottommargin=4pt, | |||
% backgroundcolor=\color{lightgray}, | |||
showstringspaces=false | |||
} | |||
\lstloadlanguages{ % Check documentation for further languages ... | |||
% [Visual]Basic, | |||
% Pascal, | |||
% C, | |||
% C++, | |||
% XML, | |||
% HTML, | |||
TeX | |||
} | |||
%Listings line numbers that match the linerange specification | |||
\makeatletter | |||
\lst@Key{matchrangestart}{f}{\lstKV@SetIf{#1}\lst@ifmatchrangestart} | |||
\def\lst@SkipToFirst{% | |||
\lst@ifmatchrangestart\c@lstnumber=\numexpr-1+\lst@firstline\fi | |||
\ifnum \lst@lineno<\lst@firstline | |||
\def\lst@next{\lst@BeginDropInput\lst@Pmode | |||
\lst@Let{13}\lst@MSkipToFirst | |||
\lst@Let{10}\lst@MSkipToFirst}% | |||
\expandafter\lst@next | |||
\else | |||
\expandafter\lst@BOLGobble | |||
\fi} | |||
\makeatother | |||
%space: | |||
\makeatletter | |||
\def\lst@MSkipToFirst{% | |||
\global\advance\lst@lineno\@ne | |||
\ifnum \lst@lineno=\lst@firstline | |||
\def\lst@next{\lst@LeaveMode \global\lst@newlines\z@ | |||
\lst@OnceAtEOL \global\let\lst@OnceAtEOL\@empty | |||
\ifnum \c@lstnumber>0 | |||
\\ ... | |||
\vspace{2 mm} | |||
\fi | |||
\lst@InitLstNumber % Added to work with modified \lsthk@PreInit. | |||
\lsthk@InitVarsBOL | |||
\c@lstnumber=\numexpr-1+\lst@lineno % this enforces the displayed line numbers to always be the input line numbers | |||
\lst@BOLGobble}% | |||
\expandafter\lst@next | |||
\fi} | |||
\makeatother | |||
% end | |||
% \DeclareCaptionFont{blue}{\color{blue}} | |||
% \captionsetup[lstlisting]{singlelinecheck=false, labelfont={blue}, textfont={blue}} | |||
\usepackage{caption} | |||
\DeclareCaptionFont{white}{\color{white}} | |||
\DeclareCaptionFormat{listing}{\colorbox[cmyk]{0.43, 0.35, 0.35,0.01}{\parbox{\textwidth}{\hspace{15pt}#1#2#3}}} | |||
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}} | |||
%-------- |
@ -0,0 +1,7 @@ | |||
\documentclass{book} | |||
\input{lst-config} | |||
\begin{document} | |||
Here is a code example with showing only specific ranges: | |||
\lstinputlisting[label=ls:figure, caption=Using the configuration., linerange={1-5, 18-23, 39},matchrangestart=t]{code.txt} | |||
\end{document} |