2

I'm currently working on a layout that is divided in article and alinea. Basically I've two functions. In each functions there is an environment dedicated to show the texts in a certain layout. Sometimes there are many alineas in an article. But sometimes, there's only one. In that case, I would like to Not show the number of the alinea. But, I don't know how to achieve that. I was thinking to use some conditions... but I don't know how to retrieve the number of alineas in the environment of the articles as there are resets to 0 as a last instruction in that environment. As anyone an idea? thanks for your reading and maybe your help.

\documentclass[a4paper,11pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\newtheorem{article}{Art.}

\newtheorem{alinea}{}%nom du théorème ; ce qui apparaît ; devant quoi la numérotation reprend de à 1
\newcommand{\resettheoremcounters}{%va remettre à zéro le compteur
  \setcounter{alinea}{0}%
} 
\newcommand{\art}[1]{\begin{article}#1\end{article}%
                                    \resettheoremcounters}
\newcommand{\ali}[1]{\begin{alinea}#1\end{alinea}}  

\begin{document}
    \art{
        \ali{ali 1}
        }
    \art{
        \ali{ali 1}
        \ali{ali 2}
        }

\end{document}  
2

You can count the number of \ali command inside the argument to \art; do it inside a box that's then discarded.

\documentclass[a4paper,11pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\newtheorem{article}{Art.}

\newtheorem{alinea}{}[article]
\renewcommand{\thealinea}{\arabic{alinea}}

\newcommand{\art}[1]{%
  \setcounter{countali}{0}%
  \setbox0=\vbox{\let\ali\countali#1}%
  \begin{article}
  \ifnum\value{countali}<2
    \let\ali\ignoreali
  \fi
  #1%
  \end{article}
}
\newcommand{\ali}[1]{\begin{alinea}#1\end{alinea}}
\newcounter{countali}
\newcommand{\countali}[1]{\stepcounter{countali}}
\newcommand{\ignoreali}[1]{#1}

\begin{document}

\art{
  \ali{ali 1}
}

\art{
  \ali{ali 1}
  \ali{ali 2}
}

\art{
  \ali{ali 1}
  \ali{ali 2}
}

\end{document}  

enter image description here

With \newtheorem{ali}{}[article] you get automatic resetting without the need of issuing an explicit command.

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.