# How can I add some line numbers of emacs into pdf created by latex

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: $$L60: Some Equation L61:$$

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

• 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

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

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

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

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

\renewcommand{\theFancyVerbLine}{{\scriptsize Line \arabic{FancyVerbLine}}}
\begin{Verbatim}[numbers=left]
Some text ...
Some text ...
\printLineNumberOfEmacsIntoPDF
$$1+1=2$$
\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]