%%
%% This is file `attinormativi.cls',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% attinormativi.dtx  (with options: `class')
%% 
%% attinormativi.cls
%% ------------------------------------------------------------------
%% LaTeX class for Italian normative acts.
%% Classe LaTeX per la composizione di atti normativi italiani.
%% 
%% Version 1.1  --  2026/05/17
%% 
%% Copyright (C) 2026 Federico Gallo <gallofede75@gmail.com>
%% 
%% This work may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3c of this license
%% or (at your option) any later version.
%% The latest version of this license is at:
%%   https://www.latex-project.org/lppl.txt
%% This work has the LPPL maintenance status `maintained'.
%% The Current Maintainer of this work is Federico Gallo.
%% 
%% This file is generated from attinormativi.dtx.
%% Do NOT edit this file directly; edit attinormativi.dtx instead.
%% ------------------------------------------------------------------
%% 


\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{attinormativi}[2026/05/17 v1.1 Classe per atti normativi italiani]

\def\ANclassversion{v1.1 (2026/05/17)}


\newif\ifAN@bozza
\AN@bozzafalse
\newif\ifANbozza
\ANbozzafalse
\DeclareOption{bozza}{\AN@bozzatrue\ANbozzatrue}

\newif\ifAN@sansserif
\AN@sansseriffalse
\DeclareOption{sansserif}{\AN@sansseriftrue}
\DeclareOption{sanserif}{\AN@sansseriftrue}  % alias tollerante (un solo 's')
\DeclareOption{serif}{}

\newif\ifAN@duplex
\AN@duplexfalse
\DeclareOption{duplex} {\AN@duplextrue}
\DeclareOption{simplex}{\AN@duplexfalse}
\DeclareOption{twoside}{\AN@duplextrue}
\DeclareOption{oneside}{\AN@duplexfalse}

\def\AN@margin@left  {35mm}
\def\AN@margin@right {30mm}
\def\AN@margin@top   {25mm}
\def\AN@margin@bottom{25mm}

\def\AN@str@left  {left}
\def\AN@str@right {right}
\def\AN@str@top   {top}
\def\AN@str@bottom{bottom}

\def\AN@parseMarginOption#1=#2\relax{%
  \def\AN@optkey{#1}%
  \def\AN@optval{#2}%
  \ifx\AN@optval\empty
    \PassOptionsToClass{\AN@currentopt}{book}%
  \else
    \ifx\AN@optkey\AN@str@left   \edef\AN@margin@left  {\AN@optval}\else
    \ifx\AN@optkey\AN@str@right  \edef\AN@margin@right {\AN@optval}\else
    \ifx\AN@optkey\AN@str@top    \edef\AN@margin@top   {\AN@optval}\else
    \ifx\AN@optkey\AN@str@bottom \edef\AN@margin@bottom{\AN@optval}\else
      \PassOptionsToClass{\AN@currentopt}{book}%
    \fi\fi\fi\fi
  \fi
}

\DeclareOption*{%
  \edef\AN@currentopt{\CurrentOption}%
  \expandafter\AN@parseMarginOption\AN@currentopt=\relax\relax
}

\ProcessOptions\relax

\ifAN@duplex
  \LoadClass[twoside,openright]{book}
\else
  \LoadClass[oneside,openany]{book}
\fi

\RequirePackage{iftex}


\ifPDFTeX
  \RequirePackage[utf8]{inputenc}
  \RequirePackage[T1]{fontenc}
  \RequirePackage{lmodern}
  \ifAN@sansserif
    \renewcommand{\familydefault}{\sfdefault}
  \fi
\else
  \RequirePackage{fontspec}
  \ifAN@sansserif
    \setmainfont{Latin Modern Sans}
    \setsansfont{Latin Modern Sans}
    \setmonofont{Latin Modern Mono}
  \else
    \setmainfont{Latin Modern Roman}
    \setsansfont{Latin Modern Sans}
    \setmonofont{Latin Modern Mono}
  \fi
\fi


\RequirePackage{geometry}
\ifAN@duplex
  \geometry{
    a4paper,
    twoside,
    top    = \AN@margin@top,
    bottom = \AN@margin@bottom,
    inner  = \AN@margin@left,
    outer  = \AN@margin@right
  }
\else
  \geometry{
    a4paper,
    top    = \AN@margin@top,
    bottom = \AN@margin@bottom,
    left   = \AN@margin@left,
    right  = \AN@margin@right
  }
\fi


\RequirePackage[italian]{babel}
\RequirePackage{microtype}


\RequirePackage{xcolor}

\@ifpackagelater{LaTeX}{2020/10/01}{}{%
  \RequirePackage{xparse}%
}

\RequirePackage{titlesec}
\RequirePackage{chngcntr}
\RequirePackage{enumitem}
\RequirePackage{hyperref}

\AtBeginDocument{\emergencystretch=2em}

\setcounter{secnumdepth}{6}
\setcounter{tocdepth}{3}

\hypersetup{
  colorlinks = true,
  linkcolor  = black,
  citecolor  = black,
  urlcolor   = black,
  pdfborder  = {0 0 0}
}

\newcounter{ANnotaredaz}

\NewDocumentCommand{\notaredaz}{+m}{%
  \ifAN@bozza
    \refstepcounter{ANnotaredaz}%
    \par\smallskip
    \noindent
    \fbox{%
      \begin{minipage}{0.96\linewidth}
        \small
        \textbf{Nota redazionale \theANnotaredaz.} #1
      \end{minipage}%
    }%
    \par\smallskip
  \fi
}

\NewDocumentCommand{\notaredazinline}{+m}{%
  \ifAN@bozza
    \textcolor{red}{[\textbf{Nota redazionale:} #1]}%
  \fi
}

\NewDocumentCommand{\bozzainfo}{}{%
  \ifAN@bozza
    \begin{center}
      \fbox{%
        \begin{minipage}{0.85\linewidth}
          \centering
          \textbf{VERSIONE DI BOZZA}\\
          Documento compilato il \today.\\
          Le note redazionali sono visibili solo in modalit\`a bozza.
        \end{minipage}%
      }
    \end{center}
    \newpage
  \fi
}

\newcommand*{\ANLibroName}{Libro}
\newcommand*{\ANTitoloName}{Titolo}
\newcommand*{\ANCapoName}{Capo}
\newcommand*{\ANSezioneName}{Sezione}
\newcommand*{\ANArticoloName}{Articolo}
\newcommand*{\ANCommaName}{Comma}

\addto\captionsitalian{%
  \renewcommand*{\partname}{\ANLibroName}%
  \renewcommand*{\chaptername}{\ANTitoloName}%
}

\newcommand*{\ANtipoatto}{}
\newcommand*{\ANnumeroatto}{}
\newcommand*{\ANdataatto}{}
\newcommand*{\ANautoritaatto}{}
\newcommand*{\ANtitoloatto}{}
\newcommand*{\ANoggettoatto}{}

\NewDocumentCommand{\tipoatto}    {m}{\renewcommand*{\ANtipoatto}{#1}}
\NewDocumentCommand{\numeroatto}  {m}{\renewcommand*{\ANnumeroatto}{#1}}
\NewDocumentCommand{\dataatto}    {m}{\renewcommand*{\ANdataatto}{#1}}
\NewDocumentCommand{\autoritaatto}{m}{\renewcommand*{\ANautoritaatto}{#1}}
\NewDocumentCommand{\titoloatto}  {m}{\renewcommand*{\ANtitoloatto}{#1}}
\NewDocumentCommand{\oggettoatto} {m}{\renewcommand*{\ANoggettoatto}{#1}}

\NewDocumentCommand{\frontespizioatto}{}{%
  \begin{titlepage}
  \centering
  \vspace*{2cm}
  \ifx\ANautoritaatto\empty\else
    {\Large \ANautoritaatto\par}\vspace{2cm}
  \fi
  \ifx\ANtipoatto\empty\else
    {\huge\bfseries \ANtipoatto\par}\vspace{0.5cm}
  \fi
  \ifx\ANnumeroatto\empty\else
    {\Large n.~\ANnumeroatto\par}\vspace{0.5cm}
  \fi
  \ifx\ANdataatto\empty\else
    {\large \ANdataatto\par}\vspace{2cm}
  \fi
  \ifx\ANtitoloatto\empty\else
    {\LARGE\bfseries \ANtitoloatto\par}\vspace{1.5cm}
  \fi
  \ifx\ANoggettoatto\empty\else
    \begin{minipage}{0.82\textwidth}
      \centering\large \ANoggettoatto
    \end{minipage}
  \fi
  \vfill
  \end{titlepage}
}

\let\maketitle\frontespizioatto

\renewcommand*{\thepart}{\Roman{part}}
\renewcommand*{\thechapter}{\Roman{chapter}}
\renewcommand*{\thesection}{\Roman{section}}
\renewcommand*{\thesubsection}{\Roman{subsection}}

\counterwithout{subsubsection}{subsection}
\renewcommand*{\thesubsubsection}{\arabic{subsubsection}}

\counterwithin*{paragraph}{subsubsection}
\renewcommand*{\theparagraph}{\arabic{paragraph}}

\newcounter{articoloecomma}
\renewcommand*{\thearticoloecomma}{art.~\thesubsubsection, c.~\theparagraph}

\titleformat{\part}[display]
  {\normalfont\Huge\bfseries\centering}
  {\ANLibroName~\thepart}{1ex}{}

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\centering}
  {\ANTitoloName~\thechapter}{1ex}{}

\titleformat{\section}[display]
  {\normalfont\Large\bfseries\centering}
  {\ANCapoName~\thesection}{1ex}{}

\titleformat{\subsection}[display]
  {\normalfont\large\bfseries\centering}
  {\ANSezioneName~\thesubsection}{1ex}{}

\titleformat{\subsubsection}[display]
  {\normalfont\normalsize\bfseries\centering}
  {\ANArticoloName~\thesubsubsection}{0.5ex}{\itshape}

\titleformat{\paragraph}[runin]
  {\normalfont\normalsize}
  {\theparagraph.}{0pt}{}

\titlespacing*{\part}         {0pt}{0pt}{4ex}
\titlespacing*{\chapter}      {0pt}{2ex plus 1ex minus .2ex}{3ex}
\titlespacing*{\section}      {0pt}{2.5ex plus 1ex minus .2ex}{1.5ex}
\titlespacing*{\subsection}   {0pt}{2ex plus 1ex minus .2ex}{1ex}
\titlespacing*{\subsubsection}{0pt}{2ex plus 1ex minus .2ex}{1ex}
\titlespacing*{\paragraph}    {0pt}{0.6ex plus .2ex minus .1ex}{0.75em}

\newcommand*{\artref}[1]{art.~\ref{#1}}
\newcommand*{\commaref}[1]{comma~\ref{#1}}
\newcommand*{\artcommaref}[1]{\ref{a+c:#1}}
\newcommand*{\articoloeref}[1]{articolo~\ref{#1}}
\newcommand*{\commaeref}[1]{comma~\ref{#1}}
\newcommand*{\artcomma}[2]{art.~\ref{#1}, comma~\ref{#2}}
\newcommand*{\articolocomma}[2]{articolo~\ref{#1}, comma~\ref{#2}}

\AtBeginDocument{%
  \@ifpackageloaded{cleveref}{%
    \crefname  {part}          {libro}      {libri}
    \Crefname  {part}          {Libro}      {Libri}
    \crefname  {chapter}       {titolo}     {titoli}
    \Crefname  {chapter}       {Titolo}     {Titoli}
    \crefname  {section}       {capo}       {capi}
    \Crefname  {section}       {Capo}       {Capi}
    \crefname  {subsection}    {sezione}    {sezioni}
    \Crefname  {subsection}    {Sezione}    {Sezioni}
    \crefname  {subsubsection} {articolo}   {articoli}
    \Crefname  {subsubsection} {Articolo}   {Articoli}
    \crefname  {paragraph}     {comma}      {commi}
    \Crefname  {paragraph}     {Comma}      {Commi}
    \crefname  {articoloecomma}{comma}      {commi}
    \Crefname  {articoloecomma}{Comma}      {Commi}
    \crefname  {ANdefinizione} {definizione}{definizioni}
    \Crefname  {ANdefinizione} {Definizione}{Definizioni}
    \crefname  {ANallegato}    {allegato}   {allegati}
    \Crefname  {ANallegato}    {Allegato}   {Allegati}
  }{}%
}
\NewDocumentCommand{\AN@emit}{m m m m m}{%
  \IfNoValueTF{#3}
    {%
      #1{#4}%
      \IfNoValueF{#5}{\label{#5}}%
    }
    {%
      \begingroup
        % Salva il valore del contatore PRIMA dell'incremento automatico
        % che il comando strutturale eseguirà globalmente.
        % Il ripristino finale riporta il contatore a questo valore,
        % garantendo la corretta progressione automatica successiva.
        \edef\AN@saved@counter{\the\value{#2}}%
        \expandafter\renewcommand\csname the#2\endcsname{#3}%
        #1{#4}%
        \IfNoValueF{#5}{\label{#5}}%
        \setcounter{#2}{\AN@saved@counter}%
      \endgroup
    }%
}

\NewDocumentCommand{\libro}  {o m o}{\AN@emit{\part}       {part}       {#1}{#2}{#3}}
\NewDocumentCommand{\titolo} {o m o}{\AN@emit{\chapter}    {chapter}    {#1}{#2}{#3}}
\NewDocumentCommand{\capo}   {o m o}{\AN@emit{\section}    {section}    {#1}{#2}{#3}}
\NewDocumentCommand{\sezione}{o m o}{\AN@emit{\subsection} {subsection} {#1}{#2}{#3}}

\NewDocumentCommand{\articolo}{o m o}{%
  \AN@emit{\subsubsection}{subsubsection}{#1}{#2}{#3}%
  \IfNoValueTF{#1}
    {\ANaddarticleindex{\thesubsubsection}{#2}}
    {\ANaddarticleindex{#1}{#2}}%
}

\NewDocumentCommand{\comma}{o +m o}{%
  \IfNoValueTF{#1}
    {%
      \paragraph{}#2\par
      \IfNoValueF{#3}{%
        \label{#3}%
        \refstepcounter{articoloecomma}%
        \label{a+c:#3}%
      }%
    }
    {%
      \begingroup
        \edef\AN@saved@para{\the\value{paragraph}}%
        \renewcommand*{\theparagraph}{#1}%
        \paragraph{}#2\par
        \IfNoValueF{#3}{%
          \label{#3}%
          \refstepcounter{articoloecomma}%
          \label{a+c:#3}%
        }%
        \setcounter{paragraph}{\AN@saved@para}%
      \endgroup
    }%
}

\newlist{lettere}{enumerate}{1}
\setlist[lettere]{
  label      = \alph*),
  ref        = \alph*),
  leftmargin = 2.5em,
  itemsep    = 0.2ex,
  topsep     = 0.5ex
}

\newlist{numeri}{enumerate}{1}
\setlist[numeri]{
  label      = \arabic*),
  ref        = \arabic*),
  leftmargin = 2.5em,
  itemsep    = 0.2ex,
  topsep     = 0.5ex
}

\newcounter{ANdefinizione}
\renewcommand*{\theANdefinizione}{\alph{ANdefinizione}}
\newcommand*{\ANDefinizioneName}{Definizione}

\NewDocumentCommand{\indicedefinizioni}{}{%
  \chapter*{Indice delle definizioni}%
  \markboth{Indice delle definizioni}{Indice delle definizioni}%
  \addcontentsline{toc}{chapter}{Indice delle definizioni}%
  \@starttoc{dfn}%
}

\newcommand*{\l@ANdefinizione}{\@dottedtocline{1}{0pt}{0em}}
\newcommand*{\ANadddefinitionindex}[1]{\addcontentsline{dfn}{ANdefinizione}{#1}}

\NewDocumentEnvironment{definizioni}{}
  {%
    \begin{list}{}{%
      \setlength{\leftmargin}{2.5em}%
      \setlength{\labelwidth}{2em}%
      \setlength{\labelsep}{0.75em}%
      \setlength{\itemsep}{0.4ex}%
      \setlength{\topsep}{0.6ex}%
    }%
    \setcounter{ANdefinizione}{0}%
  }
  {\end{list}}

\NewDocumentCommand{\definizione}{m +m o}{%
  \refstepcounter{ANdefinizione}%
  \protected@edef\@currentlabelname{#1}%
  \item[\textbf{\theANdefinizione)}]\textbf{#1}: #2%
  \ANadddefinitionindex{#1}%
  \IfNoValueF{#3}{\label{#3}}%
}

\newcommand*{\definizioneref}[1]{\emph{\nameref{#1}}}
\newcommand*{\defref}[1]{\definizioneref{#1}}

\NewDocumentEnvironment{preambolo}{+b}
  {\chapter*{Preambolo}\addcontentsline{toc}{chapter}{Preambolo}#1}{}

\NewDocumentEnvironment{relazione}{+b}
  {\chapter*{Relazione illustrativa}%
   \addcontentsline{toc}{chapter}{Relazione illustrativa}#1}{}

\NewDocumentCommand{\AN@articoloFisso}{m m +m m}{%
  \IfNoValueTF{#2}
    {%
      \IfNoValueTF{#4}{\articolo{#1}}{\articolo{#1}[#4]}%
    }
    {%
      \IfNoValueTF{#4}{\articolo[#2]{#1}}{\articolo[#2]{#1}[#4]}%
    }%
  \comma{#3}%
}

\NewDocumentCommand{\entrataInVigore} {o +m o}{\AN@articoloFisso{Entrata in vigore}{#1}{#2}{#3}}
\NewDocumentCommand{\abrogazioni}     {o +m o}{\AN@articoloFisso{Abrogazioni}{#1}{#2}{#3}}
\NewDocumentCommand{\normatransitoria}{o +m o}{\AN@articoloFisso{Norma transitoria}{#1}{#2}{#3}}

\newcounter{ANallegato}
\renewcommand*{\theANallegato}{\Alph{ANallegato}}
\newcommand*{\ANAllegatoName}{Allegato}
\newcommand*{\allegatoref}[1]{\ANAllegatoName~\ref{#1}}

\NewDocumentCommand{\indiceallegati}{}{%
  \chapter*{Indice degli allegati}%
  \markboth{Indice degli allegati}{Indice degli allegati}%
  \addcontentsline{toc}{chapter}{Indice degli allegati}%
  \@starttoc{alg}%
}

\newcommand*{\l@ANallegato}{\@dottedtocline{1}{0pt}{10.5em}}

\newcommand*{\ANaddattachmentindex}[2]{%
  \addcontentsline{alg}{ANallegato}{\protect\numberline{\ANAllegatoName~#1}#2}%
}

\NewDocumentCommand{\ANallegatoheading}{m m o}{%
  \clearpage\phantomsection
  \chapter*{\ANAllegatoName~#1\\[0.5ex]\large #2}%
  \markboth{\ANAllegatoName~#1}{#2}%
  \addcontentsline{toc}{chapter}{\ANAllegatoName~#1 -- #2}%
  \ANaddattachmentindex{#1}{#2}%
  \IfNoValueF{#3}{\label{#3}}%
  \vspace{1em}%
}

\NewDocumentCommand{\allegato}{o m o}{%
  \IfNoValueTF{#1}
    {%
      \refstepcounter{ANallegato}%
      \IfNoValueTF{#3}
        {\ANallegatoheading{\theANallegato}{#2}}
        {\ANallegatoheading{\theANallegato}{#2}[#3]}%
    }
    {%
      \begingroup
        \renewcommand*{\theANallegato}{#1}%
        \refstepcounter{ANallegato}%
        \IfNoValueTF{#3}
          {\ANallegatoheading{#1}{#2}}
          {\ANallegatoheading{#1}{#2}[#3]}%
      \endgroup
    }%
}

\NewDocumentCommand{\indicearticoli}{}{%
  \chapter*{Indice degli articoli}%
  \markboth{Indice degli articoli}{Indice degli articoli}%
  \addcontentsline{toc}{chapter}{Indice degli articoli}%
  \@starttoc{art}%
}

\newcommand*{\l@ANarticolo}{\@dottedtocline{1}{0pt}{8.5em}}

\newcommand*{\ANaddarticleindex}[2]{%
  \addcontentsline{art}{ANarticolo}{\protect\numberline{\ANArticoloName~#1}#2}%
}

%% 
%% End of file attinormativi.cls.
%%
%% End of file `attinormativi.cls'.
