如何编写LaTeX类和包

如何编写LaTeX类和包,第1张

Latex宏包就是模板,分为class(以.cls为后缀,在documentclass命令中使用)和style(以.sty为后缀,在usepackage命令中使用),如常见的book,article类;以及graphicx,caption包等。Latex提供了专门的工具doc/docstrip来编写宏包。

简单的包完全可以自己动手写,先看一个简单的例子,我们的目的是最终写出一个完整的毕业论文模板thesis.cls。

编写thesis.cls内容如下:

\NeedsTeXFormat{LaTeX2e}[2007/10/19]

\ProvidesClass{thesis}

[2011/04/05 v0.1 Thesis Template for Doctor]

\LoadClass[cs4size,a4paper,fancyhdr,fntef, UTF8]{ctexbook}[2007/10/19]

\RequirePackage{amsmath,amsthm,amsfonts,amssymb,bm}

\RequirePackage{apjfonts, epigraph, titlesec, textcomp}

\RequirePackage{natbib}

\renewcommand\title[1]{\def\IHEP@value@title{#1}}

\renewcommand\author[1]{\def\IHEP@value@author{#1}}

\renewcommand\maketitle{%

\clearpage

\thispagestyle{empty}

\vspace*{50pt}

\begin{center}

\bf\songti\zihao{-1}中国科学院研究生院\\博士学位论文

\vskip 50pt

\bf\heiti\zihao{3} \underline{~\IHEP@value@title~}

\vskip 20pt

\bf\kaishu\zihao{4} \underline{~\IHEP@value@author~}

\end{center}

}

\makeatletter

\def\IHEP@value@title{~~~~~(论~文~题~目)~~~~~}

\def\IHEP@value@author{~~~~~(作~者~姓~名)~~~~~}

\makeatother

\endinput

写测试文件test.tex,内容如下

\documentclass{thesis}

\begin{document}

\title{编写论文模板}

\author{Liyropt}

\maketitle

\end{document}

将thesis.cls和test.tex放在同一目录下,用Latex编译

你是否正确的安装了你的MacTex这个包呢,这个包中会给你自动安装pdflatex和其他相关工具,单独安装texshop是不能使用的。。。

并且你可以尝试使用其他的方式,如xelatex。看看是否其他的已经安装上了额。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11558207.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存