Latex2e class and package design (1)

Source: Internet
Author: User
Latex2e class and package design (1)
I. Introduction to classes and packages
Latex2.09 provides little support for writing class and package, and users have to use underlying commands.
Latex2e provides many advanced commands for organizing package files. It is also easier to create another class or package based on the existing class and package.
Ii. writing classes and packages
1) Use Doc and docstrip tools
If you want to write a Large Latex class or package, consider using the doc software released with latex.
The. CLs and. sty files can be generated by the docstrip software.
The doc software automatically generates definitions and commands using indexes and updates the directory list. --> It is useful for creating documents for large-scale Tex resource maintenance.
2) Document classes and packages
Determine the principles of class and package: if these commands can be used for all document classes, process them into a package; otherwise, process them into a class.
Document Class Classification: 1) exists independently, such as article and report; 2) It cannot exist independently and is an extension or variant of other document classes.
3) latex command:
1. Author command: used by the author of the document, which consists of lowercase letters. For example,/section,/emph,/times, etc;
2. Class and package writing commands: Both uppercase and lowercase. For example:/inputiffileexists;
3. Internal Command: used to implement the latex system. The command contains the @ symbol. For example,/tempcnta.
4) command and color of the box
Always use latex box commands instead of Tex box primitives. Try to use commands such as/sbox,/mbox,/parbox, and minpage environments.
5) define text and mathematical characters
This part of latex2e is still under construction. The/declarerobustcommand command should be used to define such code-independent commands.
6) Basic commands
6.1) load other commands:
/Loadclass,/loadclasswitexceptions,
/Requirepackage,/requirepackagewitexceptions
These commands are used to use other classes or packages in a class or package.
6.2) Optimize your own class or package files:
Use as many latex commands as possible; Use/packageerror,/packagewarning,/packageinfo, and so on.
For example, use the/ds @ <option> define option to reference it with/@ options --> instead of the/declareoption and/processoptions commands.
6.3) enhance the compatibility of class or package files:
The document should contain only visible 7-bit encoded documents, and the file name also adopts the 8.3 format;
7) structure of class and Package
1. File ID: It indicates a latex2e package or class file. It also contains a brief introduction to yourself;
2. pre-declaration: Some commands are declared. These commands are generally used only for option declaration and processing, and other files can also be loaded;
3. Optional: Description and processing optional;
4. Further Declaration: most of the content of the file, such as declaring new variables, commands, and fonts, and loading all other necessary files.
7.1) File ID
Package ID format:
/Needstexformat {latex2e} [date other-Information]
/Providespackage {package} [date other-Information]
Class ID format:
/Needstexformat {latex2e}
/Providesclass {class-name} [date other-Information]
The class description is displayed in use, and the package description is stored in the log file. The information can be displayed using the/listfiles command.
7.2) Use of other classes and packages
Latex2e classes and packages support modular design. You can use smaller modules in the file to enter other classes or package files, instead of defining all functions in a large file.
Use another package file in the latex class and package file:
/Requirepackage [Options] {package} [date]
Use another class file in latex class and package files:
/Loadclass [Options] {date-name} [date]
If you want to use the option used by the current class when using another class or package, you can usually use the following two commands:
/Loadclasswitexceptions {class-name} [date]
/Requrepackagewitexceptions {package} [date]
7.3) Option description and handling
/Declareoption {Option} {code}
Note: In a mounted class or package file, sometimes the options provided by the user are not defined in the class or package file. If the class is used, the system generates a warning; if a package is used, the system will fail.
/Declareoption * {code} indicates the code to be executed when an undefined option is used.
After all the optional statements are declared, the corresponding code is not executed and the command:/processoptions/relax is used.
Example:
/Declareoption {Foo} {/typeout {saw Foo .}}
/Declareoption {Baz} {/typeout {saw Baz .}}
/Declareoption * {/typeout {What's/currentoption ?}}
/Processoptions/relax
The user wrote the/usepackage [Foo, bar] {Jame} command in the document. The following information is displayed:
Saw Foo. What's bar?
Run the following command: You can choose to transfer another class or package file from a class or package file:
/Passoptionstopackage {Option} {package}
/Passoptionstoclass {Option} {class}
For example, if a new class is defined in article, all undefinable options are handed over to article for processing:
/Declareoption * {%
/Passoptionstoclass {/currentoption} {Article} %
}
Note: If the above method is used, the target class or package must be loaded after this, because the class or package file can be processed only when it is loaded.
7.4) Minimum class file
To write a class or package file, the greatest workload is to define new commands or change the appearance of the document, and use commands such as/newcommand and/setlength.
The minimum class file is as follows:
/Needstexformat {latex2e}
/Providesclass {minimal} [1995/10/30 standard latex minimal class]
/Renewcommand {/normalsize} {/fontsize {10pt} {12pt}/selectfont}
/Setlength {/textwidth} {6.5in}
/Setlength {/textheight} {8in}
7.5) class file instance
7.5.1) internal company Correspondence Class, not named neplet. CLs
1. Identify a class file
/Needstexformat {latex2e}
/Providesclass {neplet} [1995/04/01 nonexistent press letter class]
2. Pass the option to the letter class and load the letter class with A4 paper
/Declareoption * {/passoptionstoclass {/currentoption {letter }}
/Processoptions/relax
/Loadclass [a4paper] {letter}
3. Redefine the firstpage type and use your own title and footer.
/Renewcommand {/PS @ firstpage} {%
/Renewcommand {/@ oddhead} {newletterhead} %
/Renewcommand {/@ oddfoot} {newletterfoot} %
}
7.5.2) time-sensitive communication class named smphnews. CLs
1. Identify a class file
/Needstexformat {latex2e}
/Providesclass {smplnews} [2005/05/22 the simple news newsletter class]
/Newcommand {/headlinecolor} {/normalcolor}
2. Option transfer and processing: You can process the onecolumn option by yourself, and the other items are handed over to article for processing. You can customize the option green and set the title to green.
/Declareoption {onecolumn} {/optionnotused}
/Declareoption {green} {/renewcommand {/headlinecolor} {/color {green }}}
/Declareoption * {/passoptionstoclass {/currentoption} {Article }}
/Processoptions/relax
3. Mount necessary classes and package files: Use twocolumn to mount the article class with the option
/Loadclass [twocolumn] {Article}
/Requirepackage {color}
4. Redefine/maketitle and subscribe commands to set the title Font and color
/Renewcommand {/maketitle} {%
/Twocolumn {%
/Fontsize {72} {80}/fontfamily {Pho}/fontseries {B} %
/Fontshape {SL}/selectfont/headlinecolor
// @ Title
} %
}
5. Rename the section command and disable the section number function.
/Renewcommand {/section} {%
/@ Startsection {Section} {1} {0pt} {-1.5ex plus-1ex minus-. 2ex} %
{1ex plus. 2ex} {/large/sffamily/slshape/headlinecolor} %
}
6. perform three basic settings
/Renewcommand {/normalsize} {/fontsize {9} {10}/selectfont}
/Setlength {/textwidth} {17.5}
/Setlength {/textheight} {25 cm}
7. Other work: you also need to define instructions such as the article author and page style.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.