From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- info/context-notes-zh-cn/README | 12 + info/context-notes-zh-cn/ctxnotes.pdf | Bin 0 -> 738337 bytes info/context-notes-zh-cn/src/Makefile | 22 + info/context-notes-zh-cn/src/basis.tex | 242 +++++++++++ info/context-notes-zh-cn/src/bibl-lyr.tex | 77 ++++ info/context-notes-zh-cn/src/bibliography.bib | 53 +++ info/context-notes-zh-cn/src/ctxnotes.tex | 88 ++++ info/context-notes-zh-cn/src/doc-env.tex | 153 +++++++ info/context-notes-zh-cn/src/figures/bookmark.png | Bin 0 -> 33739 bytes info/context-notes-zh-cn/src/figures/cow.pdf | Bin 0 -> 5526 bytes .../src/figures/gardeninglion.jpg | Bin 0 -> 59719 bytes info/context-notes-zh-cn/src/figures/header.png | Bin 0 -> 30981 bytes info/context-notes-zh-cn/src/fonts.tex | 219 ++++++++++ info/context-notes-zh-cn/src/layout.tex | 233 +++++++++++ info/context-notes-zh-cn/src/metafun.tex | 463 +++++++++++++++++++++ info/context-notes-zh-cn/src/project.tex | 67 +++ info/context-notes-zh-cn/src/references.tex | 362 ++++++++++++++++ info/context-notes-zh-cn/src/t-layout.tex | 411 ++++++++++++++++++ info/context-notes-zh-cn/src/t-zhfonts.lua | 272 ++++++++++++ info/context-notes-zh-cn/src/t-zhfonts.mkiv | 37 ++ info/context-notes-zh-cn/src/t-zhspuncs.lua | 178 ++++++++ 21 files changed, 2889 insertions(+) create mode 100644 info/context-notes-zh-cn/README create mode 100644 info/context-notes-zh-cn/ctxnotes.pdf create mode 100644 info/context-notes-zh-cn/src/Makefile create mode 100644 info/context-notes-zh-cn/src/basis.tex create mode 100644 info/context-notes-zh-cn/src/bibl-lyr.tex create mode 100644 info/context-notes-zh-cn/src/bibliography.bib create mode 100644 info/context-notes-zh-cn/src/ctxnotes.tex create mode 100644 info/context-notes-zh-cn/src/doc-env.tex create mode 100644 info/context-notes-zh-cn/src/figures/bookmark.png create mode 100644 info/context-notes-zh-cn/src/figures/cow.pdf create mode 100644 info/context-notes-zh-cn/src/figures/gardeninglion.jpg create mode 100644 info/context-notes-zh-cn/src/figures/header.png create mode 100644 info/context-notes-zh-cn/src/fonts.tex create mode 100644 info/context-notes-zh-cn/src/layout.tex create mode 100644 info/context-notes-zh-cn/src/metafun.tex create mode 100644 info/context-notes-zh-cn/src/project.tex create mode 100644 info/context-notes-zh-cn/src/references.tex create mode 100644 info/context-notes-zh-cn/src/t-layout.tex create mode 100644 info/context-notes-zh-cn/src/t-zhfonts.lua create mode 100644 info/context-notes-zh-cn/src/t-zhfonts.mkiv create mode 100644 info/context-notes-zh-cn/src/t-zhspuncs.lua (limited to 'info/context-notes-zh-cn') diff --git a/info/context-notes-zh-cn/README b/info/context-notes-zh-cn/README new file mode 100644 index 0000000000..eb41b59ff0 --- /dev/null +++ b/info/context-notes-zh-cn/README @@ -0,0 +1,12 @@ +This is an introductory tutorial on ConTeXt in Chinese written by Yanrui Li. + +ConTeXt installation, fonts, layout design, cross-reference, project structure, metafun are covered in this tutorial. + +This package is licensed in GFDL (GNU Free Documentation License). + +If you are interested in the process of development you may observe + + http://code.google.com/p/ctex-doc/updates/list + +Report feedback in the Issues section of ctex-doc project, +or in http://bbs.ctex.org forum. diff --git a/info/context-notes-zh-cn/ctxnotes.pdf b/info/context-notes-zh-cn/ctxnotes.pdf new file mode 100644 index 0000000000..5b13416d1e Binary files /dev/null and b/info/context-notes-zh-cn/ctxnotes.pdf differ diff --git a/info/context-notes-zh-cn/src/Makefile b/info/context-notes-zh-cn/src/Makefile new file mode 100644 index 0000000000..f49149b0dc --- /dev/null +++ b/info/context-notes-zh-cn/src/Makefile @@ -0,0 +1,22 @@ +PRODUCT=ctxnotes +READER=evince + +all: + context --mode=screen $(PRODUCT) + +print: + context --mode=print $(PRODUCT) + context --purge + +bib: + context --mode=screen --once $(PRODUCT) \ + && bibtex $(PRODUCT) \ + && context --mode=screen $(PRODUCT) + +pdf: + $(READER) $(PRODUCT).pdf & + +clean: + context --purge + rm -f *.aux *.bbl *.blg + rm -f *.pdf diff --git a/info/context-notes-zh-cn/src/basis.tex b/info/context-notes-zh-cn/src/basis.tex new file mode 100644 index 0000000000..6d1e46590b --- /dev/null +++ b/info/context-notes-zh-cn/src/basis.tex @@ -0,0 +1,242 @@ +\startcomponent basis +\product ctxnotes + +\chapter{让 \CONTEXT\ 工作起来} +\bookmark{让 ConTeXt 工作起来} + +目前,只有 \ConTeXt\ Minimals(\ConTeXt\ 最小包)提供了最新的 ConTeXt 版本并且可以使之与系统所安装的其它 TeX 发行版友好共存。本章介绍 \ConTeXt\ Minimals 的安装、基本使用以及 MkIV 的中文支持等知识,目的在于让你多快好省地拥有一个 \CONTEXT\ 文档编译环境。本章的最后介绍了一些初学者应当阅读的文档以及一些学习资源。 + +\section[installmkiv]{\ConTeXt\ Minimals} +\bookmark{ConTeXt Minimals} + +首先,在本地机器上创建一个 \ConTeXt\ 安装目录,该目录的位置与名字视个人嗜好而定,我喜欢用 \type{/opt/context}。为了不引起混乱,下文提及 \ConTeXt\ 安装目录皆以如下设定的 Bash 变量 \type{$CTXDIR} 代替: + +\starttyping +$ export CTXDIR=/opt/context +$ mkdir -p $CTXDIR +\stoptyping + +然后下载 ConTeXt 最小包安装脚本,将其存放于 \type{$CTXDIR} 目录并执行: + +\starttyping +$ cd $CTXDIR +$ rsync -ptv \ +rsync://contextgarden.net/minimals/setup/linux/first-setup.sh . +$ ./first-setup.sh +\stoptyping + +由于安装脚本需要联网下载 \ConTeXt\ Minimals,需要等待一段时间才可以完成安装。这段时间,你可以做点自己喜欢做的事情。 + +\ConTeXt\ Minimals 安装完毕后,就开始进行 \ConTeXt\ 运行环境的配置,这需要设置许多的系统环境变量。不过莫要担心,\ConTeXt\ Minimals 提供了一个配置脚本,使用 source(亦称点命令)命令加载该文件即可完成所有 \ConTeXt\ 所需环境变量的设定。 + +\starttyping +$ . $CTXDIR/tex/setuptex $CTXDIR/tex +\stoptyping + +上述命令行可将 setuptex 配置文件中的诸多环境变量的设定在当前终端环境中保持有效性。这意味着,每次使用 \ConTeXt\ Minimals,可以开一个终端窗口,然后执行一次上述命令,之后就可以在该终端中使用 \ConTeXt\ 环境。如果需要使用系统所安装的其它 \TeX\ 发行套件,可另建一个未开启 \ConTeXt\ 环境的终端即可。 + +虽然每次启用 \ConTeXt\ Minimals 所输入的命令行并不复杂,但是尽力让命令行简约且易于输入一向是 Unix-like 系统的光荣传统,因此我在 \type{$HOME/myscript} 目录下建立了一个配置文件 ctx,该文件内容如下: + +\starttyping +export TEXDIR=/opt/context/tex +source $TEXDIR/setuptex $TEXDIR +export OSFONTDIR="/usr/share/fonts/{adobe,winfonts}" +\stoptyping + +然后将 \type{$HOME/myscript} 目录添加到系统环境变量 \type{$PATH} 并使之生效: + +\starttyping +$ echo "PATH=$PATH:$HOME/myscript" >> ~/.bashrc +$ . ~/.bashrc +\stoptyping + +这样,以后每次启用 \ConTeXt\ 环境时,只需执行以下命令: + +\starttyping +$ . ctx +\stoptyping + +注意,在 ctx 文件中设置了 \type{$OSFONTDIR} 变量,该变量的意义在下一章讲述 MkIV 中文排版时会进行详细阐述,现在可不予理会。 + +使用 \type{ctxtools} 命令并配合 \type{-updatecontext} 参数可对所安装的 \ConTeXt\ Minimals 进行在线升级,不过前提是要建立 \type{$TEXMFLOCAL} 目录。因为 \ConTeXt\ Minimals 升级包是一个 zip 压缩档,升级时会将该压缩档下载到 \type{$TEXMFLOCAL} 目录并进行解压缩。 + +\CONTEXT\ Minimals 的升级很简单,那就是再重装一遍。 + +\section{若需要 \TeX\ 与 \LaTeX} +\bookmark{若需要 TeX 与 LaTeX} + +\ConTeXt\ Minimals 可以与其它 \TeX\ 发行套件友好共存。最近,我打算使用 \XeTeX\ + plain \TeX\ 格式写一份文档,但是 \ConTeXt\ Minimals 默认未提供 \XeTeX\ 的 plain \TeX\ 格式并且缺乏一些 plain \TEX\ 必须的字体,因此基于 \XeTeX\ 的 plain \TEX\ 及 \LATEX\ 环境均无法正常运行。对于这个问题,我能想到的比较轻省的解决方案是安装一个 \TeX\ Live 2008,使用它所包含的 plain \TeX\ 环境,另外再安装一个 \LATEX\ 环境以备不时之需。 + +首先从清华的 CTAN 镜像 FTP 服务器下载 \TEX\ Live 2008 的网络安装程序并解包: + +\starttyping +$ wget ftp://ftp.tsinghua.edu.cn/mirror/CTAN/systems/texlive/\ +tlnet/tldev/install-tl-unx.tar.gz +$ tar -zxvf install-tl-unx.tar.gz && cd install-tl-unx +\stoptyping + +\TEX\ Live 2008 的安装程序兼顾了不同用户的软件使用习惯,同时提供了文本界面与图形界面两种安装模式: + +\starttyping +$ install-tl # 文本界面安装 +$ install-tl --gui # 图形界面安装模式 +\stoptyping + +\type{install-tl} 程序在运行时会自动访问预设定的 CTAN 镜像 FTP 服务器,如果连接失败,安装过程也就终止了。对于国内用户,可以通过 \type{--location} 参数将 CTAN 镜像服务器设为清华的 FTP: + +\starttyping +$ install-tl --location=ftp://ftp.tsinghua.edu.cn/\ +mirror/CTAN/systems/texlive/tlnet/tldev +\stoptyping + +如果网速足够,那么应当很快就可以在终端中显示文本安装界面了,具体的安装过程应当参考 \TEX\ Live 2008 中文指南\footnote{http://tug.org/texlive/doc/texlive-zh-cn/}。\TEX\ Live 2008 成功安装后,只要不在终端中开启 \ConTeXt\ Minimals 的 \ConTeXt\ 环境,就不会影响它的使用。 + +\section[helloworld]{Hello World} + +将下面代码使用文本编辑器保存为 hello-world.tex 文件,这就是一个最简单的 \ConTeXt\ 源文档。 + +\starttyping +% hello-world.tex +\starttext +Hello World. +\stoptext +\stoptyping + +我们可以在终端中使用 \type{context} 命令将这份源文档编译、输出为 PDF 文档: + +\starttyping +$ . ctx +$ context hello-world +\stoptyping + +上述命令将在当前目录产生 hello-world.pdf 文档,使用 PDF 阅读器查看它,可以看到文档中除了“Hello World.”字串之外,就剩下一个置于顶端的页码了。 + +在编译 hello-world.tex 时,生成了许多中间文件,如果你不喜欢看到它们,可以使用以下命令将其清除: + +\starttyping +$ context --purge +\stoptyping + +\section{\TeX\ 与 \ConTeXt\ 的关系} +\bookmark{TeX 与 ConTeXt 的关系} + +在上一节 hello-world.tex 文档的编译过程中,我们可以获得的直观认识如下图所示: + +\setupFLOWcharts[nx=3,ny=1, + dx=2\bodyfontsize,dy=4\bodyfontsize, + width=8\bodyfontsize, height=4\bodyfontsize, + maxwidth=.8\textwidth] + +\startFLOWchart[context-flow] + +\startFLOWcell +\name{texfile}\location{1,1}\shape{singledocument} +\text{\ConTeXt\ 源文档} +\connection[rl]{context} +\stopFLOWcell + +\startFLOWcell +\name{context}\location{2,1}\shape{} +\text{\ConTeXt\ 程序} +\connection[rl]{pdf} +\stopFLOWcell + +\startFLOWcell +\name{pdf}\location{3,1}\shape{singledocument} +\text{PDF 文档} +\stopFLOWcell + +\stopFLOWchart + +\placefigure[force][fig:context-flow]{\ConTeXt\ 文档编译过程的直观认识} + {\FLOWchart[context-flow]} + +实际上是没有所谓的“\ConTeXt\ 程序”的,真正实现 \TeX\ 文档编译的的是 \TeX\ 引擎。在 \ConTeXt\ MkIV 中,\type{context} 程序只是一个脚本文件,只有一行代码: + +\starttyping +mtxrun --script context "$@" +\stoptyping + +\type{mtxrun} 是一个 Lua 脚本,它需要调用 Lua\TEX\ 引擎并读入 cont-en.fmt 文件才可以对 \ConTeXt\ 文档进行编译处理。cont-en.fmt 是 \ConTeXt\ 的格式文件,可以将它理解为一本词典,当编译 \ConTeXt\ 文档时,Lua\TeX\ 引擎遇到文档中的排版命令时,就去 cont-en.fmt 文件中查找这些排版命令的定义并依命行事。可还记得 2.3 节中使用 \type{context --make} 命令么?这个命令就是用于产生 cont-en.fmt 之类的格式文件的。这就是为什么我们经常说 \ConTeXt\ 或 \LaTeX\ 是 \TeX\ 的一种格式的原因。 + +\section{让 MkIV 讲中文} + +要让 \ConTeXt\ MkIV 讲中文,首先要让它能够找到中文字体所在。还记得 \in{}[installmkiv]\ 节中我们写的那个 \ConTeXt\ 环境配置文件 ctx 么?其中有一行代码如下: + +\starttyping +export OSFONTDIR="/usr/share/fonts/{adobe,winfonts}" +\stoptyping + +\type{$OSFONTDIR} 可以让 Lua\TeX\ 知道系统所安装的字体所在。 + +我在 \type{/usr/share/fonts/adobe} 目录中存放了 4 款 Adobe OTF 中文字体,在 \type{/usr/share/fonts/winfonts} 目录中存放了一些从 Windows XP 中复制过来的一些中文字体。 + +有了中文字体,还需要一份字体配置文件。\ConTeXt\ 提供了一套比较高级的字体机制,叫做 Typescript,它可以设置三种字型:衬线 (Serif)、非衬线 (Sans)与等宽 (Mono) 字型。这三种字型均为英文字体机制中的术语,就像我们中文字体有楷体、宋体、黑体等类型一样。\ConTeXt\ 的 Typescript 机制牵涉太多的字体知识,对它们的详细描述已超出我之所能,这里仅给出一份我照猫画虎搞出来的的一份字体配置文件——\type{zhfonts.tex},它是随这份文档一起发布的,只需将它放到 \type{TEX} 目录树中,譬如: + +\startniceTEX +$ mkdir -p $TEXMFLLOCAL/tex/context/third +$ mv zhfonts.tex $TEXMFLLOCAL/tex/context/third +\stopniceTEX + +\noindent 然后执行: + +\starttyping +$ context --generate +\stoptyping + +\noindent 刷新一下文档数据库,就可以使用该字体配置文件了。 + +在 zhfonts.tex 中,我使用了 Adobe 宋、黑、楷体作为主要的中文字体。如果你没有这些字体,可以将其替换为其它 TTF 或 OpenType 中文字体,但是要保证 Lua\TEX\ 可以找到它们。由于中文字体所包含的英文字形通常比较丑陋,因此在 zhfonts.tex 文件中利用了 MkIV 的混合字体机制,将 lmroman、lmsans、lmmono 以及它们的粗体的英文字形区域分别注入到相应的中文字体中。 + +现在,将 \in[helloworld] 节中的 hello-world.tex 文档修改为: + +\startTEX +\usetypescriptfile[zhfonts] +\usetypescript[myfont] +\setupbodyfont[myfont,rm,11pt] +\starttext +世界,你好! +\stoptext +\stopTEX + +重新编译这份文档,即可得到中文版的 hello-world.pdf 文档。 + +\tex{usetypescriptfile} 命令用于加载 typescript 文件,要求 typescript 文件与 helloworld.tex 文件均在同一目录或者前者位于 \ConTeXt\ Minimals 的某个可以检索到的目录中。 + +\tex{usetypescript} 命令表示使用 typescript 文件中定义的 typeface。所谓 typeface,就是一个字型族。在 zhfonts.tex 文件中所定义的 typeface为 myfont,该字型族包含了 3 种字型:Serif、Sans 与 Mono。\tex{setupbodyfont} 命令是用于定义 hello-world.tex 文档的默认字体,也就是正文字体,这里是将 myfont 字型族中的 Serif 字型作为文档的默认字体,并且默认尺寸为 11pt。 + +现在,MkIV 基本上已经解决了中文排版问题,我们应当为此感谢 Hans、Taco 等开发者的辛勤劳动。另外,还要感谢 Wang Yue、SDE 诸位同学,他们提出了许多有关 \ConTeXt\ 中文支持的要求并报告了许多 bug。特别是 Wang Yue 同学,自去年始,一直在关注 Lua\TeX\ \& \ConTeXt\ MkIV 等项目的发展,并积极地与开发者们沟通,使得开发者认真考虑了有关中文处理的诸多需求。 + +\section{开始 \ConTeXt\ 的旅程} +\bookmark{开始 ConTeXt 的旅程} + +\ConTeXt\ MkIV 中文支持的成功尝试,奠定了我开始学习 \ConTeXt\ 的信心。\CONTEXT\ 的文档非常丰富,不过大部分都是英文的,这多少让我有点沮丧。虽然读英文文档不是什么大障碍,但是总没有中文文档来得亲切。现状如此,只好忍了。 + +目前,\ConTeXt\ 的大多数文档是针对 MkII 版本的,除了 MkIV 手册之外,似乎再也没有其它文档来讲述 MkIV 的应用。不过,由于 MkIV 改变的主要是 \CONTEXT\ 底层,用户界面基本上没有改变,对于中文用户而言,基本上只需将 MkII 的中文字体支持机制改换为 MkIV 的即可,这样原来适用于 MkII 的文档基本上也适用于 MkIV。现在,\ConTeXt\ 项目组现在正在组织进行新的 \ConTeXt\ 文档撰写,这个工程非常浩大,其意在于将这么多年零散的文档汇总到一起,并追随 \CONTEXT\ 的最新进展,估计要到明年方能竣工。远水解不了近渴,现在学习 \CONTEXT,还是要从 MKII 版本的文档开始。 + +作为初学者,{\it\ConTeXt, an excursion}\cite[ms-cb-en]文档是官方制作的新手入门必读文档。\ConTeXt\ 的官方文档通常是分为屏幕阅读版本与打印版本,我读的 {\it\ConTeXt, an excursion} 是屏幕阅读版本,第一次打开这份文档,就惊愕了一下,没想到 PDF 文档居然可以做得如此精致。内容浅显易懂,文档版面美观,我觉得 \ConTeXt\ 是非常礼遇初学者的。 + +当读过 {\it\ConTeXt, an excursion} 时\footnote{实际上我是用到什么就去看什么,现在大概看了有一半内容。},就可以使用 \ConTeXt\ 排版手头上正在写作的一些文档,其实这才是真正的开始学习 \CONTEXT。对于其它任何一种 \TEX\ 都是如此,只有真正开始使用它,才有可能掌握它。一开始,文档的版面丑点没关系,毕竟内容是最重要的。随着对 \CONTEXT\ 的认识日益深刻,你的文档便会愈发具备可观赏性。在实践的过程中,\CONTEXT\ 用户手册\cite[cont-eni]是主要的参考书。当你遇到不解的命令/参数,或者想了解一些命令更多的细节,都可以使用 PDF 阅读器打开 \CONTEXT\ 用户手册,利用阅读器提供的查询功能找到你所感兴趣的内容,并掌握它们。 + +字体在排版中是决定版面美观的重要因素,阅读 \CONTEXT\ 新手册中已经基本完工的 {\it fonts}\mycite{fonts} 部分,便可以理解 \CONTEXT\ 的字体机制,你将获得可以在 \CONTEXT\ 自如使用你喜欢的字体的能力;同时,我制作的那份 MkIV 中文字体配置文件也不再会令你感到困惑。 + +若使用 \ConTeXt\ 排版时存在矢量图绘制需求,推荐使用 \METAPOST。不过,在 \ConTeXt\ 中,我们要面对的不是 \METAPOST,而是 \METAFUN\mycite{metafun},后者对前者进行了封装,实现了 \CONTEXT\ 与 \METAPOST\ 的完美结合。{\it\ConTeXt, an excursion} 文档版面之所以美观,是因为在排版中大量使用 \METAFUN 来美化版面布局的结果。 + +若你对 \ConTeXt\ 已经有所认识,那么 \ConTeXt\ Wiki\footnote{\type{http://wiki.contextgarden.net/Main_Page}} 是非常好的网络学习资源。若有能力,可以在该 Wiki 上与整个世界的 \ConTeXt\ 用户分享你的学习经验;若暂时没能力,可以选择潜水。目前,我是这个 Wiki 众多潜水员中的一名。 + +目前,\CONTEXT\ MkIV 也许还存在许多的 bug,当你发现它们,应当提交 \CONTEXT\ 邮件列表\footnote{http://archive.contextgarden.net/list/context.en.html}中;当你使用 \CONTEXT\ 时有不解的问题,也可以去邮件列表中寻找答案。说来惭愧,我英文不好,并且不熟悉邮件列表的交流规则,所以一直都胆怯于邮件列表上的交流。 + +介绍了以上学习资源之后,我开始如释重负。以后再在这份文档上折腾,心里就不会总是想着自己在写一本 \CONTEXT\ 教程,那样子很累,并且很容易丧失乐趣。这份笔记的真正的意图是自我备忘,将它投放到网络上,是希望我的经验能够对他人有所帮助并且能够一同学习、讨论 \CONTEXT\ 排版知识。 + +\section{更多阅读……} + +如果上述内容有误或者你认为讲述的不够细致,那么请阅读以下文档: + +\startitemize +\item “序幕有些长”,介绍了 \TEX\ 与 \CONTEXT\ MkIV 的背景知识:\crlf \hbox{\tt http://garfileo.is-programmer.com/2011/1/10/zhfonts-usage.23740.html} +\item “这就是 \CONTEXT\ Minimals”,讲述了 \CONTEXT\ Minimals 的安装方法:\crlf\hbox{\tt http://liyanrui.is-programmer.com/2009/10/7/this-is-context-minimals.11971.html} +\stopitemize + +我计划今年年底将这些外部文档归整到这份文档中。 + +\stopcomponent diff --git a/info/context-notes-zh-cn/src/bibl-lyr.tex b/info/context-notes-zh-cn/src/bibl-lyr.tex new file mode 100644 index 0000000000..6e30f43781 --- /dev/null +++ b/info/context-notes-zh-cn/src/bibl-lyr.tex @@ -0,0 +1,77 @@ +\setupcite[num][inbetween={, }, lastpubsep={, },compress=yes] + +\def\withbrackets#1{[#1]~~} +\setuppublications + [sorttype=, + criterium=, + refcommand=num, + numbering=yes, + numbercommand=\withbrackets, + autohang=yes] + +\setuppublicationlist + [artauthor=\normalauthor, + editor=\normalauthor, + author=\normalauthor, + namesep={,}, + lastnamesep={ and }, + finalnamesep={ and }, + firstnamesep={ }, + juniorsep={ }, + vonsep={ }, + surnamesep={ }, + authoretallimit=5, + editoretallimit=5, + artauthoretallimit=5, + authoretaldisplay=5, + editoretaldisplay=5, + artauthoretaldisplay=5, + authoretaltext={ etc}, + editoretaltext={ etc}, + artauthoretaltext={ etc}, +] + +\setuppublicationlayout[article]{% + \insertartauthors{}{\unskip.}{}% + \insertarttitle{\bgroup }{\egroup[J].}{}% + \insertjournal{\bgroup }{\egroup}{}% + \insertpubyear{,}{}{}% + \insertvolume{,}{}{}% + \insertissue{(}{)}{}% + \insertpages{:}{.}{}% +} + +\setuppublicationlayout[phdthesis]{% + \insertauthors{}{\unskip.}{}% + \inserttitle{}{\unskip[D].}{}% + \insertpubname{}{,}{}% + \insertpubyear{}{.}{}% +} + +\setuppublicationlayout[techreport]{% + \insertauthors{}{.}{}% + \inserttitle{}{[R].}{}% + \insertpubname{}{}{}% + \insertpubyear{,}{.}{}% +} + +\setuppublicationlayout[inproceedings]{% + \insertauthors{}{.}{}% + \insertarttitle{}{[C].}{}%% + \inserttitle{}{}{}% + \insertpubyear{,}{.}{}% +} + +\setuppublicationlayout[book]{% + \insertauthors{}{.}{}% + \inserttitle{}{[M].}{}% + \insertpubname{}{}{}% + \insertpubyear{,}{.}{}% + \insertnote{}{}{}% +} + +\setuppublicationlayout[unpublished]{% + \insertauthors{}{.}{}% + \inserttitle{}{.}{}% + \inserturl{}{}{}% +} diff --git a/info/context-notes-zh-cn/src/bibliography.bib b/info/context-notes-zh-cn/src/bibliography.bib new file mode 100644 index 0000000000..0203a2de9a --- /dev/null +++ b/info/context-notes-zh-cn/src/bibliography.bib @@ -0,0 +1,53 @@ +@unpublished{bibtex, + title = {{Tame the BeaST: The B to X of Bib\TeX}}, + author = {Nicolas Markey}, + url = {http://www.ctan.org/tex-archive/info/bibtex/tamethebeast/}, +} + +@unpublished{fonts, + title = {{Fonts in \ConTeXt}}, + author = {PRAGMA}, + url = {http://context.aanhet.net/svn/contextman/context-reference/en/co-fonts.pdf}, +} + +@unpublished{Taco, + title = {{Bibliographies}}, + author = {Taco Hoekwater}, + url = {http://modules.contextgarden.net/bib}, +} + +@unpublished{TacoCTXWiki, + title = {{Bibliography}}, + author = {Taco Hoekwater}, + url = {http://wiki.contextgarden.net/Bibliography}, +} + +@unpublished{widgets, + title = {{WIDGETS uncovered}}, + author = {PRAGMA}, + url = {http://pragma-ade.com/general/manuals/mwidget-s.pdf}, +} + +@unpublished{cont-eni, + title = {{\ConTeXt the manual}}, + author = {PRAGMA}, + url = {http://www.pragma-ade.com/general/manuals/cont-eni.pdf}, +} + +@unpublished{ms-cb-en, + title = {{\ConTeXt an excursion}}, + author = {PRAGMA}, + url = {http://www.pragma-ade.com/general/manuals/ms-cb-en.pdf}, +} + +@unpublished{metafun, + title = {{METAFUN}}, + author = {Hans Hagen}, + url = {http://www.pragma-ade.com/general/manuals/metafun-s.pdf}, +} + +@unpublished{lnotes, + title = {{\LATEX 学习笔记}}, + author = {Alpha Huang}, + url = {http://www.ctan.org/tex-archive/info/lnotes/lnotes.pdf}, +} diff --git a/info/context-notes-zh-cn/src/ctxnotes.tex b/info/context-notes-zh-cn/src/ctxnotes.tex new file mode 100644 index 0000000000..87059cd3f5 --- /dev/null +++ b/info/context-notes-zh-cn/src/ctxnotes.tex @@ -0,0 +1,88 @@ +\environment doc-env +%\startproduct ctxnotes +\starttext + +% 封面 +\startMPinclusions + def random_hash_frame (expr width, height, offset, linewidth ) = + + def delta = ((uniformdeviate .5offset) + .25offset) enddef ; + x1 := offset ; y1 := offset ; x2 := width-offset ; y2 := height-offset ; + + drawoptions(withpen pencircle scaled linewidth withcolor transparent(1,.8,\MPcolor{BackgroundColor})) ; + fill z1--(x2,y1)--z2--(x1,y2)--cycle ; + + drawoptions(withpen pencircle scaled linewidth withcolor \MPcolor{OrnamentColor}) ; + draw (x1-delta,y1)--(x2+delta,y1) ; + draw (x2,y1-delta)--(x2,y2+delta) ; + draw (x2+delta,y2)--(x1-delta,y2) ; + draw (x1,y2+delta)--(x1,y1-delta) ; + + drawoptions(); + setbounds currentpicture to unitsquare xscaled width yscaled height ; + enddef ; +\stopMPinclusions + +\startuseMPgraphic{TitleGraphic} + for i=1 upto 400 : + offset := uniformdeviate 10pt ; + width := 2*offset + 40pt + uniformdeviate 30pt ; + height := 2*offset + 30pt + uniformdeviate 10pt ; + addto currentpicture also + image(random_hash_frame(width,height,offset,1pt)) shifted + (uniformdeviate OverlayWidth, uniformdeviate OverlayHeight) ; + endfor ; +\stopuseMPgraphic + +\defineoverlay [TitleGraphic] [\useMPgraphic{TitleGraphic}] + +% 前文 +\startfrontmatter +\setupbackgrounds [page][background=TitleGraphic] +\startstandardmakeup + \startcolor[white] + \startframedtext[middle][width=.8\textwidth,height=5cm] + \dontleavehmode + \blank[.5cm] + \hfil\bfd\ConTeXt\ 学习笔记\hfil + \blank[.5cm] + \hfil\bfc Using MkIV\hfil + \blank[1cm] + \hfil\bfa Li Yanrui (liyanrui.m2@gmail.com)\hfil + \stopframedtext + \stopcolor + \blank[14cm] +\stopstandardmakeup +\setupbackgrounds [page][background=] +\setuppagenumbering[conversion=romannumerals] +\setuppagenumber[number=1] +\title{目\;\;录}\blank +\placecontent +\stopfrontmatter + +% 正文 +\startbodymatter +\setuppagenumbering[conversion=number] +\setuppagenumber[number=1] +\setups{HeaderFooter} +\component basis +\component fonts +\component layout +\component references +\component project +\component metafun +\stopbodymatter + +% 附录 +\startappendices +\title{参考文献} +\placepublications[criterium=all] +\stopappendices + +% 后文 +\startbackmatter +未完成…… +\stopbackmatter + +%\stopproduct +\stoptext diff --git a/info/context-notes-zh-cn/src/doc-env.tex b/info/context-notes-zh-cn/src/doc-env.tex new file mode 100644 index 0000000000..138b60d565 --- /dev/null +++ b/info/context-notes-zh-cn/src/doc-env.tex @@ -0,0 +1,153 @@ +\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 diff --git a/info/context-notes-zh-cn/src/figures/bookmark.png b/info/context-notes-zh-cn/src/figures/bookmark.png new file mode 100644 index 0000000000..7dc8c6f060 Binary files /dev/null and b/info/context-notes-zh-cn/src/figures/bookmark.png differ diff --git a/info/context-notes-zh-cn/src/figures/cow.pdf b/info/context-notes-zh-cn/src/figures/cow.pdf new file mode 100644 index 0000000000..2441faf74e Binary files /dev/null and b/info/context-notes-zh-cn/src/figures/cow.pdf differ diff --git a/info/context-notes-zh-cn/src/figures/gardeninglion.jpg b/info/context-notes-zh-cn/src/figures/gardeninglion.jpg new file mode 100644 index 0000000000..262d8e4c7f Binary files /dev/null and b/info/context-notes-zh-cn/src/figures/gardeninglion.jpg differ diff --git a/info/context-notes-zh-cn/src/figures/header.png b/info/context-notes-zh-cn/src/figures/header.png new file mode 100644 index 0000000000..04cd4ec195 Binary files /dev/null and b/info/context-notes-zh-cn/src/figures/header.png differ diff --git a/info/context-notes-zh-cn/src/fonts.tex b/info/context-notes-zh-cn/src/fonts.tex new file mode 100644 index 0000000000..c597b23ee5 --- /dev/null +++ b/info/context-notes-zh-cn/src/fonts.tex @@ -0,0 +1,219 @@ +\startcomponent fonts +\environment doc-env +\product ctxnotes + +\chapter{在字体中挣扎} + +当我刚开始学用 \LATEX\ 时,就患上了字体恐惧症。如果只是写英文文档,那么对于初学者而言实在是太简单了,基本上不需要怎么关心字体的问题;但是对于中文或者其它非西语文字而言,\TEX\ 的易用性依然很弱,以至于用户不得不去弄清楚诸多有关字体方面的知识及其配置方法。我很憎恶这些东西,但是也没有办法,排版本来就不是一件易事,只好秉承“为之,则难者易易也”的精神去摸索一下。我开始阅读 \CONTEXT\ Fonts 文档\mycite{fonts},这一章内容就是我的阅读笔记。 + +\section{字体、别名与特征} + +为字体文件取个别名,这是 \CONTEXT\ 字体机制推荐的做法。比如,我们可以将 AdobeSongStd-Light.otf 字体取名为 Song: + +\startniceTEX +\definefontsynonym + [Song][AdobeSongStd-Light][features=zh] +\stopniceTEX + +\noindent \type{features=zh} 参数是用来告诉 \CONTEXT\ MkIV 应当采用中文 (zh) 方式来处理这款字体。\type{features} 的值并非 \CONTEXT\ 提供的标准值,而是要用户自己定义: + +\startniceTEX +\definefontfeature + [zh][mode=node,script=hang,lang=zhs] +\stopniceTEX + +\noindent \type{zh} 这个 font feature 名字可根据自己的嗜好来定;至于第二组参数,对于简体中文用户,通常这样设置就可以。 + +\tex{definefontfeature} 与 \tex{definefontsynonym} 命令的用法在与本文档一同发布的 zhfonts.tex 文件中均有体现,可参照理解。 + +这里需要注意一下字体别名定义中的字体名称。上面的示例中,我直接使用 \type{AdobeSongStd-Light} 告诉 MkIV:我使用的是 AdobeSongStd-Light.otf 字体。实际上,这样的效率会有点低。因为 MkIV 有两种搜索字体的方式,第一种是根据字体开发商给出的字体名 (name),第二种是字体的文件名 (file)。字体名可以使用 \type{fc-list} 命令来查,譬如查询搜索 AdobeSongStd-Light.otf 的字体名: + +\starttyping +> fc-list | grep Song +Adobe 宋体 Std L,Adobe Song Std,Adobe 宋体 Std, +Adobe Song Std L:style=L,Regular +\stoptyping + +\noindent 我们可以得到许多字体名,推荐从中选择一个纯英文的供给 MkIV,譬如: + +\startniceTEX +\definefontsynonym + [Song][name:Adobe Song Std][features=zh] +\stopniceTEX + +如果想使用字体文件名,可以为其冠以 \type{file} 前缀: + +\startniceTEX +\definefontsynonym + [Song][file:AdobeSongStd-Light][features=zh] +\stopniceTEX + +在本节最初的那个例子中,既没有 \type{name} 前缀,也没有 \type{file} 前缀,那么 MkIV 就只好先尝试字体名;如果找不到字体,再去尝试字体文件名。 + +我觉得使用字体名比较正规一些,因为字体的文件名很容易被改掉;字体名是由开发商设定的,一般用户不会想到去修改它,因此使用它可以提高文档的可移植性。 + +\CONTEXT\ 预定义了一些标准的字体别名,我们常用的是\crlf\type{[Serif|Sans|Mono][Bold|Italic|BoldItalic]},它们在 zhfonts.tex 中均出现了。 + +还值得注意的一个问题就是:我们可以定义字体别名的别名。 + +\section{简单的字体定义} + +使用 \tex{definefont} 命令可以实现最快捷、最容易理解的字体定义与使用。比如我想定义 Adobe 宋体并使用它: + +\startniceTEX +\definefont + [Song] + [{name:Adobe Song Std*zh} at 14pt] + +\starttext +\Song 我使用的是 Adobe 宋体 +\stoptext +\stopniceTEX + +或许上面这个例子看起来有点古怪,我将字体定义的部分改写一下,或许就会清楚一些: + +\startniceTEX +\definefontsynonym + [SongTi][name:Adobe Song Std][features=zh] + +\definefont + [Song][SongTi at 14pt] +\stopniceTEX + +如果在定义字体时,不去硬性地设定字体尺寸,那么 \CONTEXT\ 可以根据具体的排版环境自动为字体设定合适的尺寸。 + +\section{Typescript 与 typeface} + +说实在的,typescript 的中文意思我真的说不出来,词典上可以查到的解释是“用打字机打的文件”。我在中文里也实在找不出简洁、准确的翻译,所以还是直称 typescript 为好。 + +简单来说,typescript 是 \CONTEXT\ 的最上层的字体配置文件。目前,MkIV 没有提供面向中文用户的 typescript 文件,这就需要我们自行去实现,因此掌握 typescript 文件的写法非常重要。 + +在只针对 MkIV 的 typescript 配置与使用中,常用命令如下: + +\startitemize +\item typescript 环境 +\item \tex{definefontsynonym} +\item \tex{definetypeface} +\item \tex{usetypescriptfile} +\item \tex{usetypescript} +\stopitemize + +\noindent 下面我将结合 zhfonts.tex 中的部分内容来理解这些命令的用法。 + +在 zhfonts.tex 文件中可以看到,typescript 文件内容是被 typescript 环境分为多个小节的,每个小节实现了一组字体的配置: + +\startniceTEX +\definefontfeature + [zh][mode=node,script=hang,lang=zhs] + +\starttypescript[serif] [zhfont] + ... ... +\stoptypescript + +\starttypescript[sans][zhfont] + ... ... +\stoptypescript + +\starttypscript[mono][zhfont] + ... ... +\stoptypescript + +\starttypescript[myfont] + ... ... +\stoptypescript +\stopniceTEX + +上述代码,我设置了三种字样 (typeface):衬线 (serif)、非衬线 (sans) 与等宽 (mono)。最后的那个 typescript 环境是打算用来定义字样集合的。有关这里的字样的概念,可参考黄老师的《\LATEX\ 学习笔记》\mycite{lnotes}的第 8 章来理解,同时你也可以从中额外获得一些 \TEX\ 字体的常识。 + +我们是在 typescript 环境中定义具体的字体,比如下面定义衬线字样的一组字体: + +\startniceTEX +\starttypescript[serif] [zhfont] + \definefontsynonym + [Serif][name:adobesongstd] + \definefontsynonym + [SerifBold][name:adobeheitistd] + \definefontsynonym + [SerifItalic][name:adobekaitistd] + \definefontsynonym + [SerifBoldItalic][name:adobeheitistd] +\stoptypescript +\stopniceTEX + +\noindent 因为已经知道了 \tex{definefontsynonym} 命令的作用,因此上述字体的定义看起来就非常简单了,就是用我们所指定的一组字体去替换 \ConTeXt\ 标准字体别名默认所使用的字体而已。我们可以按照这样的方式完成非衬线与等宽字样的字体定义,不再赘述。 + +下面来看一下字样的定义: + +\startniceTEX +\starttypescript[myfont] + \definetypeface[myfont][rm][serif][zhfont][features=zh] + \definetypeface[myfont][ss][sans][zhfont][features=zh] + \definetypeface[myfont][tt][mono][zhfont] +\stoptypescript +\stopniceTEX + +\noindent \tex{definetypeface} 命令的第三个参数与第四个参数是与前面的 typescript 环境参数对应一致的,比如: + +\startniceTEX +\definetypeface + [adobe][rm][serif][zhfont] +\stopniceTEX +\noindent 对应: +\startniceTEX +\starttypescript[serif][zhfont] + ... ... ... +\stoptypescript +\stopniceTEX +\noindent 其中含义就是将 adobe 字样集合的衬线 (rm) 字样设为该 typescript 文件中具有 \type{[serif][zhfont]} 参数的 typescript 环境所定义的字体集;也就是说,\CONTEXT\ 可以根据 \tex{definetypeface} 的第三、四个参数来匹配对应的 typescript 环境。不知我有没有说明白。总之,在此要认真体会一下 typescript 环境参数的作用,姑且可以将其当作是对应 typescript 环境唯一的标识符号。至于 \tex{definetypeface} 前两个参数,其实也是作为一个标识符来用的,这在使用 typescript 文件时就可以看到。 + +将上述的知识汇在一起,就可以写出类似 zhfonts.tex 这样的 typescript 文件,若将其投入到 \TEX\ 目录树中,就可以在排版时使用它了,譬如: + +\startniceTEX +\usetypescriptfile[zhfonts] +\usetypescript[myfont] +\setupbodyfont[adobe,rm,11pt] +\stopniceTEX + +\noindent 首先 \tex{usetypescriptfile} 命令驱使 \CONTEXT\ 在 \TEX\ 目录树中找到 zhfonts.tex 这个 typescript 文件;然后 \tex{usetypescript} 命令可以在 zhfonts.tex 文件中匹配含有一个参数为 myfont 的 typescript 环境,并读取该环境所定义的字样信息;最后使用 \tex{setupbodyfont} 命令将 typescript 文件中所定义的某种字样其定位文档的默认字体集,\tex{definetypeface} 命令的前两个参数的用途再次便得以体现出来。 + +\section{混合字体} + +从概念上讲,混合字体就是将两种或更多的字体的不同编码部分合成到一起,形成一种新的字体。比如,中文字体往往也会包含了英文部分,偏偏这部分字体设计的又太差。所以,目前对于中文用户而言,混合字体机制实在是重之又重,因为我们可以利用这套机制来实现将一部分好看的英文字体注入到中文字体中,以此来实现美观的中英文混合文本排版。 + +下面展示一个小例子,用以说明如何使用 MkIV 的混合字体机制: + +\startniceTEX +\definefontsynonym + [zhserif][name:adobesongstd] +\definefontfallback + [serifwhatever][lmroman10-regular][0x0000-0x0400][force=yes] +\definefontsynonym + [ZhSerif][zhserif][fallbacks=serifwhatever] +\definefont[FbSong][ZhSerif at 12pt] +\definefont[Song][name:adobesongstd at 12pt] + +\starttext +\FbSong +中英文混合:To do or not to do, this is the question! + +\Song +中英文混合:To do or not to do, this is the question! +\stoptext +\stopniceTEX + +字体切换命令 \tex{ZhSerif} 使用的是混合字体,是 Adobe 宋体的 \type{0x0000-0x0400} 区域中掺入了 lmroman10 字体的对应区域;而 \tex{Song} 命令使用的则是纯的 Adobe 宋体。上面的例子也许看不出来混合字体的优势所在,这主要是因为 Adobe 宋体中的英文部分设计的还算不错。如果将 Adobe 宋体换成 SimSun,对比效果会更明显一些。 + +我们可以将这种混合字体机制与 MkIV 的 typescript 机制相结合,在不同风格的中文字体中掺入类似风格的英文字符,这样中英文混合排版的问题就能够得到较好的解决。 + +\section{更多阅读……} + +如果上述内容有误或者你认为讲述的不够细致,那么请阅读以下文档: + +\startitemize +\item “不仅仅是为了中文”,详细介绍了 \CONTEXT\ 的 Typescript 机制:\crlf \hbox{\tt http://liyanrui.is-programmer.com/2009/10/21/not-just-for-chinese.12264.html} +\item “zhfonts 模块的用法”,zhfonts 模块可支持中文字体加载、标点间距调整等功能:\crlf \hbox{\tt http://garfileo.is-programmer.com/2011/1/10/zhfonts-usage.23740.html} +\stopitemize + +我计划今年年底将这些外部文档归整到这份文档中。 + +\stopcomponent diff --git a/info/context-notes-zh-cn/src/layout.tex b/info/context-notes-zh-cn/src/layout.tex new file mode 100644 index 0000000000..52691d16d8 --- /dev/null +++ b/info/context-notes-zh-cn/src/layout.tex @@ -0,0 +1,233 @@ +\startcomponent layout +\product ctxnotes + +\chapter{版面设计} + +其实我不懂排版,我只是希望这份文档的版面看上去不那么丑陋,所以我经常留意有关排版的知识,并乐于使用 \CONTEXT\ 来实践。我将这个实践的过程整理出来,就是本章所记述的内容,并且每当我修改本文档的版面风格时,这一章的内容也会适应性的变动。可以将本章看作是这份笔记版面设计的说明书。 + +\section{页面与纸张} + +页面尺寸就是文档的版面尺寸,而纸张尺寸是指文档印刷用纸的规格,它们的取值一般是相同的;只有在要求每张印刷用纸上实现多页排版时,二者的取值才不一样。这份笔记的屏幕阅读文档页面与纸张尺寸设定如下: + +\startniceTEX +\definepapersize[SCREEN][width=24cm,height=18cm] +\setuppapersize[SCREEN][SCREEN] +\stopniceTEX + +\noindent 其意是指页面与纸张的尺寸的宽高分别为 24cm 与 18cm,这是考虑到显示屏幕尺寸的宽高比一般为 4:3,这样可以充分利用屏幕区域,并且翻页方便。 + +页面与纸张的规格可以采用 \CONTEXT\ 已经预定义好的国际标准规格,如 A0~A10、B0~B5 等;也可以采用自定义尺寸: + +\startniceTEX +\definepapersize[I18][width=18.5cm,height=23cm] +\setuppapersize[I18][I18] +\stopniceTEX + +\noindent 这里定义的 I18 规格的页面与纸张尺寸,是近年来计算机技术书籍排版常用的纸张规格。 + +\section{版面布局} + +\CONTEXT\ 将版面划分为 25 个区域,具体的区域划分在 {\it\CONTEXT, an excursion}\cite[ms-cb-en]文档的第 32 章 {\it Page Layout} 中可以看到,也可以在 \CONTEXT\ Wiki 的 {\it Layout} 页面看到\footnote{http://wiki.contextgarden.net/Layout}。 + +我为这份文档所规划的版面布局如下: + +\startmode[print] +\startniceTEX +\setuplayout + [leftmargin=2cm, + rightmargin=3cm, + width=fit, + height=fit, + topspace=1cm, + header=1.5cm, + footer=1.5cm] +\stopniceTEX +\stopmode + +\startmode[screen] +\startniceTEX +\setuplayout + [width=fit, + height=middle, + leftmargin=3cm, + rightmargin=3cm, + backspace=4cm, + topspace=.5cm, + headerdistance=.4cm, + footerdistance=.4cm, + header=1cm, + footer=1cm] +\stopniceTEX +\stopmode + +\noindent 下一页的插图显示了这些参数的布局效果,这里交代一下,那幅插图是利用了 Patrick 写的一个模块 (Module)\footnote{\type{http://modules.contextgarden.net/t-layout}}绘制的。 + +\type{\setuplayout} 命令所具有的参数,在数量上堪称是 \ConTeXt\ 命令之最,如果我没有数错,应该是 44 个,常用的参数也就是下一页插图中所示的那些了。通过这些参数,\ConTeXt\ 可实现各种复杂的版面布局。 + +说点闲话。如果我没记错的话,MS Word 用来设置版面布局的参数不超过 10 个。在 \LATEX\ 中,需要借助一些宏包才可以比较方便地实现版面布局控制。复杂与统一,也许这是 \CONTEXT\ 的一个很重要的特征,复杂是追求功能强大的必然结果,而统一可以让用户只需一份官方提供的技术手册就可以毫无争议地使用这些功能。 + +注意,将 \type{\setuplayout} 的 \type{width} 与 \type{height} 参数设为 \type{fit} 或 \type{middle} 都可以让 \CONTEXT\ 自动为我们确定它们的值。\type{fit} 参数的确定是根据周边邻域参数计算出来的,而 \type{middle} 不是很关心周边参数,它只需要将 \type{width} 或 \type{height} 所确定的尺度相对于同一维向的页面尺度是居中的。 + +\type{location} 这个参数让我费解了许久,历经多次尝试,总算知道一点所以然。当我们将版面尺寸与纸张尺寸设为相同时,\type{location} 这个参数无论如何设定都是看不到效果的。当纸张尺寸大于版面尺寸时,\type{location} 的值可以表示版面在纸张的位置,譬如 left、right、middle、singlesided 以及 doublesided。 + +\page +\ShowLayout[digit=1,showmore=0] +\page + +\section[HFer]{页眉、页脚} + +对于这份文档的页眉,我将奇数页的页眉设为当前章标题(左)+ 页码(右);偶数页的页眉设为当前节标题(左)+ 页码(右): + +\startniceTEX +\def\CurrentChapter{% + 第 \headnumber[chapter]\ 章% + \hbox to wem{}% + \getmarking[chapter]% +} + +\def\CurrentSection{% + \headnumber[section]% + \hbox to 2em{}% + \getmarking[section]% +} + + \setupheadertexts + [\CurrentChapter][pagenumber] + [pagenumber][\CurrentSection] +\stopniceTEX + +\tex{setupheadertexts} 命令的参数设置的有些古怪,按手册上讲的,前两个参数分别用于设置奇数页的页眉左侧与右侧内容,后两个参数则用于设置偶数页的页眉左侧与右侧内容,但是在上述的页眉设置语句中,我只有将偶数页的页眉内容的左右位置掉换过来才可以得到这份文档的页眉结构。我并不知道为什么要这样设置,只是多次尝试才知道只有如此才能实现我的要求。 + +由于设置在页眉中显示页码,所以应当引去 \CONTEXT\ 自动为页面添加的页码,顺便把页码的字号也设置一下: + +\startniceTEX +\setuppagenumbering + [style=\tfx,location=] +\stopniceTEX + +我感觉 \CONTEXT\ 是有点另类,居然让 \tex{setuppagenumbering} 来设置双面打印文档模式。如果,我想将本文档的页眉结构变成:奇数页的页眉设为当前章标题(左)+ 页码(右);偶数页的页眉设为当前节标题(右)+ 页码(左),只需在 \tex{setuppagenumbering} 命令中设定 \type{alternative} 参数即可: + +\startniceTEX +\setuppagenumbering + [alternative=doublesided,style=\tfx,location=] +\stopniceTEX + +\noindent 感觉有点莫名其妙,也许因为我还未发现正确的页眉设置方法的缘故。 + +页脚的设定方法与页眉类似,我在页脚的左侧设置了显示这份文档的名称,在其右侧显示可以跳往目录页的链接: + +\startniceTEX +\startmode[screen] +\setupfootertexts + [{\ConTeXt\ MkIV 学习笔记}][{\goto{回目录}[content]}] + [{\goto{回目录}[content]}][{\ConTeXt\ MkIV 学习笔记}] +\stopmode +\stopniceTEX + +\noindent 用到了 \CONTEXT\ 的 mode 环境,这就像 C 语言中的编译宏。只有在 \CONTEXT\ 编译命令中设定对应的 mode 值,对应 mode 环境中的语句才是有效的。要让 screen mode 环境生效,可: + +\starttyping +$ context --mode=screen ctxnotes +\stoptyping + +\noindent \CONTEXT\ 的 mode 环境非常有用,许多 \CONTEXT\ 官方制作的文档都是利用 mode 环境同时产生屏幕阅读版本与打印版本。将来,我打算将这一环境用于制作演示文档与讲稿。 + +在页脚右侧显示的“回目录”的链接需要设置目录代码的支持,因为这需要利用 \ConTeXt\ 的引用机制: + +\startniceTEX +% 我的目录页 +\title[content]{目录} +\placecontent +\stopniceTEX + +\noindent 有关文档目录设置的细节,准备单独开一个章节来记述。 + +\section{封面设计} + +\CONTEXT\ 没有像 \LATEX\ 那样提供了专用于封面制作的命令,只是提供了一个 \type{standardmakeup} 环境,该环境的作用就是建立一个不增加页码计数的页面,使得用户可以在其中排版封面、扉页之类的页面。这份文档的封面的具体设计如下: + +\startniceTEX +\startstandardmakeup + \startcolor[mydarkred] + \switchtobodyfont[14pt] + \hfil\bfd\ConTeXt 学习笔记\hfil + \blank[1.5cm] + \hfil\bfc Using MkIV\hfil + \blank[12cm] + + \startalignment[flushright] + \ssa + \bTABLE + \setupTABLE[r][each][frame=off] + \bTR \bTD Athor: Li Yanrui\eTD \eTR + \bTR \bTD Email: lyanry@gmail.com\eTD \eTR + \bTR \bTD \date \eTD \eTR + \eTABLE + \stopalignment + \stopcolor +\stopstandardmakeup +\stopniceTEX + +请宽恕我在上述语句中很可耻地使用了 1.5cm、12cm 这样确定的长度。因为我还不怎么会驾驭 \CONTEXT,还无法灵活地实现可根据版面的变化自适应调整的封面设计。 + +要设计一个美观的封面真得很难,而且这也不是我所擅长的。现在,拥有这样一个简单的封面,我已经心满意足。也许等我以后渐渐熟悉 \METAFUN\ 之时,会让它再美观一些。 + +\section{标题样式} + +惯见的文档章、节标题一般都是采用黑体,字号通常也比正文字号大一些,另外标题前后也留出了一些垂直间距。这些设置无非是为了告诉读者,它们是标题,而不是正文。这份文档的标题样式设置如下: + +\startniceTEX +\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] +\stopniceTEX + +\noindent\tex{setupheads} 命令可以设置所有类型的章节标题默认状态。在设置章标题时,由于其所在页面通常不需要页眉与页脚,所以 \type{header} 与 \type{footer} 都应设为 \type{empty}。 + +现在使用 MkIV 排版中文,要想实现章节的编号格式为“第 x 章”、“第 x 节”,或者实现图、表标题格式为“图 x”、“表 x”,可能需要自己来做一些有些 dirty 工作。\ConTeXt\ 提供了 \tex{setuplabeltext} 命令,可用于设置表格、图、章节、附录的编号格式。譬如,要设置中文的章节编号: + +\startniceTEX +\setuplabeltext [en] [chapter={第\;,\;章}] +\setuplabeltext [en] [section={第\;,\;节}] +\stopniceTEX + +\noindent 遗憾的是,我不知道怎样将编号中的数字也使用中文来表示,这在 MkII 中是可以的。 + +\section{段落与行} + +中文排版,段落间距通常等于行间距,因为中文段落是通过首行缩进来标示的,下面代码可将段落文本首行缩进 2 个汉字距离: + +\startniceTEX +\setupindenting[always,2em,first] +\stopniceTEX + +\ConTeXt\ 默认是将段间距设置为 0,这碰巧符合中文的排版规范。如果有设定段间距的需求,就查一下 \tex{setupwhitespace} 命令的用法。 + +对文档正文而言,行间距的设置对于排版的美观性是至关重要的:行间距过小则阅读困难;行间距过大又显得版面稀疏,浪费纸张。\ConTeXt\ 默认的文本行间距的值对于中文排版而言过小,可通过 \tex{setupinterlinespace} 命令结合自己的审美嗜好对行间距进行调整。我习惯将行高设为 1.5em: + +\startniceTEX +\setupinterlinespace[line=1.5em] +\stopniceTEX + +\section{更多阅读……} + +如果上述内容有误或者你认为讲述的不够细致,那么请阅读以下文档: + +\startitemize +\item “页面布局控制”:\crlf \hbox{\tt http://garfileo.is-programmer.com/2011/1/19/layout-control.23895.html} +\item “\CONTEXT\ 文稿的逻辑结构”:\crlf \hbox{\tt http://garfileo.is-programmer.com/2011/1/16/context-manuscript-logic-structure.23826.html} +\stopitemize + +我计划今年年底将这些外部文档归整到这份文档中。 + +\stopcomponent diff --git a/info/context-notes-zh-cn/src/metafun.tex b/info/context-notes-zh-cn/src/metafun.tex new file mode 100644 index 0000000000..c7a121d47b --- /dev/null +++ b/info/context-notes-zh-cn/src/metafun.tex @@ -0,0 +1,463 @@ +\startcomponent metafun +\product ctxnotes + +\chapter{我是这样学习 MetaFun 的} + +其实,我本来是想尽快制作一份有关 \CONTEXT\ 演示文档的学习笔记,尝试了几次之后,都铩羽而归。我渐渐意识到如果不了解 \METAFUN,那么使用 \CONTEXT\ 是很痛苦的,就像拿到了一座金山却无处消费它一般。我开始认真学习 \METAFUN,并且也很后悔当初没有学习 \METAPOST,而在 PGF/TikZ 上却曾经浪费了很多时间。 + +\section{从画一个矩形开始} + +在这份这份文档的封面上,画有许多形态各异的矩形,它们不是我画的,而是我从一份 \CONTEXT\ 演示文档模板中扣出来的一段代码。我从现在开始逐步研究它们是如何绘制出来的。 + +先进行一个矩形区域的填充: + +\startniceTEX[numbering=line] +\setupcolors[state=start] +\setupcolor[hex] +\definecolor[BackgroundColor][h=cccccc] + +\starttext +\startuseMPgraphic{box} +offset := uniformdeviate 10pt; +width := 2*offset + 30pt + uniformdeviate 30pt; +height := 2*offset + 20pt + uniformdeviate 10pt; +x1 := offset ; y1 := offset; x2 := width-offset; y2 := height-offset; +fill z1--(x2,y1)--z2--(x1,y2)--cycle + withcolor \MPcolor{BackgroundColor}; +\stopuseMPgraphic + +\useMPgraphic{box} +\stoptext +\stopniceTEX + +\definecolor[BackgroundColor][h=cccccc] +\startuseMPgraphic{box} +offset := uniformdeviate 10pt; + +width := 2*offset + 30pt + uniformdeviate 30pt; +height := 2*offset + 20pt + uniformdeviate 10pt; +x1 := offset ; y1 := offset; +x2 := width-offset; y2 := height-offset; + +fill z1--(x2,y1)--z2--(x1,y2)--cycle + withcolor \MPcolor{BackgroundColor}; +\stopuseMPgraphic + +这个小例子可在页面中绘制一个灰色的矩形填充域\;\useMPgraphic{box}\;\;。实际上,单单要完成这个例子所实现的目标,没必要去定义那么多的变量,这里之所以如此,不妨认为我想借此来熟悉一下 \METAPOST\ 的变量赋值与运算语法。 + +代码第 1-3 行的大意是启用颜色环境,并将颜色描述格式设为 16 进制码形式,最后使用灰色定义了一种名曰 BackgroundColor 的颜色;在 \METAFUN\ 中,我们可以使用 \tex{MPcolor} 命令将 \CONTEXT\ 中定义的颜色转换为 \METAFUN\ 所使用的颜色值,详见代码第 12 行。这多少可以体现出 \METAFUN\ 的一些特点,它实现了 \CONTEXT\ 与 \METAPOST\ 的沟通。 + +代码第 7 行演示了 uniformdeviate 命令的用法,它的作用就是从 \type{[0pt - 10pt]} 这个尺寸区间中随机取一个尺寸。 + +代码第 11-12 行演示了如何填充一条路径,比较值得注意的是路径构成中的 \type{z1} 与 \type{z2} 的含意,这似乎是 \METAPOST\ 约定的,它们分别表示 \type{(x1,y1)} 与 \type{(x2,y2)},但愿我没有理解错。 + +代码第 6-13 行构造了一幅 \METAFUN\ 图形,第 15 行代码将该图形插入至文档中。这就是 \METAFUN\ 图形嵌入于 \CONTEXT\ 的一般方式。另外,也可以像插入普通图片那样: + +\startniceTEX +\placefigure + [here,force][fig:box] + {嵌入 \METAFUN\ 图形}{\useMPgraphic{box}} +\stopniceTEX + +\placefigure + [here,force][fig:box] + {嵌入 \METAFUN\ 图形}{\useMPgraphic{box}} + +下面为这个矩形填充域绘制边框。如果只是绘制一个矩形框,这比较简单,以下示例便可以: + +\startniceTEX +\setupcolors[state=start] +\setupcolor[hex] +\definecolor[BackgroundColor][h=cccccc] +\definecolor[OrnamentColor][h=99ccff] + +\starttext +\startuseMPgraphic{box-ornament} +offset := uniformdeviate 10pt; +width := 2*offset + 30pt + uniformdeviate 30pt; +height := 2*offset + 20pt + uniformdeviate 10pt; +x1 := offset ; y1 := offset; x2 := width-offset; y2 := height-offset; +fill z1--(x2,y1)--z2--(x1,y2)--cycle + withcolor \MPcolor{BackgroundColor}; +draw z1--(x2,y1)--z2--(x1,y2)--cycle + withcolor \MPcolor{OrnamentColor}; +\stopuseMPgraphic + +\useMPgraphic{box-ornament} +\stoptext +\stopniceTEX + +\definecolor[BackgroundColor][h=cccccc] +\definecolor[OrnamentColor][h=99ccff] +\startuseMPgraphic{box-ornament} +offset := uniformdeviate 10pt; +width := 2*offset + 30pt + uniformdeviate 30pt; +height := 2*offset + 20pt + uniformdeviate 10pt; +x1 := offset ; y1 := offset; x2 := width-offset; y2 := height-offset; +fill z1--(x2,y1)--z2--(x1,y2)--cycle + withcolor \MPcolor{BackgroundColor}; +draw z1--(x2,y1)--z2--(x1,y2)--cycle + withpen pencircle scaled 2pt withcolor \MPcolor{OrnamentColor}; +\stopuseMPgraphic + +\noindent 得到\;\useMPgraphic{box-ornament}\;,但是它无法实现本文档封面页上的那些小矩形框的效果,它们是无法采用一条路径来实现,而是要四个边框逐个的画: + +\startniceTEX[numbering=line] +... ... +def delta = ((uniformdeviate .5offset) + .25offset) enddef; +drawoptions(withpen pencircle scaled 2pt + withcolor \MPcolor{OrnamentColor}); +draw (x1-delta,y1)--(x2+delta,y1); +draw (x2,y1-delta)--(x2,y2+delta); +draw (x2+delta,y2)--(x1-delta,y2); +draw (x1,y2+delta)--(x1,y1-delta); + +drawoptions(); +setbounds currentpicture to unitsquare xyscaled (width,height); +\stopniceTEX + +\startuseMPgraphic{box-random-ornament} +offset := uniformdeviate 10pt; +def delta = ((uniformdeviate offset) + .25offset) enddef; +width := 2*offset + 30pt + uniformdeviate 30pt; +height := 2*offset + 20pt + uniformdeviate 10pt; +x1 := offset ; y1 := offset; x2 := width-offset; y2 := height-offset; +fill z1--(x2,y1)--z2--(x1,y2)--cycle + withcolor \MPcolor{BackgroundColor}; +drawoptions(withpen pencircle scaled 2pt + withcolor \MPcolor{OrnamentColor}); +draw (x1-delta,y1)--(x2+delta,y1); +draw (x2,y1-delta)--(x2,y2+delta); +draw (x2+delta,y2)--(x1-delta,y2); +draw (x1,y2+delta)--(x1,y1-delta); + +drawoptions(); +setbounds currentpicture to unitsquare xyscaled (width,height); +\stopuseMPgraphic + +\noindent 这样才可以得到那种类似于手绘矩形框的效果\;\useMPgraphic{box-random-ornament}\;\;。注意,第 2 行代码所定义的 \type{delta} 似乎是一个变量,实际它是一个宏,一个不带任何参数的宏。宏可以避免许多重复的输入,并且使得代码更为易读;\type{drawoptions} 也具有类似作用。在上述代码片段中,宏还起到了让 \type{delta} 返回的尺寸大小居于随机变化的效果,因为宏在被 \METAPOST\ 处理时要被其定义替换,因为 \type{delta} 定义中的 \type{uniformdeviate} 运算符就被反复调用,生成不同的随机数。\type{setbounds} 语句用于设置图形的边界,这样可以保证将所绘制的图形完全地显示出来(其实我觉得这有点多余)。 + +下面,来看一下带参数的宏该如何写。带参数的宏,可将它理解为可重复调用的函数。对于前面的示例,可以将这一系列的绘制过程定义为下面的宏: + +\startniceTEX +def random_box (expr width, height, offset, linewidth ) = + def delta = ((uniformdeviate .5offset) + .25offset) enddef; + + x1 := offset; y1 := offset; x2 := width-offset; y2 := height-offset; + + drawoptions(withcolor transparent(1,.8,\MPcolor{BackgroundColor})); + fill z1--(x2,y1)--z2--(x1,y2)--cycle; + + drawoptions(withpen pencircle scaled linewidth + withcolor \MPcolor{OrnamentColor}); + draw (x1-delta,y1)--(x2+delta,y1); + draw (x2,y1-delta)--(x2,y2+delta); + draw (x2+delta,y2)--(x1-delta,y2); + draw (x1,y2+delta)--(x1,y1-delta); + + drawoptions(); + setbounds currentpicture to unitsquare xyscaled (width,height); +enddef; +\stopniceTEX + +\type{random_box} 宏是可以接受传入参数的。\METAPOST\ 宏所支持的参数类型有: +\type{expr}、\type{text} 与 \type{suffix}。\type{expr} 参数类型的用法正如上例 \type{random_box} 宏定义所示,它表示宏的使用者可以向其传入表达式的值。至于 \type{text} 与 \type{suffix} 参数类型,由于现在尚未用到它们,所以我可以暂时不理睬它们的功用。 + +下面演示如何使用上述定义的 \type{random_box} 宏: + +\startniceTEX +offset := uniformdeviate 10pt ; +width := 2*offset + 40pt + uniformdeviate 30pt ; +height := 2*offset + 30pt + uniformdeviate 10pt ; + +random_box (width,height,offset,1pt); +\stopniceTEX + +\section[ordinary-repeat]{平凡的重复} + +一个士兵会踢正步,实在太平凡了;一群士兵会踢同样节奏的正步,就开始不平凡起来了。平凡的重复,往往是不平凡的。现在,我们开始重复上一节所绘制的那个 Box。先来看下面这个可编译的示例: + +\startniceTEX[numbering=line] +\startuseMPgraphic{random-box} +def random_box (expr width, height, offset, linewidth ) = + def delta = ((uniformdeviate .5offset) + .25offset) enddef; + + x1 := offset; y1 := offset; x2 := width-offset; y2 := height-offset; + + drawoptions(withcolor \MPcolor{BackgroundColor}); + fill z1--(x2,y1)--z2--(x1,y2)--cycle; + + drawoptions(withpen pencircle scaled linewidth + withcolor \MPcolor{OrnamentColor}); + draw (x1-delta,y1)--(x2+delta,y1); + draw (x2,y1-delta)--(x2,y2+delta); + draw (x2+delta,y2)--(x1-delta,y2); + draw (x1,y2+delta)--(x1,y1-delta); + + drawoptions(); + setbounds currentpicture to unitsquare xyscaled (width,height); +enddef; + +for i=1 upto 400 : + offset := uniformdeviate 4pt ; + width := 2*offset + 10pt + uniformdeviate 10pt ; + height := 2*offset + 5pt + uniformdeviate 4pt ; + + addto currentpicture also + image(random_box (width,height,offset,1pt)) shifted + (uniformdeviate 8cm, uniformdeviate 6cm) ; +endfor ; +\stopuseMPgraphic +\stopniceTEX + +\startuseMPgraphic{random-box} +def random_box (expr width, height, offset, linewidth ) = + def delta = ((uniformdeviate .5offset) + .25offset) enddef; + + x1 := offset; y1 := offset; x2 := width-offset; y2 := height-offset; + + drawoptions(withcolor \MPcolor{BackgroundColor}); + fill z1--(x2,y1)--z2--(x1,y2)--cycle; + + drawoptions(withpen pencircle scaled linewidth + withcolor \MPcolor{OrnamentColor}); + draw (x1-delta,y1)--(x2+delta,y1); + draw (x2,y1-delta)--(x2,y2+delta); + draw (x2+delta,y2)--(x1-delta,y2); + draw (x1,y2+delta)--(x1,y1-delta); + + drawoptions(); + setbounds currentpicture to unitsquare xyscaled (width,height); +enddef; + +for i=1 upto 400 : + offset := uniformdeviate 4pt ; + width := 2*offset + 10pt + uniformdeviate 10pt ; + height := 2*offset + 5pt + uniformdeviate 4pt ; + + addto currentpicture also + image(random_box (width,height,offset,1pt)) shifted + (uniformdeviate 8cm, uniformdeviate 6cm) ; +endfor ; +\stopuseMPgraphic + +\noindent 我得到如下图所示的图形: + +\placefigure + [here,force][fig:random-box] + {平凡的重复}{\useMPgraphic{random-box}} + +第 26-28 行是解决 \type{random_box} 重复绘制的核心代码。\type{addto ... also} 是 \METAPOST\ 内部定义的宏,它可以将一幅图形 (picture) 添加到另一幅图形中。图形是 \METAPOST\ 中的一个数据结构,它可以存储多条已被绘制的路径,并且图形与图形之间是可以包容的。\type{image} 也是 \METAPOST\ 内部定义的宏,它可以将某一被绘制的路径转变为图形。至于 \type{shifted},顾名思义,它是用来进行几何平移变换的,而且变换的位置是随机坐标来确定的。 + +\section{Overlay 与背景} + +Overlay 这是 \CONTEXT\ 的一个术语,它的名字取的不是很正确,其本意是“覆盖,覆盖图”,但是在 \CONTEXT\ 中,它通常是位于文本之下的图形,或者说它是被文本覆盖。不过,overlay 可以分为许多个层次,因此这个术语的名字取得也不是完全不正确。 + +很多时候,我都是将 overlay 作为一个背景层来对待的,下面的这个例子便可以说明这个问题: + +\startniceTEX[numbering=line] +\setupcolors[state=start] + +\starttext +\defineoverlay[tea][{\darkgreen\ss\bfc 绿茶}] +\framed[background=tea, align=middle]{今\\天\\出\\售} +\stoptext +\stopniceTEX + +\defineoverlay[tea][{\darkgreen\ss\bfd 绿\;茶}] + +\noindent 这个例子可以将“绿茶”作为“今天出售”的背景:\framed[background=tea, align=middle]{今\\天\\出\\售}\;\;。 + +\tex{defineoverlay} 的命令使用起来很简单,第一个参数是 overlay 名,第二个参数是 overlay 的内容,通常是一组排版或绘图命令的集合,推荐使用 \type{{}} 将其括起来。 + +在上述示例中,已经演示了使用文本作为 overlay 内容,下面来看一下使用图片的例子: + +\startniceTEX +\defineoverlay[cow][{\externalfigure[cow]% + [width=\overlaywidth,height=\overlayheight]}] +\framed[width=3cm,height=2cm,background=cow,align=right] + {\vfill\color[darkred]{这是一头奶牛}} +\stopniceTEX + +\defineoverlay[cow][{\externalfigure[cow][width=\overlaywidth,height=\overlayheight]}] + +\noindent 于是我们便拥有了一头漂亮的奶牛 \framed[width=3cm,height=2cm,background=cow,align=right]{\vfill\color[darkred]{这是一头奶牛}} 。 + +上述以图片作为 overlay 的代码没必要多费口舌,多看几遍,动手尝试一下便可以明了。值得注意的倒是 \tex{framed} 命令的 \type{align} 参数,它的取值有些另类,明明是左对齐,但是它的值却是 right;如果你想让文本右对齐,就不得不将其设为 left。这实际上是 Hans 犯得一个错误,因为他当年在写 \CONTEXT\ 时,满脑子是 ragged left(左边不齐) 与 ragged right(右边不齐)。这样的错误一旦犯下了,便不好再改,主要是因为无法兼容过去的文档,后来 Hans 又加入了 flushleft 与 flushright 参数值,这是与我们普遍的习惯是相符的。 + +我们还可以将 \METAFUN\ 绘制的图形作为 overlay,这也是本章一个非常重要的内容,它是 \METAFUN\ 与 \CONTEXT\ 集成的基础,来看这个示例: + +\startniceTEX +\startuseMPgraphic{demo circle} + path p ; + p := fullcircle xscaled \overlaywidth yscaled \overlayheight ; + fill p withcolor \MPcolor{BackgroundColor}; + draw p withpen pencircle scaled 2pt withcolor \MPcolor{OrnamentColor}; +\stopuseMPgraphic + +\defineoverlay[demo circle][\useMPgraphic{demo circle}] +\framed[background=demo circle,frame=off]{被椭圆包围的文本} +\stopniceTEX + +\startuseMPgraphic{demo circle} + path p ; + p := fullcircle xscaled \overlaywidth yscaled \overlayheight ; + fill p withcolor \MPcolor{BackgroundColor}; + draw p withpen pencircle scaled 2pt withcolor \MPcolor{OrnamentColor}; +\stopuseMPgraphic +\defineoverlay[demo circle][\useMPgraphic{demo circle}] + +\noindent 我们可以得到 \framed[background=demo circle,frame=off,height=22pt]{被椭圆包围的文本}\;。 + +由上例可见,我们发现 \METAFUN\ 可以将 \CONTEXT\ 中的一些尺寸,比如 \tex{overlaywidth} 与 \tex{overlayheight} 等参数传入 \METAFUN\ 环境中。在本章开始的时候,还用过一个 \tex{MPcolor} 宏,可以将 \CONTEXT\ 的颜色定义转换为 \METAPOST\ 的颜色定义。我们还可以通过使用 \tex{the} 作为前缀,实现在 \METAFUN\ 环境中访问诸如 \tex{textwidth}、\tex{textheight}、\tex{topspace} 等尺寸参数。 + +前面说过,overlay 是可以叠加的,下面再来用一个例子演示一下: + +\startniceTEX +\startuseMPgraphic{demo ellipse} + path p ; + p := fullcircle xscaled (.95*\overlaywidth) yscaled (.95*\overlayheight); + fill p withcolor \MPcolor{BackgroundColor}; + draw p withpen pencircle scaled 2pt withcolor \MPcolor{OrnamentColor}; +\stopuseMPgraphic + +\startuseMPgraphic{demo square} + path p ; + p := fullsquare xscaled \overlaywidth yscaled \overlayheight; + fill p withcolor \MPcolor{OrnamentColor}; +\stopuseMPgraphic + +\defineoverlay[demo ellipse][\useMPgraphic{demo ellipse}] +\defineoverlay[demo square][\useMPgraphic{demo square}] + +\framed[background={demo square,demo ellipse},frame=off]{被矩形与椭圆包围的文本} +\stopniceTEX + +\startuseMPgraphic{demo ellipse} + path p ; + p := fullcircle xscaled \overlaywidth yscaled \overlayheight; + fill p withcolor \MPcolor{BackgroundColor}; + draw p withpen pencircle scaled 2pt withcolor \MPcolor{OrnamentColor}; +\stopuseMPgraphic + +\startuseMPgraphic{demo square} + path p ; + p := fullsquare xyscaled (1.1*\overlaywidth,1.1*\overlayheight); + fill p withcolor \MPcolor{OrnamentColor}; +\stopuseMPgraphic + +\defineoverlay[demo ellipse][\useMPgraphic{demo ellipse}] +\defineoverlay[demo square][\useMPgraphic{demo square}] + +\noindent 我们可以得到\quad\framed[background={demo square,demo ellipse},frame=off,height=22pt]{被矩形与椭圆包围的文本} 。这其实没什么技巧,只需多定义几个 overlay,然后将它们作为 \tex{framed} 的 \type{background} 的参数列表并按照先后的显示次序排列即可。 + +本节所举的例子,只是使用 \tex{framed} 命令来演示。事实上,\CONTEXT\ 有许多命令都支持 overlay,只要它具备 \type{background} 参数。 + +\section{代码的分离} + +有时候,会希望能够在多个 \METAFUN\ 图形环境中引用同样的一段代码,在我不知道存在 \type{MPinclusions} 环境时,我写过下面这般风格的代码: + +\startniceTEX +\startuseMPgraphic{TitlePage} +def random_box (expr width, height, offset, linewidth ) = + ... ... ... +enddef + +for i=1 upto 400 : + ... ... ... + addto currentpicture also + image(random_hash_frame(width,height,offset,1pt)) shifted + (uniformdeviate OverlayWidth, uniformdeviate OverlayHeight) ; +endfor ; +\stopuseMPgraphic + +\startuseMPgraphic{PageNumberBox} +def random_box (expr width, height, offset, linewidth ) = + ... ... ... +enddef + +offset := uniformdeviate 10pt ; +random_box (\overlaywidth, \overlayheight, offset, 1pt); +\stopuseMPgraphic +\stopniceTEX + +\noindent 虽然这样的代码可以用,但是它很脏。比如,如果我想修改 \type{random_box} 宏的定义,就意味着这两个图形环境中的 \type{random_box} 都要修改。当我我在 \METAFUN\ 手册中发现了 \type{MPinclusions} 这个环境时,立刻就将上述的代码格式修改为: + +\startniceTEX + +\startMPinclusions +def random_box (expr width, height, offset, linewidth ) = + ... ... ... +enddef +\stopMPinclusions + +\startuseMPgraphic{TitlePage} +for i=1 upto 400 : + ... ... ... + addto currentpicture also + image(random_hash_frame(width,height,offset,1pt)) shifted + (uniformdeviate OverlayWidth, uniformdeviate OverlayHeight) ; +endfor ; +\stopuseMPgraphic + +\startuseMPgraphic{PageNumberBox} +offset := uniformdeviate 10pt ; +random_box (\overlaywidth, \overlayheight, offset, 1pt); +\stopuseMPgraphic +\stopniceTEX + +\noindent 可以看出,\type{MPinclusions} 环境的作用就是用于存放各 \METAFUN\ 图形的公共代码,类似于 C 程序的 .h 文件。 + +我们还可以在 \METAFUN\ 图形环境中使用 \tex{includeMPgraphic} 来引用其它的 \METAFUN\ 图形: + +\startniceTEX +\setupcolors[state=start] + +\starttext +\startuseMPgraphic{test} + fill fullsquare rotated 45 scaled 4cm withcolor \MPcolor{yellow} ; +\stopuseMPgraphic + +\startuseMPgraphic{demo} + \includeMPgraphic{test} + fill fullsquare scaled 2cm withcolor \MPcolor{red} ; +\stopuseMPgraphic + +\useMPgraphic{demo} +\stoptext +\stopniceTEX + +\section{还有一些图形环境} + +除了 \type{useMPgraphic} 环境之外,还有 \type{uniqueMPgraphic}、\type{MPpage} 图形环境,当然还有其它类型的,只是我目前认为掌握这三种,基本上够用了。 + +\type{uniqueMPgrahpic} 环境与 \type{useMPgraphic} 环境的区别是:前者只生成一份图形,可供多次使用;后者是在每一次使用时,都要生成图形。如果是要实现随机图形效果,也就是说多次使用同一份绘图代码生成的图形却不相同,这就只好使用 \type{useMPgraphic} 环境,这个问题在 \in[ordinary-repeat] 节中有所体现。 + +\type{MPpage} 环境可专门用于生成单独的矢量图形,试验一下这个例子便可体验其用处: + +\startniceTEX +\setupcolors[state=start] +\setupMPpage + [offset=1pt, + background=color, + backgroundcolor=gray] + +\startuseMPgraphic{test} + fill fullsquare rotated 45 scaled 4cm withcolor \MPcolor{yellow} ; +\stopuseMPgraphic + +\starttext +\startMPpage + \includeMPgraphic{test} + fill fullsquare scaled 2.5cm withcolor \MPcolor{red} ; +\stopMPpage +\stoptext +\stopniceTEX + +\section{后记} + +这篇文章的内容,支离破碎。这是自然的。因为 \METAFUN\ 所涵括的内容远非我这一篇小文所能覆盖得了的。我以为 \METAFUN\ 手册最好是能通读一遍,不过我现在做不到,只好用什么,看什么。在这用与看的过程中,我想尽量地建立系统的认识。这是一个长期的过程。我唯一能做的就是尽量寻找可以使用 \METAFUN\ 的机会。 + +我觉得使用 \CONTEXT\ 排版文档,如果能够充分结合 \METAFUN\ 图形环境来设计文档版面的外观,这是非常具有挑战性的。个人的审美观以及绘制图形的能力决定了文档样式能否体现出个性。 + +\stopcomponent \ No newline at end of file diff --git a/info/context-notes-zh-cn/src/project.tex b/info/context-notes-zh-cn/src/project.tex new file mode 100644 index 0000000000..861c51f179 --- /dev/null +++ b/info/context-notes-zh-cn/src/project.tex @@ -0,0 +1,67 @@ +\startcomponent project +\environment doc-env +\product ctxnotes + +\chapter{大文档项目} + +对于规模比较大的文档项目而言,采用 \TEX\ 的优越性要高于 WYSIWYG 的字处理器 (MS Word)。众人谓之曰字处理器使用起来比较方便,实际这只不过表面现象,在其背后是文档更新方面的困难——难以进行多人协同撰写与版本维护。本章主要介绍 \CONTEXT\ 所提供的文档项目管理功能,探讨如何在文档项目中布置版本控制系统,建立一种比较稳定的大文档项目撰写模式。 + +\section{项目的部署} + +一个 \TeX\ 文档项目,通常可以将文档结构分为:环境、宏、文档主体内容。这样划分的意图就是让文档的样式与内容分离开。环境,主要用于定制版面样式。宏,主要是封装一些排版命令,实现一些特定的排版功能。在 \CONTEXT\ 中,环境或宏可以由一份或多份专门的环境文件来定义,环境文件的格式如下: + +\startniceTEX +\startenvironment 环境文件名 +... 环境内容 ... +\stopenvironment +\stopniceTEX + +如果不对文档的主体内容进行划分的话,那么它就与普通的 \CONTEXT\ 文档无异,只是多了加载环境文件的命令: + +\startniceTEX +\environment 环境文档名 +... ... ... +\starttext +... 文档内容 +\stoptext +\stopniceTEX + +如果对文档的主体内容细分下去,可以有封面、前言、正文章节、附录、封底等。文档结构划分的深浅程度,这个主要由用户来把握,主要视文档的规模而定。对于 \CONTEXT\ 而言,文档的主体内容实际上只有产品 (product) 与 组件 (component) 这两种划分\footnote{事实上还有比产品更高层的结构,就是项目 (project),不过我们写文档一般用不到它,如果是出版期刊杂志倒是有可能用到它。}\;。对于产品与组件之间的关系,这在产品文档中便可以直观地看到,譬如: + +\startniceTEX +\startproduct 产品文档名 +\environment 环境文档名 + +\component 组件文档 1 +\component 组件文档 2 +... ... ... +\stopproduct +\stopniceTEX + +产品文档将环境与组件的信息都记录了下来,因此当我们在使用 \CONTEXT\ 编译一个文档项目时,只需要编译产品文档即可。 + +组件文档的格式如下: + +\startniceTEX +\startcomponent 组件文档名 +\environment 环境文档名 +\product 所属产品名 + +... 组件内容 ... + +\stopcomponent +\stopniceTEX + +也可以直接编译组件文档,因为在组件文档中已经记录了所使用的环境文档信息;在撰写文档的过程中,推荐使用编译组件文档的方式来查看排版效果。 + +\section{更多阅读……} + +如果上述内容有误或者你认为讲述的不够细致,那么请阅读以下文档: + +\startitemize +\item “\CONTEXT\ 文稿的物理结构”:\crlf \hbox{\tt http://garfileo.is-programmer.com/2011/1/12/project-structure.23773.html} +\stopitemize + +我计划今年年底将这些外部文档归整到这份文档中。 + +\stopcomponent diff --git a/info/context-notes-zh-cn/src/references.tex b/info/context-notes-zh-cn/src/references.tex new file mode 100644 index 0000000000..2fe85785d9 --- /dev/null +++ b/info/context-notes-zh-cn/src/references.tex @@ -0,0 +1,362 @@ +\startcomponent bibliography +\product ctxnotes +\chapter{引用} + +当我用我这个代号来进行对话的同时,你的代号也是我,这意味着什么呢?这是否意味着你就是我,而我也就是你? + +\section{目录} + +如果不那么在乎目录的样式,可以在期望插入目录之处添加: + +\startniceTEX +\completecontent +% 或者 +\placecontent +\stopniceTEX + +\noindent \tex{completecontent} 与 \tex{placecontent} 的区别就是前者是生成的目录列表页面是带有标题的;而后者只生成目录列表,如果需要页面带有标题,可以使用 \tex{title} 之类的无编号的标题命令实现: + +\startniceTEX +\title{目录} +\placecontent + [alternative=a, + style=normal, + numberstyle=bold] +\stopniceTEX + +在章标题之后使用 \tex{placecontent}: + +\startniceTEX +\chapter{引用} +\placecontent + [alternative=a, + style=normal, + pagenumber=no, + margin=2em] +\stopniceTEX + +\noindent 可以实现在当前章标题下面显示出这一章所有小节的列表。 + +由于我比较喜欢 \CONTEXT\ 手册的那种目录样式,便从手册的源码中找到了该样式的具体设置,然后照虎画猫一番,并添加了一些小创意: + +\startniceTEX +\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] +\stopniceTEX + +\noindent + +\noindent 结果便是这份文档目录页中所显示的那个样子。我所说得小创意,实际上就是让章节编号变成半中文化(因为还夹着阿拉伯语呢);另外就是让目录列表中各小节的页码显示为灰色,不那么抢眼。 + +\section[cross references]{交叉引用} + +交叉引用实在是太有用了,即便也不怎么经常用到它,也还可以借此嘲笑一下 Word 交叉引用功能的孱弱,赢得一次口水战的胜利。 + +这份文档的页脚的右侧的“回目录”链接就是通过交叉引用来实现的,在\in[HFer]{} 节(瞧,这就是一个交叉引用)中的页脚设置: + +\startniceTEX +\setupfootertexts + [{\ConTeXt\ MkIV 学习笔记}][{\goto{回目录}[content]}] + [{\goto{回目录}[content]}][{\ConTeXt\ MkIV 学习笔记}] +\stopniceTEX + +\noindent 其中,\tex{goto} 这个命令可以跳到任何设置了引用的文档位置。这里,它要跳到 \type{content} 引用所在的位置,由于这个引用我是在设置目录页面时设定的: + +\startniceTEX +\startfrontmatter + \setuppagenumbering + [conversion=romannumerals] + \title[Content]{目录} % 在此设定了引用 + \placecontent +\stopfrontmatter +\stopniceTEX + +\noindent 因此 \tex{goto} 会带你跳到目录页。目录页面的引用是通过 \type{content} 这个名称标识的,\tex{goto} 命令可以根据这个标识确定所要跳往的页面位置。 + +\CONTEXT\ 许多排版命令都支持引用设置,譬如章节标题、插图、表格等命令。一定要记住,文档中只要出现诸如“第 xxx 章”、“xxx 节”、“图 xxx”、“表 xxx”之类的内容时,这就意味着您应当使用交叉引用机制了。比如,我要引用当前这一节,首先要为节标题命令设定引用名称: + +\startniceTEX +\section[cross references]{交叉引用} +\stopniceTEX + +\noindent 然后在需要引用本节之处,通过 \tex{in} 命令即可获取节号;如果是屏幕阅读文档,还可以让节号作为一个链接,指向本节所在页面位置。同类的命令还有 \tex{at} 与 \tex{about},前者可以获取引用所在的页面,后者可以得到引用的内容。下面仿照 \CONTEXT\ 手册中的例子,演示这三个命令的用法: + +\startniceTEX +我引用了第 \at[cross references] 页的 \in[cross references] 节\about[corss references]的一些内容。 +\stopniceTEX + +\noindent 效果:{\ss 我引用了第 \at[cross references] 页的 \in[cross references] 节 \about[cross references]的一些内容。} + +现在,MkIV 还未能实现引用在页面的准确定位,所以在屏幕阅读文档中的一些链接只是将你带往这些引用所在的页面而不是将准确的位置展示在你眼前。 + +\section{索引} + +在阅读 {\it \CONTEXT\ 手册}或者 {\it \CONTEXT, an excursion} 之类的文档时,在附录中可以看到许多命令的索引,这些索引会告诉你那些命令在哪些页面出现了;如果是屏幕阅读文档,还可以将页码变成指向对应页面的链接。利用这些索引功能,我可以快速找到这些命令的细节知识。这在写技术文档时非常重要。在这份文档中,我没有使用索引的功能,因为很少有人会为了一份学习笔记如此大动干戈。将它记述于此,仅仅是为了将来有可能使用到它。 + +要定义索引很简单,使用\tex{index} \index[index]{\tex{index}} 这个命令就可以: + +\startniceTEX +我在这里演示 index\index[index]{\tex{index}} 与 + placeindex\index[placeindex]{\tex{placeindex}} 命令的用法。 + +\placeindex +\stopniceTEX + +\noindent 然后使用 \tex{placeindex}\index[placeindex]{\tex{placeindex}} 或 \tex{completeindex}\index[completeindex]{\tex{completeindex}} 命令在需要放置索引的页面显示索引。 + +索引列表默认是以字母进行分组与排序的,这对于西文文档排版很适用,但是没法处理中文。可以采用汉语拼音\index[HYPY]{汉语拼音}来解决这个问题。譬如: + +\startniceTEX +……可以采用汉语拼音\index[HYPY]{汉语拼音}来解决这个问题…… +\stopniceTEX + +\noindent 生成的索引列表如下: + +\placeindex + +索引与目录的用法很相似。实际上这一章中所有的内容都是基于 \CONTEXT\ 的引用机制实现的。索引与目录存在着更为高级的用法,但是我没有那么多兴趣和精力去折腾它们,以后若有这方面的需要再下手也不迟。 + +\section{参考文献} + +写科技文档必然离不开参考文献 (Bibliography) 的支撑,所以要评价一个文档排版软件的优劣,其参考文献管理功能是一项非常重要的指标。与 \LaTeX\ 类似,\ConTeXt\ 主要是基于 Bib\TeX\ 维护参考文献,这是借助 Taco Hoekwater 写的 t-bib.tex 模块来实现的。 + +\subsubject{Bib\TEX} + +Bib\TeX\ 的主要功能是管理参考文献信息并提供排版格式。在使用 Bib\TeX\ 之前,用户需要建立参考文献数据库,不要害怕,这里的数据库实际上就是一个扩展名为 .bib 的文本文件,我们在其中记录文献信息。下面是一份 .bib 文件示例: + +\startTEX +@book{诸葛专著2008, + author = "诸葛亮", + year = "2008", + title = "木牛流马制造工艺 [M]", + publisher = "蜀国机械工业出版社" +}; + +@article{诸葛论文2008, + author = "诸葛亮", + title = "论伐魏的必要性与可行性 [J]", + journal = "蜀国军事", + volume = "13", + number = "110", + year = "2007" +} +\stopTEX + +在文献数据库中,可以存储许多种文献类别,常用条目类型有 article、book、conference、manual、misc、techreport 等。每种参考文献类别由多个域组成,有些是必须写得,没写会给出警告,而有些是可选。譬如 book 类别中,不可省略的域有 author, title, journal, year,可省略的域有 volume, number, pages, month, note。推荐做法是在参考文献数据库中尽可能地提供文献的详细信息。关于 .bib 文件的格式说明,请参考 Bib\TeX\ 文档\cite[bibtex]。 + +Bib\TeX\ 为便于用户管理参考文献列表的排版风格,提供了 .bst 文件。.bib 文件与 .bst 文件之间的关系宛若 HTML 与 CSS 之间的关系,它们都遵守内在数据与外在表现分离的游戏规则。用户在 .bst 文件中可使用 Bib\TeX\ 定义的一种微型语言来实现对参考文献列表风格的控制,但是在 \ConTeXt\ 的 bib 模块中,仅使用 .bst 文件控制参考文献条目的排列次序。一般情况下,用户不需要制作 .bst,所以这个了解一下就可以了。 + +Bib\TeX\ 与 \ConTeXt\ 的协同工作时,需要 \ConTeXt\ 文档编译命令输出 .aux 文件。基于 .aux 文件,Bib\TeX\ 在 .bib 检索所需的文献信息,并结合 .bst 文件实现参考文献列表外观控制,最终输出 .bbl 文件。一旦我们得到了 .bbl 文件(实际是 \TeX\ 文档),那么就可以继续进行 \ConTeXt\ 文档编译过程,最终输出带有参考文献信息的文档,这一工作流程如下图所示。 + +\setupFLOWcharts[nx=4,ny=4, + dx=\bodyfontsize,dy=\bodyfontsize, + width=7.5\bodyfontsize, height=4\bodyfontsize, + maxwidth=.8\textwidth] + +\startFLOWchart[bibtex-flow] + +\startFLOWcell +\name{texfile}\location{1,2}\shape{singledocument} +\text{\ConTeXt\ 源文档}\connection[rl]{ctx} +\stopFLOWcell + +\startFLOWcell +\name{ctx}\location{2,2}\shape{action} +\text{编译 \ConTeXt\ 文档}\connection[rl]{aux} +\stopFLOWcell + +\startFLOWcell +\name{aux}\location{3,3}\shape{singledocument} +\text{.aux 文档}\connection[rln]{bibtex} +\stopFLOWcell + +\startFLOWcell +\name{bib}\location{3,1}\shape{singledocument} +\text{.bib 文档}\connection[rlp]{bibtex} +\stopFLOWcell + +\startFLOWcell +\name{bst}\location{3,2}\shape{singledocument} +\text{.bst 文档}\connection[rl]{bibtex} +\stopFLOWcell + +\startFLOWcell +\name{bibtex}\location{4,2}\shape{action} +\text{Bib\TeX}\connection[bt]{bbl} +\stopFLOWcell + +\startFLOWcell +\name{bbl}\location{4,4}\shape{singledocument} +\text{.bbl 文档}\connection[lr]{ctxagain} +\stopFLOWcell + +\startFLOWcell +\name{ctxagain}\location{3,4}\shape{action} +\text{编译 \ConTeXt\ 文档}\connection[lr]{pdf} +\stopFLOWcell + +\startFLOWcell +\name{pdf}\location{2,4}\shape{singledocument} +\text{含参考文献的 PDF 文档} +\stopFLOWcell + +\stopFLOWchart +\placefigure[here][fig:bibtex-flow]{Bib\TeX\ 工作过程} + {\FLOWchart[bibtex-flow]} + +\subsubject{\ConTeXt\ 的 bib 模块} + +\ConTeXt\ 是通过 Taco 写的 bib 模块取得 Bib\TeX\ 的协同(现已集成至 \CONTEXT\ 中),用户可以在 \ConTeXt\ 文档中实现参考文献列表排版样式的设置。下面是一份最为简单的 \ConTeXt\ 参考文献示例文档 \type{example/ex-4.tex}: + +\startTEX +\setupbibtex[database=example] + +\starttext +这一年,诸葛亮同学出版了一本专著\cite[诸葛专著2008],并在核心学术期刊上发表了一篇论文\cite[诸葛论文2008],因此深得刘备的赏识。 +\completepublications +\stoptext +\stopTEX + +上例中 \tex{setupbibtex} 命令的 \type{database} 参数的值为 .bib 文件名,我是将上一节中的那个 .bib 文件命名为 example.bib,然后在此使用。\tex{completepublications} 命令会在所排版的文档中插入参考文献列表。 + +编译上述示例文档的过程正如图 \in[fig:bibtex-flow] 所示的那样,需要三个处理步骤,如下: + +\starttyping +$ context --once ex-4 # 产生 .aux 文档 +$ bibtex ex-4 # 产生 .bbl 文档 +$ context ex-4 # 完成文档编译 +\stoptyping + +如果嫌每次编译文档都要重复输入三次命令过于繁琐,花上 20 分钟学习一下 Makefile 的简单用法会让我们更轻松一些。 + +查看一下带有参考文献的 PDF 文档,可能你会发现参考文献并非是我们常见的那种风格,不要着慌,\ConTeXt\ 提供了一些用于设置参考文献风格的命令供我们使用。下面对 \type{ex-4.tex} 文件略作修改,添加了 \tex{setuppublications} 代码: + +\startTEX +... +\setupbibtex[database=example] +\setuppublications[alternative=num] +... +\stopTEX + +重新编译一次 \type{ex-4.tex} 文档\footnote{若是未有改动 .bib 文档或者未引用新的文献,只需使用常规 \ConTeXt\ 文档编译方式即可。},现在参考文献的样式基本符合我们常见的风格了。有关 \tex{setuppublications} 命令的详细用法请参考 bib 模块文档\mycite{Taco}。 + +\subsubject{Zotero} + +Zotero 是 Firefox 的一款扩展 (Extension),号称是下一代研究工具\footnote{至于上一代是谁,不可考,也许是那些脱离网络环境的文献管理软件吧。},我使用它来管理参考文献数据。除 Zotero 之外,还有许多其它文献管理软件,比如 Endnote、RefWorks、jabref 等,与它们相比,Zotero 将我们进行文献管理的整个过程──搜集、整理、阅读和引用等步骤都很好地集成在一起,并且与 Firefox 取得完美的结合,莫要忘记我们通常要在网上寻找文献的。关于 Zotero 的详情见其项目主页\footnote{\type{http://www.zotero.org/}}。 + +大多数情况下,使用 Zotero 的流程可以归纳为:在互联网上发现文献──利用导入功能得到文件信息和有关附件──制作文献阅读笔记、tag 以及相关文件链接──搜索文献──输出有关文献为其他软件格式──在 TeX 或字处理软件中引用。除最后一步外都不需要打开任何其他软件。 + +关于 Zotero 的具体用法……咳咳……实在不知道该如何用文字来讲述一款 GUI 工具的使用,又不胜一副一副配图介绍的那般繁琐。自我开脱一下,毕竟这是一份个人学习笔记,而不是一份教材,所以推荐去看 Zotero 的操作视频教程\footnote{\type{http://www.zotero.org/videos/tour/zotero_tour.htm}}。 + +\subsubject{设置参考文献列表的样式} + +在制作这份学习笔记的参考文献时,因为有一些文献来自于网络,我希望在参考文献列表中提供它们的网址 (URL) 并且要求是超级链接格式的,这样便于读者直接驱动网页浏览器去下载它们。按照 Bib\TeX\ 的 .bib 文档语法,我采用以下文献条目格式提供此类文献的信息: + +\startTEX +@booklet{Taco, + title = {{Bibliographies}}, + author = {Taco Hoekwater}, + url = {http://modules.contextgarden.net/bib} +} +\stopTEX + +但是在文档中去引用上述文献时,其 URL 信息无法在参考文献列表中显示,更谈不上超级链接格式了。在 \ConTeXt\ Wiki 中的 Bibliography 文档\mycite{TacoCTXWiki}中讲述了如何在参考文献中启用 URL 的方法,并提供了一个示例。我对这个示例进行了一些简化,贵在于理解其要义。将以下代码添加到文档导言区,位于 bib 模块加载及其设置代码区域的下面: + +\startTEX +\unprotect +\setuppublicationlayout[booklet]{% + \insertauthors{}{\unskip.}{}% + \inserttitle{ \bgroup\it }{\/\egroup\unskip.}{}% + \insertbiburl{ URL: }{\unskip.}{}% + \insertnote{ }{\unskip.}{}} +\protect +\stopTEX + +\tex{setuppublicationlayout} 命令是用于设置参考文献列表的排版布局的,上例中,其参数我设为 booklet,这是因为我在 .bib 文档中将将网络文档类型定义为 booklet(小册子)类型,它是 Bib\TeX\ 的标准文献条目类型之一,将其作为 \tex{setuppublicationlayout} 的参数,表示这里要设置该类型文献条目的排版风格。 + +在这份笔记中,我只需要 booklet 条目由 author(作者)、title(标题)、URL(文献网址)以及 note(文献注解)附加注释信息构成,因此在设置 booklet 文献条目的排版风格时,对于每一条目要素都对应一个 \tex{insertxxx} 命令。\tex{insertxxx} 命令有三个参数,可用于设定每一文献条目构成要素的排版环境,前两个参数分别用于设置对应排版文献条目构成要素的前后排版命令,第三个参数用于设置对应的文献条目构成要素缺省状态。以 \type{\insertauthors{}{\unskip.}{}} 为例,第一个参数是空的,表示采用默认排版环境;第二个参数为 \type{\unskip.},表示消除 booklet 文献条目中作者信息之后的空格,并且添加句点,第三个参数为空,表示当 .bib 文件中的 booklet 条目未提供作者信息时不作任何处理。 + +注意,在上述示例中,\tex{insertbiburl} 命令是启来 .bib 中所提供的文献 URL 信息的。如果你希望文档中的 URL 是超级链接格式,那么还需要在 \ConTeXt\ 文档导言区添加以下代码: + +\startTEX +\setupinteraction[state=start] % 启用文档的可交互功能 +\stopTEX + +利用上述方法并配合 \ConTeXt\ 各种排版命令可以灵活地控制参考文献列表的排版格式,这就是为什么 \ConTeXt\ 的 bib 模块只是将 Bib\TeX\ 的 .bst 文档用来实现参考文献列表排序的主要原因。 + +\section{书签} + +在阅读很长的 PDF 文档时,书签 (Bookmark) 是很有用的,它们通常显示于 PDF 阅读器的侧栏,用户用鼠标点击书签就可以快速打开书签所指向的页面。对于如何使用 \CONTEXT\ 实现书签,由于我是没有耐心的人,所以看到 \ConTeXt\ Wiki 上提供了适合没耐心的人对文档书签的生成快速建立初步认识的代码,便直接抄过来: + +\startniceTEX +% 启用书签功能 +\setupinteraction[state=start] +\setupinteractionscreen[option=bookmark] +\placebookmarks[chapter][chapter] + +\starttext +\chapter{飞刀与快剑} +冷风如刀,以大地为砧板,视众生为鱼肉。\par +万里飞雪,将穹庐作洪炉,熔万物为白银。\par +…… +\chapter{海内存知己} +马车里堆着好几坛酒,这酒是那少年买的, +所以他一碗又一碗地喝着,而且喝得很快。\par +…… +\stoptext +\stopniceTEX + +\noindent 用常规的 PDF 阅读器打开所生成的文档,若开启侧栏面板,应当可以看到书签了。如果你看不到,那么就见识一下图 \in{}[fig:bookmark]\quad。 + +\placefigure[here][fig:bookmark] + {带书签的 PDF 文档} + {\externalfigure[bookmark][bookmark][width=.6\textwidth]} + +要开启 \ConTeXt\ 的书签功能,必须 \tex{setupinteraction[state=start]}。另外,PDF 阅读器的侧栏的书签窗口默认是隐藏的,要让阅读器打开文档时自动开启书签窗口,那就是上例中 \tex{setupinteractionscreen} 命令所做的。 + +将章、节标题作为书签的想法很好,这样在书签窗口中,可以通过章节标题对文档的大致内容有所了解。在上例中,我通过 \tex{placebookmarks} 命令设置 chapter 标题作为书签。\tex{placebookmarks} 的第一个参数是设定各层次的章节类型作为书签,第二个参数是设置默认可见的书签。看下面一个更复杂的示例: + +\startTEX +\placebookmarks[chapter,section,subsection][chapter] +\stopTEX + +\noindent 这个示例的含义是:将章、节、小节的标题作为书签,默认只在书签窗口中显示由章标题生成的书签。 + +在 MkIV 中,不知是特性还是缺陷,在将章节标题作为书签时,若标题中出现了格式化文本,譬如 \type{\ConTeXt} 这样的文本,那么书签中就会将 \type{\ConTeXt} 的 \TeX\ 定义显示出来,而不是显示 \type{ConTeXt} 或者 \ConTeXt。现在,我未能找到解决这一问题的好方法,笨方法是有的。在撰写某章节标题时,若是需要使用格式化文本,那么就在章节命令之后使用 \tex{bookmark} 命令手动设定书签标题: + +\startTEX +\section{安装 \ConTeXt\ Minimals} +\bookmark{安装 ConTeXt Minimals} +\stopTEX + +\noindent 本文档目前正是使用这种方法去除书签中出现的格式化文本,勉强对付过去。 + +\section{更多阅读……} + +如果上述内容有误或者你认为讲述的不够细致,那么请阅读以下文档: + +\startitemize +\item “\CONTEXT\ 对参考文献的处理”:\crlf \hbox{\tt http://liyanrui.is-programmer.com/2009/12/17/bibliographic-in-ConTeXt.14078.html} +\item “\CONTEXT\ 对参考文献的处理——整容篇”,讲述了 \CONTEXT\ Minimals 的安装方法:\crlf\hbox{\tt http://liyanrui.is-programmer.com/2009/12/18/bibliographic-style-in-ConTeXt.14103.html} +\stopitemize + +我计划今年年底将这些外部文档归整到这份文档中。 + +\stopcomponent diff --git a/info/context-notes-zh-cn/src/t-layout.tex b/info/context-notes-zh-cn/src/t-layout.tex new file mode 100644 index 0000000000..7ca9d6e1b6 --- /dev/null +++ b/info/context-notes-zh-cn/src/t-layout.tex @@ -0,0 +1,411 @@ +%% Last Change: Fri Apr 22 11:06:09 2005 + +%D \module +%D [ file=t-layout, +%D version=2003.03.26, +%D title=\CONTEXT\ User Module, +%D subtitle=show layout, +%D author=Patrick Gundlach, +%D date=\currentdate, +%D copyright={Patrick Gundlach}] + + +%C filename: t-layout.tex +%C module layout, shows layout of current page + + +%C copyright 2003,2007 Patrick Gundlach, patrick@gundla.ch +%C may be distributed under the terms of the GNU General Public License +%C URL: http://levana.de/context/ + +%D \subject{Introduction} +%D This third-party module \quote{layout} draws a representation of +%D the of the layout of the +%D current page and displays the sizes of the widths and heights of the +%D margins, header, footer and text body. + +%D \subject{Usage} +%D Include this module into your ConTeXt files: +%D \type{\usemodule[t][layout]} and show the layout with \type{\ShowLayout}. + +%D You can set some parameters using \type{\SetupShowLayout}. The +%D parameters are: units, digits, round, showmore and graphonly. +%D If graphonly (0/1) is 0, this module shows the lenghts of some text areas. +%D units (cm, mm, in or pt) sets the unit in which the lengths will be +%D displayed, digits (any number $\geq 0$) +%D sets the number of digits after the decimal period, round (any +%D number $\neq 0$) states +%D the place where rounding of the displayed numbers should occur +%D (\TeX\ is bad at calculating such things) and showmore (0/1) tells +%D this module to display information about the edge and top/bottom. + +%D Example: +%D \starttyping +%D \ShowLayout +%D [units=cm, +%D digits=2, +%D round=0.1, +%D showmore=1, +%D graphonly=1] +%D +%D \stoptyping + +%D The idea was taken from the \type{\layout} command from the layout LaTeX +%D package. (Kent McPherson and others) + +%C the following settings will be recognized: +%C units = cm, mm, in or pt +%C digits = any number >= 0, those are the digits after the decimal period +%C round = any number != 0, just play with it, example 0.1 or 0.01. +%C Explanation will be done later + +%D \subject{The code} + +%D This section is not meant as documentation + +\newdimen\ShowLayoutdimen + +\setvalue{Layoutmm}{0.351459804} % 2.54/72.27 * 10 +\setvalue{Layoutcm}{0.0351459804} % 2.54/72.27 +\setvalue{Layoutin}{0.0138370001} % 1/72.27 +\setvalue{Layoutpt}{1} + +\def\ShowLayoutB(#1.#2)#3{% + \counttokens #2\to\scratchcounter + #1\ifnum#3>0% + \ifnum#3 > \the\scratchcounter \else \scratchcounter=#3 \fi + \splitofftokens \scratchcounter \from #2 \to\test .\test \fi} + +% taken from ConTeXt source +\def\LayoutConvert#1#2#3% + {\ShowLayoutdimen=\getvalue{ShowLayoutround}pt + \begingroup + \scratchdimen#1\relax + \scratchdimen\getvalue{Layout#2}\scratchdimen + \advance\scratchdimen by 0.5\ShowLayoutdimen + \divide\scratchdimen by \ShowLayoutdimen + \multiply\scratchdimen by \ShowLayoutdimen + \expandafter\ShowLayoutB\expandafter(\number\withoutpt{\the\scratchdimen}){#3}\thinspace #2 + \endgroup} + +\def\ShowLayoutA#1{% + \LayoutConvert{#1}% + {\getvalue{ShowLayoutunits}}% + {\getvalue{ShowLayoutdigits}}}% + +\startuniqueMPgraphic{ShowLayout}{showmore} +% make sure that the label is on the same side as the posa +vardef swapifnecessary (suffix posa, posb)(expr labelpos) = + if ( (labelpos < posa) and (posa > posb)) + or ( (labelpos > posa) and (posa < posb)) : + save c; %swap 'em + c:=posa; + posa:=posb; + posb:= c; + fi +enddef; +% num: labelnumber +% vertical: horizontal or vertical label? +% pos: for horizontal the y coord, for vertical the x corrd +% posa, posb: positions of the borders (x coord for horizontal) +% labelpos: position for label, only for outer labels, given in the +% same direction as posa, posb +def layoutshowmark(expr num, vertical, pos, posa, posb, labelpos) = + save b,e,c,p,arrow; + numeric b,e; pair p[]; path arrow[],c; + + b:=posa; + e:=posb; + + % p0 is labelposition + % p1 is from + % p2 is to + % p3 is opposite arrow in outer marking + + if labelpos = 0 : % inner label |<----(n)---->| + p0 := (.5[b,e], pos); + else: % outer label --->| |<----(n) + swapifnecessary (b,e, labelpos); + p0 := (labelpos, pos); + p3 := ( if b < labelpos: e-5mm else: e+5mm fi ,pos); + fi + + p1 := (b,pos); + p2 := (e,pos); + + if vertical: + p0:=(ypart p0,xpart p0); + p1:=(ypart p1,xpart p1); + p2:=(ypart p2,xpart p2); + p3:=(ypart p3,xpart p3); + fi + c:= fullcircle scaled .7cm shifted p0; + + if (center(c) -- p1) intersectiontimes c = (-1,-1): + % don't draw the arrows, because there is not enough room for them. + else: + arrow1 :=center(c) -- p1 cutbefore (center(c) -- p1) intersectionpoint c ; + arrow2 := + if labelpos = 0 : % inner + center(c) -- p2 cutbefore (center(c) -- p2) intersectionpoint c + else: + p3 -- p2 + fi; + + label (decimal (num), center(c)); + draw c; + drawarrow arrow1; + drawarrow arrow2; + fi + +enddef; + + + +StartPage; +numeric xpos,ypos; + +path body,leftmargin,header,footer,rightmargin; + + +% backspace: +draw llcorner Page shifted (BackSpace,0) -- + ulcorner Page shifted (BackSpace,0) dashed evenly; + +%topspace +draw urcorner Page shifted (0,-TopSpace) -- + ulcorner Page shifted (0,-TopSpace) dashed evenly; + + +header := Field [Header] [Text]; +footer := Field [Footer] [Text]; +leftmargin := Field [LeftMargin] [Text]; +rightmargin:= Field [RightMargin][Text]; +body := Field [Text] [Text]; + +pickup pencircle scaled 2pt; + +draw Page; +draw leftmargin; +draw rightmargin; +draw header; +draw footer; +draw body; + + + +label ("Body", center (body)); +label ("Header",center (header)); +label ("Left Margin", center (leftmargin)); +label ("Right Margin", center (rightmargin)); +label ("Footer", center (footer)); +%% label (textext("\tfb Body"), center (body)); +%% label (textext("\tfa Header"),center (header)); +%% label (textext("Left Margin"), center (leftmargin)); +%% label (textext("Right Margin"), center (rightmargin)); +%% label (textext("\tfa Footer"), center (footer)); + + +if \MPvar{showmore}=1: + path top, bot, leftedge, rightedge; + + top := Field [Top] [Text]; + bot := Field [Bottom] [Text]; + leftedge := Field [LeftEdge] [Text]; + rightedge := Field [RightEdge][Text]; + + draw top; + draw bot; + draw leftedge; + draw rightedge; +fi + +pickup pencircle scaled 1pt; + +% (num, vertical, pos, from, to, labelpos) + +%backspace +layoutshowmark (1, false, .5[ypart(ulcorner Page),Vstep[Top]], 0,BackSpace,0) + + +ypos := Vstep[HeaderSeparator] -1cm; + +% leftmargin +layoutshowmark (2, false, ypos, + Hstep[LeftMargin], + Hstep[LeftMargin]+Hsize[LeftMargin],0); + +% leftmargindistance +layoutshowmark (3, false, ypos -1cm, + Hstep[LeftMarginSeparator], + Hstep[Text], + Hstep[Text]+1cm); + +% makeupwidth +layoutshowmark (4, false, Vstep[Text]+2cm, + Hstep[Text], Hstep[Text]+Hsize[Text],0); + +% rightmargin +layoutshowmark (5, false, ypos, + Hstep[RightMargin], + Hstep[RightMargin]+Hsize[RightMargin],0); + +% rightmargindistance +layoutshowmark (6, false, ypos-1cm, + Hstep[RightMargin], + Hstep[RightMarginSeparator], + Hstep[RightMarginSeparator] -1cm); + + +%topspace + +xpos:=xpart(ulcorner Page)+BackSpace+1cm; +layoutshowmark (7, true, xpos, PaperHeight,PaperHeight-TopSpace,0) + +%header +xpos:=xpos+1cm; +ypos:=.5[PaperHeight,PaperHeight-TopSpace]; +layoutshowmark (8, true, xpos , + Vstep[Header], + Vstep[Header]+Vsize[Header],ypos); + +%headerseparator +xpos:=xpos+1cm; +layoutshowmark (9, true,xpos, + Vstep[HeaderSeparator], + Vstep[HeaderSeparator]+Vsize[HeaderSeparator],ypos); + +xpos:=xpos+1cm; + +if \MPvar{showmore}=1: + % top + layoutshowmark (17, true, xpos, + Vstep[Top], + Vstep[Top]+Vsize[Top], ypos); + + xpos:=xpos+1cm; + layoutshowmark (18, true, xpos, + Vstep[TopSeparator], + Vstep[TopSeparator]+Vsize[TopSeparator], ypos); + +fi + +% makeupheight +layoutshowmark (10, true,Hstep[RightMarginSeparator]-2cm, + Vstep[Header]+Vsize[Header], + Vstep[Footer],0); + + +%footerseparator +xpos:=xpart(ulcorner Page)+BackSpace+2cm; +ypos:=.5(Vstep[Footer]); + +layoutshowmark (11, true,xpos, + Vstep[FooterSeparator], + Vstep[FooterSeparator]+Vsize[FooterSeparator],ypos); + +%footer +xpos:=xpos+1cm; +layoutshowmark (12, true,xpos, + Vstep[Footer],Vstep[Footer]+Vsize[Footer],ypos); + +xpos:=xpos+1cm; + +if \MPvar{showmore}=1: + % bottom + layoutshowmark (19, true, xpos, + Vstep[Bottom], + Vstep[Bottom]+Vsize[Bottom], ypos); + xpos:=xpos+1cm; + layoutshowmark (20, true, xpos, + Vstep[BottomSeparator], + Vstep[BottomSeparator]+Vsize[BottomSeparator], ypos); + +fi + +if \MPvar{showmore}=1: + + ypos := Vstep[HeaderSeparator] -3cm; + + % LeftEdge + layoutshowmark (13, false, ypos, + Hstep[LeftEdge], + Hstep[LeftEdge]+Hsize[LeftEdge],Hstep[Text]+1cm); + ypos := ypos-1cm; + % LeftEdgeSeparator + layoutshowmark (14, false, ypos, + Hstep[LeftEdgeSeparator], + Hstep[LeftEdgeSeparator]+Hsize[LeftEdgeSeparator], + Hstep[Text]+1cm); + + ypos := Vstep[HeaderSeparator] -3cm; + + layoutshowmark (15, false, ypos, + Hstep[RightEdge], + Hstep[RightEdge]+Hsize[RightEdge], + Hstep[RightMarginSeparator] -1cm); + + ypos := ypos-1cm; + + layoutshowmark (16, false, ypos, + Hstep[RightEdge], + Hstep[RightEdgeSeparator], + Hstep[RightMarginSeparator] -1cm); + + + +fi + +currentpicture := currentpicture scaled .5; + +\stopuniqueMPgraphic +\defineoverlay[ShowLayout][\uniqueMPgraphic{ShowLayout}] + +\def\SetupShowLayout{\dosingleempty\getparameters[ShowLayout]} +\SetupShowLayout[units=pt,digits=1,round=0.1,showmore=0,graphonly=0] + +\def\ShowLayout{\dosingleempty\doShowLayout} + + +\def\doShowLayout[#1]{% + \getparameters[ShowLayout][#1] + \setMPvariables[ShowLayout][showmore=\getvalue{ShowLayoutshowmore}] + \framed[width=.5\paperwidth, + height=.5\paperheight, + background=ShowLayout, + frame=off, +% frame=on, + ]{}% +\ifnum\getvalue{ShowLayoutgraphonly}=0 + \bgroup\tfxx +\startcolumns[n=2] +\starttabulate[|r|l|] +\NC 1 \NC backspace \ShowLayoutA{\the\backspace} \NR +\NC 2 \NC leftmargin \ShowLayoutA{\the\leftmarginwidth}\NR +\NC 3 \NC leftmargindistance \ShowLayoutA{\the\leftmargindistance}\NR +\NC 4 \NC width \ShowLayoutA{\the\makeupwidth}\NR +\NC 5 \NC rightmargin \ShowLayoutA{\the\rightmarginwidth}\NR +\NC 6 \NC rightmargindistance \ShowLayoutA{\the\rightmargindistance}\NR +\NC 7 \NC topspace \ShowLayoutA{\the\topspace}\NR +\NC 8 \NC header \ShowLayoutA{\the\headerheight}\NR +\NC 9 \NC headerdistance \ShowLayoutA{\the\headerdistance}\NR +\NC 10\NC height \ShowLayoutA{\the\makeupheight}\NR +\NC 11\NC footerdistance \ShowLayoutA{\the\footerdistance}\NR +\NC 12\NC footer \ShowLayoutA{\the\footerheight}\NR +\ifnum\getvalue{ShowLayoutshowmore}=1% +\NC 13\NC leftedge \ShowLayoutA{\the\leftedgewidth}\NR +\NC 14\NC leftedgedistance \ShowLayoutA{\the\leftedgedistance}\NR +\NC 15\NC rightedge \ShowLayoutA{\the\rightedgewidth}\NR +\NC 16\NC rightedgedistance \ShowLayoutA{\the\rightedgedistance}\NR +\NC 17\NC top \ShowLayoutA{\the\topheight}\NR +\NC 18\NC topdistance \ShowLayoutA{\the\topdistance}\NR +\NC 19\NC bottom \ShowLayoutA{\the\bottomheight}\NR +\NC 20\NC bottomdistance \ShowLayoutA{\the\bottomdistance}\NR +\fi +\NC \NC paperwidth \ShowLayoutA{\the\paperwidth}\NR +\NC \NC paperheight \ShowLayoutA{\the\paperheight}\NR +\stoptabulate +\stopcolumns +\egroup +\fi +} diff --git a/info/context-notes-zh-cn/src/t-zhfonts.lua b/info/context-notes-zh-cn/src/t-zhfonts.lua new file mode 100644 index 0000000000..c40219febf --- /dev/null +++ b/info/context-notes-zh-cn/src/t-zhfonts.lua @@ -0,0 +1,272 @@ +zhfonts = {} + +local function init_fonts_table () + local f = {} + f.serif, f.sans, f.mono = {}, {}, {} + for k in pairs (f) do + f[k] = {regular = {},bold = {}, italic = {}, bolditalic = {}} + end + return f +end + +local cjkfonts, latinfonts = init_fonts_table (), init_fonts_table () + +cjkfonts.serif.regular = {name = 'adobesongstd', rscale = '1.0'} +cjkfonts.serif.bold = {name = 'adobeheitistd', rscale = '1.0'} +cjkfonts.serif.italic = {name = 'adobesongstd', rscale = '1.0'} +cjkfonts.serif.bolditalic = {name = 'adobeheitistd', rscale = '1.0'} +cjkfonts.sans.regular = {name = 'adobeheitistd', rscale = '1.0'} +cjkfonts.sans.bold = {name = 'adobeheitistd', rscale = '1.0'} +cjkfonts.sans.italic = {name = 'adobeheitistd', rscale = '1.0'} +cjkfonts.sans.bolditalic = {name = 'adobeheitistd', rscale = '1.0'} +cjkfonts.mono.regular = {name = 'adobesongstd', rscale = '1.0'} +cjkfonts.mono.bold = {name = 'adobesongstd', rscale = '1.0'} +cjkfonts.mono.italic = {name = 'adobesongstd', rscale = '1.0'} +cjkfonts.mono.bolditalic = {name = 'adobesongstd', rscale = '1.0'} + +latinfonts.serif.regular = {name = 'texgyrepagellaregular'} +latinfonts.serif.bold = {name = 'texgyrepagellabold'} +latinfonts.serif.italic = {name = 'texgyrepagellaitalic'} +latinfonts.serif.bolditalic = {name = 'texgyrepagellabolditalic'} +latinfonts.sans.regular = {name = 'texgyreherosregular'} +latinfonts.sans.bold = {name = 'texgyreherosbold'} +latinfonts.sans.italic = {name = 'texgyreherositalic'} +latinfonts.sans.bolditalic = {name = 'texgyreherosbolditalic'} +latinfonts.mono.regular = {name = 'lmmono10regular'} +latinfonts.mono.bold = {name = 'lmmonolt10bold'} +latinfonts.mono.italic = {name = 'lmmono10italic'} +latinfonts.mono.bolditalic = {name = 'lmmonolt10boldoblique'} + +local mathfonts = {roman = {}} +mathfonts.roman.name = 'xitsmathregular' +mathfonts.roman.feature = 'math\mathsizesuffix' +mathfonts.roman.goodies = 'xits-math' + +local function strsplit(str, sep) + local start_pos = 1 + local split_pos = 1 + local result = {} + local stop_pos = nil + while true do + stop_pos = string.find (str, sep, start_pos) + if not stop_pos then + result[split_pos] = string.sub (str, start_pos, string.len(str)) + break + end + result[split_pos] = string.sub (str, start_pos, stop_pos - 1) + start_pos = stop_pos + string.len(sep) + split_pos = split_pos + 1 + end + return result +end + +local function strtrim (str) + return string.gsub (str, "^%s*(.-)%s*$", "%1") +end + +local function str_split_and_trim (str, sep) + local strlist = strsplit (str, sep) + local result = {} + for i, v in ipairs (strlist) do + result[i] = strtrim (v) + end + return result +end + +local function gen_cjk_typescript (ft) + local fb = '\\definefontfallback' + local fb_area = '[0x00400-0x2FA1F]' + local s1 = nil + + context ('\\starttypescript[serif][zhfonts]') + context ('\\setups[font:fallbacks:serif]') + s = ft.serif.regular + context (fb..'[zhSerif][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + s = ft.serif.bold + context (fb..'[zhSerifBold][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + s = ft.serif.italic + context (fb..'[zhSerifItalic][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + s = ft.serif.bolditalic + context (fb..'[zhSerifBoldItalic][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + context ('\\stoptypescript') + + context ('\\starttypescript[sans][zhfonts]') + context ('\\setups[font:fallbacks:sans]') + s = ft.sans.regular + context (fb..'[zhSans][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + s = ft.sans.bold + context (fb..'[zhSansBold][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + s = ft.sans.italic + context (fb..'[zhSansItalic][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + s = ft.sans.bolditalic + context (fb..'[zhSansBoldItalic][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + context ('\\stoptypescript') + + context ('\\starttypescript[mono][zhfonts]') + context ('\\setups[font:fallbacks:mono]') + s = ft.mono.regular + context (fb..'[zhMono][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + s = ft.mono.bold + context (fb..'[zhMonoBold][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + s = ft.mono.italic + context (fb..'[zhMonoItalic][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + s = ft.mono.bolditalic + context (fb..'[zhMonoBoldItalic][name:'..s.name..']'..fb_area..'[rscale='..s.rscale..']') + context ('\\stoptypescript') +end + +local function gen_latin_typescript (ft) + local la = '\\definefontsynonym[latin' + + context ('\\starttypescript[serif][zhfonts]') + context (la..'Serif][name:' .. ft.serif.regular.name .. ']') + context (la..'SerifBold][name:' .. ft.serif.bold.name .. ']') + context (la..'SerifItalic][name:' .. ft.serif.italic.name .. ']') + context (la..'SerifBoldItalic][name:' .. ft.serif.bolditalic.name .. ']') + context ('\\stoptypescript') + + context ('\\starttypescript[sans][zhfonts]') + context (la..'Sans][name:' .. ft.sans.regular.name .. ']') + context (la..'SansBold][name:' .. ft.sans.bold.name .. ']') + context (la..'SansItalic][name:' .. ft.sans.italic.name .. ']') + context (la..'SansBoldItalic][name:' .. ft.sans.bolditalic.name .. ']') + context ('\\stoptypescript') + + context ('\\starttypescript[mono][zhfonts]') + context (la..'Mono][name:' .. ft.mono.regular.name .. ']') + context (la..'MonoBold][name:' .. ft.mono.bold.name .. ']') + context (la..'MonoItalic][name:' .. ft.mono.italic.name .. ']') + context (la..'MonoBoldItalic][name:' .. ft.mono.bolditalic.name .. ']') + context ('\\stoptypescript') +end + +local function gen_fallback_typescript () + context ('\\starttypescript[serif][zhfonts]') + context ('\\setups[font:fallbacks:serif]') + context ('\\definefontsynonym[zhSeriffallback][latinSerif][fallbacks=zhSerif]') + context ('\\definefontsynonym[Serif][zhSeriffallback]') + context ('\\definefontsynonym[zhSerifBoldfallback][latinSerifBold][fallbacks=zhSerifBold]') + context ('\\definefontsynonym[SerifBold][zhSerifBoldfallback]') + context ('\\definefontsynonym[zhSerifItalicfallback][latinSerifItalic][fallbacks=zhSerifItalic]') + context ('\\definefontsynonym[SerifItalic][zhSerifItalicfallback]') + context ('\\definefontsynonym[zhSerifBoldItalicfallback][latinSerifBoldItalic][fallbacks=zhSerifBoldItalic]') + context ('\\definefontsynonym[SerifBoldItalic][zhSerifBoldItalicfallback]') + context ('\\stoptypescript') + + context ('\\starttypescript[sans][zhfonts]') + context ('\\setups[font:fallbacks:sans]') + context ('\\definefontsynonym[zhSansfallback][latinSans][fallbacks=zhSans]') + context ('\\definefontsynonym[Sans][zhSansfallback]') + context ('\\definefontsynonym[zhSansBoldfallback][latinSansBold][fallbacks=zhSansBold]') + context ('\\definefontsynonym[SansBold][zhSansBoldfallback]') + context ('\\definefontsynonym[zhSansItalicfallback][latinSansItalic][fallbacks=zhSansItalic]') + context ('\\definefontsynonym[SansItalic][zhSansItalicfallback]') + context ('\\definefontsynonym[zhSansBoldItalicfallback][latinSansBoldItalic][fallbacks=zhSansBoldItalic]') + context ('\\definefontsynonym[SansBoldItalic][zhSansBoldItalicfallback]') + context ('\\stoptypescript') + + context ('\\starttypescript[mono][zhfonts]') + context ('\\setups[font:fallbacks:mono]') + context ('\\definefontsynonym[zhMonofallback][latinMono][fallbacks=zhMono]') + context ('\\definefontsynonym[Mono][zhMonofallback]') + context ('\\definefontsynonym[zhMonoBoldfallback][latinMonoBold][fallbacks=zhMonoBold]') + context ('\\definefontsynonym[MonoBold][zhMonoBoldfallback]') + context ('\\definefontsynonym[zhMonoItalicfallback][latinMonoItalic][fallbacks=zhMonoItalic]') + context ('\\definefontsynonym[MonoItalic][zhMonoItalicfallback]') + context ('\\definefontsynonym[zhMonoBoldItalicfallback][latinMonoBoldItalic][fallbacks=zhMonoBoldItalic]') + context ('\\definefontsynonym[MonoBoldItalic][zhMonoBoldItalicfallback]') + context ('\\stoptypescript') +end + +local function gen_math_typescript (ft) + if mathfonts.roman.name then + local s = ft.roman + context ('\\starttypescript[math][zhfonts]') + context ('\\setups[font:fallbacks:math]') + context ('\\definefontsynonym[MathRoman][name:'..s.name..'][features='..s.feature..', goodies='..s.goodies..']') + context ('\\stoptypescript') + end +end + +local function gen_typeface () + context ('\\starttypescript[zhfonts]') + context ('\\definetypeface[zhfonts][rm][serif][zhfonts][default][features=zh]') + context ('\\definetypeface[zhfonts][ss][sans][zhfonts][default][features=zh]') + context ('\\definetypeface[zhfonts][tt][mono][zhfonts][default]') + if mathfonts.roman.name then + context ('\\definetypeface[zhfonts][mm][math][zhfonts]') + end + context ('\\stoptypescript') +end + +function zhfonts.gen_typescript () + gen_cjk_typescript (cjkfonts) + gen_latin_typescript (latinfonts) + gen_fallback_typescript () + gen_math_typescript (mathfonts) + gen_typeface () +end + +local function setup_cjkfonts (meta, fontlist) + local f, g = nil, nil + for i, v in ipairs (fontlist) do + f = str_split_and_trim (v, '=') + g = str_split_and_trim (f[2], '@') + if g[1] ~= '' then cjkfonts[meta][f[1]].name = g[1] end + if g[2] then cjkfonts[meta][f[1]].rscale = g[2] end + end +end + +local function setup_latinfonts (meta, fontlist) + local f, g = nil, nil + for i, v in ipairs (fontlist) do + f = str_split_and_trim (v, '=') + latinfonts[meta][f[1]].name = f[2] + end +end + +local function setup_mathfonts (fontlist) + local f, g = nil, nil + for i, v in ipairs (fontlist) do + f = str_split_and_trim (v, '=') + if f[2] ~= '' then + mathfonts[f[1]].name = f[2] + else + mathfonts[f[1]].name = nil + end + end +end + + +local fontfeatures = "mode=node,protrusion=myvector,liga=yes," +local function setup_fontfeatures (s) + fontfeatures = fontfeatures .. s + print (fontfeatures) +end + +function zhfonts.setup (metainfo, fontinfo) + local m = str_split_and_trim (metainfo, ',') + local f = str_split_and_trim (fontinfo, ',') + if #m == 1 and m[1] == 'feature' then setup_fontfeatures (fontinfo) end + if #m == 1 and cjkfonts[m[1]] then setup_cjkfonts (m[1], f) end + if #m == 1 and m[1] == 'math' then setup_mathfonts (f) end + if #m == 2 then + if m[1] == 'latin' and latinfonts[m[2]] then setup_latinfonts (m[2], f) end + if m[2] == 'latin' and latinfonts[m[1]] then setup_latinfonts (m[1], f) end + end +end + +function zhfonts.use (param) + context ('\\setscript[hanzi]') + zhspuncs.opt () + context ('\\definefontfeature[zh][default][' .. fontfeatures .. ']') + context ('\\setupalign[hz,hanging]') + local f = strtrim (param) + if f ~= "none" then + zhfonts.gen_typescript () + if f ~= "hack" then + context ('\\usetypescript[zhfonts]') + context ('\\setupbodyfont[zhfonts, ' .. param .. ']') + end + end +end diff --git a/info/context-notes-zh-cn/src/t-zhfonts.mkiv b/info/context-notes-zh-cn/src/t-zhfonts.mkiv new file mode 100644 index 0000000000..5549845cce --- /dev/null +++ b/info/context-notes-zh-cn/src/t-zhfonts.mkiv @@ -0,0 +1,37 @@ +%D \module +%D [ file=t-zhfonts, +%D version=2010.01.06, +%D title=\CONTEXT\ User Module, +%D subtitle=zhfonts, +%D author=Li Yanrui, +%D date=\currentdate, +%D copyright=Li Yanrui, +%D email=liyanrui.m2@gmail.com, +%D license=Public Domain] + +\writestatus{loading}{ConTeXt User Module / zhfonts} +\startmodule[zhfonts] +\unprotect +\setupmodule[style=rm,size=11pt] + +%D Lua code +\ctxloadluafile{t-zhfonts} +\ctxloadluafile{t-zhspuncs} + +\def\setupzhfonts{\dodoubleempty\dosetupzhfonts} +\def\dosetupzhfonts[#1][#2]{% + \ctxlua{zhfonts.setup ('#1', '#2')} +} + +\def\zhfonts[#1]{% + \ctxlua{zhfonts.use ("#1")} +} + +\edef\@@@@??style{\currentmoduleparameter{style}} +\edef\@@@@??size{\currentmoduleparameter{size}} +\prependtoks \zhfonts[\@@@@??style, \@@@@??size] \to \everystarttext + +\protect +\stopmodule +\endinput + diff --git a/info/context-notes-zh-cn/src/t-zhspuncs.lua b/info/context-notes-zh-cn/src/t-zhspuncs.lua new file mode 100644 index 0000000000..a739bf4c03 --- /dev/null +++ b/info/context-notes-zh-cn/src/t-zhspuncs.lua @@ -0,0 +1,178 @@ +zhspuncs = zhspuncs or {} + +local glyph = nodes.pool.register (node.new ("glyph", 0)) + +local glyph_flag = node.id ('glyph') +local glue_flag = node.id ('glue') +local hlist_flag = node.id ('hlist') +local kern_flag = node.id ('kern') +local penalty_flag = node.id ('penalty') +local math_flag = node.id ('math') + +local fonthashes = fonts.hashes +local fontdata = fonthashes.identifiers +local quaddata = fonthashes.quads + +local node_count = node.count +local node_dimensions = node.dimensions +local node_traverse_id = node.traverse_id +local node_slide = node.slide +local list_tail = node.tail +local insert_before = node.insert_before +local insert_after = node.insert_after +local new_glue = nodes.pool.glue +local new_kern = nodes.pool.kern +local new_glue_spec = nodes.pool.glue_spec +local new_penalty = nodes.pool.penalty +local new_rule = nodes.pool.rule + +local tasks = nodes.tasks + + +local puncs = { + [0x2018] = {0.5, 0.1, 1.0, 1.0}, -- ‘ + [0x201C] = {0.5, 0.1, 0.5, 1.0}, -- “ + [0x3008] = {0.5, 0.1, 1.0, 1.0}, -- 〈 + [0x300A] = {0.5, 0.1, 1.0, 1.0}, -- 《 + [0x300C] = {0.5, 0.1, 1.0, 1.0}, -- 「 + [0x300E] = {0.5, 0.1, 1.0, 1.0}, -- 『 + [0x3010] = {0.5, 0.1, 1.0, 1.0}, -- 【 + [0x3014] = {0.5, 0.1, 1.0, 1.0}, -- 〔 + [0x3016] = {0.5, 0.1, 1.0, 1.0}, -- 〖 + [0xFF08] = {0.5, 0.1, 1.0, 1.0}, -- ( + [0xFF3B] = {0.5, 0.1, 1.0, 1.0}, -- [ + [0xFF5B] = {0.5, 0.1, 1.0, 1.0}, -- { + [0x2019] = {0.1, 0.5, 1.0, 0.0}, -- ’ + [0x201D] = {0.1, 0.5, 1.0, 0.0}, -- ” + [0x3009] = {0.1, 0.5, 1.0, 0.5}, -- 〉 + [0x300B] = {0.1, 0.5, 1.0, 0.5}, -- 》 + [0x300D] = {0.1, 0.5, 1.0, 0.5}, -- 」 + [0x300F] = {0.1, 0.5, 1.0, 0.5}, -- 』 + [0x3011] = {0.1, 0.5, 1.0, 0.5}, -- 】 + [0x3015] = {0.1, 0.5, 1.0, 0.5}, -- 〕 + [0x3017] = {0.1, 0.5, 1.0, 0.5}, -- 〗 + [0xFF09] = {0.1, 0.5, 1.0, 0.5}, -- ) + [0xFF3D] = {0.1, 0.5, 1.0, 0.5}, -- ] + [0xFF5D] = {0.1, 0.5, 1.0, 0.5}, -- } + -- 需要特殊处理 + [0x2014] = {0.0, 0.0, 1.0, 1.0}, -- — + [0x2026] = {0.1, 0.1, 1.0, 1.0}, -- … + [0x2500] = {0.0, 0.0, 1.0, 1.0}, -- ─ + [0x3001] = {0.15, 0.5, 1.0, 0.5}, -- 、 + [0x3002] = {0.15, 0.6, 1.0, 0.3}, -- 。 + [0xFF01] = {0.15, 0.5, 1.0, 0.5}, -- ! + [0xFF05] = {0.0, 0.0, 1.0, 0.5}, -- % + [0xFF0C] = {0.15, 0.5, 1.0, 0.3}, -- , + [0xFF0E] = {0.15, 0.5, 1.0, 0.5}, -- . + [0xFF1A] = {0.15, 0.5, 1.0, -0.1}, -- : + [0xFF1B] = {0.15, 0.5, 1.0, 0.5}, -- ; + [0xFF1F] = {0.15, 0.5, 1.0, 0.5}, -- ? +} + +local function is_zhcnpunc_node (n) + local n_is_punc = 0 + if puncs[n.char] then + return true + end + return false +end + +local function is_zhcnpunc_node_group (n) + local n_is_punc = 0 + if puncs[n.char] then + n_is_punc = 1 + end + local nn = n.next + local nn_is_punc = 0 + -- 还需要穿越那些非 glyph 结点 + while nn_is_punc == 0 and nn and n_is_punc == 1 do + if nn.id == glyph_flag then + if puncs[nn.char] then nn_is_punc = 1 end + break + end + nn = nn.next + end + return n_is_punc + nn_is_punc +end + +local function is_cjk_ideo (n) + -- CJK Ext A + if n.char >= 13312 and n.char <= 19893 then + return true + -- CJK + elseif n.char >= 19968 and n.char <= 40891 then + return true + -- CJK Ext B + elseif n.char >= 131072 and n.char <= 173782 then + return true + else + return false + end +end + +local function quad_multiple (font, r) + local quad = quaddata[font] + return r * quad +end + +local function process_punc (head, n, punc_flag, punc_table) + local desc = fontdata[n.font].descriptions[n.char] + if not desc then return end + local quad = quad_multiple (n.font, 1) + + -- 像 $\ldots$ 这样的符号竟然没有边界盒,只好忽略并返回 + -- if desc.boundingbox == nil then return end + + local l_space = desc.boundingbox[1] / desc.width + local r_space = (desc.width - desc.boundingbox[3]) / desc.width + local l_kern, r_kern = 0.0, 0.0 + + if punc_flag == 1 then + l_kern = (punc_table[n.char][1] - l_space) * quad + r_kern = (punc_table[n.char][2] - r_space) * quad + elseif punc_flag == 2 then + l_kern = (punc_table[n.char][1] * punc_table[n.char][3] - l_space) * quad + r_kern = (punc_table[n.char][2] * punc_table[n.char][4] - r_space) * quad + end + + insert_before (head, n, new_kern (l_kern)) + insert_after (head, n, new_kern (r_kern)) +end + +local function compress_punc (head) + for n in node_traverse_id (glyph_flag, head) do + local n_flag = is_zhcnpunc_node_group (n) + if n_flag ~= 0 then + process_punc (head, n, n_flag, puncs) + end + end +end + +function zhspuncs.my_linebreak_filter (head, is_display) + compress_punc (head) + return head, true +end + +function zhspuncs.opt () + tasks.appendaction("processors","after","zhspuncs.my_linebreak_filter") +end + +fonts.protrusions.vectors['myvector'] = { + [0xFF0c] = { 0, 0.60 }, -- , + [0x3002] = { 0, 0.60 }, -- 。 + [0x2018] = { 0.60, 0 }, -- ‘ + [0x2019] = { 0, 0.60 }, -- ’ + [0x201C] = { 0.60, 0 }, -- “ + [0x201D] = { 0, 0.60 }, -- ” + [0xFF1F] = { 0, 0.60 }, -- ? + [0x300A] = { 0.60, 0 }, -- 《 + [0x300B] = { 0, 0.60 }, -- 》 + [0xFF08] = { 0.50, 0 }, -- ( + [0xFF09] = { 0, 0.50 }, -- ) + [0x3001] = { 0, 0.50 }, -- 、 + [0xFF0E] = { 0, 0.50 }, -- . +} +fonts.protrusions.classes['myvector'] = { + vector = 'myvector', factor = 1 +} + -- cgit v1.2.3