chap20150917002719代码如下:

\begin{filecontents}{chapterhead.sty}
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{chapterhead}[2012/07/16 v0.0.1 Chapter head and epigraph (AM)]
\RequirePackage{xkeyval}
\RequirePackage{catoptions}
\new@def\chd@alltoendif#1\endif{#1}
\new@def\chd@firsttoendif#1#2\endif{#1}
\new@def*\chdifnumcmpTF#1#2#3{\ifnumcmpTF#1#2{#3}}
% \chdifchoice can be used to define choice keys via command keys:
\new@def*\chdifchoice{\chdifcase\ifstrcmpTF}
\new@def*\chdifcase#1#2{%
 \ifstrcmpTF{#1}\ifnone{%
 \chd@alltoendif
 }{%
 \ifstrcmpTF{#1}\endif{}{%
 \ifstrcmpTF{#2}\ifnone{%
 \chd@alltoendif
 }{%
 \ifstrcmpTF{#2}\endif{}{\chd@ifcase{#1}{#2}}%
 }%
 }%
 }%
}
\new@def*\chd@ifcase#1#2#3{%
 \ifstrcmpTF{#3}\ifnone{%
 \chd@alltoendif
 }{%
 \ifstrcmpTF{#3}\endif{}{%
 #1{#2}{#3}\chd@firsttoendif{\chd@ifcase@i{#1}{#2}}%
 }%
 }%
}
\new@def*\chd@ifcase@i#1#2#3{\chd@ifcase{#1}{#2}}
\define@cmdkey[DKV]{definekeys}[defkey@]{prefix}[KV]{}
\define@cmdkey[DKV]{definekeys}[defkey@]{family}{}
\define@cmdkey[DKV]{definekeys}[defkey@]{holder prefix}[mp@]{}
\define@boolkey[DKV]{definekeys}[defkey@]{initialize}[true]{}
\define@boolkey[DKV]{definekeys}[defkey@]{preset}[true]{}
% Keys not specified in the optional argument of \chddefinekeys will
% get default values:
\presetkeys[DKV]{definekeys}{prefix,family,holder prefix,
 initialize=false,preset=false}{}

