为了养成良好的习惯,我们把 ConTeXt 文档拆分到几个单独的
.tex
文件中,这样维护起来比较方便。
首先是主文档 product.tex
[73],生成 PDF 只要编译此文件即可
%%%%%此文件使用 product 环境,起始声明 \startproduct{} %%%导言区使用 \environment 载入文件 %载入样式文件 style.tex \environment style %载入词汇定义文件 gloss.tex \environment gloss %%%正文起始 \starttext %%%正文区使用 \component 载入文件 %封面 cover.tex \component cover %目录 \title{目录} \placecontent %%正文内容 %载入章节 1.tex 2.tex 3.tex \component 1 \component 2 \component 3 %%%正文结束 \stoptext %%%%% product 环境结束声明 \stopproduct
在导言区载入的文件,要使用 environment
环境,例如样式定义文件 style.tex
\startenvironment{} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 中文设置 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usetypescriptfile[zhfonts] %加载打印字体配置文件(typescript) zhfonts.tex \usetypescript[myscript] %使用打印字体配置文件中定义打印字体的脚本 myscript \setupbodyfont[myfont,rm,11pt] %设置正文字体 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 正文 标题 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 启用颜色模式, 设置链接文本颜色 \setupcolors[state=start] \definecolor[linktext][darkred] \setupinteraction[state=start,color=linktext] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %正文 \setupindenting[always,2em,first] %设置中文缩进格式(首行缩进两字) \setupheads[indentnext=yes] %每节的首段也要缩进 \setupinterlinespace[big] %设置行距(big=1.5倍) \setupwhitespace[small] %设置段间距[small, medium, big] %标题 \setupheads[indentnext=yes] \setuphead [chapter] [style=\bfc,header=empty,footer=empty] \setuphead [section] [style=\bfa] \setuphead [title] [style=\bfb,header=empty,foote=empty] \setuphead [subsubject] [style=\bf] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 页面设置 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %定义页面尺寸为 SCREEN \definepapersize[mySCREEN][width=21cm,height=29.7cm] %纸张尺寸,通常和页面尺寸相同。(除非在印刷用纸上实现多页排版) \setuppapersize[SCREEN][mySCREEN] %布局 \setuplayout [width=fit, height=middle, leftmargin=3cm, rightmargin=3cm, backspace=4cm, topspace=.5cm, headerdistance=.4cm, footerdistance=.4cm, header=1cm, footer=1cm] %去掉页眉正中 自动添加的页码 \setuppagenumbering [style=\tfx,location=] %页眉 \def\CurrentChapter{% 第 \headnumber[chapter]\ 章% \hbox to 2em{}% \getmarking[chapter]% } \def\CurrentSection{% \headnumber[section]% \hbox to 2em{}% \getmarking[section]% } \setupheadertexts [\CurrentChapter][pagenumber] [pagenumber][\CurrentSection] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %边注 \setupinmargin[left,right][style=\tfx] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %PDF 阅读器中自适应页宽 \setupinteraction[state=start,openaction=FitWidth] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 目录 书签 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 启用书签功能 \setupinteraction[state=start] \setupinteractionscreen[option=bookmark] \placebookmarks[chapter,section,subsection][chapter] %%%经典目录样式 %% turn off numbering of some levels %\setuphead[subsection][number=no] %\setuphead[subsubsection][number=no] %% TOC %% level=4, \subsubsubsections are not listed in TOC %% alternative=c, space to the page number is filled with dots %\setupcombinedlist[content][level=4,alternative=c] %%\setuplist[chapter][width=5mm,style=bold] %\setuplist[section][width=10mm,style=bold] %\setuplist[subsection][width=20mm] %% pagestyle=normal for changing the appearance of pagenumber %\setuplist[subsubsection][width=20mm,style=slanted,pagestyle=normal] %目录样式 \def\ChapterNumber#1{\doiftext{#1}{第\;#1\;章\quad}} \setuplist [chapter] [alternative=a, before={\page[preference]\blank}, after=\blank, style=bold, width=fit, pagestyle=boldslanted, pagenumber=no, numbercommand=\ChapterNumber] \def\PageNumber#1{\color[darkgray]{#1}.} \setuplist [section] [alternative=d, style=small, pagecommand=\PageNumber, pagestyle=\itx] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \stopenvironment
词汇定义文件 gloss.tex
\startenvironment{} %使用命令 \hello{mom} %得到 Good morning mom \define[1]\hello{Good morning, #1} %使用命令 \lxsc %得到 《开源世界旅行手册》 \define\lxsc{《开源世界旅行手册》} \stopenvironment
章节放在单独的文件中,例如 1.tex
\startcomponent{} \chapter{第一章} ConTeXt 组件文档 \stopcomponent