Tag Info

Hot answers tagged

72

Alright, here's a go at numbering lines in a PDF (or any other image format) without access to the source. I wrote a little shell script that, using ImageMagick (at least version 6.6.9-4), converts a given PDF into separate raster images for each page, splits these into half pages, shrinks them to a width of one pixel (so takes the horizontal average, ...


49

This solution is very similar to that contained in How to make text copy in PDF previewers ignore lineno line numbers? \protecting the accsupp is the only requirement, perhaps due to the nature in which listings treats everything: \documentclass{article} \usepackage{xcolor}% http://ctan.org/pkg/xcolor \usepackage{listings}% http://ctan.org/pkg/listings ...


27

According to the manual you can do this the following way: An optional argument to the \begin{algorithmic} statement can be used to turn on line numbering by giving a positive integer indicating the required frequency of line numbering. For example, \begin{algorithmic}[5] would cause every fifth line to be numbered. Obviously, \begin{algorithmic}[1] ...


25

Due to problems that came to light in the first answer when loading also the hyperref package, a related question was asked (How do I prevent conflicts between accsupp and hyperref?). The following solution is based on Ulrike Fischer's answer to that question, and illustrates one other advantage of this solution (as pointed out by Heiko Oberdiek) even if ...


23

Have a look at the lineno package. I use it often like follows: % number the lines \usepackage{lineno,xcolor} % Running line numbers: \linenumbers \setlength\linenumbersep{5pt} \renewcommand\linenumberfont{\normalfont\tiny\sffamily\color{gray}} % Same, but that reset on every page: %\pagewiselinenumbers % Number only every 5:th line: %\modulolinenumbers[5] ...


21

Using a method similar to that proposed in How to make listings code correct copyable from PDF and with hyperlink, the following works (at least in Adobe Reader). The accsupp package provides accessibility support for PDFs. By using the \BeginAccSupp and \EndAccSupp group, the line numbers can be typeset in the PDF, but actually replaced by an empty space ...


15

Use the switch option for the lineno package. \documentclass[twocolumn]{article} \usepackage[switch]{lineno} \usepackage{lipsum} %Creates example text \begin{document} \linenumbers \lipsum[1-20] \end{document}


14

The last annotation in the .aux file made by lineno is of the form \@LN{251}{5} where 251 is the global number of counted lines and 5 is the last page number. Of course this will depend on the document. If you say \AtEndDocument{\typeout{Total number of lines: \thelinenumber}} in your preamble, you'll see a message such as Total number of lines: 251 ...


14

