1

How can I number the lines (using lineno) of a text while using obeylines such that I don't have to put a \\ at the end of every line. I've tried:

\newenvironment{foo}
{ \begin{linenumbers}[1] \bgroup\obeylines }
{ \egroup \end{linenumbers} }

But this results in a number in front of every outputted line but I'd like to have only numbers on front of every input line.

Also how can I turn off the indent for every line inside this environment?

Using verbatim isn't an alternative because then I can't use footnotes and similar stuff inside this environment.

  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Jan 18 '15 at 17:45
1

Apart from spaces in the input that shouldn't be used, your definition works.

Here's how you remove the indentation.

\documentclass{article}
\usepackage{lineno}
\newenvironment{foo}
 {\begin{linenumbers}[1]%
  \setlength{\parindent}{0pt}%
  \bgroup\obeylines}
 {\egroup\end{linenumbers}}

\begin{document}

\begin{foo}
aaaa
bbbb
cccc
\end{foo}

\end{document}

enter image description here

The purpose of lineno is to count the number of lines in the output, so it's not really clear what you want to achieve.

Perhaps something like

\documentclass{article}
\newenvironment{foo}
 {\par
  \setcounter{foocount}{0}%
  \setlength{\parindent}{0pt}%
  \everypar{\stepcounter{foocount}\makebox[0pt][r]{\tiny\thefoocount\enspace}}%
  \bgroup\obeylines}
 {\par\egroup}
\newcounter{foocount}

\begin{document}

\begin{foo}
aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa aaaa
bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb
cccc
\end{foo}

\end{document}

enter image description here

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.