LaTeX/C3/Adding-Line-Numbers-in-LaTeX/English

From Script | Spoken-Tutorial
Revision as of 11:51, 1 December 2025 by ANJALISATDIVE (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Title of the Script: Adding line numbers in LaTeX

Author: Ambika Vanchinathan

Keywords: LaTeX, lineno package, line numbers, math environments, linelabel, modulolinenumbers, mathlines, video tutorial.

Pre-requisite: Writing Style Files in LaTeX


Visual Cue Narration
Slide 1

Title Slide

Welcome to the spoken tutorial on Adding Line Numbers in LaTeX.
Slide 2

Learning Objectives

In this tutorial, we will learn to
  • Add line numbers to a document
  • Enable line numbers in math environment
  • Label and cross reference a line number
  • Enable line numbering in steps and change its font size
Slide 3

System Requirements


  • Linux Mint OS version 21.3
  • TeXworks Editor version 0.6.6
To record this tutorial, I am using the following setup.
Slide 4

Pre-requisites

To follow this tutorial, learners should have basic knowledge of LaTeX.
Slide 5:

Code files

The following code files are required to practice this tutorial:

1. lineno-eg.tex


These files are provided in the Code Files link of this tutorial page.

The following code file is required to practice this tutorial.


This file is provided in the Code Files link of this tutorial page.

Let us get started.
Highlight:

\usepackage{lineno}

This command loads the line number package.

It is recommended to keep the installation up to date.


If any issue arises, please update the packages by downloading them from ctan.org.

Highlight:

\linenumbers


Click the green Typeset button and show the output

\linenumbers command enables printing line numbers on the document.

Click the green Typeset button to run the code.

Output shows the line numbers printed on all lines except the math equations.


Comment line 5

Uncomment line 7

Click the green Typeset button and show the output

Comment line 5

Uncomment line 7

Run the code to see the output.


Observe the line numbers in math equations.

Highlight:

line 7

Option [mathlines, displaymath] with

\usepackage{lineno}, enables line numbers in math environments.


This applies to both numbered and unnumbered equations.

Uncomment lines 23, 49

Click the green Typeset button and show the output

Uncomment lines 23 and 49.

Run the code

Here we must compile the code twice.

In the first run we see question marks.

That is, the first run assigns line numbers.

The second run fixes the references.


Like cross-references, line numbers need, two compilations to appear correctly.

Let us compile again.

Here is the output after the second compilation.

Observe the line number and page number reference at the end of the document.

Highlight:

line 23, 49

\linelabel command labels the line number.


\ref and \pageref generate the line number and page number of a text in a line.

Uncomment line 17

Click the Typeset button and show the output

Uncomment line 17.

Run the code

Here is the output.

We see that line numbers are printed after every 5 lines.

Highlight:

line 17

Command \modulolinenumbers[5]

enables line numbering in steps of 5.

We can change the number 5 to reset to a required jump.

Uncomment line 14

Click the Typeset button and show the output

Uncomment the line 14.

Run the code.

Here is the output.

Highlight:

line 14


We can see that the font color and size of the line numbers have changed.


The command \linenumberfont resets, line numbers to red and font to script size.


Note that, we have also loaded the color package to get the colours.

Slide 6

Summary


In this tutorial, we have learnt to

  • Add line numbers to a document
  • Enable line numbers in math environment
  • Label and cross reference a line
  • Enable line numbering in steps and change its font size
With this we come to the end of this tutorial.

Let us summarise.


Slide 7

Assignment

As an Assignment,

Print line numbers after every 3 lines in blue colour.

Slide 8

Thank you

Thank you for joining

Contributors and Content Editors

ANJALISATDIVE