(This is a copy of the comment I posted above. Now an answer due to Will Robertson's suggestion.) This addresses, partially, problem 2 described in the question. I've never seen problem 1 happen myself; then again, I haven't used lineno that much. Take a look at ulineno.pdf from http://www.ctan.org/tex-archive/macros/latex/contrib/lineno/ (the user's ...


12

You can easily treat your parameter file as a standard figure or a table; in the third example code below I used this approach. To add captions outside floating environments, you could use the \captionof command from the caption (or capt-of) package; in the last example code below I used this approach. To have automatic number line, monospaced font and ...


12

You can do (1) easily with the pdfpages package. \documentclass{article} \usepackage{pdfpages} \begin{document} \includepdf[pages=1-,pagecommand={\thispagestyle{plain}}]{<pdffile>} \end{document} In the example document, I simply passed the pagestyle plain to the pagecommand, but using the fancyhdr package you can make any kind of extra ...


12

If you don't want to use the package lstlinebgrd, this is what you can do with the code borrowed from that answer. The command \zebra takes three arguments. If you use only two as in that answer numberstyle=\zebra{green!35}{yellow!35} you don't get the line numbers printed. To have them you have to give a third empty argument like ...


12

The listings package manual has an example that covers this: \begin{lstlisting}[firstnumber=100] for i:=maxint to 0 do begin { do nothing } end; \end{lstlisting}


11

This answer only deals with latex/dvips/ps2pdf. Package accsupp works well with dvips. The generated PostScript file contains the right pdfmark operators. However ghostscript (version 9.05) has not implemented these tags, from the source file gdevpdfm.c: /* [ tag propdict /BDC pdfmark */ static int pdfmark_BDC(gx_device_pdf *pdev, gs_param_string *pairs, ...


11

Put this in your preamble, at the end (after the math package are loaded): \makeatletter % Make a copy of macros responsible for entering display math mode \let\start@align@nopar\start@align \let\start@gather@nopar\start@gather \let\start@multline@nopar\start@multline % Add the "empty line" command to the macros \long\def\start@align{\par\start@align@nopar} ...


10

Two versions: \pageoflines{1cm} is without numbers; with \pageofnumberedlines you get tiny numbers in the margin. \documentclass{article} % to show the page frame \usepackage{xcolor,showframe} \renewcommand*\ShowFrameColor{\color{red}} \renewcommand*\ShowFrameLinethickness{.2pt} % don't show the margin par space (not needed for the macros) ...


10

Your MWE can be greatly reduced to be \documentclass{revtex4} \usepackage{lineno} \usepackage{blindtext} \pagewiselinenumbers \begin{document} \Blindtext \end{document} With such a simple MWE it becomes clear that the problem is an interaction between revtex4 and lineno. Searching the lineno documentation yields: if a class changes \output (APS ...


10

Page 1, lines 11-12 of the lineno states: lineno.sty can only number lines in the main text. Lines in any kind of boxes cannot be numbered. But see section 7.4 below. The AMS class file typesets the abstract as part of the title page, but the abstract is specified using an environment. So it has to slurp in the text and save it for reuse. It does ...


9

Why do you say that lineno cannot be used with memoir? I couldn't find any reference to this in the lineno documentation nor in the memoir manual. The only problem I see is that lineno doesn't number footnote text, but this is not for memoir, but also for the standard classes. To number footnote text too, you can use lineno and fnlineno (for numbering ...


9

$$...$$ is obsolete, see Why is [ … ] preferable to $$. If you use the correct LaTeX displayed math environment, the numbering works without the empty line: \documentclass[12pt]{article} \usepackage{amsmath} \usepackage{lineno} \linenumbers \begin{document} Lorem ipsum dolor sit amet, consectetur adipiscing elit: \[1+1=2\] \end{document}


9

It isn't such simple as it sounds. You have to hook every line. Here a small solution which needs more testing: \documentclass{article} \usepackage{listings} \lstset{numbers=left,numberblanklines=false,escapeinside=||} \let\origthelstnumber\thelstnumber \makeatletter \newcommand*\Suppressnumber{% \lst@AddToHook{OnNewLine}{% ...


9

This seems to work very well: \documentclass{article} \newlength{\linespagelength} \newcounter{linespage} \newcommand\linespage[2][0.4pt]{ \newpage \begingroup \baselineskip0pt \setlength{\linespagelength}{\textheight} \setcounter{linespage}{0} \loop \addtolength{\linespagelength}{-#2} \stepcounter{linespage} \ifdim\linespagelength>0pt ...


9

Page 2 of my copy of the manual mentions the modulo option: "Print line numbers only if they are multiples of five". \documentclass{article} \usepackage[modulo]{lineno} \linenumbers \usepackage{lipsum} \begin{document} \lipsum[1] \end{document}


9

I would avoid to redefine \thelstnumber in such a way. The command can be used in various places where such fragile content can break easily. In the case of listings I would suggest to use the key numberstyle instead: \documentclass{article} \usepackage{listings} \usepackage{accsupp} \newcommand\emptyaccsupp[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}} ...


9

The following minimal example shows how to modify the starting line number for an algorithm. Within the algorithmic environment, add the code \makeatletter\setcounter{ALG@line}{<n>}\makeatother where <n> is one smaller than the first line number. The reason for this is because the \State command increments the counter first, before typesetting ...


8

mdframed clips the box at the frame. But I don't know if it intended or a bug. \documentclass{article} \usepackage[framemethod=tikz]{mdframed} \newdimen\linenumbersep \newcommand{\linenumber}[1]{% \linenumbersep 4pt% \advance\linenumbersep\mdflength{innerleftmargin}% \advance\linenumbersep\mdflength{innerlinewidth}% ...


8

The key is numberstyle: \lstset{numberstyle=\ttfamily}


8

You can use numberblanklines=false; a little example: \documentclass{article} \usepackage{listings} \lstset{numbers=left,numberblanklines=false} \begin{document} \begin{lstlisting} First line. Second line. \end{lstlisting} \end{document} The above approach will not number blank lines, but will take them into account for increasing the counter ...


8

A slightly different approach to that of the faq pointed out by Lockstep. Firsty, we need to build a box 3em wide to hold the numbers of all the lines. This box will be later positioned at the left margin and unboxed. \newsavebox{\@linebox} \savebox{\@linebox}[3em][t]{\parbox[t]{3em}{% \@tempcnta\@ne\relax ...


8

In essence, this is the same, since align issues $$ before assembling the environment contents. Here is the definition of the align environment in amsmath: \newenvironment{align}{% \start@align\@ne\st@rredfalse\m@ne }{% % <removed \end{align} part for brevity> } So, at \begin{align} is equivalent to \start@align{\@ne}{\st@rredfalse}{\m@ne} ...



Only top voted, non community-wiki answers of a minimum length are eligible