1

The \newcounter{<counter-name>}[<outer-counter>] commands will define a new counter. For example, \newcounter{example}[section] command creates a new counter called example that will be reset every time the section counter is increased.

But for paragraph counter, the \newcounter{<counter-name>}[paragraph] doesn't work.

Here is the MWE:

\documentclass{article}


\newcounter{sentencenum}[paragraph]
\newcommand{\sno}[0]{\refstepcounter{sentencenum}$_{\arabic{sentencenum}}$}


\begin{document}


\sno{}Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
\sno{}Ut purus elit, vestibulum ut, placerat ac,adipiscing vitae, felis. Curabitur dictum gravida mauris.
\sno{}Nam arcu libero, nonummy eget, consectetuerid, vulputate a, magna.
\sno{}Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus etnetus et malesuada fames ac turpis egestas.
\sno{}Mauris ut leo. Cras viverra metus rhoncus sem.
\sno{}Nulla et lectusvestibulum urna fringilla ultrices.
\sno{}Phasellus eu tellus sit amet tortor gravida placerat.
\sno{}Integer sapien est,iaculis in, pretium quis, viverra ac, nunc.
\sno{}Praesent eget sem vel leo ultrices bibendum.
\sno{}Aenean faucibus.
\sno{}Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla.
\sno{}Curabitur auctor semper nulla.
\sno{}Donec variusorci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orcidignissim rutrum.



%
% Bug: The second paragraph should reset the counter value of `sentencenum` since here start a new paragraph
%
\sno{}Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi.
\sno{}Morbi auctor lorem non justo.
\sno{}Namlacus libero, pretium at, lobortis vitae, ultricies et, tellus.
\sno{}Donec aliquet, tortor sed accumsan bibendum,erat ligula aliquet magna, vitae ornare odio metus a mi.
\sno{}Morbi ac orci et nisl hendrerit mollis.
Suspendisseut massa.


\end{document}
  • In your document you not use \paragraph{<title>} ... – Zarko Aug 18 at 6:09
  • @Zarko ... he possibly means to make the counter zero between the paragraphs of the text and not the sectioning command \paragraph. – koleygr Aug 18 at 6:23
  • 1
    @koleygr, I understood what OP want, I only note him that his approach will not work since he doesn't use `\paragraph{...} titles. Possible solution gives your answer – Zarko Aug 18 at 6:43
  • Ok @Zarko... Thanks for the reply ... Although I first tried with a \paragraph command to make sure it would work ... but may be some depth should added too or renewing the command paragraph should be needed too, – koleygr Aug 18 at 6:50
  • The name of the \paragraph command is misleading you. It is not executed when a paragraph is started. It’s very unfortunate that Leslie Lamport chose it to mean \subsubsubsection. – egreg Aug 19 at 12:42
2

I can't say that this is a recommended way to do that but could solve this problem. Please test it in more complex documents because I can't really know the side effects. Here is the code on your example:

\documentclass{article}



\newcounter{sentencenum}
\newcommand{\sno}[0]{\refstepcounter{sentencenum}$_{\arabic{sentencenum}}$}

\let\oldpar\par
\def\par{\setcounter{sentencenum}{0}\oldpar}


\begin{document}


\sno{}Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
\sno{}Ut purus elit, vestibulum ut, placerat ac,adipiscing vitae, felis. Curabitur dictum gravida mauris.
\sno{}Nam arcu libero, nonummy eget, consectetuerid, vulputate a, magna.
\sno{}Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus etnetus et malesuada fames ac turpis egestas.
\sno{}Mauris ut leo. Cras viverra metus rhoncus sem.
\sno{}Nulla et lectusvestibulum urna fringilla ultrices.
\sno{}Phasellus eu tellus sit amet tortor gravida placerat.
\sno{}Integer sapien est,iaculis in, pretium quis, viverra ac, nunc.
\sno{}Praesent eget sem vel leo ultrices bibendum.
\sno{}Aenean faucibus.
\sno{}Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla.
\sno{}Curabitur auctor semper nulla.
\sno{}Donec variusorci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orcidignissim rutrum.



%
% Bug: The second paragraph should reset the counter value of `sentencenum` since here start a new paragraph
%
\sno{}Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi.
\sno{}Morbi auctor lorem non justo.
\sno{}Namlacus libero, pretium at, lobortis vitae, ultricies et, tellus.
\sno{}Donec aliquet, tortor sed accumsan bibendum,erat ligula aliquet magna, vitae ornare odio metus a mi.
\sno{}Morbi ac orci et nisl hendrerit mollis.
Suspendisseut massa.


\end{document}

enter image description here

The idea is:

For every new paragraph in latex, the \par command is executed. So, I added the functionality of making zero your counter by redefining \par (seems dangerous to me in first thinking about... but MAY BE it is ok....)

PS: Paragraph of text is created with empty lines between text ... But there is a sectioning command \paragraph too that you "tried to use" by mistake in your MWE.

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.