\startenvironment doc-env

\usemodule[zhfonts]

\usemodule[chart]
\usemodule[t][layout]

\setupcolor[hex]
\definecolor [BackgroundColor] [h=cccccc]
\definecolor [OrnamentColor]   [h=99ccff]
\definecolor [TitleColor] [h=336699]

\setupinteraction
        [state=start,
		 focus=standard,
		 color=darkblue,
         title={ConTeXt 学习笔记},
         subtitle={Using MkIV},
         author={Li Yanrui},
         keyword={TeX, ConTeXt, MkIV, LuaTeX}]

%\setupinteractionscreen[option=max]

\setuppapersize[A4][A4]
\setuplayout[width=fit,height=middle,
             leftmargin=2cm,rightmargin=2cm,
             backspace=2.5cm,topspace=2cm,
             headerdistance=.5cm,footerdistance=.5cm,
	         leftmargindistance=.5cm,rightmargindistance=.5cm,
             header=1cm,footer=1cm]
\setuppagenumbering[style=\tfx,location=]

\setuptolerance[horizontal, stretch]

% 图片目录
\setupexternalfigures[directory={./figures}]

%-------- 标题设置 --------
\setupheads[indentnext=yes]

\setuphead[title][style=\bfb,align={broad,middle},header=empty,foote=empty]
\setuphead[chapter][style=\bfb,header=empty,footer=empty]
\setuphead[section][style=\bfa]
\setuphead[subsubject][style=\bf]

% 代码环境
\setuplinenumbering[color=darkgray,style=small]
\setuptyping[option=color,palet=graypretty,
	     before={\blank[.5em]\setupinterlinespace[line=1.2em]},
             after={\blank[.5em]}]

\definetyping[niceTEX][option=TEX]

%-------- 中文化 --------
\setuplabeltext [en] [chapter={第\;,\;章}]
\setuplabeltext [en] [figure=图\;]
\setuplabeltext [en] [table=表\;]
\setupheadtext[en][pubs={\bfc 参考文献}]
\setupheadtext[en][content={\bfc 目录}]

%% 目录 %%
\def\ChapterNumber#1{\doiftext{#1}{第\;#1\;章\quad}}
\setuplist
    [chapter]
    [alternative=a,
     before=\blank,
     after=\blank,
     style=\bf,
     width=fit,
     pagestyle=boldslanted,
     pagenumber=no,
     numbercommand=\ChapterNumber]

\def\PageNumber#1{\underbars{#1}.}
\setuplist
    [section]
    [alternative=d,
     style=normal,
     pagecommand=\PageNumber,
     pagestyle=\itx]

% 页眉页脚
\startsetups HeaderFooter
        \def\CurrentChapter{%
                第 \headnumber[chapter]\ 章%
                \hbox to 2em{}%
                \getmarking[chapter]%
                }
        \def\CurrentSection{%
                \headnumber[section]%
                \hbox to 2em{}%
                \getmarking[section]%
                }
        \setupheadertexts
                [\CurrentChapter][pagenumber]
                [pagenumber][\CurrentSection]
        \setupheader[style=\bfx,color=darkgray]
\stopsetups

% 书签
\setupinteractionscreen[option=bookmark]
\placebookmarks[chapter,section][chapter]

% 参考文献
\setupbibtex[database=bibliography]
\setuppublications[alternative=lyr]

%---- 其它一些零碎设置 ----
\setupinterlinespace[line=1.5em]
\setupwhitespace[big]

\setupfloats[indentnext=yes] 
\setupcaptions[style=\tfx, headstyle=\normal]

\setupitemize[each][packed,serried,inmargin][margin=2em]

\setupfootnotes[way=bychapter]

\setupinmargin[left,right][style=\tfx]

\definedescription[definition]
        [location=top,hang=20,width=broad,indenting=always,style=\ss,headstyle=\bf]

\def\mycite#1{\cite[#1]}

%% 阴影盒

\startuniqueMPgraphic{shade box}
    path p;
    u := 1cm; w := \overlaywidth; h := \overlayheight;
    roundcorner := 8pt; offset := 12pt;
    
    color shade;
    shade := (.6,.6,.6);

    for i = 0 step .02 until 1:
        fill unitsquare xyscaled (w-i*u,h-i*u) squeezed (8pt,6pt) 
             shifted (offset+i*u/2,-offset+i*u/2)
             withcolor transparent (1,.1,shade);
    endfor;

    p := unitsquare xyscaled (w, h);
    draw p withcolor transparent (1,0,white);

    p := p shifted (offset/2, -offset/2) squeezed (8pt,6pt);
    fill p withcolor \MPcolor{darkgray};
    draw p withcolor \MPcolor{OrnamentColor};
\stopuniqueMPgraphic

\defineoverlay[shade box][\uniqueMPgraphic{shade box}]
\setupframedtexts[frame=off,background={shade box}]

\stopenvironment
