\startenvironment entorno
\enableregime[utf]
\mainlanguage[es]
\usemodule[core-math]
\usemodule[math-ext]
\usemodule[tikz]
\usemodule[chart]

\usemodule[bib]
\usemodule[bibltx]
\setupbibtex[database=biblioderecho, sort=author]
\setuppublications[sorttype=bbl, alternative=ama]
\setupcite[authoryears][otherstext={{\it et al.}}]
\setupcite[author][left=,right=,otherstext={{\it et al.}}]

\setupheadtext[en][pubs=Referencias]

\setupinteraction[state=start]

\definereferenceformat
  [eqref]
  [left=\normal(,
   right=)]

%%%%%% para refenrenciar f��rmulas 
%\placeformula[tag] \startformula
%   E = mc^2
%\stopformula
%And then \eqref[tag]..
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\tablebrace#1#2%
  {$\left.\vrule width\zeropoint height#1\right\{ \text{#2}$}

%\setupframed[align=middle,offset=1pt,framecorner=round]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\startuseMPgraphic{mpos:par:columnset} % Shift underlining down a touch
   \iftracepositions show_multi_pars \else draw_multi_pars \fi ;
   path p ; p := boundingbox currentpicture ;
   currentpicture := currentpicture shifted (0,-StrutDepth/3) ;
   setbounds currentpicture to p ;
\stopuseMPgraphic

\definetextbackground[Sub]
  [location=text,alternative=1,background=,frame=off]
\definestartstop
  [underline]
  [before={\starttextbackground[Sub]},
   after=\stoptextbackground]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\startalign{\startformula
  \let\\\cr
  \null\vcenter\bgroup
  \openup\jot {\mathsurround=0pt}%
  \everycr={}\tabskip=4pt plus1fil%
  \halign to \displaywidth\bgroup
      \strut\hfil$\displaystyle{##}$%
      \tabskip=0pt &$\displaystyle{{}##}$\hfil%
      \tabskip=4pt plus1fil &&\hfil$\displaystyle{##}$%
      \tabskip=0pt &$\displaystyle{{}##}$\hfil%
      \tabskip=4pt plus1fil \crcr}
\def\stopalign{\crcr\crcr\egroup\egroup\stopformula}

\def\startgather{\startformula
  \let\\\cr
  \null\,\vcenter\bgroup
  \openup\jot {\mathsurround=0pt}%
  \ialign\bgroup
      \strut\hfil$\displaystyle{##}$\hfil
      \crcr}
\def\stopgather{\crcr\crcr\egroup\egroup\,%
  \stopformula}
\def\startsplit{%
  \let\\\cr
  \null\,\vcenter\bgroup
  \openup\jot {\mathsurround=0pt}%
  \ialign\bgroup
     \strut\hfil$\displaystyle{##}$%
     &$\displaystyle{{}##}$\hfil
     \crcr}
\def\stopsplit{\crcr\egroup\egroup\,}

\def\AC{{ \setupbodyfont[12pt]{\sl a.\sc \sl C.}\hbox{} }}
\def\DC{{ \setupbodyfont[12pt]{\sl d.\sc \sl C.}\hbox{} }}
\def\c��{Constituci��n}
\def\Lat{\doLat}
\def\doLat#1{{\bf {\em #1}}}
\def\CE{\doCE}
\def\doCE#1{Art��culo #1 CE}
\def\CC{\doCC}
\def\doCC#1{Art��culo #1 CC}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%  \def\Diario{\doDiario}
%   \def\doDiario#1#2#3#4{\blank[2*big]\bTABLE[offset=5pt,width=.22\textwidth,frame=off,align=middle,bottomframe=on,topframe=on]
%   \bTR\bTD[align=rigth]#1\eTD\bTD[align=rigth]#2\eTD\bTD ----- A -----\eTD\bTD[align=left]#3\eTD\bTD[align=left]#4\eTD
%   \eTR
%   \eTABLE \blank[big]
%   }

% \def\Mayor{\doMayor}
% \def\doMayor#1#2#3#4#5#6#7#8
% {\bTABLE
% \setupTABLE[row][align=left,width=.25\textwidth,frame=off]
% \bTR \bTD[nx=3,bottomframe=on,align=middle]#1\eTD\eTR 
% \bTR \bTD[rightframe=on]
%  #2 \eTD\bTD 
%  #3 \eTD\eTR
% \bTR \bTD[rightframe=on]
%  #4 \eTD\bTD 
%  #5 \eTD\eTR
% %%%TOTALES
% \bTR\bTD[rightframe=on,topframe=on] 
% #6\eTD\bTD[topframe=on] 
% #7\eTD
% \bTD[topframe=on,leftframe=on,align=left]Saldo=#8
%  \eTD\eTR
% \eTABLE
% }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setupcolors[state=start]      
\definecolor[headingcolor][r=0,g=0,b=0]

\setupinteraction[state=start,color=blue]

 \def\insertdoi#1#2#3%
     {{\bibdoifelse{\@@pb@doi}%
        {\edef\ascii{\@EA\detokenize\@EA{\@@pb@doi}}%
         #1\expanded{\gotoDOI{\@@pb@thekey}{\ascii}}#2}{#3}}}

   \def\insertbiburl#1#2#3%
     {{\bibdoifelse{\@@pb@biburl}%
        {\edef\ascii{\@EA\detokenize\@EA{\@@pb@biburl}}%
         #1\expanded{\gotoURL{\@@pb@thekey}{\ascii}}#2}{#3}}}

\setuppapersize[A4][A4]
 \setuplayout[topspace=0.5in, backspace=1in, header=24pt, footer=36pt,
   height=middle, width=middle]

\setupfootnotes[bodyfont=10pt]
\setupfooter[style=\it]
\setupfootertexts[]
\setuppagenumbering[location={footer,right}, style=bold]

%definici�� dels tipus de lletra
%\usetypescript[modern][ec]		
%\usetypescript[berry][ec] 		
\usetypescript[palatino][ec] 	

%\definetypeface[charter][rm][serif][charter][default][encoding=ec]
%\definetypeface[bookman][rm][serif][bookman][default][encoding=ec]
%\definetypeface[utopia][rm][serif][utopia][default][encoding=ec]
\definetypeface[palatino][ppl][serif][utopia][default][encoding=ec]

%\usetypescript[postscript][\defaultencoding]
%\setupencoding[default=texnansi]
%\setupbodyfont[postscript,12pt]
%\setupbodyfont[12pt]

\setupinterlinespace[big]
\setupwhitespace[medium]
%\setupindenting[small,yes]

\setupitemize[inbetween={},style=bold,identnext=no,]
%% 1 redondo negro, 2 gui��n, 3 asterisco, 4 tr��ngulo vac��o, 5 circulo
%% peque��o vac��o, 6 circulo grande vac��o, 7 circulo m��s grande vac��o,
%% 8 cuadrado vac��o
\setupitemize[1][
1%n
,packed][width=10pt,margin=5pt,after={\blank[10pt]},before={\blank[10pt]}]

\setupitemize[2][
2%a
,packed][width=10pt,after={\blank[10pt]},before={\blank[10pt]},left=,right=.,stopper=]

\setupitemize[3][
3%r
,packed][width=10pt,left=,right=]

\setupitemize[4][
4%i
,packed][width=10pt,left=,right=] 

\setupheadtext[en][pubs=Referencias]

\def\Dot#1{#1.}

\setuphead[title][part, style={\bfa},
  before={\begingroup\setupbodyfont[20pt]},
  after={\centerline{\tfa}
         \bigskip\bigskip\endgroup}]


\setuphead[chapter][style={\bfd},
,numbercommand=\Dot%,numbercommand={\groupedcommand{}{.}}
]

\setuphead[section,subject][%
%textcommand=\underbar,
style={\bfa},
  before={\blank[10pt]}, after={\blank[10pt]}
,numbercommand=\Dot%,numbercommand={\groupedcommand{}{.}}
]




\setuphead[subsection][
 textcommand=\underbar,
 style={\sl},
 before={\blank[8pt]}, after={\blank[8pt]},
 numbercommand=\Dot%,numbercommand={\groupedcommand{}{}}
]

\def\MyHeader#1#2{%
    \framedtext
        [width= \overlaywidth,
          height=\bodyfontsize,
          offset=0pt,
          strut=no,
          frame=on,
        align=right
        ]
        {\headtext{subsection}#1#2}}


\setuphead[subsubsection,subject][%
%textcommand=\underbar,
style={\sl},
before={\blank[6pt]}, after={\blank[6pt]}
,numbercommand=\Dot%,numbercommand={\groupedcommand{}{.}}
]

 \setupinteraction[state=start,color=blue]
 \setuplist[chapter][alternative=f,style=bold,interacction=all,after={\medskip}]
 \setuplist[section,figure,table][alternative=f,style=bold,interacction=all,after={\medskip},margin=15pt]
 \setuplist[subsection][alternative=f,style=slanted,interacction=all,after={\medskip},margin=25pt]

%%%%%%    otro tipo de indice de materias
% \setuphead[chapter][number=yes,textcommand=\tfb]
% \setuphead[section][number=yes,textcommand=\bf]
% \setuphead[subsection][number=yes]
% \setuphead[subsubsection][number=yes]


% \setupinteraction[state=start,color=blue]
% \setuplist[chapter][alternative=f,style=bold,interaction=all]
% \setuplist[section][alternative=f,style=bold,interaction=all]
% \setuplist[subsection][alternative=f,interaction=all]
% \setuplist[subsubsection][alternative=a,interaction=all]

% \setuppublications[alternative=apa]
% \setuppublicationlayout[article]{%
%    \insertartauthors{}{ }{\insertthekey{}{ }{}}%
%    \insertpubyear{(}{). }{\unskip.}%
%    \insertarttitle{\bgroup }{\egroup. }{}%
%    \insertjournal{\bgroup \it}{\egroup}
%     {\insertcrossref{En }{}{}}%
%    \insertvolume
%     {, }
%     {\insertissue{(}{)}{}\insertpages{:}{.}{.}}
%     {\insertpages{, p��ginas }{.}{.}}%
%    \insertnote{ }{.}{}%
%    \insertcomment{}{.}{}%
% }

% \setuppublicationlayout[book]{%
%    \insertauthors{}{ }{\insertthekey{}{ }{}}%
%    \insertpubyear{(}{). }{\unskip.}%
%    \inserttitle{\bgroup }{\egroup, }{}%
%     {\insertcrossref{En }{}{}}%
%    \insertvolume {vol }
%     {\insertissue{(}{)}{}\insertpages{:}{.}{.}}
%     {\insertpages{ p��ginas }{.}{.}}%
%    \insertnote{ }{.}{}%
%    \insertcomment{}{.}{}%
% }

\setupcaptions[location=top]

\switchtobodyfont[palatino]

\stopenvironment


