【问题标题】:Can I write cls files in LaTeX instead of TeX?我可以用 LaTeX 而不是 TeX 编写 cls 文件吗?
【发布时间】:2010-09-13 16:09:01
【问题描述】:

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

【问题讨论】:

    标签: latex xelatex


    【解决方案1】:

    您可以将前导代码放入.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 for class and package writers guide。它将引导您更详细地了解这一点。

    【讨论】:

    • 感谢您的指点,这足以让我开始。在这种情况下,提及命令 \LoadClass[options]{article} 也会有所帮助。
    • 哎呀!我的意思是忘记了。我已将其添加到我的答案中,因此对其他人更有帮助。我还添加了一些代码来处理传递给文档类的选项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-07
    • 1970-01-01
    相关资源
    最近更新 更多