LaTeX2e类和包的设计(四)

简介: 注意:在tex的编写中,如果用到带@的命令,必须把它包含在/makeatletter和/makeatother之间。如果是在宏包中使用,则无需此两个命令。 一、class and package的结构: 1) Identification:    1.

注意:在tex的编写中,如果用到带@的命令,必须把它包含在/makeatletter和/makeatother之间。如果是在宏包中使用,则无需此两个命令。

一、class and package的结构:
1) Identification: 
  1.1)Package files do this as follows:
 /NeedsTeXFormat{LaTeX2e}
 /ProvidesPackage{}[]
For example:
 /NeedsTeXFormat{LaTeX2e}
 /ProvidesPackage{latexsym}[1994/06/01 Standard LaTeX package]
  1.2)Class files do this as follows:
 /NeedsTeXFormat{LaTeX2e}
 /ProvidesClass{}[]
For example:
 /NeedsTeXFormat{LaTeX2e}
 /ProvidesClass{article}[1994/06/01 Standard LaTeX class]
的格式应该是:年/月/日
2) Using classes and packages:
  2.1)A LaTeX package or class can load a package as follows:
 /RequirePackage[]{}[]
For example:
 /RequirePackage{ifthen}[1994/06/01]
  2.2)A LaTeX class can load one other class as follows:
 /LoadClass []{}[]
For example:
 /LoadClass [twocolumn]{article}
  2.3)Simply load a class or package file:
 /LoadClassWithOptions{}[]
 /RequirePackageWithOptions{}[]
For example:
 /LoadClassWithOptions{article}
 /RequirePackageWithOptions{graphics}[1995/12/01]
3) Declaring options:
 /DeclareOption{}{}
For example:
 /DeclareOption{dvips}{/input{dvips.def}}
For example another:
 /DeclareOption{a4paper}{%
   /setlength{/paperheight}{297mm}%
   /senlength{/paperwidth}{210mm}%
   }
  3.1)pass options on to another package or class,using the command:
 /PassOptionsToPackage
 or /PassOptionsToClass
For example, to pass every unknown option on to the article class:
 /DeclareOption*{%
   /PassOptionsToClass{/CurrentOption}{article}%
   }
To process the options with which the file was called, you should use:
 /ProcessOptions/relax
For example, if the jane package file contains:
 /DeclareOption{foo}{/typeout{Saw foo.}}
 /DeclareOption{baz}{/typeout{Saw baz.}}
 /DeclareOption*{/typeout{What's /CurrentOption?}}
 /ProcessOptions/relax
4) A minimal class file
  There are four things that every class file must contain: these are a definition of /normailsize, values fro /textwidth and /textheight and a specification for page-numbering.
  So a minimal document class file looks like this:
 /NeedsTeXFormat{LaTeX2e}
 /ProvidesClass{minimal}[1995/10/30 Standard LaTeX minimal class]
 /renewcommand{/normalsize}{/fontsize{10pt}{12pt}/selectfont}
 /setlength{/textwidth}{6.5in}
 /setlength{/textheight}{8in}
 /pagenumbering{arabic}
 %needed even though this class will not show page numbers
5) Example: a local letter class
  The class begins by announcing itself as neplet.cls.
 /NeedsTeXFormat{LaTeX2e}
 /ProvidesClass{neplet}[1995/04/01 NonExistent Press letter class]
 %passes any options on to the letter class. a4paper option.
 /DeclareOption*{/PassOptionsToClass{/CurrentOption}{letter}}
 /ProcessOptions/relax
 /LoadClass[a4paper]{letter}
 %redefine the firstpage page style.
 /renewcommand{/ps@firstpage}{%
   /renewcommand{/@oddhead}{}%
   /renewcommand{/@oddfoot}{}%
   }
