📄 custom.tex
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 我的翻译部分已经完全结束:P
% Contents: Customising LaTeX output
% $Id: custom.tex,v 1.2 2002/05/26 22:44:33 zuohuijun Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{定制 \LaTeX}
\begin{intro}
%Documents produced by using the commands you have learned up to this
%point will look acceptable to a large audience. While they are not
%looking fancy, they obey all the established rules of good
%typesetting, which will make them easy to read and pleasant to look at.
到目前为止,运用你所学过的命令可以制作出能被绝大多数读者接受的文档。
尽管这些文档看上去不够奇妙,但它们遵循了好的出版系统必须遵守的基本规则。
这些规则可以使得文档容易被阅读,同时看起来也非常舒适。
%However there are situations where \LaTeX{} does not provide a
%command or environment which matches your needs, or the output
%produced by some existing command may not meet your requirements.
然而在一些情况下,\LaTeX{}~也许并没有提供适合你需要的命令或者环境,
或者利用已有的命令产生的输出和你想要的不同。
%In this chapter, I will try to give some hints on
%how to teach \LaTeX{} new tricks and how to make it produce output
%which looks different than what is provided by default.
在这章中,我将尝试给出一些新的技术,运用这些技术可以教会~\LaTeX{}~玩
一些新的把戏,或者也可以使得~\LaTeX{}~产生与众不同的输出。
\end{intro}
\section{建立新的命令、环境和包}
%You may have noticed that all the commands I introduce in this
%book are typeset in a box, and that they show up in the index at the end
%of the book. Instead of directly using the necessary \LaTeX{} commands
%to achieve this, I have created a \wi{package} in which I defined new
%commands and environments for this purpose. Now I can simply write:
你也许已经注意到我在这本书中介绍的所有命令都被包含在一个长方形框中,
并且在文章最后的索引中还有他们的标记。 我并没有直接采用标准的~\LaTeX{}~
命令来实现这个,我创建了一个所谓的宏包(\wi{package}),并在其中定义了我
所需要的命令和环境。 因此我可以简化我的文档为:
\begin{example}
\begin{lscommand}
\ci{dum}
\end{lscommand}
\end{example}
%In this example, I am using both a new environment called
%\ei{lscommand} which is responsible for drawing the box around the
%command and a new command named \ci{ci} which typesets the command
%name and also makes a corresponding entry in the index. You can check
%this out by looking up the \ci{dum} command in the index at the back
%of this book, where you'll find an entry for \ci{dum}, pointing to
%every page where I mentioned the \ci{dum} command.
在这个例子中, 我使用了一个新的环境~-- \ei{lscommand}。这个环境负责在命令
的周围画出一个矩形框。同时我还使用了一个命令:\ci{ci}, 这个命令负责输出
宏包的名字,并且在索引中添加相应的条目。你可以在文章最后的索引中查找命令~\ci{dum},
然后你会发现有一个~\ci{dum}~的条目,这个条目中列出了包含有~\ci{dum}~命令
的所有页的页码。
%If I ever decide that I do not like the commands to be typeset in
%a box any more, I can simply change the definition of the
%\texttt{lscommand} environment to create a new look. This is much
%easier than going through the whole document to hunt down all the
%places where I have used some generic \LaTeX{} commands to draw a
%box around some word.
一旦我觉得这个命令在一个矩形框中进行排版的行为不再适合,我可以轻松的
改变~\texttt{lscommand}~环境的定义,使得命令的输出具有新的外观。这种
做法比起浏览整个文档逐个进行格式修改的方法要轻松得多。而如果我们使用
~\LaTeX{}~原有的命令来做这件事情(在矩形框中显示命令并加入到索引中),
那唯一的做法就是浏览整个并手动修改。
\subsection{建立新的命令}
为了增加你自己的命令,可以使用如下的命令:
\begin{lscommand}
\ci{newcommand}\verb|{|%
\emph{name}\verb|}[|\emph{num}\verb|]{|\emph{definition}\verb|}|
\end{lscommand}
基本上,这个命令需要两个参数,第一个参数~\emph{name}~是你想要建立的命令
的名称,第二个参数~\emph{definition}~是命令的定义。第三个参数~\emph{num}~
是可选的,用于指定命令所需的参数数目(命令最多可以有9个参数)。如果不给
出这个参数,那么新建的命令将不接受任何参数。
接下来的两个例子将帮助你理解这种机制。第一个例子定义了一个新的命令~-- \ci{tnss}。
这个命令是句子~``The\ Not\ So\ Short\ Introduction\ to\ \LaTeXe''~的缩写。
如果你需要在文档中多次使用本书的名称,那么定义这个命令将是非常方便的。
\begin{example}
\newcommand{\tnss}{The not
so Short Introduction to
\LaTeXe}
This is ``\tnss'' \ldots{}
``\tnss''
\end{example}
下一个例子演示了如何建立一个接受唯一参数的命令。在命令的定义中,标记~\verb|#1|~
将被你指定的参数所代替。如果你想使用多个参数,那么可以依次使用~\verb|#2|、\ldots、
\verb|#9|等标记。
\begin{example}
\newcommand{\txsit}[1]
{This is the \emph{#1} Short
Introduction to \LaTeXe}
% in the document body:
\begin{itemize}
\item \txsit{not so}
\item \txsit{very}
\end{itemize}
\end{example}
\LaTeX{}~不允许你用~\ci{newcommand}~新建一个与原有命令重名的命令。 有一个特殊
的命令专门用于处理这种情况:\ci{renewcommand}。它使用与命令~\verb|\newcommand|~
相同的语法。
在某些情况之下,你可能会需要使用~\ci{providecommand}~命令。它完成与~\ci{newcommand}~
命令相同的工作。但如果命令已经存在,\LaTeXe{}~将会忽略这个命令。
处理~\LaTeX{}~命令后尾随的空格有一些要注意的事项,参看第~\pageref{whitespace}~页
可以获得更多这方面的信息。
\subsection{建立新的环境}
与~\verb|\newcommand|~命令类似,有一个命令用于建立新的环境。这个命令就是
~\ci{newenvironment},它的语法如下所示:
\begin{lscommand}
\ci{newenvironment}\verb|{|%
\emph{name}\verb|}[|\emph{num}\verb|]{|%
\emph{before}\verb|}{|\emph{after}\verb|}|
\end{lscommand}
与~\verb|\newcommand|~命令类似,你可以为~\ci{newenvironment}~命令提供一个可选的
参数。在参数~\emph{before}~中提供的内容将在被命令包含的文本之前处理,而在参数
~\emph{after}~中提供的内容将恰好在~\verb|\end{|\emph{name}\verb|}|~的前面处理。
下面的例子演示了~\ci{newenvironment}~命令的用法:
\begin{example}
\newenvironment{king}
{\rule{1ex}{1ex}%
\hspace{\stretch{1}}}
{\hspace{\stretch{1}}%
\rule{1ex}{1ex}}
\begin{king}
My humble subjects \ldots
\end{king}
\end{example}
参数~\emph{num}~使用的方式与~\verb|\newcommand|~命令相同。\LaTeX{}~还同样保证你
不会不小心改变了已有环境的定义。如果你确实希望改变一个存在的环境,你可以使用命令
~\ci{renewenvironment},它使用和命令~\ci{newenvironment}~相同的语法。
在这个例子中用到一些命令将在随后解释:\ci{rule}~命令的解释可以参看第~\pageref{sec:rule}~页,
\ci{stretch}~命令的解释可以参看第~\pageref{cmd:stretch}~页,关于~\ci{hspace}~的
信息可以在第~\pageref{sec:hspace}~页找到。
\subsection{建立你自己的宏包}
如果你建立了很多自己的环境和命令,你的文档的导言部分将变得很长,在这种情况下,
建立一个新的~\LaTeX{}~包来存放所有你自己定义的命令和环境将是一个好的处理方式。
你可以在文档中使用~\ci{usepackage}~命令来引入自定义宏包中的环境和命令。
\begin{figure}[!htbp]
\begin{lined}{\textwidth}
\begin{verbatim}
% Demo Package by Tobias Oetiker
\ProvidesPackage{demopack}
\newcommand{\tnss}{The not so Short Introduction to \LaTeXe}
\newcommand{\txsit}[1]{The \emph{#1} Short
Introduction to \LaTeXe}
\newenvironment{king}{\begin{quote}}{\end{quote}}
\end{verbatim}
\end{lined}
\caption{Example Package.} \label{package}
\end{figure}
写一个宏包的基本工作就是将你原本很长的文档导言拷贝到一个分离的文件中去,
这个文件需要以~\texttt{.sty}~结尾。你还需要使用一个专用的命令:
\begin{lscommand}
\ci{ProvidesPackage}\verb|{|\emph{package name}\verb|}|
\end{lscommand}
这个命令应该在你的包的最前面使用。\verb|\ProvidesPackage|~用于告诉~\LaTeX{}~
宏包的名称从而允许~\LaTeX{}~在你尝试两次引入同一个宏包的时候给出一个良好的
错误信息,图~\ref{package}~给出了一个小的包,其中包含了我们之前定义的一些命令。
\section{字体和尺寸}
\subsection{字体变换命令}
\index{font}\index{font size} \LaTeX{}~根据文档的逻辑结构(章节、脚注、……)
来选择合适的字体和字体大小。在某些情况下,你可能会想要手工改变文档使用的
字体及其大小。为了完成这个目的,你可以使用表\nbs\ref{fonts}~和表\nbs\ref{sizes}~中
列出的那些命令。每个字体的实际尺寸是一个设计问题,并且它依赖于文档所使用
的文档类。表\nbs\ref{tab:pointsizes}~列出了这些字体变换命令在标准文档类中的绝对尺寸。
\begin{example}
{\small The small and
\textbf{bold} Romans ruled}
{\Large all of great big
\textit{Italy}.}
\end{example}
\LaTeXe{}~的一个重要特征是字体的各种属性是相互独立的,这意味着你可以改变字体
的大小而仍然保留字体原有的粗体或者斜体的特性。
在\emph{数学模式}中你可以使用字体变换命令来暂时的退出\emph{数学模式},然后输入
一些一般的文字。如果你希望改变数学公式本身所使用的字体,\LaTeX{}提供了另外一套命令。
参看表\nbs\ref{mathfonts}。
\begin{table}[!bp]
\caption{字体} \label{fonts}
\begin{lined}{12cm}
%
% Alan suggested not to tell about the other FORM of the command
% eg \verb|\sffamily| or \verb|\bfseries|. This seems a good thing to me.
%
\begin{tabular}{@{}rl@{\qquad}rl@{}}
\ci{textrm}\verb|{...}| & \textrm{\wi{roman}}&
\ci{textsf}\verb|{...}| & \textsf{\wi{sans serif}}\\
\ci{texttt}\verb|{...}| & \texttt{typewriter}\\[6pt]
\ci{textmd}\verb|{...}| & \textmd{medium}&
\ci{textbf}\verb|{...}| & \textbf{\wi{bold face}}\\[6pt]
\ci{textup}\verb|{...}| & \textup{\wi{upright}}&
\ci{textit}\verb|{...}| & \textit{\wi{italic}}\\
\ci{textsl}\verb|{...}| & \textsl{\wi{slanted}}&
\ci{textsc}\verb|{...}| & \textsc{\wi{small caps}}\\[6pt]
\ci{emph}\verb|{...}| & \emph{emphasized} &
\ci{textnormal}\verb|{...}| & \textnormal{document} font
\end{tabular}
\bigskip
\end{lined}
\end{table}
\begin{table}[!bp]
\index{font size}
\caption{字体尺寸} \label{sizes}
\begin{lined}{12cm}
\begin{tabular}{@{}ll}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -