The repository includes a great configuration for shown listings in LaTeX with the option to show only a specific range of line numbers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.6 KiB

4 years ago
  1. \usepackage{listings}
  2. \usepackage{courier}
  3. \usepackage{xcolor}
  4. \lstset{
  5. basicstyle=\footnotesize\ttfamily, % Default font
  6. numbers=left, % Location of line numbers
  7. numberstyle=\tiny, % Style of line numbers
  8. % stepnumber=2, % Margin between line numbers
  9. numbersep=5pt, % Margin between line numbers and text
  10. tabsize=2, % Size of tabs
  11. extendedchars=true,
  12. breaklines=true, % Lines will be wrapped
  13. keywordstyle=\color{red},
  14. frame=b,
  15. % keywordstyle=[1]\textbf,
  16. % keywordstyle=[2]\textbf,
  17. % keywordstyle=[3]\textbf,
  18. % keywordstyle=[4]\textbf, \sqrt{\sqrt{}}
  19. stringstyle=\color{white}\ttfamily, % Color of strings
  20. showspaces=false,
  21. showtabs=false,
  22. xleftmargin=17pt,
  23. framexleftmargin=17pt,
  24. framexrightmargin=5pt,
  25. framexbottommargin=4pt,
  26. % backgroundcolor=\color{lightgray},
  27. showstringspaces=false
  28. }
  29. \lstloadlanguages{ % Check documentation for further languages ...
  30. % [Visual]Basic,
  31. % Pascal,
  32. % C,
  33. % C++,
  34. % XML,
  35. % HTML,
  36. TeX
  37. }
  38. %Listings line numbers that match the linerange specification
  39. \makeatletter
  40. \lst@Key{matchrangestart}{f}{\lstKV@SetIf{#1}\lst@ifmatchrangestart}
  41. \def\lst@SkipToFirst{%
  42. \lst@ifmatchrangestart\c@lstnumber=\numexpr-1+\lst@firstline\fi
  43. \ifnum \lst@lineno<\lst@firstline
  44. \def\lst@next{\lst@BeginDropInput\lst@Pmode
  45. \lst@Let{13}\lst@MSkipToFirst
  46. \lst@Let{10}\lst@MSkipToFirst}%
  47. \expandafter\lst@next
  48. \else
  49. \expandafter\lst@BOLGobble
  50. \fi}
  51. \makeatother
  52. %space:
  53. \makeatletter
  54. \def\lst@MSkipToFirst{%
  55. \global\advance\lst@lineno\@ne
  56. \ifnum \lst@lineno=\lst@firstline
  57. \def\lst@next{\lst@LeaveMode \global\lst@newlines\z@
  58. \lst@OnceAtEOL \global\let\lst@OnceAtEOL\@empty
  59. \ifnum \c@lstnumber>0
  60. \\ ...
  61. \vspace{2 mm}
  62. \fi
  63. \lst@InitLstNumber % Added to work with modified \lsthk@PreInit.
  64. \lsthk@InitVarsBOL
  65. \c@lstnumber=\numexpr-1+\lst@lineno % this enforces the displayed line numbers to always be the input line numbers
  66. \lst@BOLGobble}%
  67. \expandafter\lst@next
  68. \fi}
  69. \makeatother
  70. % end
  71. % \DeclareCaptionFont{blue}{\color{blue}}
  72. % \captionsetup[lstlisting]{singlelinecheck=false, labelfont={blue}, textfont={blue}}
  73. \usepackage{caption}
  74. \DeclareCaptionFont{white}{\color{white}}
  75. \DeclareCaptionFormat{listing}{\colorbox[cmyk]{0.43, 0.35, 0.35,0.01}{\parbox{\textwidth}{\hspace{15pt}#1#2#3}}}
  76. \captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white, singlelinecheck=false, margin=0pt, font={bf,footnotesize}}
  77. %--------