6) Example: a newsletter class
  A simple newsletter can be typeset with LaTeX, using a variant of the article class. The class begins by announcing itself as smplnews.cls.
 /NeedsTeXFormat{LaTeX2e}
 /ProvidesClass{smplnews}[1995/04/01 The Simple News newsletter class]
 /newcommand{/headlinecolor}{/normalcolor}
 % pass most specified options on to the article class
 /DeclareOption{onecolumn}{/OptionNotUsed}
 /DeclareOption{green}{/renewcommand}{/headlinecolor}{/color{green}}}
 /DeclareOption*{/PassOptionsToClass{/CurrentOption}{article}}
 /ProcessOptions/relax
 %load the class article with the option twocolumn
 /LoadClass[twocolumn]{article}
 %load the color package
 /RequirePackage{color}
 %redefine /maketitle to produce the title 
 %in 72pt Helvetica bold oblique
 /renewcommand{/maketitle}{%
   /twocolumn[%
     /fontsize{72}{80}/fontfamily{phv}/fontseries{b}%
     /fontshape{sl}/selectfont/headlinecolor
     /@title
     ]%
   }
 %redefine /section and switches off section numbering.
 /renewcommand{/section}{%
   /@startsection
     {section}{1}{0pt}{-1.5ex plus -1ex minus -.2ex}%
     {1ex plus .2ex}{/large/sffamily/slshape/headlinecolor}%
   }
 /setcounter{secnumdepth}{0}
 %set the three essential things
 /renewcommand{/normalsize}{/fontsize{9}{10}/selectfont}
 /setlength{/textwidth}{17.5cm}
 /setlength{/textheight}{25cm}
In practice, a class would need more than this: it would provide commands for issue numbers, authors of articles, page styles and so on; but this skeleton gives a start. the ltnews class file is not much more complex than this one.

二、Commands for class and package writers
1) Identification
/NeedsTeXFormat{}[]
/ProvidesClass{}[]
/ProvidesPackage{}[]

information is displayed by /listfiles and should therefore not be too long.
example:
/ProvidesClass{article}[1994/06/01 v1.0 Standard LaTeX class]
/ProvidesPackage{ifthen}[194/06/01 v1.0 Standard LaTeX package]

/ProvidesFile{}[]
It is used for declaring any files other than main class and package files.
Example:
/ProvidesFile{T1enc.def}[1994/06/01 v1.0 Standard LaTeX file]
2) Loading files
/RequirePackage[]{}[]
/RequirePackageWithOptions{}[release-info>]
This group of commands can be used to create your own document class or package by building on existing classes or packages.
Example:
/RequirePackage{ifthen}[1994/06/01]
/RequirePackageWithOptions{graphics}[1995/12/01]

/LoadClass[]{}[]
/LoadClassWithOptions{}[]

Examples:
/LoadClass{article}[1994/06/01]
/LoadClassWithOptions{article}[1995/12/01]
3) Option declaration
/DeclareOption{}{}
This makes a 'delcared option' of the class or package in which it is put.
The argument contains the code to be executed if that option is specified for the class or package; it can contain any valid LaTeX2e construct.
Example:
/DeclareOption{twoside}{/@twosidetrue}

/DeclareOption*{}
This declares the to be executed for every option which is specified for, but otherwise not explicitly declared by, the class or package; this code is called the 'default option code' and it can contain any valid LaTeX2e construct.
4) Commands within option code
/CurrentOption
This expands to the name of the current option.
/OptionNotUsed
This causes the current option to be added to the list of 'unused options'.
5) Moving options around
/PassOptionsToPackage{}{}
/PassOptionsToClass{}{}
The command /PassOptionsToPackage passes the option names in to package . This means it adds the to the list of options used by any future /RequirePackage or /usepackage command for package .
Example:
/PassOptionsToPackage{foo,bar}{fred}
/RequirePackage[baz]{fred}
is the same as:
/RequirePackage[foo,bar,baz]{fred}
For example:
/LoadClassWithOptions{article}
This should be compared with the slightly different construction.
/DeclareOption*{/PassOptionsToClass{/CurrentOption}{article}}
/ProcessOptions/relax
/LoadClass{article}
If, however, the class declares options of its own then the two constructions are different.
/DeclareOption{landscape}{/@landscapetrue}
/ProcessOptions/relax
/LoadClassWithOptions{article}
with:
/DeclareOption{landscape}{/@landscapetrue}
/DeclareOption*{/PassOptionsToClass{/CurrentOption}{article}}
/ProcessOptions/relax
/LoadClass{article}

6) Delaying code
/AtEndOfClass{}
/AtEndOfPackage{}
These commands declare that is saved away internally and then executed after processing the whole of teh current class or package file.
/AtBeginDocument{}
/AtEndDocument{}
You should include a /clearpage at the appropriate point in .
Permit to repeat use of these commands.
/AtBeginDvi{}

7) Option processing
/ProcessOptions
This command executes the for each selected option.
Local options:
/PassOptionsToPackage{} 
/usepackage[]
/RequirePackage[]
Global options:
are any other options that are specified by the author in the argument of /documentclass[]
For example, suppose that a document begins:
/documentclass[german,twocolumn]{article}
/usepackage{gerhardt}
whilst package gerhardt calls package fred with:
/PassOptionsToPackage{german,dvips,a4paper}{fred}
/RequirePackage[errorshow]{fred}
then:
fred's local options are german, dvips, a4paper and errowshow;
fred's global options is twocolumn.
example:
/DeclareOption{dvips}{/typeout{DVIPS}}
/DeclareOption{german}{/typeout{GERMAN}}
/DeclareOption{french}{/typeout{FRENCH}}
/DeclareOption*{/PackageWarning{fred}{Unknown '/CurrentOption'}}
/ProcessOptions/relax

/ProcessOptions*
/@options
This is like /ProcessOptions but it executes the options in the order specified in the calling commands, rather than in the order of declaration in the class or package. For a package this means that the golbal options are processed first.
The /@options command from LaTeX2.09 has been made equivalent to this in order to ease the task of updating old document styles to LaTeX2e class files.

/ExecuteOptions{}
execute the command /ds@, It can be used to provide a 'default option list' just before /ProcessOptions.
example:
/ExecuteOptions{11pt,twoside,twocolumn}

8) Safe file commands
These commands deal with file input; they ensure that the non-existence of a requested file can be handled in a user-friendly way.
/IfFileExists{}{}{}

/InputIfFileExists{}{}{}

9) Reporting errors, etc.
/ClassError{}{}{}
/PackageError{}{}{}
For example:
/newcommand{/foo}{F00}
/PackageError{ethel}{%
  Your hovercraft is full of eels, /MessageBreak
  and /protect/foo/space is /foo
}{%
  Oh dear! Something's gone wrong. /MessageBreak
  /space /space Try typing /space
  /space to proceed, ignoring /protect/foo.
}

/ClassWarning{}{}
/PackageWarning{}{}
/ClassWarningNoLine{}{}
/PackageWarningNoLine{}{}
/classInfo{}{}
/PackageInfo{}{}
Within the and : /protect can be used to stop a command from expanding; /MessageBreak causes a line-break; and /space prints a space. Also, these should not end with a full stop as on eis automatically added.

10) Defining commands
/DeclareRobustCommand{}[][]{}
/DeclareRobustCommand*{}[][]{}
This command takes the same arguments as /newcommand but it declares a robust command, even if some code within the is fragile. You can use this command to define new robust commands, or to redefine existing commands and make them robust. A log is put into the transcript file if a command is redefined.
For example:
/DeclareRobustCommand{/seq}[2][n]{%
 /ifmmode
   #1_{1}/ldots#1_{#2}%
 /else
   /PackageWarning{fred}{You can't use /protect/seq/space in text}%
 /fi
}
for example:
/section{Stuff about sequences $/seq{x}$}

/CheckCommand{}[][]{}
/CheckCommand*{}[][]{}

11) Moving arguments
The setting of protect whilst processing moving arguments has been reimplemented, as has the method of writing information from the .aux file to other files such as the .toc file. Details can be found in the file ltdefns.dtx.

三、Miscellaneous commands
1) Layout parameters
/paperheight
/paperwidth
2) Case changing
/MakeUppercase{}
/MakeLowercase{}
3) The 'openany' option in the 'book' class
The openany option allows chapter and similar openings to occur on left hand pages. Previously this option affected only /chapter and /backmatter. It now also affects /part, /frontmatter and /mainmatter.
4) Better user-defined math display environments
/ignorespacesafterend
Suppose that you want to define an environment for displaying text that is numbered as an equation. A straightforward way to do this is as follows:
/newenvironment{texteqn}
 {/begin{equation}
   /begin{minipage}{0.9/linewidth}}
 {/end{minipage}
   /end{equation}}
