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.

目录
相关文章
|
存储 资源调度 JavaScript
轻松搞定 reduxjs/toolkit
轻松搞定 reduxjs/toolkit
371 0
|
开发者
LaTeX高效写作系列:word表格转LaTeX
Fancy版本见九天学者的个人博客,关注文集博士干点啥或者微信公众号九天学者及时获取连载更新。 如何将word表格转为格式 迫于无奈从刚开始学习计算机就上了某软这条贼船,不少情况下,将表格写为了word文件。
3627 0
LaTeX高效写作系列:word表格转LaTeX
|
4月前
|
传感器 机器学习/深度学习 人工智能
从仿真到现实:数字孪生解锁具身AI全景应用
Embodied AI正在重塑智能机器人系统的格局,尤其通过为复杂且动态的环境中的行动执行提供许多现实可行的解决方案。然而,具身AI需要生成大量数据用于训练和评估,以确保其与物理环境交互的安全性。因此,有必要构建一个成本效益高的模拟环境,能够从物理特性、物体属性及交互中提供充足的训练和优化数据。Digital Twins是工业5.0中的关键议题,它通过镜像真实世界对应体的状态和行动,实现对物理过程的实时监控、模拟与优化。本综述探讨了将数字孪生与具身AI结合的方式,通过将虚拟环境转化为动态且数据丰富的平台,弥合仿真与现实之间的差距。
521 7
|
弹性计算
阿里云服务器公网IP和私网IP地址在哪查询?
阿里云服务器公网IP和私网IP地址在哪查询?阿里云服务器IP地址在哪查看?在云服务器ECS管理控制台即可查看,阿里云服务器IP地址包括公网IP和私有IP,阿里云百科分享阿里云服务器IP地址查询方法
596 0
|
Web App开发 网络协议 安全
基于Web攻击的方式发现并攻击物联网设备介绍
基于Web攻击的方式发现并攻击物联网设备介绍
206 4
|
人工智能 API 语音技术
用Python解锁微软Edge的文本转语音服务
近来,TTS模型工具给大家也分享了不少,对于一些小白或有需要的人是提供了一个额外的选项。 但作为编程人员/研发人员,或者需要集成TTS服务的人来说,好像又有点麻烦。 今天就为大家分享一个非常有趣的项目—edge-tts。
|
数据安全/隐私保护 iOS开发 MacOS
Mac终端出现 brew command not found 解决
Mac终端出现 brew command not found 解决
835 3
|
SQL BI 数据库
数据库慢查询:DBA的挑战与应对策略
NineData的慢查询分析功能。它可以自动采集并记录数据库中的所有慢查询,比较亮眼的是它通过对每一条慢查询进行性能诊断,最终提供优化建议,包含添加或修改索引、调整表结构等,同时还可以根据业务类型配置SQL开发规范,配置完成后,系统还会基于这些规范诊断慢SQL。
1286 2
数据库慢查询:DBA的挑战与应对策略
|
5G UED
5G NR中的寻呼过程是如何工作的?
【8月更文挑战第31天】
578 0
|
安全 测试技术 Swift
Llama 3开源,魔搭社区手把手带你推理,部署,微调和评估
Meta发布了 Meta Llama 3系列,是LLama系列开源大型语言模型的下一代。在接下来的几个月,Meta预计将推出新功能、更长的上下文窗口、额外的模型大小和增强的性能,并会分享 Llama 3 研究论文。
Llama 3开源,魔搭社区手把手带你推理,部署,微调和评估