Can I refer to a line number from the imported file without escaping chars inside the file?

Say, I import my file like this


and I want to \hyperref{} line 50 without modifying it or copying to my .tex file.

  • 1
    Welcome to TeX.SX! I'm not sure that I understand. The whole point of using \ref{...} is to be able to dynamically refer to other parts of the document. From want you have said you simply want to refer to line 50 so why not write by line 50...? – Andrew Aug 15 '15 at 4:49
  • @Andrew yeah, you are correct. What I actually want though is to hyperref this part of the document. Sorry for not asking this straight away. – orestisf Aug 15 '15 at 9:28

The following example sets a label for the listings by option label. The anchor name of the label is extracted and analyzed to get the internal listings number. In this case the unnumbered listings has anchor lstlisting.-1 with the number -1 for the listings. The anchor names for the line numbers follow the pattern lstnumber.<listings number>.<line number>. Macro \lstlinelink references the line, given the label for the listings and the line number. Two LaTeX runs are necessary because of the label.



Line~\lstlinelink{foo}{5} loads package \texttt{hyperref}
and the document starts at line~\lstlinelink{foo}{25}.


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.