For example:
/newenvironment{texteqn}
 {/begin{equation}
  /begin{minipage}{0.9/linewidth}}
 {/end{minipage}
  /end{equation}
  /ignorespacesafterend}

5) Normalising spacing
/normailsfcodes
This command should be used to restore the normal settings of the parameters that affect spacing between words, sentences, etc.

四、Upgrading LaTeX2.09 classes and packages
1) Try it first
test your style in 'compatibility mode'.
2) Troubleshooting
3) Accommodating compatibility mode
accommodate old edition
/if@compatibility
 
/else
 
/fi

4) Font commands
Some font and size commands are now defined by the document class.
/newcommand{/rm}{/rmfamily}
/newcommand{/sc}{/scshape}
Another possible definition is:
/DeclareOldFontCommand{/rm}{/rmfamily}{/mathrm}
/DeclareOldFontCommand{/sc}{/scshape}{/mathsc}

/normalsize
/@normalsize

5)Obsolete commands
Some packages will not work with LaTeX2e, normally because they relied on an internal LaTeX command which was never supported and has now changed, or been removed.

目录
相关文章
|
5月前
|
运维 Shell Python
第九章 Python自定义模块及导入方法
第九章 Python自定义模块及导入方法
|
5月前
|
数据可视化
esquisse包—不写代码生成ggplot图
esquisse包—不写代码生成ggplot图
68 5
|
Python
Python程序结构:模块和包的组织与导入
Python程序结构:模块和包的组织与导入
113 0
|
JSON 数据格式 Python
24.从入门到精通:__name__属性 dir() 函数 标准模块 包 从一个包中导入*
24.从入门到精通:__name__属性 dir() 函数 标准模块 包 从一个包中导入*
|
数据可视化 数据挖掘 Python
【python可视化】python编码规范、标准库与扩展库对象的导入与使用
代码布局和排版在很大程度上决定了代码可读性的好坏,变量名、函数名、类名等标识符名称也会对代码的可读性带来一定的影响。一个好的python代码不仅应该是正确的,还应该是漂亮的、优雅的。
|
Python
Python语法之模块和包
这一节,我将为大家介绍模块和包: 在开发大型软件时,随着代码写的越来越多,如果将所有的代码都放在一个文件里,势必为以后的维护带来很大的困难。正如仓颉造字一样,仓颉是黄帝的史官,用祖传结绳记事的老办法记载史实。时间一长,那些大大小小,奇形怪状的绳结都记了些什么,连他自己也没法辨认了。于是,仓颉开始想新的办法,用什么方式可以帮助大家分辨清不同的事物,在仓颉的努力下,他创造了文字,解决了这个问题。而在 Python 中,为了编写易于维护的代码,我们会将代码拆分放到不同的文件里,这样每个文件包含的代码相对就会减少。在 Python 中,一个 .py 文件称为一个模块(Module)。
106 0
|
Python
python创建类导入(简化版纯代码)
python创建类导入(简化版纯代码)
117 0
|
编解码 数据安全/隐私保护 Python
Python 技术篇 - 通过pyminifier库实现源码压缩、混淆、加密保护实例演示,pyminifier的使用方法
Python 技术篇 - 通过pyminifier库实现源码压缩、混淆、加密保护实例演示,pyminifier的使用方法
598 0
Python 技术篇 - 通过pyminifier库实现源码压缩、混淆、加密保护实例演示,pyminifier的使用方法
|
Python
Python 技术篇 - 查看python库都包含什么方法,查看python模块某个方法的具体用法源码,查看python模块所在的物理位置,查看python库都包含哪些属性
Python 技术篇 - 查看python库都包含什么方法,查看python模块某个方法的具体用法源码,查看python模块所在的物理位置,查看python库都包含哪些属性
1021 0
Python 技术篇 - 查看python库都包含什么方法,查看python模块某个方法的具体用法源码,查看python模块所在的物理位置,查看python库都包含哪些属性
|
存储 图形学
R语言-包的安装、载入及使用方法
R语言-包的安装、载入及使用方法
610 0
R语言-包的安装、载入及使用方法
下一篇
无影云桌面