5
votes
1answer
68 views

Adapt labelling facilities of listings package

I compiled a catalogue from past exercises for a lecture (running to several hundred pages), which makes consistent labelling a bit of an issue. My solution is to use labels of the form ...
8
votes
1answer
111 views

How do I refer to a line of code from a C file?

I have a source code listing in my appendix. I have added it like this: \lstinputlisting[language=C]{Appendix/tcas/tcas.c} I want to refer a line, e.g., line 72, from this file. How do I do this ? ...
4
votes
1answer
93 views

Lstlistings reference to line number

How can I place a 'label' marker inside a lstlisting environment (external file imported and formatted via the listinputlisting command) so that I can cross-reference a particular line number? In ...
2
votes
1answer
178 views

Cross reference line number within program listing in lyx

I'm trying to cross reference program code line numbers within a program listing using lyx. From what I can tell, both labels and ERT are disabled within the program listing, but I'm not sure why. I ...
5
votes
2answers
219 views

mdframed label multiply defined (with listings and paracol)

I use three packages (in a latex "book" document) to display source files (not only tex and sometimes loaded from external files) and their outputs (sometimes loaded from external files) side by side. ...
6
votes
3answers
198 views

Referring to a whole line of code instead of a line number

This code fits quite nicely my needs: \documentclass{article} \usepackage{xcolor} \usepackage{listings} \usepackage{lipsum} \usepackage{hyperref} \usepackage{lstlinebgrd} ...
5
votes
1answer
131 views

Reference to a listing returns wrong number

I'm using the following code to create a listing with sourcecode: \begin{lstlisting}[caption={caption_text}\label{lst:a_label},language=Java] // Code... \end{lstlisting} Unfortunately, a ...
1
vote
1answer
140 views

Minted cross reference line

I used to use listings a lot but minted+pygmentize has outstanding output. However, there are a few features from listings that are hard to find in minted, like having the line numbers on the right. ...
5
votes
1answer
570 views

label within lstlisting prefix gives strange output on \ref

I have all kinds of labeltypes for my own convenience defined like "sec:", "cha:", "fig:", "lst:" and so on. Now I wanted to point to a certain line of code within one of my listings. There is no ...
0
votes
1answer
205 views

Listings and multiline labels

I wish a multiline label in the lstlisting environment. I would like to reference more than one line within the same listing. Can you help me to find a solution? I have found this link but this only ...
8
votes
1answer
167 views

cleveref doesn't print correct caption for listings

I want to set the caption for referenced listings: \documentclass{scrbook} \usepackage{listings} \usepackage{varioref} \usepackage{hyperref} \usepackage{cleveref} \begin{document} ...
8
votes
1answer
308 views

Label inside a code listing

Does anybody know how to use labels inside a code listing that it looks something similarly like this: I know that it's easier to use the line number but I prefer using some labels.
2
votes
1answer
682 views

How to extend fancyref for listings?

I use a listings environment to format source code such as a JSON file. \begin{lstlisting}[label={lst:json-example},caption=A JSON example] { "title" : "JSON specification", "author" : "Douglas ...
4
votes
2answers
833 views

How to cross-reference inside of a verbatim (or listings) environment

I would like to reference other parts of my document (e.g. equations, figures) inside of some source code. Is there an escape sequence such that \ref will be parsed instead of printed as a literal ...
3
votes
1answer
4k views

\usepackage{caption} breaks references to tables

I'm formatting the listings captions as follows: \usepackage{caption} \DeclareCaptionFont{white}{\color{white}} \DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}} ...
10
votes
2answers
194 views

Including sections of source code as a listing, while being robust to source code edits

Is there a way to input particular sections of source code using \lstinputlisting (from the listings package) in a flexible way? It's possible to use the firstline and lastline options to input ...
8
votes
1answer
556 views

Cleveref can't refer to line numbers in listings

Consider the following minimal example: \documentclass{article} \usepackage{listings} \usepackage{cleveref} % \crefname{lstnumber}{line}{Line} \begin{document} % \section{Section} ...
5
votes
1answer
1k views

cleveref + listings

\documentclass{scrbook} \usepackage{listings} \usepackage{cleveref} \begin{document} Ref: \ref{test}. Cref: \cref{test}. \begin{lstlisting}[caption={Test},label={test}] test \end{lstlisting} ...
1
vote
1answer
407 views

How to use example code (of any language) and reference it?

How to use Java or any code in LaTeX and refer it in my document?
13
votes
3answers
2k views

\autoref does not capitalize initial character in sentence when referencing label in listings environment

I have defined the following \providecommand*{\lstnumberautorefname}{line} and within my text \begin{lstlisting} |\label{sdd_1}|<sqlCallStatistics>YES</sqlCallStatistics> ...
4
votes
1answer
566 views

How to modify the equivalent of \thefigure for listings?

In my appendix I have figures and listings. The figures are now labeled very well (see this question). Now I have the same issue with listings: in the appendix it is labeled as A.1, but in my text ...
2
votes
1answer
1k views

“Wrong” numbers while referencing lstlistings in text

I'm using the lstlisting package to put sourcecode in my pdf file: \documentclass{scrbook} \usepackage{listings} \lstset{ % language=xml, basicstyle=\footnotesize, % the size of the fonts that ...
4
votes
2answers
2k views

How to get autoref working with different counters for different listing environments?

In my document I want several different custom listing environments. The solution from fraktalek works like a charm, except for one thing: \autoref doesn't work for me. I have tried the following: ...