\robust@def*\chddefinekeys{\@testopt\chd@definekeys{}}
\new@def*\chd@definekeys[#1]#2{%
 \setkeys[DKV]{definekeys}{#1}%
 \def\defkey@defaultlist{}%
 \edef\reserved@a{\cptcommanormalize{#2}}%
 \expandafter\defkey@loop\reserved@a,\defkey@nil,%
 \ifboolTF{defkey@preset}{%
 \cptexpanded{\noexpand\presetkeys
 [\defkey@prefix]{\defkey@family}{\expandcsonce\defkey@defaultlist}{}%
 }%
 }{}%
 \ifboolTF{defkey@initialize}{%
 \cptexpanded{\noexpand\setkeys
 [\defkey@prefix]{\defkey@family}{\expandcsonce\defkey@defaultlist}%
 }%
 }{}%
}
\begingroup
\lccode`\&=1 \catcode`\&=7
\lowercase{\endgroup
 \new@def*\chd@rejecttoks{&}%
 \new@def*\defkey@loop#1,{%
 \def\reserved@a{\defkey@nil}%
 \edef\reserved@b{\cpttrimspace{#1}}%
 \ifx\reserved@a\reserved@b\expandafter\@gobble\else\expandafter\@iden\fi
 {\defkey@splitatslash#1/&/&/&/&/&/&/&/\defkey@nil\defkey@loop}%
 }
}
\new@def*\chd@cmprejecttoks#1{\ifx#1\chd@rejecttoks\else\expandcsonce#1\fi}
\new@def*\defkey@splitatslash#1/#2/#3/#4/#5/#6/#7/#8/#9\defkey@nil{%
 \edef\keytype{\cpttrimspace{#1}}%
 \edef\keyname{\cpttrimspace{#2}}%
 \edef\keydefault{\cpttrimspace{#3}}%
 \edef\keycode{\cpttrimspace{#4}}%
 \ifx\keyname\chd@rejecttoks
 \@latexerr{Empty key name}\@ehd
 \fi
 \def\reserved@a##1{%
 \def\reserved@a####1##1####2####3\@nil{%
 \def\reserved@a{####2}%
 }%
 \reserved@a cmd{0}bool{1}\@nil
 }%
 \expandafter\reserved@a\expandafter{\keytype}%
 \ifcase\reserved@a\relax
 \let\reserved@a\define@cmdkey
 \or
 \xifinsetTF{,\cptoxdetok\keydefault,}{,\detokenize{true,false},}{%
 \let\reserved@a\define@boolkey
 }{%
 \@latexerr{Illegal default value '\cptoxdetok\keydefault'
 \MessageBreak for bool key '\keyname'}\@ehd
 }%
 \else
 \@latexerr{Illegal key type '#1'}\@ehd
 \fi
 \cptexpanded{\noexpand\reserved@a
 [\defkey@prefix]{\defkey@family}[\usecsn{defkey@holder prefix}]%
 {\chd@cmprejecttoks\keyname}%
 \ifx\keydefault\chd@rejecttoks\else[\expandcsonce\keydefault]\fi
 {\chd@cmprejecttoks\keycode}%
 }%
 \edef\defkey@defaultlist{%
 \ifx\defkey@defaultlist\@empty\else\expandcsonce\defkey@defaultlist,\fi
 \keyname
 \ifx\keydefault\chd@rejecttoks\else=%
 \oifstrcmpTF\keytype{bool}{%
 \oifstrcmpTF\keydefault{true}{false}{false}%
 }{%
 \expandcsonce\keydefault
 }%
 \fi
 }%
}
\chddefinekeys[
 prefix=CHD,family=epigraf,holder prefix=epg@,initialize,preset
]{%
 cmd/width/\hsize,
 cmd/author/,
 cmd/color/black,
 cmd/authorcolor/black,
 bool/use italics for author/true,
 cmd/fontencoding/\encodingdefault,
 cmd/fontfamily/\familydefault,
 cmd/fontseries/\seriesdefault,
 cmd/fontshape/\shapedefault,
 cmd/fontsize/10pt,
 cmd/hskip/0ex,
 cmd/prevskip/0ex,
 cmd/postvskip/1ex,
 bool/frame/true,
}
\chddefinekeys[
 prefix=CHD,family=chapterhead,holder prefix=chd@,initialize,preset
]{%
 cmd/textcolor/black,
 cmd/textfontencoding/\encodingdefault,
 cmd/textfontfamily/\familydefault,
 cmd/textfontseries/eb,
 cmd/textfontshape/\shapedefault,
 cmd/textfontsize/100pt,
 cmd/numberfontencoding/\encodingdefault,
 cmd/numberfontfamily/\familydefault,
 cmd/numberfontseries/eb,
 cmd/numberfontshape/\shapedefault,
 cmd/numberfontsize/100pt,
% cmd/leftmargin/\leftmargin,
% cmd/rightmargin/\rightmargin,
 cmd/texthskip/0em,
 cmd/textprevskip/0ex,
 cmd/textpostvskip/1ex,
 cmd/numberprevskip/0ex,
 cmd/numberpostvskip/0ex,
 cmd/numberhskip/0em,
 cmd/numbercolor/black,
 cmd/pagestyle/empty,
 bool/make text raggedleft/true,
 bool/make number raggedleft/true,
 bool/print number before text/true,
 bool/frame number/true,
 bool/no clear page/true
}
\newbox\chd@boxa
\newcommand\epigraf[2][]{%
 \setkeys[CHD]{epigraf}{#1}%
 \setbox\chd@boxa=\vbox{%
 \ifepg@frame\fbox{\fi
 \parbox\epg@width{%
 \fontsize{\epg@fontsize}{1.5\epg@fontsize}%
 \usefont{\epg@fontencoding}{\epg@fontfamily}%
 {\epg@fontseries}{\epg@fontshape}%
 \ignorespaces
 \textcolor{\epg@color}{#2}%
 \hspace*{\fill}\nolinebreak[1]%
 \quad\hspace*{\fill}\finalhyphendemerits\z@pt\relax
 \begingroup
 \ifboolTF{epg@use italics for author}{\itshape}{}%
 \textcolor{\epg@authorcolor}{\epg@author}%
 \endgroup
 }%
 \ifepg@frame}\fi
 }%
 \global\let\chd@printepigraf\chd@bprintepigraf
 \@ignoretrue
}

\AtBeginDocument{%
 \@ifundefined{@mainmattertrue}{\newif\if@mainmatter\@mainmattertrue}{}%
}
\new@def*\chd@insertchaptertext#1{%
 \begingroup
 \ifboolTF{chd@make text raggedleft}{%
 \raggedleft
 }{%
 \hskip\chd@texthskip\relax
 }%
 \advance\leftmargin10em
 \interlinepenalty\@M
 \vskip\chd@textprevskip\relax
 \fontsize{\chd@textfontsize}{1.2\chd@textfontsize}%
 \usefont{\chd@textfontencoding}{\chd@textfontfamily}%
 {\chd@textfontseries}{\chd@textfontshape}%
 \textcolor{\chd@textcolor}{\ignorespaces#1}%
 \par\nobreak
 \vskip\chd@textpostvskip\relax
 \endgroup
}
\new@def*\chd@insertchapternumber{%
 \begingroup
 \ifnum\c@secnumdepth>\m@ne
 \if@mainmatter
 \vskip\chd@numberprevskip\relax
 \fontsize{\chd@numberfontsize}{1.2\chd@numberfontsize}%
 \usefont{\chd@numberfontencoding}{\chd@numberfontfamily}%
 {\chd@numberfontseries}{\chd@numberfontshape}%
 \usecsn{ifchd@frame number}\fbox{\fi
 \textcolor{\chd@numbercolor}{\thechapter}%
 \usecsn{ifchd@frame number}}\fi
 \par\nobreak
 \vskip\chd@numberpostvskip\relax
 \fi
 \fi
 \endgroup
}
\renewcommand\chapter[1][]{%
 \setkeys[CHD]{chapterhead}{#1}%
 \ifboolTF{chd@no clear page}{}{%
 \if@openright\cleardoublepage\else\clearpage\fi
 }%
 \thispagestyle{\chd@pagestyle}%
 \global\@topnum\z@
 \ifdefTF\chd@printepigraf\chd@printepigraf\relax
 \@afterindentfalse
 \secdef\@chapter\@schapter
}
\renewcommand{\@makechapterhead}[1]{%
 \begingroup
 \begingroup
 \leavevmode
 \ifboolTF{chd@make number raggedleft}{%
 \raggedleft
 }{%
 \hskip\chd@numberhskip\relax
 }%
 \ifboolTF{chd@print number before text}{%
 \chd@insertchapternumber\chd@insertchaptertext{#1}%
 }{%
 \chd@insertchaptertext{#1}\chd@insertchapternumber
 }%
 \endgroup
 \nobreak
 \endgroup
}
\renewcommand{\@makeschapterhead}[1]{%
 \begingroup
 \let\c@secnumdepth\m@ne\@makechapterhead{#1}%
 \endgroup
}
\newcommand*\chd@bprintepigraf{%
 \vskip\epg@prevskip
 \hskip\epg@hskip\relax
 \copy\chd@boxa
 \vskip\epg@postvskip
 \global\let\chd@printepigraf\relax
}
\endinput
\end{filecontents}

\documentclass{book}
\usepackage{chapterhead}
\usepackage[dvipsnames]{xcolor}

\begin{document}
\epigraf[
 author={Lewis Carroll, \textit{Alice in Wonderland}},
 color=blue,
 width=.75\hsize,
 use italics for author=false,
 fontsize=8pt,
 fontfamily=cmr,
 hskip=10em,
 postvskip=2ex,
 frame,
]{
 ``Begin at the beginning,'' the King said, gravely, ``and go on till you
 come to an end; then stop.''
}

\chapter[
 numberpostvskip=.2ex,
 numberfontseries=ux,
 numberfontfamily=cmbr,
 textfontseries=ex,
 textfontsize=50pt,
 textfontfamily=cmbr,
 textfontshape=it,% not obtainable because of other choices above
 textcolor=red,
 make text raggedleft=false,
 make number raggedleft=false,
 print number before text,
 no clear page
]{Graph Theory}

\noindent The Pregolya River passes through the city once known as K\"onigsberg.
In the 1700s seven bridges were situated across this river in a manner similar
to what you see in Figure \ldots

\par\vskip3\baselineskip
\hrule height.5pt depth .4pt \relax

\epigraf[
 author={Lewis Carroll, \textit{Alice in Wonderland}},
 color=black,
 width=.75\hsize,
 use italics for author,
 fontsize=8pt,
 fontfamily=cmr,
 hskip=-3em,
 prevskip=2ex,
 postvskip=2ex,
]{
 ``Begin at the beginning,'' the King said, gravely, ``and go on till you
 come to an end; then stop.''
}

\chapter[
 numberpostvskip=.2ex,
 numberfontseries=ux,
 numberfontfamily=cmbr,
 textfontseries=ex,
 textfontsize=50pt,
 textfontfamily=cmss,
 textfontshape=it,
 textcolor=Brown,
 numbercolor=ForestGreen,
 make text raggedleft,
 make number raggedleft,
 frame number,
 no clear page
]{Graph Theory}

\noindent The Pregolya River passes through the city once known as K\"onigsberg.
In the 1700s seven bridges were situated across this river in a manner similar
to what you see in Figure \ldots
\end{document}

选自:http://tex.stackexchange.com/questions/53377/inspirational-quote-at-start-of-chapter

点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部