1

Is it possible to print Line Number in emacs to the Latex pdf for lines that I prefer?

If it is easy, I want to use those numbers with M-g M-g (goto-line command)

I asked the same question here, I am not sure which one is correct.

Edit: To make the question more clear, lets say

L56: Some text....
L57: Some text....
L58: \printLineNumberOfEmacsIntoPDF
L59: \begin{equation}
L60:     Some Equation
L61: \end{equation}

I am looking for a command like this such that it will print 'Line 58' into the pdf created by Latex.

1
  • Please clarify the use case, or cases, you have in mind. E.g., are you looking to typeset a code block "as is" or "verbatim", with a monospaced font and indentations exactly as they occur in the input file? If so, have you looked into the fancyvrb package, which lets you achieve these objectives in a straightforward fashion.
    – Mico
    Jan 16, 2021 at 7:53

2 Answers 2

2

If I understand you correctly you are searching for the primitive \inputlineno:

\documentclass{article}
\newcommand*\printLineNumberOfEmacsIntoPDF{Line \the\inputlineno}
\begin{document}
\printLineNumberOfEmacsIntoPDF
\end{document}

enter image description here

0

The fancyvrb package lets you print line numbers along with verbatim material, and it lets you customize how the line numbers are formatted.

enter image description here

\documentclass{article}
\usepackage{fancyvrb} % for 'Verbatim' environment
\begin{document}

\renewcommand{\theFancyVerbLine}{{\scriptsize Line \arabic{FancyVerbLine}}}
\begin{Verbatim}[numbers=left]
Some text ...
Some text ...
\printLineNumberOfEmacsIntoPDF
\begin{equation}
     1+1=2
\end{equation}
\end{Verbatim}
\end{document}

Addendum: If the first line number is supposed to be different from 1, simply add a firstnumber=<DesiredNumber> option, i.e., change

\begin{Verbatim}[numbers=left]

to

\begin{Verbatim}[numbers=left,firstnumber=55]

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.