Skip to content

Read number lines in a file - in LaTeX

Probably a rare needed feature, but i had to count the number lines in a text file - in LaTeX.

Counting the line numbers is done by using a counter (what else, eh?) and readling the file line by line:






    \read#1 to \FileLine
    \else % if last line already is read, EOF appears here



Lines in file: \arabic{FileLines}


\File is a TeX file descriptor. Note that TeX has a very limited number of this file descriptors, but fortunately they can be re-used, as long as the descriptor is not used in parallel by different commands for a different operation.

The number of file lines is available in the \FileLines counter, which can be exported in arabic numerals by using \arabic{}.

More possible counter representations are explained in my previous post.


No Trackbacks


Display comments as Linear | Threaded

Jonas Winkler on :

Thanks for sharing, exactly what I was looking for. Works like a charm :)
Comments ()

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.
Form options