diff options
Diffstat (limited to 'macros/latex/contrib/zhlipsum/zhlipsum.dtx')
-rw-r--r-- | macros/latex/contrib/zhlipsum/zhlipsum.dtx | 1505 |
1 files changed, 1505 insertions, 0 deletions
diff --git a/macros/latex/contrib/zhlipsum/zhlipsum.dtx b/macros/latex/contrib/zhlipsum/zhlipsum.dtx new file mode 100644 index 0000000000..3ef3fd63a8 --- /dev/null +++ b/macros/latex/contrib/zhlipsum/zhlipsum.dtx @@ -0,0 +1,1505 @@ +% \iffalse meta-comment +% +% Copyright (C) 2017, 2018 by Xiangdong Zeng <xdzeng96@gmail.com> +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either +% version 1.3c of this license or (at your option) any later +% version. The latest version of this license is in: +% +% http://www.latex-project.org/lppl.txt +% +% and version 1.3 or later is part of all distributions of +% LaTeX version 2005/12/01 or later. +% +% This work has the LPPL maintenance status `maintained'. +% +% The Current Maintainer of this work is Xiangdong Zeng. +% +% This work consists of the files zhlipsum.dtx, +% zhlipsum-text.dtx, +% and the derived files zhlipsum.ins, +% zhlipsum.sty, +% zhlipsum-utf8.def, +% zhlipsum-gbk.def, +% zhlipsum-big5.def, +% zhlipsum-en.tex, +% zhlipsum.pdf, +% zhlipsum-en.pdf, +% and README.md. +% +%<*internal> +\iffalse +%</internal> +% +%<*readme> +The `zhlipsum` package +====================== + +The `zhlipsum` package provides an interface to dummy text in +Chinese language, which will be useful for testing Chinese +documents. + +`zhlipsum` supports UTF-8, GBK and Big5 encodings. + +Basic usage +----------- + + \zhlipsum + \zhlipsum*[1-5] + \zhlipsum[6-10,18][name=trad] + +More information can be found in the package documentation +[zhlipsum.pdf](http://mirror.ctan.org/macros/latex/contrib/zhlipsum/zhlipsum.pdf) +(Chinese version) or [zhlipsum-en.pdf](http://mirror.ctan.org/macros/latex/contrib/zhlipsum/zhlipsum-en.pdf) +(English version). + +Installation +------------ + +To install `zhlipsum`, you can use one of the following methods: + +- If you are running TeX Live, the simplest way is to run + + tlmgr install zhlipsum + +- Download + [zhlipsum.tds.zip](http://mirror.ctan.org/install/macros/latex/contrib/zhlipsum.tds.zip) + from CTAN, extract it in the root of one of your TDS trees, and + update the filename database. + +Contributing +------------ + +[Issues](https://github.com/Stone-Zeng/zhlipsum/issues) and +[pull requests](https://github.com/Stone-Zeng/zhlipsum/pulls) +are always welcome. + +License +------- + +This work may be distributed and/or modified under the conditions of +the [LaTeX Project Public License](http://www.latex-project.org/lppl.txt), +either version 1.3c of this license or (at your option) any later +version. + +----- + +Copyright (C) 2017, 2018 by Xiangdong Zeng <xdzeng96@gmail.com>. +%</readme> +% +%<*internal> +\fi +\begingroup + \def\NameOfLaTeXe{LaTeX2e} +\expandafter\endgroup\ifx\NameOfLaTeXe\fmtname\else +\csname fi\endcsname +%</internal> +% +%<*install> +\input ctxdocstrip.tex +\keepsilent + +\preamble + + Copyright (C) 2017, 2018 by Xiangdong Zeng <xdzeng96@gmail.com> + + This work may be distributed and/or modified under the + conditions of the LaTeX Project Public License, either + version 1.3c of this license or (at your option) any later + version. The latest version of this license is in: + + http://www.latex-project.org/lppl.txt + + and version 1.3 or later is part of all distributions of + LaTeX version 2005/12/01 or later. + + This work has the LPPL maintenance status `maintained'. + + The Current Maintainer of this work is Xiangdong Zeng. + + This work consists of the files zhlipsum.dtx, + zhlipsum-text.dtx, + and the derived files zhlipsum.ins, + zhlipsum.sty, + zhlipsum-utf8.def, + zhlipsum-gbk.def, + zhlipsum-big5.def, + zhlipsum-en.tex, + zhlipsum.pdf, + zhlipsum-en.pdf, + and README.md. + +\endpreamble + +\generate{ + \usedir{tex/latex/zhlipsum} + \file{\jobname.sty} {\from{\jobname.dtx}{package}} + \file{\jobname-utf8.def} {\from{\jobname.dtx}{text,utf8} + \from{\jobname-text.dtx}{text,utf8}} + \file{\jobname-gbk.def} {\from{\jobname.dtx}{text,gbk} + \from{\jobname-text.dtx}{text,gbk}} + \file{\jobname-big5.def} {\from{\jobname.dtx}{text,big5} + \from{\jobname-text.dtx}{text,big5}} +%</install> +%<*internal> + \usedir{source/latex/zhlipsum} + \file{\jobname.ins} {\from{\jobname.dtx}{install}} +%</internal> +%<*install> + \usedir{doc/latex/zhlipsum} + \nopreamble\nopostamble + \file{README.md} {\from{\jobname.dtx}{readme}} +} + +\obeyspaces +\Msg{****************************************************} +\Msg{* *} +\Msg{* To finish the installation you have to move the *} +\Msg{* following file into a directory searched by TeX: *} +\Msg{* *} +\Msg{* zhlipsum.sty *} +\Msg{* zhlipsum-utf8.def *} +\Msg{* zhlipsum-gbk.def *} +\Msg{* zhlipsum-big5.def *} +\Msg{* *} +\Msg{* The recommended directory is *} +\Msg{* TDS:tex/latex/zhlipsum *} +\Msg{* *} +\Msg{* To produce the documentation run the file *} +\Msg{* zhlipsum.dtx through XeLaTeX. *} +\Msg{* *} +\Msg{* Happy TeXing! *} +\Msg{* *} +\Msg{****************************************************} + +\endbatchfile +%</install> +% +%<*internal> +\fi +%</internal> +% +%<package>\NeedsTeXFormat{LaTeX2e} +%<package>\RequirePackage{expl3} +%<*!(driver|install)> +%<!readme>\GetIdInfo $Id: zhlipsum.dtx 1.1.1 2018-09-08 12:00:00Z Xiangdong Zeng <xdzeng96@gmail.com> $ +%<package> {Chinese dummy text} +%<package>\ProvidesExplPackage{\ExplFileName} +%<utf8> {Chinese dummy text with UTF-8 encoding (for zhlipsum)} +%<utf8>\ProvidesExplFile{\ExplFileName-utf8.def} +%<gbk> {Chinese dummy text with GBK encoding (for zhlipsum)} +%<gbk>\ProvidesExplFile{\ExplFileName-gbk.def} +%<big5> {Chinese dummy text with Big5 encoding (for zhlipsum)} +%<big5>\ProvidesExplFile{\ExplFileName-big5.def} +%<!readme> {\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} +%</!(driver|install)> +%<*driver> +%\PassOptionsToPackage{showframe}{geometry} +%^^A! \PassOptionsToPackage{scheme=plain, linespread=1.1}{ctex} +%^^A+ +\documentclass{ctxdoc} +\usepackage{multirow} +\setCJKmonofont{FangSong}[ItalicFont=KaiTi] +%^^A- +\hypersetup{% + pdftitle={zhlipsum: 中文乱数假文(Lorem ipsum)}, + pdfauthor={曾祥东}, + bookmarksnumbered=true +} +%^^A! \hypersetup{% +%^^A! pdftitle={zhlipsum: Chinese dummy text}, +%^^A! pdfauthor={Xiangdong Zeng}, +%^^A! bookmarksnumbered=true +%^^A! } +%^^A! \ctexset{% +%^^A! section={name={}, format+=\raggedright}, +%^^A! subsubsection/tocline={\CTEXnumberline{#1}#2} +%^^A! } +%^^A! \pagestyle{headings} +%^^A+ +% Use `!` for comment in `ctexexam`. +\makeatletter +\catcode`!=\active +\RecustomVerbatimEnvironment{ctexexam}{Verbatim}{% + frame=single, framesep=10pt, +%^^A- + gobble=4, + label=\rule{0pt}{12pt}\textnormal{\bfseries 例 \arabic{ctexexam}}, +%^^A! gobble=2, +%^^A! label=\rule{0pt}{12pt}\textnormal{\bfseries Example \arabic{ctexexam}}, +%^^A+ + listparameters=% + \setlength\topsep{\bigskipamount}% + \refstepcounter{ctexexam}\ctexexamlabelref + \appto\FV@EndList{\nointerlineskip}, + defineactive=\def!{\color{gray}\itshape\%}} +\preto\ctexexam{\catcode`!=\active} +\preto\endctexexam{\catcode`!=12} +\catcode`!=12 +% Do not add hyperlink for `TF`, and do not change color. +\ExplSyntaxOn +\cs_set_protected:Npn \__codedoc_typeset_TF: + { + \group_begin: + \exp_args:No \__codedoc_if_macro_internal:nT \l__codedoc_tmpa_tl + { \color[gray]{0.5} } + \itshape TF + \makebox[0pt][r] + { + \color{red} + \underline{\phantom{\itshape TF} \kern-0.1em} + } + \group_end: + } +% From l3doc, to make @@ -> <module> while @@@@ -> @@ +\cs_set_protected:Npn \__ctxdoc_replace_at_at_aux:Nn #1#2 + { + \tl_replace_all:Nnn #1 { \token_to_str:N @ } { @ } + \tl_replace_all:Nnn #1 { \token_to_str:N _ } { _ } + \tl_replace_all:Nnn #1 { @ @ @ @ } { \token_to_str:N a a } + \tl_replace_all:Nnn #1 { _ _ @ @ } { _ _ #2 } + \tl_replace_all:Nnn #1 { _ @ @ } { _ _ #2 } + \tl_replace_all:Nnn #1 { @ @ } { _ _ #2 } + \tl_replace_all:Nnn #1 { \token_to_str:N a a } { @ @ } + } +\ExplSyntaxOff +\makeatother +\RenewDocumentEnvironment{arguments}{}% + {\enumerate[label={\texttt{\#\arabic*:~}}, + leftmargin=2em, labelsep=0pt, nolistsep]}% + {\endenumerate} +%^^A- +\def\IndexLayout{% + \newgeometry{hmargin=1.00in, vmargin={1.25in, 1.00in}}% + \ctexset{section/numbering=false}% + \StopSpecialIndexModule} +\DoNotIndex{\\} +\begin{document} + \DocInput{\jobname.dtx} + \IndexLayout + \PrintChanges + \PrintIndex +\end{document} +%</driver> +% \fi +% +% \changes{v0.1}{2017/04/08}{开始编写宏包。} +% \changes{v0.2}{2017/04/14}{仿照 \pkg{kantlipsum} 宏包,实现 +% 任意的段落选取。} +% \changes{v0.2}{2017/04/14}{使用名字空间。} +% \changes{v0.4}{2017/09/16}{将安装、测试文件集成进源文件。} +% \changes{v0.4}{2017/09/16}{优化宏包实现。} +% \changes{v0.5}{2018/01/06}{添加英文版用户文档。} +% \changes{v1.1.1}{2018/09/08}{完善持续集成系统,在多平台上进行测试。} +% +% \CheckSum{0} +% +% \CharacterTable +% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z +% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z +% Digits \0\1\2\3\4\5\6\7\8\9 +% Exclamation \! Double quote \" Hash (number) \# +% Dollar \$ Percent \% Ampersand \& +% Acute accent \' Left paren \( Right paren \) +% Asterisk \* Plus \+ Comma \, +% Minus \- Point \. Solidus \/ +% Colon \: Semicolon \; Less than \< +% Equals \= Greater than \> Question mark \? +% Commercial at \@ Left bracket \[ Backslash \\ +% Right bracket \] Circumflex \^ Underscore \_ +% Grave accent \` Left brace \{ Vertical bar \| +% Right brace \} Tilde \~} +% +% \title{\textbf{zhlipsum: 中文乱数假文(Lorem ipsum)}} +% \author{曾祥东} +% \date{2018/09/08 \quad v1.1.1^^A +% \thanks{\url{https://github.com/Stone-Zeng/zhlipsum}.}} +%^^A! \title{\textbf{The \pkg{zhlipsum} Package: Chinese Dummy Text}} +%^^A! \author{Xiangdong Zeng} +%^^A! \date{2018/09/08 \quad v1.1.1% +%^^A! \thanks{\url{https://github.com/Stone-Zeng/zhlipsum}.}} +%^^A! +% +%^^A 标题页页边距 +% \newgeometry{hmargin={1.25in, 1.25in}, vmargin={1.25in, 1.00in}} +% +%^^A! \begin{document} +%^^A! +% +% \maketitle +% +% \begin{minipage}{0.9\textwidth} +% \small \itshape +% \mbox{} \par \mbox{} \par +% \qquad 如彭奇和瓦特曼的公共事业所证实的那样有一个胡子雪雪白的上帝超 +% 越时间超越空间确确实实存在他在神圣的冷漠神圣的疯狂神圣的喑哑的高处深 +% 深地爱着我们除了少数的例外不知什么原因但时间将会揭示他像神圣的密兰达 +% 一样和人们一起忍受着痛苦这班人不知什么原因但时间将会揭示生活在痛苦中 +% 生活在烈火中这烈火这火焰如果继续燃烧毫无疑问将使穹苍着火也就是说将地 +% 狱炸上天去天是那么蓝那么澄澈那么平静这种平静尽管时断时续总比没有好得 +% 多但是别这么快还要进一步考虑到泰斯丢和丘那德的人体测定学院的未完成的 +% 研究结果早已断定毫无疑问换句话说除了依附着人类的疑问之外别无其他疑问 +% 根据泰斯丢和丘那德的未完成的劳动的结果早已作出如下的论断但是别这么快 +% 不知什么原因根据彭奇和瓦特曼的公共事业的结果已毫无疑问地断定鉴于波波 +% 夫和贝尔契不知什么原因未完成的劳动以及泰斯丢和丘那德的未完成的劳动已 +% 经就业已被许多人所否认的论点作出论断认为泰斯丢和丘那德所假设的人认为 +% 实际存在的人认为人类总而言之统而言之尽管有进步的营养学和通大便药却在 +% 衰弱萎缩衰弱萎缩而且与此同时尤其是不知什么原因尽管体育运动在各方面都 +% 有很大进展如网球足球田径车赛游泳飞行划船骑马滑翔溜冰各式各样的网球各 +% 种各样致人死命的飞行运动各式各样的秋天夏天冬天冬天网球各种各样的曲棍 +% 球盘尼西林和代用品总之我接下去讲与此同时不知什么原因要萎缩要减少尽管 +% 有网球我接下去讲飞行滑翔九穴和十八穴的高尔夫球各种各样的网球总之不知 +% 什么原因在番克汉贝克汉福尔汉克莱普汉换句话说与此同时尤其是不知什么原 +% 因但时间将会揭示要减少减少我接下去讲福尔汉克莱普汉总之自从塞缪尔·约 +% 翰逊去世以后到现在每个人的全部损失共计每人一吋四唡只是大概约略粗粗计 +% 算到小数点分量很足保持整数赤裸裸的光穿着袜子在康纳马拉总之不知什么原 +% 因不管怎样无论如何事实俱在尤其是考虑到更加远为严肃的看来更加严肃的鉴 +% 于斯丹威格和彼特曼的徒劳看来更加严肃的鉴于鉴于鉴于斯丹威格和彼特曼徒 +% 劳在平原在山地在海洋在烈火沸腾的河里天空是一样的随后是大地换句话说天 +% 空随后是大地在一片寒冷一片漆黑中天空大地石头的住所在一片寒冷中哎哟哟 +% 在我们的主诞生六百年左右天空大地海洋大地石头的住所汪洋中一片寒冷中在 +% 海上在陆地在空中我接下去讲不知什么原因尽管有网球事实俱在但时间将会揭 +% 示我接下去讲哎哟哟总之一句话石头的住所谁能怀疑我接下去讲但是别这么快 +% 我接下去讲头颅要萎缩衰弱减少与此同时尤其是不知什么原因尽管有网球胡子 +% 火焰球队石头那么蓝那么平静哎哟哟头颅头颅头颅头颅在康纳马拉尽管有网球 +% 未完成的徒然的劳动更加严肃的石头的住所总之我接下去讲哎哟哟徒劳的未完 +% 成的头颅头颅在康纳马拉尽管有网球头颅哎哟石头丘那德(混战,最后的狂 +% 喊)网球……石头……那么平静……丘那德……未完成的…… +% \end{minipage} +% +% \begin{flushright} +% \small \itshape ——萨缪尔·贝克特《等待戈多》 +% \end{flushright} +% +%^^A 用户手册的页边距 +%^^A+ +% \newgeometry{% +% hmargin={2.0in, 0.8in}, +% vmargin={1.2in, 1.0in}, +% marginpar=1.8in +% } +%^^A- +%^^A! +% +%^^A! \maketitle +%^^A! +% +% \section{简介} +%^^A! \section{Introduction} +%^^A! +% +% \pkg{zhlipsum} 宏包用于输入中文乱数假文(拉丁语为 \emph{Lorem +% ipsum})。乱数假文是大段无意义的文字,常用来测试排版效果。支持其他 +% 语言乱数假文的宏包还有 \pkg{lipsum}、\pkg{kantlipsum}、 +% \pkg{blindtext} 等。 +%^^A! The \pkg{zhlipsum} package is used for typesetting dummy text +%^^A! (i.e.\ ``\emph{Lorem ipsum}'') as \pkg{lipsum}, +%^^A! \pkg{kantlipsum}, \pkg{blindtext} etc., but for Chinese +%^^A! language. Dummy text will be pretty useful, for example, when +%^^A! testing fonts or page styles. +%^^A! +% +% \pkg{zhlipsum} 宏包支持 UTF-8、GBK 和 Big5 编码,依赖 \LaTeX3{} 项目 +% 中的 \pkg{expl3}、\pkg{xparse} 和 \pkg{l3keys2e} 宏包。为正确输入中 +% 文,\pkg{zhlipsum} 需要与 \pkg{CJK} 宏包或 \CTeX{} 宏集等配套使用。 +%^^A! \pkg{zhlipsum} supports UTF-8, GBK and Big5 encodings. Packages +%^^A! \pkg{expl3}, \pkg{xparse} and \pkg{l3keys2e} in the \LaTeX3{} +%^^A! Project are required. To typeset Chinese properly, \pkg{zhlipsum} +%^^A! should be used with \pkg{CJK} package or \CTeX{} bundle. +%^^A! +% +% \section{使用说明} \label{sec:user-guide} +%^^A! \section{User's guide} \label{sec:user-guide} +%^^A! +% +%^^A+ +% \begin{function}[added=2017-09-16,updated=2018-04-01]{encoding} +% \begin{syntax} +% encoding = <(utf8)|gbk|big5> +% \end{syntax} +%^^A- +% 用于指定编码的宏包选项,可在调用宏包的时候设定。默认为 +% \opt{utf8}。对于 \XeLaTeX{}、\LuaLaTeX{} 和 \upLaTeX{} 等 Unicode +% 引擎,\opt{gbk} 和 \opt{big5} 编码无效,宏包将强制使用 \opt{utf8} +% 编码。 +% \end{function} +%^^A! Package option for selecting encoding. Default value is +%^^A! \opt{utf8}. For Unicode engines as \XeLaTeX{}, \LuaLaTeX{} and +%^^A! \upLaTeX{}, \opt{gbk} / \opt{big5} encodings are invalid and +%^^A! \opt{utf8} will be used forcibly. +%^^A! \end{function} +%^^A! +% +% 如果使用了 \CTeX{} 宏集,则编码会根据 \CTeX{} 自动确定。但需注意, +% 在 \CTeX{} 宏集中,相应的宏包选项为 \opt{UTF8} 和 \opt{GBK},而本 +% 宏包中所有选项均为小写。 +%^^A! If you have loaded \CTeX{} bundle, then the encoding will be +%^^A! selected automatically according to \CTeX{}. Note that in \CTeX{} +%^^A! bundle, the correspoding options are \opt{UTF8} and \opt{GBK}, +%^^A! while the options in \pkg{zhlipsum} are all in \emph{lowercase}. +%^^A! +% +%^^A+ +% \begin{function}[updated=2018-04-08]{\zhlipsum} +%^^A- +% \begin{syntax} +% \cs{zhlipsum}\oarg{段落}\oarg{选项} +% \cs{zhlipsum}*\oarg{段落}\oarg{选项} +% \end{syntax} +% 插入假文文本。参数 \meta{段落} 和 \meta{选项} 都是可选的。注意各 +% 参数之间不可以有空格。 +% \end{function} +%^^A! \begin{syntax} +%^^A! \cs{zhlipsum}\oarg{paragraph}\oarg{options} +%^^A! \cs{zhlipsum*}\oarg{paragraph}\oarg{options} +%^^A! \end{syntax} +%^^A! Produce dummy text. Both arguments \meta{paragraph} and +%^^A! \meta{options} are optional. Note that spaces are not allowed +%^^A! between the arguments. +%^^A! \end{function} +%^^A! +% +% 默认情况下,不带星号的命令 \cs{zhlipsum} 会在假文段落之前、之后与 +% 之间进行分段(即插入 \tn{par}),而带星号的命令 \cs{zhlipsum}|*| +% 则不做额外处理。您可以利用后文给出的 \opt{before}、\opt{after}、 +% \opt{inter} 选项来更改默认设置。 +%^^A! By default, the \cs{zhlipsum} command will insert \tn{par} before, +%^^A! after and between dummy text paragraphs, while \cs{zhlipsum}|*| +%^^A! will not give any extra processing. To change the default +%^^A! behavior, you can use the \opt{before}, \opt{after} and +%^^A! \opt{inter} options described below. +%^^A! +% +% 第一个可选参数 \meta{段落} 为英文逗号分隔的段落编号列表,举例如下: +%^^A! The first optional argument \meta{paragraph} should be a comma +%^^A! list. It can be specified as the following: +%^^A! +% +% \begin{ctexexam} +% ! 假设假文最大段落数为 50 +% \zhlipsum[2-4] ! 可用 a-b 的形式指定 +% \zhlipsum[4,12,3-8] ! 也可用单个数字指定 +% \zhlipsum[-10,40-] ! 输出 1-10 段和 40-50 段 +% \zhlipsum[-] ! 输出全部段落,即 1-50 段 +% \zhlipsum ! 默认输出 1-3 段 +% \zhlipsum[48-52] ! 超出部分会自动忽略,即只输出 48-50 段 +% \end{ctexexam} +%^^A! \begin{ctexexam} +%^^A! ! Suppose the dummy text has 50 paragraphs. +%^^A! \zhlipsum[2-4] ! Can be specified as a-b +%^^A! \zhlipsum[4,12,3-8] ! A single number is also acceptable +%^^A! \zhlipsum[-10,40-] ! Produce paragraphs 1-10 and 40-50 +%^^A! \zhlipsum[-] ! Produce all paragraphs, i.e. 1-50 +%^^A! \zhlipsum ! Default value is 1-3 +%^^A! \zhlipsum[48-52] ! Numbers larger than 50 will not be considered +%^^A! ! i.e. only paragraphs 48-50 are produced +%^^A! \end{ctexexam} +%^^A! +% +% 第二个可选参数 \meta{选项} 通过英文逗号分隔的键值列表形式给出。 +% 支持的选项见下。 +%^^A! The second optional argument \meta{options} should be a +%^^A! key-value list. Supported options are the listed below. +%^^A! +% +%^^A+ +% \begin{function}[added=2018-03-24]{name} +%^^A- +% \begin{syntax} +% name = \meta{假文名称} +% \end{syntax} +% 选择插入假文的名称。预定义的假文共有 6 种,见表~^^A +% \ref{tab:pre-defined-dummy-text}。当 |encoding=utf8| 或 |gbk| 时, +% 默认使用的假文为 |simp|;而当 |encoding=big5| 时,默认则为 |trad|。 +% \end{function} +%^^A! \begin{syntax} +%^^A! name = \meta{name} +%^^A! \end{syntax} +%^^A! Select the name of the dummy text. There are 6 pre-defined +%^^A! dummy texts described in table~\ref{tab:pre-defined-dummy-text}. +%^^A! The default text is |simp| when |encoding=utf8| or |gbk|, but +%^^A! |trad| when |encoding=big5|. +%^^A! \end{function} +%^^A! +% +%^^A+ +% \begingroup +% \def\B{\bullet} +% \def\M#1{\multirow{2}*{\textbf{#1}}} +% \def\T#1{\textbf{#1}} +% \begin{table}[htb] +%^^A- +% \caption{预定义假文} \label{tab:pre-defined-dummy-text} +% \centering\small +% \begin{tabular}{cccccccc} +% \toprule +% \M{名称} & \M{段落数} & \M{简体 / 繁体} & \M{描述} & +% \multicolumn{3}{c}{\T{各编码下的支持情况}} \\ +% & & & & |utf8| & |gbk| & |big5| \\ +% \midrule +% |simp| & 50 & 简 & 无意义随机假文 & \B & \B & \\ +% |trad| & 50 & 繁 & 无意义随机假文 & \B & \B & \B \\ +% |nanshanjing| & 43 & 繁 & 《山海经·南山经》 & \B & & \\ +% |xiangyu| & 45 & 繁 & 司马迁《史记·项羽本纪》 & \B & \B & \B \\ +% |zhufu| & 110 & 简 & 鲁迅《祝福》 & \B & \B & \\ +% |aspirin| & 66 & 简 & 维基百科条目:阿司匹林 & \B & \B & \\ +% \bottomrule +% \end{tabular} +% \end{table} +% \endgroup +%^^A! \caption{Pre-defined dummy texts} \label{tab:pre-defined-dummy-text} +%^^A! \centering\scriptsize +%^^A! \begin{tabular}{cccccccc} +%^^A! \toprule +%^^A! \M{Name} & \T{Paragraph} & \T{Simplified /} & \M{Description} & +%^^A! \multicolumn{3}{c}{\T{Encodings' support}} \\ +%^^A! & \T{numbers} & \T{traditional} & & |utf8| & |gbk| & |big5| \\ +%^^A! \midrule +%^^A! |simp| & 50 & S & Random dummy text & \B & \B & \\ +%^^A! |trad| & 50 & T & Random dummy text & \B & \B & \B \\ +%^^A! |nanshanjing| & 43 & T & \emph{Shanhaijing: Nanshanjing} & \B & & \\ +%^^A! |xiangyu| & 45 & T & \emph{Shiji: Xiang Yu Benji} by Sima Qian & \B & \B & \B \\ +%^^A! |zhufu| & 110 & S & \emph{Zhufu} by Lu Xun & \B & \B & \\ +%^^A! |aspirin| & 66 & S & Wikipedia: \emph{Aspirin} & \B & \B & \\ +%^^A! \bottomrule +%^^A! \end{tabular} +%^^A! \end{table} +%^^A! \endgroup +%^^A! +% +% 您也可以通过 \cs{newzhlipsum} 命令来定义新的假文。 +%^^A! You can use \cs{newzhlipsum} command to define new dummy text +%^^A! as well. +%^^A! +% +%^^A+ +% \begin{function}[added=2018-03-29]{before,after,inter} +%^^A- +% \begin{syntax} +% name = \meta{内容} +% after = \meta{内容} +% inter = \meta{内容} +% \end{syntax} +% 在假文段落之前、之后与之间插入内容。注意使用不带星号的 +% \cs{zhlipsum} 命令时插入的分段命令会被这里的设置覆盖。 +% \end{function} +%^^A! \begin{syntax} +%^^A! name = \meta{content} +%^^A! after = \meta{content} +%^^A! inter = \meta{content} +%^^A! \end{syntax} +%^^A! Insert contents before, after or between dummy text paragraphs. +%^^A! Note that the \tn{par} command inserted when using \cs{zhlipsum} +%^^A! will be overridden by the settings here. +%^^A! \end{function} +%^^A! +% +% \pagebreak[3] +% +%^^A+ +% \begin{function}[added=2018-03-29]{\newzhlipsum} +%^^A- +% \begin{syntax} +% \cs{newzhlipsum}\Arg{假文名称}\Arg{段落列表} +% \end{syntax} +% 声明新的假文。假文名称区分大小写。段落列表以英文逗号分隔,示例如下: +% \end{function} +%^^A! \begin{syntax} +%^^A! \cs{newzhlipsum}\Arg{name}\Arg{paragraphs list} +%^^A! \end{syntax} +%^^A! Declare new dummy text. The \meta{name} is case sensitive and +%^^A! the \meta{paragraphs list} is a comma list. An example is +%^^A! shown below: +%^^A! \end{function} +%^^A! +% +% \begin{ctexexam} +% ! 注意区分中文逗号与英文逗号 +% \newzhlipsum{jingyesi}{! +% {床前明月光,}, {疑是地上霜。}, {举头望明月,}, {低头思故乡。}} +% +% \zhlipsum*[-][name=jingyesi] ! 输出全部四句假文,且不分段 +% \end{ctexexam} +%^^A! \begin{ctexexam} +%^^A! ! Fullwidth comma `,' is used in Chinese language. +%^^A! ! Normal comma `,' is used as separator. +%^^A! \newzhlipsum{jingyesi}{! +%^^A! {床前明月光,}, {疑是地上霜。}, {举头望明月,}, {低头思故乡。}} +%^^A! +%^^A! \zhlipsum*[-][name=jingyesi] ! Print all the four sentences without `\par' +%^^A! \end{ctexexam} +%^^A! +% +% \section{编程接口} +%^^A! \section{Programming interface} +%^^A! +% +% 一般而言,第~\ref{sec:user-guide} 节中列出的命令足够一般用户使用。 +% 如需使用编程接口,则可以考虑以下变量和函数。注意使用时需确保开启 +% \LaTeX3 语法。 +%^^A! Usually, the commands provided in section~\ref{sec:user-guide} +%^^A! are sufficient for users. For programmers professional users, +%^^A! however, the programming interface is also necessary and provided +%^^A! here. \LaTeX3 syntax should be opened when using them. +%^^A! +% +% +%^^A+ +% \begin{variable}{\g_zhlipsum_seq} +%^^A- +% 假文名称列表。 +%\end{variable} +%^^A! A sequence of dummy text names. +%^^A! \end{variable} +%^^A! +% +%^^A+ +% \begin{function}{\zhlipsum_use:nn} +%^^A- +% 输出多段假文。 +% \begin{arguments} +% \item 假文名称 +% \item 段落编号列表 +% \end{arguments} +% \end{function} +%^^A! Produce some dummy text paragraphs. +%^^A! \begin{arguments} +%^^A! \item Name +%^^A! \item Comma list of aragraph numbers. +%^^A! \end{arguments} +%^^A! \end{function} +%^^A! +% +%^^A+ +% \begin{function}[TF]{\zhlipsum_if_exist:n} +%^^A- +% 判断是否存在对应名称的假文。 +% \begin{arguments} +% \item 假文名称 +% \end{arguments} +% \end{function} +%^^A! Test whether the name has been used for dummy text。 +%^^A! \begin{arguments} +%^^A! \item Name +%^^A! \end{arguments} +%^^A! \end{function} +%^^A! +% +%^^A+ +% \begin{function}{\zhlipsum_new:nn} +%^^A- +% 声明假文。 +% \begin{arguments} +% \item 假文名称 +% \item 文本列表 +% \end{arguments} +% \end{function} +%^^A! Declare dummy text. +%^^A! \begin{arguments} +%^^A! \item Name. +%^^A! \item Comma list of texts. +%^^A! \end{arguments} +%^^A! \end{function} +%^^A! +% +% \section{兼容性信息} +%^^A! \section{Compatibility information} +%^^A! +% +% 以下选项在测试版 \pkg{zhlipsum} 宏包中存在,但在 1.0.0 版本之后不 +% 建议继续使用。这里仅为兼容性保留。未来将可能删除对它们的支持。 +%^^A! The following option exists in the beta version of \pkg{zhlipsum} +%^^A! package, but has become deprecated after version 1.0.0. It is +%^^A! reserved only for compatibility and may be removed in the future. +%^^A! +% +% \begin{function}{script} +% 过时选项。现在相当于 \opt{name}。 +% \end{function} +%^^A! \begin{function}{script} +%^^A! Deprecated option. Now it's the same as \opt{name}. +%^^A! \end{function} +%^^A! +% +% \section{已知问题} +%^^A! \section{Known issues} +%^^A! +% +% 名称为 |nanshanjing| 和 |xiangyu| 的假文文本含有若干生僻字。如需正确 +% 显示,可使用 \pkg{xeCJK} 宏包,并设置后备字体为 SimSun-ExtB、Hanazono +% Mincho (花园明朝)等,具体方法请参考 \pkg{xeCJK} 宏包文档(仅针对 +% 编码为 UTF-8,且使用 \XeLaTeX{} 编译的情况)。 +%^^A! Dummy text |nanshanjing| and |xiangyu| have some rarely used +%^^A! characters. To display them correctly, you can use the \pkg{xeCJK} +%^^A! package and set SimSun-ExtB or Hanazono Mincho as the fallback +%^^A! font. Refer to the \pkg{xeCJK}'s user guide for specific methods +%^^A! (only for UTF-8 encoding and \XeLaTeX{} engine). +%^^A! +% +% GBK 和 Big5 编码在第二字节并没有避开 ASCII 码的范围,因此部分汉字编 +% 码的第二字节恰好是 ASCII 编码中的一些特殊字符(如 |{|、|}|、|\| +% 等),将导致编译失败。本宏包在这两种编码下的 \file{.def} 文件中采取 +%了特殊技巧(见~\ref{subsec:dummy-text} 小节),请避免修改这些文件。 +%^^A! GBK and Big5 encodings do not escape the ASCII range in the +%^^A! second byte, so the second byte of some Chinese characters may +%^^A! have the same encoding as special characters in ASCII like |{|, +%^^A! |}|, |\| etc., which will lead to compilation failure. The +%^^A! \file{.def} files in \pkg{zhlipsum} are created with special +%^^A! techniques. Please do not modify them. +%^^A! +% +% 如无特殊需要,始终建议您采用 UTF-8 编码,并使用 \XeLaTeX{}、 +% \LuaLaTeX{} 等 Unicode 引擎编译。 +%^^A! If there is no special requirement, UTF-8 encoding and Unicode +%^^A! engines as \XeLaTeX{} and \LuaLaTeX{} are always recommended. +%^^A! +% +% 特殊情况下,如果您必须使用 GBK 或 Big5 编码,并需要声明新的假文, +% 可以采取以下手段临时回避上述问题。 +%^^A! In special cases, if you must use GBK or Big5 encoding and need +%^^A! to declare new dummy text, the following method can be taken in +%^^A! order to avoid the problem temporarily. +%^^A! +% +% \begin{ctexexam} +% ! 文件编码需使用 Big5 +% ! \usepackage[encoding=big5]{zhlipsum} +% +% ! 直接使用 \newzhlipsum{big5}{許蓋功, 蓋功許, 功許蓋} 会报错 +% ! 原理:在分组内用 <、>、+ 代替 {、}、\,再将原先的 {、}、\ 设为“其他” +% ! 类(即类别码为 12) +% \begingroup +% \catcode`\<=1 +% \catcode`\>=2 +% \catcode`\+=0 +% \catcode`\{=12 +% \catcode`\}=12 +% \catcode`\\=12 +% +newzhlipsum<big5><許蓋功, 蓋功許, 功許蓋> +% +endgroup +% \zhlipsum[name=big5] +% \end{ctexexam} +%^^A! \begin{ctexexam} +%^^A! ! File encoding should be Big5. +%^^A! ! \usepackage[encoding=big5]{zhlipsum} +%^^A! +%^^A! ! Using `\newzhlipsum{big5}{許蓋功, 蓋功許, 功許蓋}' directly will +%^^A! ! lead to an error. +%^^A! ! Use <, >, + to replace {, } and \, and set the original {, } and \ +%^^A! ! to be `other' category (i.e. catcode=12). +%^^A! \begingroup +%^^A! \catcode`\<=1 +%^^A! \catcode`\>=2 +%^^A! \catcode`\+=0 +%^^A! \catcode`\{=12 +%^^A! \catcode`\}=12 +%^^A! \catcode`\\=12 +%^^A! +newzhlipsum<big5><許蓋功, 蓋功許, 功許蓋> +%^^A! +endgroup +%^^A! \zhlipsum[name=big5] +%^^A! \end{ctexexam} +%^^A! +% +%^^A! \end{document} +% +% \StopEventually{} +% +% \begin{implementation} +% +% \section{实现细节} +% +% \begin{macrocode} +%<*package> +%<@@=zhlipsum> +% \end{macrocode} +% +% 检查 \LaTeX3 编程环境。 +% \begin{macrocode} +\RequirePackage { xparse, l3keys2e } +\msg_new:nnn { zhlipsum } { l3-too-old } + { + Package~ "#1"~ is~ too~ old. \\\\ + Please~ update~ an~ up-to-date~ version~ of~ the~ bundles \\ + "l3kernel"~ and~ "l3packages"~ using~ your~ TeX~ package \\ + manager~ or~ from~ CTAN. + } +\clist_map_inline:nn { expl3, xparse, l3keys2e } + { + \@ifpackagelater {#1} { 2018/05/12 } + { } { \msg_error:nnn { zhlipsum } { l3-too-old } {#1} } + } +% \end{macrocode} +% +% \subsection{内部变量和函数} +% +% \begin{variable}{\l_@@_tmpa_tl,\l_@@_tmpa_seq,\l_@@_tmpb_seq} +% 临时变量。 +% \begin{macrocode} +\tl_new:N \l_@@_tmpa_tl +\seq_new:N \l_@@_tmpa_seq +\seq_new:N \l_@@_tmpb_seq +% \end{macrocode} +% \end{variable} +% +% \begin{variable}{\g_@@_encoding_tl} +% 编码信息。 +% \begin{macrocode} +\tl_new:N \g_@@_encoding_tl +% \end{macrocode} +% \end{variable} +% +% \begin{variable}{\g_zhlipsum_seq} +% 假文名称列表。 +% \begin{macrocode} +\seq_new:N \g_zhlipsum_seq +% \end{macrocode} +% \end{variable} +% +% \begin{variable}{\c_zhlipsum_simp_seq,\c_zhlipsum_trad_seq} +% 预定义的简体中文与繁体中文的假文名称列表。 +% \begin{macrocode} +\seq_new:N \c_zhlipsum_simp_seq +\seq_new:N \c_zhlipsum_trad_seq +\seq_set_from_clist:Nn \c_zhlipsum_simp_seq { simp, zhufu, aspirin } +\seq_set_from_clist:Nn \c_zhlipsum_trad_seq { trad, xiangyu, nanshanjing } +% \end{macrocode} +% \end{variable} +% +% \LaTeX3 函数变体。 +% \begin{macrocode} +\cs_generate_variant:Nn \file_input:n { x } +\prg_generate_conditional_variant:Nnn \tl_if_eq:nn { Vn } { T, TF } +% \end{macrocode} +% +% \begin{macro}[int,TF]{\@@_if_unicode_engine:} +% 判断是否为 Unicode 引擎。来自于 \pkg{zhnumber} 宏包。 +% \begin{macrocode} +\prg_new_protected_conditional:Npnn \@@_if_unicode_engine: { T, F, TF } + { + \bool_lazy_any:nTF + { + { \sys_if_engine_xetex_p: } + { \sys_if_engine_luatex_p: } + { \sys_if_engine_uptex_p: } + } + { \prg_return_true: } + { \prg_return_false: } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}[TF]{\@@_if_encoding:n} +% 判断当前编码。 +% \begin{macrocode} +\prg_new_protected_conditional:Npnn \@@_if_encoding:n #1 { T, F, TF } + { + \tl_if_eq:VnTF \g_@@_encoding_tl {#1} + { \prg_return_true: } { \prg_return_false: } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_msg_new:nn, +% \@@_error:n,\@@_error:nn, +% \@@_warning:nn,\@@_warning:nnn,\@@_warning:nxxx, +% \@@_info:nn} +% 各种信息函数的缩略形式。 +% \begin{macrocode} +\cs_new:Npn \@@_msg_new:nn { \msg_new:nnn { zhlipsum } } +\cs_new:Npn \@@_error:n { \msg_error:nn { zhlipsum } } +\cs_new:Npn \@@_error:nn { \msg_error:nnn { zhlipsum } } +\cs_new:Npn \@@_warning:nn { \msg_warning:nnn { zhlipsum } } +\cs_new:Npn \@@_warning:nnn { \msg_warning:nnnn { zhlipsum } } +\cs_new:Npn \@@_warning:nxxx { \msg_warning:nnxxx { zhlipsum } } +\cs_new:Npn \@@_info:nn { \msg_info:nnn { zhlipsum } } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_par:} +% 分段命令。 +% \begin{macrocode} +\cs_new_eq:NN \@@_par: \tex_par:D +% \end{macrocode} +% \end{macro} +% +% \subsection{宏包选项} +% +% \changes{v0.4}{2017/09/16}{新增 \opt{encoding} 选项。} +% \changes{v0.5}{2017/12/22}{支持 Big5 编码。} +% +% \begin{macro}{encoding} +% 设置编码。 +% \begin{macrocode} +\keys_define:nn { zhlipsum / option } + { + encoding .choices:nn = + { utf8, gbk, big5 } + { + \tl_gset_eq:NN \g_@@_encoding_tl \l_keys_choice_tl + \@@_if_unicode_engine:T + { + \@@_if_encoding:nF { utf8 } + { + \tl_gset:Nn \g_@@_encoding_tl { utf8 } + \@@_warning:nn { unicode-engine } {#1} + } + } + \@@_if_ctex_valid_encoding:F + { \@@_error:nn { ctex-invalid-encoding } {#1} } + }, + encoding / unknown .code:n = + { \@@_error:nn { invalid-encoding } {#1} }, + encoding .value_required:n = true, +% \end{macrocode} +% \end{macro} +% +% 处理未知选项。 +% \begin{macrocode} + unknown .code:n = { \@@_error:n { unknown-option } } + } +% \end{macrocode} +% +% 提示信息。 +% \begin{macrocode} +\@@_msg_new:nn { unicode-engine } + { + You~ are~ now~ using~ Unicode~ engine~ \c_sys_engine_str. \\ + Encoding~ "#1"~ is~ invalid.~ Changed~ into~ "utf8". + } +\@@_msg_new:nn { ctex-invalid-encoding } + { + Package~ option~ "encoding=#1"~ is~ in~ conflict~ with~ ctex's~ + option~ "\tl_use:N \l__ctex_encoding_tl".\\\\ + Please~ check~ the~ package~ options. + } +\@@_msg_new:nn { invalid-encoding } + { + Encoding~ "#1"~ is~ invalid. \\ + Available~ encodings~ are~ "utf8",~ "gbk"~ and~ "big5". + } +\@@_msg_new:nn { unknown-option } + { Package~ option~ "\l_keys_key_tl"~ is~ unknown. } +% \end{macrocode} +% +% \changes{v1.0.0}{2018/04/01}{根据 \CTeX{} 宏集的选项自动确定编码。} +% +% \begin{macro}[TF]{\@@_if_ctex_valid_encoding:} +% 检查 \CTeX{} 编码。 +% \begin{macrocode} +\prg_new_protected_conditional:Npnn \@@_if_ctex_valid_encoding: { F } + { + \tl_if_exist:NTF \l__ctex_encoding_tl + { + \tl_set:Nx \l_@@_tmpa_tl + { \str_lower_case:f { \l__ctex_encoding_tl } } + \str_if_eq:NNTF \g_@@_encoding_tl \l_@@_tmpa_tl + { \prg_return_true: } { \prg_return_false: } + } + { \prg_return_true: } + } +% \end{macrocode} +% \end{macro} +% +% 如果调用了 \CTeX{} 宏集,则自动确定编码;否则默认设为 UTF-8。 +% \begin{macrocode} +\tl_if_exist:NTF \l__ctex_encoding_tl + { + \tl_if_eq:VnTF \l__ctex_encoding_tl { UTF8 } + { \tl_gset:Nn \g_@@_encoding_tl { utf8 } } + { + \tl_if_eq:VnT \l__ctex_encoding_tl { GBK } + { \tl_gset:Nn \g_@@_encoding_tl { gbk } } + } + } + { \tl_gset:Nn \g_@@_encoding_tl { utf8 } } +% \end{macrocode} +% +% 将宏包选项传给 |zhlipsum/option|。 +% \begin{macrocode} +\ProcessKeysOptions { zhlipsum / option } +% \end{macrocode} +% +% \subsection{函数选项} +% +% \begin{variable}{\l_@@_name_tl} +% 保存假文名称。 +% \begin{macrocode} +\tl_new:N \l_@@_name_tl +% \end{macrocode} +% \end{variable} +% +% \begin{variable}{\l_@@_before_tl,\l_@@_after_tl,\l_@@_inter_tl} +% 保存假文之前、之后与之间插入的内容。 +% \begin{macrocode} +\tl_new:N \l_@@_before_tl +\tl_new:N \l_@@_after_tl +\tl_new:N \l_@@_inter_tl +% \end{macrocode} +% \end{variable} +% +% \begin{macrocode} +\keys_define:nn { zhlipsum } + { +% \end{macrocode} +% +% \changes{v1.0.0}{2018/03/24}{新增选项 \opt{name}。} +% +% \begin{macro}{name} +% 假文名称。Big5 编码不支持简体中文。 +% \begin{macrocode} + name .code:n = + { + \tl_set:Nn \l_@@_name_tl {#1} + \@@_if_encoding:nT { big5 } + { + \seq_if_in:NVT \c_zhlipsum_simp_seq \l_@@_name_tl + { + \@@_warning:nn { big5-require-trad } {#1} + \tl_set:Nn \l_@@_name_tl { trad } + } + } + }, +% \end{macrocode} +% \end{macro} +% +% \changes{v0.5}{2017/12/22}{新增选项 \opt{script},同时支持简体中文 +% 和繁体中文。} +% \changes{v1.0.0}{2018/03/24}{\opt{script} 成为过时选项。} +% +% \begin{macro}{script} +% 选择输入简体中文或繁体中文。过时选项。 +% \begin{macrocode} + script .code:n = + { + \@@_warning:nn { deprecated-option } + { Option~ "name=#1"~ will~ be~ set. } + \keys_set:nn { zhlipsum } { name = #1 } + }, +% \end{macrocode} +% \end{macro} +% +% \changes{v1.0.0}{2018/03/23}{新增选项 \opt{before}、\opt{after}。} +% \changes{v1.0.0}{2018/03/29}{新增选项 \opt{inter}。} +% +% \begin{macro}{before,after,inter} +% 假文之前、之后与之间插入的内容。 +% \begin{macrocode} + before .tl_set:N = \l_@@_before_tl, + after .tl_set:N = \l_@@_after_tl, + inter .tl_set:N = \l_@@_inter_tl + } +% \end{macrocode} +% \end{macro} +% +% 提示信息。 +% \begin{macrocode} +\@@_msg_new:nn { big5-require-trad } + { + Name~ "#1"~ is~ not~ available~ in~ "Big5"~ encoding. \\ + Changed~ into~ "trad". + } +\@@_msg_new:nn { deprecated-option } + { Option~ "\l_keys_key_tl"~ is~ deprecated. \\ #1 } +% \end{macrocode} +% +% 初始选项设置。 +% \begin{macrocode} +\@@_if_encoding:nTF { big5 } + { \keys_set:nn { zhlipsum } { name = trad } } + { \keys_set:nn { zhlipsum } { name = simp } } +% \end{macrocode} +% +% \subsection{输出假文} +% +% \begin{macro}{\zhlipsum} +% \changes{v0.5}{2018/01/05}{支持选项设置。} +% \changes{v1.0.0}{2018/03/23}{更改参数形式,允许利用逗号分隔列表选择 +% 段落。} +% \changes{v1.1.0}{2018/04/08}{改回使用方括号指定段落数的形式。} +% 输出假文,第一个可选参数表示段落数,默认为 |1-3|;第二个可选参数为选 +% 项列表。 +% \begin{macrocode} +\NewDocumentCommand \zhlipsum { s o +o } + { + \group_begin: + \IfBooleanF {#1} + { + \tl_set:Nn \l_@@_before_tl { \@@_par: } + \tl_set:Nn \l_@@_after_tl { \@@_par: } + \tl_set:Nn \l_@@_inter_tl { \@@_par: } + } + \IfValueTF {#3} + { + \keys_set:nn { zhlipsum } {#3} + \zhlipsum_use:Vn \l_@@_name_tl {#2} + } + { + \IfValueTF {#2} + { +% \end{macrocode} +% 如果只带一个参数,那么根据其是否含有 |=| 来判断该参数是段落数还是 +% 选项列表。 +% \begin{macrocode} + \@@_if_key_value_list:nTF {#2} + { + \keys_set:nn { zhlipsum } {#2} + \zhlipsum_use:Vn \l_@@_name_tl { 1 - 3 } + } + { \zhlipsum_use:Vn \l_@@_name_tl {#2} } + } + { \zhlipsum_use:Vn \l_@@_name_tl { 1 - 3 } } + } + \group_end: + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}[TF]{\@@_if_key_value_list:n} +% 判断是否为键值列表,即是否含有 |=|。 +% \begin{macrocode} +\prg_new_protected_conditional:Npnn \@@_if_key_value_list:n #1 { TF } + { + \tl_if_in:nnTF {#1} { = } + { \prg_return_true: } { \prg_return_false: } + } +% \end{macrocode} +% \end{macro} +% +% \begin{variable}{\l_@@_par_num_seq} +% 保存段落编号。 +% \begin{macrocode} +\seq_new:N \l_@@_par_num_seq +% \end{macrocode} +% \end{variable} +% +% \begin{macro}{\zhlipsum_use:nn,\zhlipsum_use:Vn} +% 输出多段假文。|#1| = 假文名称,|#2| = 段落编号列表。解析段落编号之 +% 后,按次序逐项输出,并在前后插入相应内容。注意最后一段需要单独处理。 +% \begin{macrocode} +\cs_new_protected:Npn \zhlipsum_use:nn #1#2 + { + \@@_if_cjk_valid_encoding:TF + { + \zhlipsum_if_exist:nTF {#1} + { + \@@_parse_par:nn {#1} {#2} + \seq_pop_right:NN \l_@@_par_num_seq \l_@@_tmpa_tl + \tl_use:N \l_@@_before_tl + \seq_map_inline:Nn \l_@@_par_num_seq + { + \@@_use:nn {#1} {##1} + \tl_use:N \l_@@_inter_tl + } + \@@_use:nn {#1} { \tl_use:N \l_@@_tmpa_tl } + \tl_use:N \l_@@_after_tl + } + { \@@_error:nn { invalid-name } {#1} } + } + { \@@_error:n { CJK-invalid-encoding } } + } +\cs_generate_variant:Nn \zhlipsum_use:nn { Vn } +\@@_msg_new:nn { invalid-name } + { + Name~ "#1"~ is~ unknown. \\\\ + Please~ use~ the~ pre-defined~ Chinese~ dummy~ texts~ or~ + declare~ new~ one. + } +\@@_msg_new:nn { CJK-invalid-encoding } + { + The~ current~ CJK~ environment~ uses~ "\tl_use:N \CJK@@@@@enc"~ + encoding,\\ + but~ zhlipsum~ package~ has~ been~ loaded~ with~ the~ option~ + "encoding=\tl_use:N \g_@@_encoding_tl".\\\\ + Please~ check~ the~ package~ options. + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}[TF]{\@@_if_cjk_valid_encoding:} +% 检查 \env{CJK} 环境编码。 +% \begin{macrocode} +\prg_new_protected_conditional:Npnn \@@_if_cjk_valid_encoding: { TF } + { + \tl_if_exist:NTF \CJK@@@@@enc + { + \tl_set:Nx \l_@@_tmpa_tl { \str_lower_case:f { \CJK@@@@@enc } } +% TODO: str or tl? + \str_if_eq:NNTF \g_@@_encoding_tl \l_@@_tmpa_tl + { \prg_return_true: } + { + \@@_if_encoding:nTF { gbk } + { + \str_if_eq:VnTF \l_@@_tmpa_tl { gb } + { \prg_return_true: } { \prg_return_false: } + } + { + \@@_if_encoding:nTF { big5 } + { + \str_if_eq:VnTF \l_@@_tmpa_tl { bg5 } + { \prg_return_true: } { \prg_return_false: } + } + { \prg_return_false: } + } + } + } + { \prg_return_true: } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}[TF]{\zhlipsum_if_exist:n} +% 判断是否存在对应名称的假文。 +% \begin{macrocode} +\prg_new_protected_conditional:Npnn \zhlipsum_if_exist:n #1 { T, F, TF } + { + \seq_if_in:NnTF \g_zhlipsum_seq {#1} + { \prg_return_true: } { \prg_return_false: } + } +% \end{macrocode} +% \end{macro} +% +% \begin{variable}{\l_@@_begin_int,\l_@@_end_int,\l_@@_max_int} +% \begin{macrocode} +\int_new:N \l_@@_begin_int +\int_new:N \l_@@_end_int +\int_new:N \l_@@_max_int +% \end{macrocode} +% \end{variable} +% +% \begin{variable}{\l_@@_modified_range_bool,\l_@@_invalid_range_bool} +% \begin{macrocode} +\bool_new:N \l_@@_modified_range_bool +\bool_new:N \l_@@_invalid_range_bool +% \end{macrocode} +% \end{variable} +% +% \begin{macro}{\@@_parse_par:nn} +% 解析段落编号列表。|#1| = 假文名称,|#2| = 段落编号列表。 +% +% 编号列表用逗号分隔,其中的每一项为单个数字或为 |a-b| 的形式。若 +% |a|、|b| 为空,则分别取为 1 或允许的最大值(即段落数)。超过范围的 +% 数字则忽略。 +% \begin{macrocode} +\cs_new_protected:Npn \@@_parse_par:nn #1#2 + { + \seq_clear:N \l_@@_par_num_seq + \int_set_eq:Nc \l_@@_max_int { g_@@_ #1 _int } + \clist_map_inline:nn {#2} + { + \@@_parse_par_aux:n {##1} + \bool_if:NTF \l@@_invalid_range_bool + { \@@_warning:nnn { invalid-range } {##1} {#2} } + { + \bool_if:NT \l_@@_modified_range_bool + { + \@@_warning:nxxx { modified-range } + {##1} {#2} { \@@_par_range: } + } + \seq_concat:NNN \l_@@_par_num_seq + \l_@@_par_num_seq \l_@@_tmpa_seq + } + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_parse_par_aux:n} +% \begin{macrocode} +\cs_new_protected:Npn \@@_parse_par_aux:n #1 + { + \bool_set_false:N \l_@@_modified_range_bool + \bool_set_false:N \l_@@_invalid_range_bool + \seq_clear:N \l_@@_tmpa_seq + \tl_if_in:nnTF {#1} { - } + { + \seq_set_split:Nnn \l_@@_tmpb_seq { - } {#1} +% \end{macrocode} +% “|-|” 左侧的数字。 +% \begin{macrocode} + \seq_pop_left:NN \l_@@_tmpb_seq \l_@@_tmpa_tl + \tl_if_empty:NTF \l_@@_tmpa_tl + { \int_set_eq:NN \l_@@_begin_int \c_one_int } + { + \int_set:Nn \l_@@_begin_int { \l_@@_tmpa_tl } + \int_compare:nNnT \l_@@_begin_int < \c_one_int + { + \int_set_eq:NN \l_@@_begin_int \c_one_int + \bool_set_true:N \l_@@_modified_range_bool + } + } +% \end{macrocode} +% “|-|” 右侧的数字。注意左右数字均由 \cs{seq_pop_left:NN} 得到,因此 +% |-3-4| 实际相当于 |-3|,进而被解析为 |1-3|。 +% \begin{macrocode} + \seq_pop_left:NN \l_@@_tmpb_seq \l_@@_tmpa_tl + \tl_if_empty:NTF \l_@@_tmpa_tl + { \int_set_eq:NN \l_@@_end_int \l_@@_max_int } + { + \int_set:Nn \l_@@_end_int { \l_@@_tmpa_tl } + \int_compare:nNnT \l_@@_end_int > \l_@@_max_int + { + \int_set_eq:NN \l_@@_end_int \l_@@_max_int + \bool_set_true:N \l_@@_modified_range_bool + } + } +% \end{macrocode} +% 检查取值范围。 +% \begin{macrocode} + \bool_lazy_or:nnTF + { \int_compare_p:nNn \l_@@_begin_int > \l_@@_max_int } + { \int_compare_p:nNn \l_@@_begin_int > \l_@@_end_int } + { \bool_set_true:N \l_@@_invalid_range_bool } + { + \int_step_inline:nnn + { \l_@@_begin_int } { \l_@@_end_int } + { \seq_put_right:Nn \l_@@_tmpa_seq {##1} } + } + } + { +% \end{macrocode} +% 单个数字的处理。 +% \begin{macrocode} + \bool_lazy_or:nnTF + { \int_compare_p:nNn {#1} > \l_@@_max_int } + { \int_compare_p:nNn {#1} < \c_one_int } + { \bool_set_true:N \l_@@_invalid_range_bool } + { \seq_put_right:Nn \l_@@_tmpa_seq {#1} } + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_par_range:} +% 显示段落范围(用在提示信息中,可以完全展开)。 +% \begin{macrocode} +\cs_new:Npn \@@_par_range: + { + \int_compare:nNnTF \l_@@_begin_int = \l_@@_end_int + { \int_use:N \l_@@_begin_int } + { \int_use:N \l_@@_begin_int - \int_use:N \l_@@_end_int } + } +% \end{macrocode} +% \end{macro} +% +% 提示信息。 +% \begin{macrocode} +\@@_msg_new:nn { modified-range } + { + Your~ required~ range~ "#1"~ in~ "#2"~ will~ be~ modified. \\ + Changed~ into~ "#3". + } +\@@_msg_new:nn { invalid-range } + { + Your~ required~ range~ "#1"~ in~ "#2"~ is~ invalid. \\ + Nothing~ will~ be~ output. + } +% \end{macrocode} +% +% \begin{macro}{\@@_use:nn} +% 输出一段假文。|#1| = 假文名称,|#2| = 段落编号。 +% \begin{macrocode} +\cs_new_protected:Npn \@@_use:nn #1#2 + { \tl_use:c { c_@@_ #1 @ #2 _tl } } +% \end{macrocode} +% \end{macro} +% +% \subsection{声明假文} +% +% \begin{macro}{\newzhlipsum,\zhlipsum_new:nn} +% 声明假文。|#1| = 假文名称,|#2| = 文本 clist。 +% \begin{macrocode} +\NewDocumentCommand \newzhlipsum { m m } + { \zhlipsum_new:nn {#1} {#2} } +\cs_new_protected:Npn \zhlipsum_new:nn #1#2 + { + \zhlipsum_if_exist:nTF {#1} + { \@@_error:nn { already-defined } {#1} } + { + \seq_gput_left:Nn \g_zhlipsum_seq {#1} + \int_new:c { g_@@_ #1 _int } + \clist_map_inline:nn {#2} { \@@_new:nn {#1} {##1} } + \@@_info:nn { defining-text } {#1} + } + } +\@@_msg_new:nn { already-defined } + { + Chinese~ dummy~ text~ "#1"~ has~ been~ used.~ + Please~ use~ another~ name. + } +\@@_msg_new:nn { defining-text } + { + Chinese~ dummy~ text~ "#1"~ is~ created.~ + It~ has~ \int_use:c { g_@@_ #1 _int }~ paragraphs. + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_new:nn} +% 定义新的假文段落。|#1| = 假文名称,|#2| = 文本。 +% \begin{macrocode} +\cs_new_protected:Npn \@@_new:nn #1#2 + { + \int_gincr:c { g_@@_ #1 _int } + \tl_const:cn + { c_@@_ #1 @ \int_use:c { g_@@_ #1 _int } _tl } {#2} + } +% \end{macrocode} +% \end{macro} +% +% 根据编码读入假文文本定义文件。 +% \begin{macrocode} +\file_input:x { zhlipsum- \g_@@_encoding_tl .def } +%</package> +% \end{macrocode} +% +% \subsection{假文文本} \label{subsec:dummy-text} +% +% \changes{v1.0.0}{2018/03/27}{利用类别码机制回避 \pkg{CJK} 宏包的 +% 预处理操作。} +% +% \begin{macro}{\@@_set_special_catcode:} +% 在声明预定义文本时,为了兼容 \pkg{CJK} 宏包的特殊处理,需要临时更改 +% 类别码。具体来说,在 GBK/Big5 编码下,由于汉字的第二个字节会与 +% \TeX{} 中的特殊符号 |\|、|{|、|}|、|~| 冲突,所以需要将它们的类别码 +% 改为 12(其他),并分别用 |+|、|<|、|>| 和 |*| 代替。星号 |*| 在 +% 开启 \LaTeX3 语法后实际相当于空格(类别码为 10)。 +% \begin{macrocode} +%<*text> +\cs_new_protected:Npn \@@_set_special_catcode: + { +%<!utf8> \@@_active_first_byte: + \char_set_catcode_escape:N \+ + \char_set_catcode_group_begin:N \< + \char_set_catcode_group_end:N \> + \char_set_catcode_space:N \* + \char_set_catcode_other:N \\ + \char_set_catcode_other:N \{ + \char_set_catcode_other:N \} + \char_set_catcode_other:N \~ + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_active_first_byte:} +% 将汉字的首字节设为活动字符(类别码 12)。UTF-8 编码下不需要该操作。 +% \begin{macrocode} +%<*!utf8> +\cs_new_protected:Npx \@@_active_first_byte: + { + \int_step_function:nnN { "81 } { "FE } + \char_set_catcode_active:n + } +%</!utf8> +%</text> +% \end{macrocode} +% \end{macro} +% +% \changes{v1.0.0}{2018/03/26}{增加预定义假文。} +% \changes{v1.1.1}{2018/07/19}{更新假文文本。} +% +% 预定义假文的声明放置在分组内,利用 \cs{@@_set_special_catcode:} 切换 +% 类别码后可以不再需要 \pkg{CJK} 的预处理操作。具体声明此处不再列出。 +% +% \end{implementation} +% |