项目管理

为了养成良好的习惯,我们把 ConTeXt 文档拆分到几个单独的 .tex 文件中,这样维护起来比较方便。

首先是主文档 product.tex[73],生成 PDF 只要编译此文件即可

  1. %%%%%此文件使用 product 环境,起始声明
  2. \startproduct{}
  3. %%%导言区使用 \environment 载入文件
  4. %载入样式文件 style.tex
  5. \environment style
  6. %载入词汇定义文件 gloss.tex
  7. \environment gloss
  8. %%%正文起始
  9. \starttext
  10. %%%正文区使用 \component 载入文件
  11. %封面 cover.tex
  12. \component cover
  13. %目录
  14. \title{目录}
  15. \placecontent
  16. %%正文内容
  17. %载入章节 1.tex 2.tex 3.tex
  18. \component 1
  19. \component 2
  20. \component 3
  21. %%%正文结束
  22. \stoptext
  23. %%%%% product 环境结束声明
  24. \stopproduct

在导言区载入的文件,要使用 environment 环境,例如样式定义文件 style.tex

  1. \startenvironment{}
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. % 中文设置 %
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5. \usetypescriptfile[zhfonts] %加载打印字体配置文件(typescript) zhfonts.tex
  6. \usetypescript[myscript] %使用打印字体配置文件中定义打印字体的脚本 myscript
  7. \setupbodyfont[myfont,rm,11pt] %设置正文字体
  8. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. % 正文 标题 %
  10. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  11. % 启用颜色模式, 设置链接文本颜色
  12. \setupcolors[state=start]
  13. \definecolor[linktext][darkred]
  14. \setupinteraction[state=start,color=linktext]
  15. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  16. %正文
  17. \setupindenting[always,2em,first] %设置中文缩进格式(首行缩进两字)
  18. \setupheads[indentnext=yes] %每节的首段也要缩进
  19. \setupinterlinespace[big] %设置行距(big=1.5倍)
  20. \setupwhitespace[small] %设置段间距[small, medium, big]
  21. %标题
  22. \setupheads[indentnext=yes]
  23. \setuphead
  24. [chapter]
  25. [style=\bfc,header=empty,footer=empty]
  26. \setuphead
  27. [section]
  28. [style=\bfa]
  29. \setuphead
  30. [title]
  31. [style=\bfb,header=empty,foote=empty]
  32. \setuphead
  33. [subsubject]
  34. [style=\bf]
  35. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  36. % 页面设置 %
  37. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  38. %定义页面尺寸为 SCREEN
  39. \definepapersize[mySCREEN][width=21cm,height=29.7cm]
  40. %纸张尺寸,通常和页面尺寸相同。(除非在印刷用纸上实现多页排版)
  41. \setuppapersize[SCREEN][mySCREEN]
  42. %布局
  43. \setuplayout
  44. [width=fit,
  45. height=middle,
  46. leftmargin=3cm,
  47. rightmargin=3cm,
  48. backspace=4cm,
  49. topspace=.5cm,
  50. headerdistance=.4cm,
  51. footerdistance=.4cm,
  52. header=1cm,
  53. footer=1cm]
  54. %去掉页眉正中 自动添加的页码
  55. \setuppagenumbering
  56. [style=\tfx,location=]
  57. %页眉
  58. \def\CurrentChapter{%
  59. \headnumber[chapter]\ 章%
  60. \hbox to 2em{}%
  61. \getmarking[chapter]%
  62. }
  63. \def\CurrentSection{%
  64. \headnumber[section]%
  65. \hbox to 2em{}%
  66. \getmarking[section]%
  67. }
  68. \setupheadertexts
  69. [\CurrentChapter][pagenumber]
  70. [pagenumber][\CurrentSection]
  71. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  72. %边注
  73. \setupinmargin[left,right][style=\tfx]
  74. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  75. %PDF 阅读器中自适应页宽
  76. \setupinteraction[state=start,openaction=FitWidth]
  77. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  78. % 目录 书签 %
  79. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  80. % 启用书签功能
  81. \setupinteraction[state=start]
  82. \setupinteractionscreen[option=bookmark]
  83. \placebookmarks[chapter,section,subsection][chapter]
  84. %%%经典目录样式
  85. %% turn off numbering of some levels
  86. %\setuphead[subsection][number=no]
  87. %\setuphead[subsubsection][number=no]
  88. %% TOC
  89. %% level=4, \subsubsubsections are not listed in TOC
  90. %% alternative=c, space to the page number is filled with dots
  91. %\setupcombinedlist[content][level=4,alternative=c]
  92. %%\setuplist[chapter][width=5mm,style=bold]
  93. %\setuplist[section][width=10mm,style=bold]
  94. %\setuplist[subsection][width=20mm]
  95. %% pagestyle=normal for changing the appearance of pagenumber
  96. %\setuplist[subsubsection][width=20mm,style=slanted,pagestyle=normal]
  97. %目录样式
  98. \def\ChapterNumber#1{\doiftext{#1}{第\;#1\;章\quad}}
  99. \setuplist
  100. [chapter]
  101. [alternative=a,
  102. before={\page[preference]\blank},
  103. after=\blank,
  104. style=bold,
  105. width=fit,
  106. pagestyle=boldslanted,
  107. pagenumber=no,
  108. numbercommand=\ChapterNumber]
  109. \def\PageNumber#1{\color[darkgray]{#1}.}
  110. \setuplist
  111. [section]
  112. [alternative=d,
  113. style=small,
  114. pagecommand=\PageNumber,
  115. pagestyle=\itx]
  116. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  117. \stopenvironment

词汇定义文件 gloss.tex

  1. \startenvironment{}
  2. %使用命令 \hello{mom}
  3. %得到 Good morning mom
  4. \define[1]\hello{Good morning, #1}
  5. %使用命令 \lxsc
  6. %得到 《开源世界旅行手册》
  7. \define\lxsc{《开源世界旅行手册》}
  8. \stopenvironment

章节放在单独的文件中,例如 1.tex

  1. \startcomponent{}
  2. \chapter{第一章}
  3. ConTeXt 组件文档
  4. \stopcomponent

[73] 文件名任意