我可以用 LaTeX 而不是 TeX 编写 cls 文件吗?

发布于 2024-09-18 18:23:06 字数 95 浏览 5 评论 0原文

我在 XeLaTeX 文件中有一些初始化代码,我想将其放入一个单独的文件中,以便我可以在以后的文本中重用它。将 XeLaTeX 代码转换为 LaTeX 类文件的最快方法是什么?

I have some initialization code in a XeLaTeX file which I would like to put into a separate file so that I can reuse it in future texts. What is the fastest way to convert my XeLaTeX code to a LaTeX class file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假装不在乎 2024-09-25 18:23:06

您可以将前导码放入 .cls 文件中,然后使用 \documentclass{mydocstyle} 加载它。您的 .cls 文件将如下所示:

% Declare that this document class file requires at least LaTeX version 2e.
\NeedsTeXFormat{LaTeX2e}

% Provide the name of your document class, the date it was last updated, and a comment about what it's used for
\ProvidesClass{mydocstyle}[2010/09/13 Bluetulip's custom LaTeX document style]

% We'll pass any document class options along to the underlying class
\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{article}% or book or whatever
}

% Now we'll execute any options passed in
\ProcessOptions\relax

% Instead of defining each and every little detail required to create a new document class,
% you can base your class on an existing document class.
\LoadClass{article}% or book or whatever you class is closest to

% Now paste your code from the preamble here.
% Replace \usepackage with \RequirePackage. (The syntax for both commands is the same.)

% Finally, we'll use \endinput to indicate that LaTeX can stop reading this file. LaTeX will ignore anything after this line.
\endinput

请注意,文档类文件可能会变得更加复杂(如果您想包含 \documentclass[option]{mydocstyle} 等选项,等),但是这个基本格式应该可以帮助您入门。

将文件另存为 mydocstyle.cls 并将其与 .tex 文件一起放入当前目录中。

您还可以查看LaTeX2e 类和包编写器指南。它将引导您更详细地完成此操作。

You can put your preamble code into a .cls file and then use \documentclass{mydocstyle} to load it. Your .cls file will look like this:

% Declare that this document class file requires at least LaTeX version 2e.
\NeedsTeXFormat{LaTeX2e}

% Provide the name of your document class, the date it was last updated, and a comment about what it's used for
\ProvidesClass{mydocstyle}[2010/09/13 Bluetulip's custom LaTeX document style]

% We'll pass any document class options along to the underlying class
\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{article}% or book or whatever
}

% Now we'll execute any options passed in
\ProcessOptions\relax

% Instead of defining each and every little detail required to create a new document class,
% you can base your class on an existing document class.
\LoadClass{article}% or book or whatever you class is closest to

% Now paste your code from the preamble here.
% Replace \usepackage with \RequirePackage. (The syntax for both commands is the same.)

% Finally, we'll use \endinput to indicate that LaTeX can stop reading this file. LaTeX will ignore anything after this line.
\endinput

Note that document class files can get much more complicated (if you want to include options like \documentclass[option]{mydocstyle}, etc.), but this basic format should get you started.

Save your file as mydocstyle.cls and put it in the current directory with your .tex file.

You can also take a look at the LaTeX2e for class and package writers guide. It'll walk you through this in more detail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文