%D \module
%D   [       file=bibl-apa-it,
%D        version=2014.10.10,
%D          title=APA bibliography style,
%D       subtitle=Publications,
%D         author={Andrea Valle \& Alan Braslau},
%D           date=\currentdate,
%D      copyright={Public Domain}]
%C
%C Donated to the public domain. Use at your own risk

\unprotect

\setupcite
  [author,year]
  [\c!andtext={ e },
   \c!otherstext={ et al.},
   \c!pubsep={, },
   \c!lastpubsep={ e },
   \c!compress=\v!no,
   \c!inbetween={ },
   \c!left={(},
   \c!right={)}]

\setupcite
  [authoryear]
  [\c!andtext={ e },
   \c!otherstext={ et al.},
   \c!pubsep={, },
   \c!lastpubsep={ e },
   \c!compress=\v!yes,
   \c!inbetween={ },
   \c!left={(},
   \c!right={)}]

\setupcite
  [authoryears]
  [\c!andtext={ e },
   \c!otherstext={ et al.},
   \c!pubsep={, },
   \c!lastpubsep={ e },
   \c!compress=\v!yes,
   \c!inbetween={, },
   \c!left={(},
   \c!right={)}]

\setupcite
  [key,serial,authornum,page,short,type,doi,url]
  [\c!andtext={ e },
   \c!otherstext={ et al.},
   \c!pubsep={, },
   \c!lastpubsep={ e },
   \c!compress=\v!no,
   \c!inbetween={ },
   \c!left={[},
   \c!right={]}]

\setupcite
  [num]
  [\c!andtext={ e },
   \c!otherstext={ et al.},
   \c!pubsep={, },
   \c!lastpubsep={ e },
   \c!compress=\v!yes,
   \c!inbetween={--},
   \c!left={[},
   \c!right={]}]

\setuppublications
  [\c!sorttype=,
   \c!criterium=,
   \c!refcommand=authoryears,
   \c!numbering=\v!no,
   \c!autohang=\v!no]

\setuppublicationlist
  [\c!width=24pt,
   \c!artauthor=\invertedshortauthor,
   \c!editor=\invertedshortauthor,
   \c!author=\invertedshortauthor,
   \c!namesep={, },
   \c!lastnamesep={ e },
   \c!finalnamesep={ e },
   \c!firstnamesep={, },
   \c!juniorsep={ },
   \c!vonsep={ },
   \c!surnamesep={, },
   \c!authoretallimit=5,
   \c!editoretallimit=5,
   \c!artauthoretallimit=5,
   \c!authoretaldisplay=5,
   \c!editoretaldisplay=5,
   \c!artauthoretaldisplay=5,
   \c!authoretaltext={ et al.},
   \c!editoretaltext={ et al.},
   \c!artauthoretaltext={ et al.}]

\def\maybeyear#1{#1}
\def\etalchar #1{#1}

%D \macros{insertchapter,insertpublisher}

%D Some shortcuts.

% ((#1(type\ |)chapter#2)|#3)

\def\insertchap#1#2#3%
  {\insertchapter
    {#1\insertbibtype{}{\ }{capitolo\ }}{#2}%
    {#3}}

% #1city, country: pubname#2
% #1country: pubname#2
% #1pubname#2
% #1city, country#2
% #3

\def\insertpublisher#1#2#3%
   {\insertpubname
       {\insertcity
            {#1}
            {\insertcountry{, }{}{}: }%
            {#1\insertcountry{}{: }{}}}%
       {#2}%
       {\insertcity
            {#1}
            {\insertcountry{, }{}{#2}}%
            {\insertcountry{#1}{#2}{#3}}}%
    }

\def\insertorg#1#2#3%
   {\insertorganization
       {\insertcity
            {#1}
            {\insertcountry{, }{}{#2}: }%
            {\insertcountry{}{: }{#2}}}%
       {}%
       {\insertcity
            {#1}
            {\insertcountry{, }{}{#2}}%
            {\insertcountry{}{#2}{#3}}}%
    }



\setuppublicationlayout[article]{%
   \insertartauthors{}{ }{\insertthekey{}{ }{}}%
   \insertpubyear{(}{). }{\unskip.}%
   \insertarttitle{\bgroup }{\egroup. }{}%
   \insertjournal{\bgroup \it}{\egroup}
    {\insertcrossref{In }{}{}}%
   \insertvolume
    {\bgroup \it, }
    {\egroup\insertissue{\/(}{)}{}\insertpages{, }{.}{.}}
    {\insertpages{, pp. }{.}{.}}%
   \insertnote{ }{.}{}%
   \insertcomment{}{.}{}%
}

% \newif\ifeditedbook

\setuppublicationlayout[book]{%
   \insertauthors{}{ }{\inserteditors{}{, a c. di%
                             \ \global\editedbooktrue
                     }{\insertthekey{}{. }{}}}%
   \insertpubyear{(}{). }{\unskip.}%
   \inserttitle
        {\bgroup\it }%
        {\/\egroup
         \ifeditedbook
           \global\editedbookfalse
           \insertvolume
                { N.~}%
                {\insertseries
                    { in~\bgroup}%
                    {\egroup. }%
                    {\insertcrossref{ in~}{}{. }}}%
                {\insertseries{ }{.}{.}}%
        \else
       \insertcrossref
        {\insertchap{, }{}{}%
         \insertpages{\unskip, pp. }{. }{. }%
         \insertvolume{Vol.~}{ di~}{}%
         }%
        {}%
        {\insertvolume
                   {, vol.~}%
                   {\insertseries
                      { di~\bgroup\it}%
                      {\egroup}
                      {}}
                   {}%
                   \insertchap{, }{}{}%
                   \insertpages{\unskip, pp. }{.}{.}%
                }%
        \fi}%
        {}%
   \insertedition{ }{ ed.}{}%
   \insertpublisher{ }{.}{.}%
   \insertpages{ }{p. }{ }%
   \insertnote{}{.}{}%
}

\setuppublicationlayout[inbook]{%
   \insertauthors{}{ }{\inserteditors{}{, a c. di%
                             \ \global\editedbooktrue
                     }{\insertthekey{}{. }{}}}%
   \insertpubyear{(}{). }{\unskip.}%
   \inserttitle
     {\bgroup\it }%
     {\/\egroup
      \ifeditedbook
         \global\editedbookfalse
         \insertvolume
           { number~}%
           {\insertseries
              { in~\bgroup}%
              {\egroup. }%
              {\insertcrossref{ in~}{}{.}}}%
           {\insertseries{ }{.}{}}%
      \else
        \insertcrossref
          {\insertchap{, }{}{}%
           \insertpages{\unskip, pp. }{. }{. }%
           \insertvolume{Volume~}{ di~}{}%
           }%
          {}%
          {\insertvolume
              {, volume~}%
              {\insertseries
                 { di~\bgroup\it}%
                 {\egroup}
                 {}}
              {}%
           \insertchap{, }{}{}%
           \insertpages{\unskip, pp. }{.}{}%
           }%
        \fi}%
     { }%
   \insertedition{ }{ ed.}{}%
   \insertpublisher{ }{.}{.}%
   \insertnote{ }{.}{}%
}

\setuppublicationlayout[booklet]{%
   \insertauthors{}{ }{\insertthekey{}{. }{}}%
   \insertpubyear{(}{). }{}%
   \inserttitle{\bgroup }{\egroup \insertseries{ (}{)}{}. }{}%
   \insertedition{ }{ ed.}{}%
   \insertpublisher{ }{.}{.}%
   \insertpages{}{p. }{}%
   \insertnote{ }{.}{}%
}

\setuppublicationlayout[manual]{%
   \insertauthors{}{ }{\insertthekey{}{. }{}}%
   \insertpubyear{(}{). }{}%
   \inserttitle{\bgroup \it }{\/\egroup \insertseries{ (}{)}{}. }{}%
   \insertedition{ }{ ed.}{}%
   \insertorg{ }{.}{.}%
   \insertpages{}{p. }{}%
   \insertnote{ }{.}{}%
}

\setuppublicationlayout[incollection]{%
   \insertartauthors{}{ }{\insertthekey{}{. }{}}%
   \insertpubyear{(}{). }{}%
   \insertarttitle{\bgroup }{\egroup. }{}%
   \inserttitle
    {In \inserteditors{}%
        {, a c. di, }%
        {}%
    \bgroup\it}%
    {\egroup
         \insertseries
              {\insertvolume{, number }{~in }{ }}%
              {}%
              {}%
         \insertchap{\unskip, }{ }{ }%
         \insertpages{\unskip, pp.~}{. }{\unskip. }%
          \insertedition{ }{ edition}{}%
          \insertpublisher{ }{.}{.}%
        }%
        {In \insertcrossref{}{}{}%
         \insertchap{\unskip, }{ }{ }%
         \insertpages{\unskip, pp.~}{. }{\unskip. }%
        }%
   \insertnote{ }{.}{}%
}

\setuppublicationlayout[inproceedings]{%
   \insertauthors{}{ }{}%
   \insertpubyear{(}{). }{}%
   \insertarttitle{\bgroup }{\egroup. }{}%%
   \inserttitle
    {In \inserteditors{}%
        {, a c. di, }%
        {}%
    \bgroup\it}%
    {\egroup
         \insertseries
              {\insertvolume{, number }{~in }{ }}%
              {}%
              {}%
         \insertchap{\unskip, }{ }{ }%
         \insertpages{\unskip, pp.~}{}{}%
         \insertorg{. }{.}{.}%
        }%
        {In \insertcrossref{}{}{}%
         \insertchap{\unskip, }{ }{ }%
         \insertpages{\unskip, pp.~}{. }{\unskip. }%
        }%
   \insertnote{ }{.}{}%
}

\setuppublicationlayout[proceedings]{%
   \inserteditors{}{, a c. di%
                             \ \global\editedbooktrue
                     }{\insertthekey{}{ }{}}%
   \insertpubyear{(}{). }{}%
   \inserttitle
    {\bgroup\it}%
    {\egroup
     \insertseries
        {\insertvolume{, number }{~in }{ }}%
        {}%
        {}%
     \insertchap{\unskip, }{ }{ }%
     \insertpages{\unskip, pp.~}{}{}%
     \insertorg{. }{.}{.}%
    }%
    {}%
   \insertnote{ }{.}{}%
}

\setuppublicationlayout[mastersthesis]{%
   \insertauthors{}{ }{}%
   \insertpubyear{(}{). }{}%
   \inserttitle{\bgroup }{\egroup \insertseries{ (}{)}{}. }{}%
   \insertbibtype{}{, }{Tesi di laurea, }%
   \insertpublisher{ }{.}{.}%
   \insertpages{ }{p. }{}%
   \insertnote{ }{.}{}%
}

\setuppublicationlayout[phdthesis]{%
   \insertauthors{}{ }{}%
   \insertpubyear{(}{). }{}%
   \inserttitle{\bgroup\it }{\egroup \insertseries{ (}{)}{}. }{}%
   \insertbibtype{}{, }{Tesi di dottorato,}%
   \insertpublisher{ }{.}{.}%
   \insertpages{ }{ p. }{}%
   \insertnote{ }{.}{}%
}

\setuppublicationlayout[misc]{%
   \insertauthors{}{ }{\insertthekey{}{. }{}}%
   \insertpubyear{(}{). }{}%
   \inserttitle{\bgroup }{\egroup \insertseries{ (}{)}. }{}%
   \insertpublisher{ }{.}{.}%
   \insertpages{ }{p. }{}%
   \insertnote{ }{.}{}%
}

\setuppublicationlayout[techreport]{%
   \insertauthors{}{ }{}%
   \insertpubyear{(}{). }{}%
   \inserttitle{\bgroup }{\egroup \insertseries{ (}{)}{}. }{}%
   \insertbibtype{}{\insertvolume{ }{, }{, }}{Relazione tecnica}%
   \insertpublisher{ }{.}{.}%
   \insertpages{ }{p. }{}%
   \insertnote{ }{.}{}%
}

\setuppublicationlayout[unpublished]{%
   \insertauthors{}{ }{}%
   \insertpubyear{(}{). }{}%
   \inserttitle{\bgroup }{\egroup \insertseries{ (}{)}{}. }{}%
 % \insertpublisher{ }{.}{.}%
   \insertpages{ }{p. }{}%
   \insertbibtype{(}{)}{}%
   \insertnote{ }{.}{}%
}

\protect
