如何編寫LaTeX package 和class

LaTeX文檔中\usepackage引用的.sty文檔就是文字性插入該package sty文檔1。相當於在LaTeX \begin{document}前的定義macros,就像定義\def,\newcommand這樣,如此該package文檔中定義的macros可以直接使用。

如何自己編寫LaTeX package?或者class文檔.cls文檔。package可以用在所有LaTeX class文檔,.cls就只能用該class文檔,比如我編寫myclass.cls,那麽,用的時候,\documentclass{myclass}。我想class文檔多用於學業和工作文檔,每個學校、公司、期刊、會議有自己的文檔模板規定。

我首先說明class文檔如何編寫。

如何創建class文檔

如果我已經將一個tex文檔調整到符合期望,可以將其設為一個class文檔。Basically,我將preamble區的所有內容存為.cls文檔。但需要修改部分命令以符合processor要求,比如指定processor \NeedsTeXFormat{LaTeX2e},定義class的標識。

我們想想看,决定文檔格式的要素是什麼:封面,標題字體、章節名稱字體,頁眉頁腳。還有,正文字體、行距、是否首行縮進,這我寫《一個LaTeX中文模板》時已學習。所以,現在的任務是:
1)封面2上面有標題,下面有一些信息,如何定位至頁面的任意部位。重點是往下。主要命令是\vspace{length},比如\vspace{5cm}。還有,\vfill,\vfill是垂直自動填充。再有,任意位置寫字,可以用\hbox,其和\vbox配合,可以畫表格。
2)標題英文字體、大小設置3,和中文字體設定4。章節名稱字體大小設置5
3)頁眉頁腳設定。package titlesec可修改6
我羅列的資料是老師們教的方法。
代碼見『附錄2:如何將tex文檔改為.cls文檔』。包含三個文檔,原.tex文檔,新建的.cls文檔,改為引用新的documentclass的.tex文檔。

如何創建package文檔

關於LaTeX macro編程的語法,例如變量定義、procedure定義、循環、if語句,我以後擴充。

現在假裝我已經會LaTeX macro programming語言,如何編寫LaTeX package?

Alan Munn博主說7,準備四個文檔:
mypackage.sty (the package itself)
mypackage.tex (the package documentation source)
mypackage.pdf (the compiled package documentation)
README (a plain text README file (with no extension))

用以下命令打包成tar.gz。
ctanify --no-tds mypackage.* *.tex=doc README

上傳到CTAN網站

舉例:Peilonrayz博主的『Hello, World!』8
mypackage.sty

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{mypackage}[2020/02/28 1.0.0 Tutorial project]

\newcommand{\hello}{Hello, World!}

\endinput

usemypackage.tex

\documentclass{article}
\usepackage{mypackage}

\begin{document}
    \hello
\end{document}

附錄1:把package和package manual文檔寫在一起的.dtx文檔

LATEX for package and class authors current version9說使用doc.tex和strip.tex。
我在Terminal打開參考文檔:
texdoc doc
texdoc docstrip

我在操作系統Spotlight search:
musixcrd.dtx
doc.tex
strip.tex

可以看出,musixcrd文檔把macros和其幫助文檔寫在一起,幫助文字用註釋寫。

這樣運行doc.tex就把該文檔生成幫助文檔pdf,註釋部分成了顯性文字。運行strip.tex,刪除註釋文字,生成只有macros的.sty文檔。

請看這個.dtx文檔,不好寫、不好讀。編程和使用手冊是不同的思路,使用手冊應有多個舉例。另外.sty文檔沒有註釋很難理解。

.dtx另一個例子:我spotlight .dtx,搜到asy-latex.dtx文檔,在TexShop打開可以直接用pdflatexxmk Typeset。

感謝StackExchange的人們,授予我兩個方法10:在寫幫助文檔時,LaTeX command 既運行又打印在pdf中。
其中dispExample*這個environment自動換行,但a)不支持空白行,需在空白行寫%,b)最多一頁,不支持換頁。
Example enviroment實際使用不用numbers=left 這個option,因為這使得PDF拷貝出錯。

\documentclass[11pt]{article}
\usepackage{musixtex} % music score

%Example enviroment. 
\usepackage{fancyvrb-ex}

% For dispExample enviroment
\usepackage{tcolorbox}
\tcbuselibrary{documentation}

\begin{document}

How to draw a blank staff?
\definecolor{darkcolor}{RGB}{87, 96, 111}
\begin{dispExample*}{title = An Example, listing and text,colframe=darkcolor,colback=white,colupper=black, fonttitle=\bfseries,center title}
\begin{music} 
\startpiece
\notes\en
\zendpiece
\end{music}
\end{dispExample*}

\begin{dispListing*}{title = An Example, listing only}
\begin{music} 
\startpiece
\notes\en
\zendpiece
\end{music}
\end{dispListing*}

\begin{Example}[frame=single]
\begin{music} 
  \startpiece
  \notes\en
  \zendpiece
\end{music}
\end{Example}

\begin{Example}[frame=single,numbers=left,xleftmargin=1cm]
\begin{equation}
y=mx+c
\end{equation}
\end{Example}

\begin{Example}[frame=single,numbers=left,xrightmargin=5cm]
\begin{itemize}
\item Animal
\item Mineral
\item Vegetable
\end{itemize}
\end{Example}

\end{document}

附錄2:如何將tex文檔改為.cls文檔

如此,假設一個.tex文檔如下(在上傳文檔中名為original.tex):

\documentclass[a4paper, titlepage]{article}
\usepackage[fontsize=11pt]{fontsize}
\usepackage[margin=1in]{geometry} % 設置頁邊距

%Ref1: https://latex.lierhua.top/docs/Font-Family/ 
%Ref2: https://gitcode.csdn.net/65e7dbd31a836825ed78ac91.html
%中文字體的名稱需在Word的字體列表查看,或Pages Format\Font\Show Font中查看
\usepackage{ctex} % 中文
\setCJKmainfont{Alibaba PuHuiTi} % 設置中文字體,阿里普惠體。開源字體還有華為鴻蒙、思源。Roman 衬线字体 	\textrm{ } 	\rmfamily 
\setCJKsansfont{Songti TC} % Sans-serif 无衬线字体 	\textsf{ } 	\sffamily
\setCJKmonofont{Heiti TC} %Typewriter 等宽字体(打字机字体) 	\texttt{ } 	\ttfamily
\setmainfont{Verdana} % 設置英文字體
\setsansfont{Times New Roman} 
\setmonofont{Tahoma} 
\linespread{1.5} % 設置1.5倍行距
\usepackage{hyperref} % 超鏈接
\usepackage[style=iso]{datetime2} % 設置日期格式為YYYY--MM--DD

%%%%%% 繁體字模板專用部分,開始 %%%%%%
\renewcommand\contentsname{目錄}
\renewcommand\refname{參考文獻}
%%%%%% 繁體字模板專用部分,結束 %%%%%%

% 定義標題(title)的字體等風格
%LitBro,『Latex 对中文字体设置的一些解决』,https://www.cnblogs.com/LitBro/p/12074820.html
%宋体 	\songti 	\CJKfamily
%黑体 	\heiti 	\CJKfamily
%仿宋 	\fangsong 	\CJKfamily
%楷书 	\kaishu 	\CJKfamily
%隶书 	\lishu 	\CJKfamily
%圆体 	\youyuan 	\CJKfamily
\newcommand\headlinecolor{\normalcolor}
\makeatletter
\renewcommand*\maketitle{%
    \begingroup
    \centering
    \fontsize{50}{60}% 50pt on 60pt leading
%	\fontfamily{phv}% Helvetica 這是英文文檔設定字體的方法
	\youyuan %這是中文文本設定字體的方法,或者\sffamily
    \fontseries{b}% Bold
    \fontshape{sl}% Slanted
    \selectfont
    \headlinecolor
    \@title
    \par
    \vskip1in
    \endgroup
}
\makeatother

% 定義頁眉頁腳的風格
%https://tex.stackexchange.com/questions/194423/page-style-plain-vs-empty
%Standard classes
%LaTeX predefines four page styles for standard classes:
%    empty Both header and footer are empty.
%    plain The header is empty; the footer contains the page number.
%    headings The footer is empty; the header contains information determined by the class (based on sectional units) and the page number.
%    myheadings It is similar to headings but the user controls the information in the header.
% titlesec可自定義頁眉頁腳
\usepackage[sf,sl,outermarks]{titlesec}
\newpagestyle{main}{
	\sethead{左页眉\usepage}{中页眉\textbf{\@title}}{右页眉}     %设置页眉
    \setfoot{左页脚}{中页脚}{右页脚\thesection. \sectiontitle}      %设置页脚,可以在页脚添加 \thepage  显示页数
    \headrule                                      % 添加页眉的下划线
    \footrule  
    }                                     %添加页脚的下划线
    
%這是一個來自titlesec.tex的例子。這個定義使得頁腳空白,這樣腳註(footnote)好看。
%\newpagestyle{myps}[\small\sffamily\slshape]{
%  \headrule
%  \sethead{\@title}{\thesection. \sectiontitle}{\usepage}}
%\pagestyle{myps}

% Specify different font for section headings
\newfontfamily\headingfont[]{Gill Sans}
\titleformat*{\section}{\LARGE\headingfont}
\titleformat*{\subsection}{\Large\headingfont}
\titleformat*{\subsubsection}{\large\headingfont}

% 一段文本用於測試
\newcommand\stories{《伊索寓言》(英語:Aesop's Fables 或 Aesopica)是一個以伊索命名的寓言故事集。事實上,該故事集是在很長一段期間內創作。在這些寓言中,敘事者通常是代表各種典型人類角色的動物。其中的童話故事常伴隨所欲傳達的道德概念。這些寓言在道德教育中被大量使用,並成為許多文藝作品的創作基礎。《伊索寓言》文字凝練,故事生動,想象豐富,飽含哲理,融思想性和藝術性於一體。其中《龜兔賽跑》、《狐狸與葡萄》、《農夫與蛇》、《狼來了》、《北風與太陽》等已成為全世界家喻戶曉的故事。--維基百科,伊索寓言\\
公元前4世纪至前3世纪之交,亚里士多德的再传弟子,雅典哲学家德墨特里俄斯所编的最早的希腊寓言集《伊索故事集》,只搜集了近200则寓言,这个集子早已失传了:公元1世纪,费德鲁斯用拉丁韵文写了《伊索式寓言》5卷,今存130篇,具有改编和再创作性质。公元2世纪巴布里乌斯编成一本古希腊语寓言诗集,1844年发现了此书的古老抄本,留下寓言诗140篇、散文寓言60篇。这是现存最早的希腊寓言集。
后世流传的伊索寓言的版本,是以拜占庭(东罗马帝国)僧侣学者普拉努得斯所编的伊索寓言为底本的。这个底本只有150则故事,编于14世纪初叶,至1479年首次印行。1610年,瑞士学者耐弗莱特刊印伊索寓言,在普拉努得斯底本的基础上增加了200多则寓言:包括梵蒂冈图书馆所藏的134则希腊寓言、阿弗托纽斯记录的40则希腊寓言、巴布里乌斯记录的43则希腊寓言。此后,伊索寓言基本定型,也使伊索成了欧洲家喻户晓的人物:虽然此后的各种版本有不同的抉择损益,但大体上不出300多则这个范畴。--百度百科,伊索寓言\\
Apollonius of Tyana, a 1st-century CE philosopher, is recorded as having said about Aesop: "like those who dine well off the plainest dishes, he made use of humble incidents to teach great truths, and after serving up a story he adds to it the advice to do a thing or not to do it. Then, too, he was really more attached to truth than the poets are; for the latter do violence to their own stories in order to make them probable; but he by announcing a story which everyone knows not to be true, told the truth by the very fact that he did not claim to be relating real events."--Wikipedia, Aesop's Fables}


\title{自建class的文檔}
\author{}

\begin{document}
\begin{titlepage}
\centering
\maketitle
\vspace*{15cm}
\leavevmode % Ref1: Tex by Topic: Macro to switch to horizontal mode if necessary
%Ref2: The \leavevmode means that it starts a paragraph. https://tex.stackexchange.com/questions/118164/differentiating-between-hbox-and-mbox
\vbox{
\hbox to 3.5 in{\Large 姓名:\hfill \rule{190pt}{1pt}}
\hbox to 3.5 in{\Large 所在地:\hfill \rule{180pt}{1pt}}
}
\end{titlepage}

\tableofcontents
\thispagestyle{empty}
\clearpage

\pagestyle{main}

\begin{abstract}
\stories
\end{abstract}
\clearpage

\section{前言}

\section{中文字體package}
\stories
\subsection{字體設置}
\subsubsection{字體大小}
\makeatletter
fontsize=\f@size
\makeatother
\section{感謝}
\end{document}

我將preamble部分另存,作3個修改:
1)加頭加尾
%頭
\NeedsTeXFormat{LaTeX2e}% LaTeX processor version
\ProvidesClass{customedclass}[2025/04/13 A class document from a tex file]% the identity of the class, used in \documentclass{customedclass}
%尾
\endinput
2)\LoadClass[a4paper, titlepage]{article}
這裏我沒有增加字體大小這個字體參數,比如11pt,而使用package fontsize定義。是因為我原來使用這個參數,但最後原文檔和新文檔的fontsize不同,乃至於看起來PDF文檔不一樣。
\usepackage[fontsize=11pt]{fontsize} 使得兩者一樣,但實際的fontsize也不是11pt,而是10.53937pt,這說明processor在生成PDF時做了微調。
3)\newcommand\settitlepage設置封面。
把原.tex文檔拆成.cls文檔和引用該cls的新.tex兩個文檔。.cls代碼如下(上傳文檔名為customedclass.cls):

\NeedsTeXFormat{LaTeX2e}% LaTeX processor version
\ProvidesClass{customedclass}[2025/04/13 A class document from a tex file]% the identity of the class, used in \documentclass{customedclass}

\LoadClass[a4paper, titlepage]{article}%Inherited from article document class, the options可參考Tom, LaTeX documentclass options illustrated, https://texblog.org/2013/02/13/latex-documentclass-options-illustrated/#google_vignette
\usepackage[fontsize=11pt]{fontsize}%
\usepackage[margin=1in]{geometry} % 設置頁邊距

%Ref1: https://latex.lierhua.top/docs/Font-Family/ 
%Ref2: https://gitcode.csdn.net/65e7dbd31a836825ed78ac91.html
%中文字體的名稱需在Word的字體列表查看,或Pages Format\Font\Show Font中查看
\usepackage{ctex} % 中文
\setCJKmainfont{Alibaba PuHuiTi} % 設置中文字體,阿里普惠體。開源字體還有華為鴻蒙、思源。Roman 衬线字体 	\textrm{ } 	\rmfamily 
\setCJKsansfont{Songti TC} % Sans-serif 无衬线字体 	\textsf{ } 	\sffamily
\setCJKmonofont{Heiti TC} %Typewriter 等宽字体(打字机字体) 	\texttt{ } 	\ttfamily
\setmainfont{Verdana} % 設置英文字體
\setsansfont{Times} 
\setmonofont{Tahoma} 
\linespread{1.5} % 設置1.5倍行距
\usepackage{hyperref} % 超鏈接
\usepackage[style=iso]{datetime2} % 設置日期格式為YYYY--MM--DD

%%%%%% 繁體字模板專用部分,開始 %%%%%%
\renewcommand\contentsname{目錄}
\renewcommand\refname{參考文獻}
%%%%%% 繁體字模板專用部分,結束 %%%%%%

% 定義標題(title)的字體等風格
%LitBro,『Latex 对中文字体设置的一些解决』,https://www.cnblogs.com/LitBro/p/12074820.html
%宋体 	\songti 	\CJKfamily
%黑体 	\heiti 	\CJKfamily
%仿宋 	\fangsong 	\CJKfamily
%楷书 	\kaishu 	\CJKfamily
%隶书 	\lishu 	\CJKfamily
%圆体 	\youyuan 	\CJKfamily
\newcommand\headlinecolor{\normalcolor}
\makeatletter
\renewcommand*\maketitle{%
    \begingroup
    \centering
    \fontsize{50}{60}% 50pt on 60pt leading
%	\fontfamily{phv}% Helvetica 這是英文文檔設定字體的方法
	\youyuan %這是中文文本設定字體的方法,或者\sffamily
    \fontseries{b}% Bold
    \fontshape{sl}% Slanted
    \selectfont
    \headlinecolor
    \@title
    \par
    \vskip1in
    \endgroup
}
\makeatother

% 定義頁眉頁腳的風格
%https://tex.stackexchange.com/questions/194423/page-style-plain-vs-empty
%Standard classes
%LaTeX predefines four page styles for standard classes:
%    empty Both header and footer are empty.
%    plain The header is empty; the footer contains the page number.
%    headings The footer is empty; the header contains information determined by the class (based on sectional units) and the page number.
%    myheadings It is similar to headings but the user controls the information in the header.
% titlesec可自定義頁眉頁腳
\usepackage[sf,sl,outermarks]{titlesec}
\newpagestyle{main}{
	\sethead{左页眉\usepage}{中页眉\textbf{\@title}}{右页眉}     %设置页眉
    \setfoot{左页脚}{中页脚}{右页脚\thesection. \sectiontitle}      %设置页脚,可以在页脚添加 \thepage  显示页数
    \headrule                                      % 添加页眉的下划线
    \footrule  
    }                                     %添加页脚的下划线

% Specify different font for section headings
\newfontfamily\headingfont[]{Gill Sans}
\titleformat*{\section}{\LARGE\headingfont}
\titleformat*{\subsection}{\Large\headingfont}
\titleformat*{\subsubsection}{\large\headingfont}

% 一段文本用於測試
\newcommand\stories{《伊索寓言》(英語:Aesop's Fables 或 Aesopica)是一個以伊索命名的寓言故事集。事實上,該故事集是在很長一段期間內創作。在這些寓言中,敘事者通常是代表各種典型人類角色的動物。其中的童話故事常伴隨所欲傳達的道德概念。這些寓言在道德教育中被大量使用,並成為許多文藝作品的創作基礎。《伊索寓言》文字凝練,故事生動,想象豐富,飽含哲理,融思想性和藝術性於一體。其中《龜兔賽跑》、《狐狸與葡萄》、《農夫與蛇》、《狼來了》、《北風與太陽》等已成為全世界家喻戶曉的故事。--維基百科,伊索寓言\\
公元前4世纪至前3世纪之交,亚里士多德的再传弟子,雅典哲学家德墨特里俄斯所编的最早的希腊寓言集《伊索故事集》,只搜集了近200则寓言,这个集子早已失传了:公元1世纪,费德鲁斯用拉丁韵文写了《伊索式寓言》5卷,今存130篇,具有改编和再创作性质。公元2世纪巴布里乌斯编成一本古希腊语寓言诗集,1844年发现了此书的古老抄本,留下寓言诗140篇、散文寓言60篇。这是现存最早的希腊寓言集。
后世流传的伊索寓言的版本,是以拜占庭(东罗马帝国)僧侣学者普拉努得斯所编的伊索寓言为底本的。这个底本只有150则故事,编于14世纪初叶,至1479年首次印行。1610年,瑞士学者耐弗莱特刊印伊索寓言,在普拉努得斯底本的基础上增加了200多则寓言:包括梵蒂冈图书馆所藏的134则希腊寓言、阿弗托纽斯记录的40则希腊寓言、巴布里乌斯记录的43则希腊寓言。此后,伊索寓言基本定型,也使伊索成了欧洲家喻户晓的人物:虽然此后的各种版本有不同的抉择损益,但大体上不出300多则这个范畴。--百度百科,伊索寓言\\
Apollonius of Tyana, a 1st-century CE philosopher, is recorded as having said about Aesop: "like those who dine well off the plainest dishes, he made use of humble incidents to teach great truths, and after serving up a story he adds to it the advice to do a thing or not to do it. Then, too, he was really more attached to truth than the poets are; for the latter do violence to their own stories in order to make them probable; but he by announcing a story which everyone knows not to be true, told the truth by the very fact that he did not claim to be relating real events."--Wikipedia, Aesop's Fables}

\newcommand\settitlepage{
\centering
\maketitle
\vspace*{15cm}
\leavevmode % leave vertical mode
%The \leavevmode means that it starts a paragraph. https://tex.stackexchange.com/questions/118164/differentiating-between-hbox-and-mbox
\vbox{
\hbox to 3.5 in{\Large 姓名:\hfill \rule{190pt}{1pt}}
\hbox to 3.5 in{\Large 所在地:\hfill \rule{180pt}{1pt}}
}
}
%end the file
\endinput

.tex代碼如下(上傳文檔名為newdoc_ref_cls.tex):

\documentclass{customedclass}

\title{自建class的文檔}
\author{cl}

\begin{document}
\begin{titlepage}
\settitlepage
\end{titlepage}

\tableofcontents
\thispagestyle{empty}
\clearpage

\pagestyle{main}

\begin{abstract}
\stories
\end{abstract}
\clearpage

\section{前言}
\section{中文字體package}
\stories
\subsection{字體設置}
\subsubsection{字體大小}
\makeatletter
fontsize=\f@size
\makeatother
\section{感謝}
\end{document}

如何debug一個class文檔?

重點是顯示layout的參數。以下代碼列舉了一些參數。

% How to debug a class file? It's not about processor warnings or syntax errors, but to see the layout systematic parameters. 
\documentclass{article}
%\usepackage{showframe}% show article framework
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}% dummy text if needed
\parindent 0em
\title{How to debug a class file}
\begin{document}
\maketitle
\section{Show systematic parameters}
\string \paperwidth=\the\paperwidth

\string \paperheight=\the\paperheight

\string \hoffset = \the\hoffset

\string \voffset = \the\voffset

\string\oddsidemargin =\the\oddsidemargin

\string\topmargin =\the\topmargin

\string\headheight =\the\headheight

\string\headsep =\the\headsep

\string\hsize=\the\hsize

\string\linewidth = \the\linewidth

\string\columnwidth = \the\columnwidth

\string\textwidth =\the\textwidth

\string\textheight =\the\textheight

\string \vsize=\the\vsize

\string\marginparwidth =\the\marginparwidth

\string\marginparsep =\the\marginparsep

\string\marginparpush =\the\marginparpush

\string\footskip =\the\footskip

\makeatletter
fontsize =\f@size
\makeatother

One inch is 72.27 points.

%box參數\width

\framebox[3\width]{Hello, World.}

\section{Write log}
%Ref: LATEX2e: An unofficial reference manual, 27.5.3 \wlog
Write string to the log file.
     \wlog{Did you hear about the mathematician who hates negatives?}
     \wlog{He’ll stop at nothing to avoid them.}
     
%     編譯後,查看class_file_debug.log
\section{Show new defined variables}
\newlength{\alphabetwidth}
\settowidth{\alphabetwidth}{abcdefghijklmnopqrstuvwxyz}
\string \alphabetwidth=\the\alphabetwidth


     \newlength{\alphabetheight}
     \settoheight{\alphabetheight}{abcdefghijklmnopqrstuvwxyz}
     \string \alphabetheight=\the\alphabetheight
     
\section{A Paper Framework}     
\verb"\usepackage{showframe}" will manifest the paper framework.

\vspace{30pt}

\centering
\definecolor{darkcolor}{RGB}{36, 70, 138}
\begin{tikzpicture}
\path[draw=darkcolor]  (0em, 0em) rectangle (30em, 50em) ;% a page frame
\path[draw=darkcolor]  (5em, 5em) rectangle (25em, 45em) ;% the text frame
\path[draw=darkcolor]  (26em, 5em) rectangle (29em, 45em);% magin side
\path[draw=darkcolor]  (5em, 46em) rectangle (25em, 47em);% header
\path[draw=darkcolor]  (5em, 3em) rectangle (25em, 2em);% footer
\coordinate [label=180:\textcolor{darkcolor}{$A$}]  (A) at (5em, 45em);% name a point, above left corner point of the text frame
\coordinate [label=90:\textcolor{darkcolor}{$B$}]  (B) at (5em, 50em);
\draw[draw=darkcolor,dashed,<->] (A) --(B) ;
\node at ($(A) !0.5! (B)$) [left=0.1cm,text width =1.2cm, rounded corners,inner sep=1ex]{Top \\ margin};% AB是上margin,上下左右margin同寬。

\coordinate [label=right:\textcolor{darkcolor}{$C$}]  (C) at (5em, 40em);% name a point, above left corner point of the text frame
\coordinate [label=above right:\textcolor{darkcolor}{$D$}]  (D) at (0em, 40em);
\draw[draw=darkcolor,dashed,<->] (C) --(D) ;
\node at ($(C) !0.5! (D)$) [below=0.1cm,text width =1.5cm, rounded corners,inner sep=1ex]{Left \\ margin};%CD是左margin

\coordinate [label=45:\textcolor{darkcolor}{$E$}]  (E) at (5em, 42em);% name a point, above left corner point of the text frame
\coordinate [label=135:\textcolor{darkcolor}{$F$}]  (F) at (25em, 42em);
\draw[draw=darkcolor,dashed,<->] (E) --(F) ;
\node at ($(E) !0.5! (F)$) [below=0.1cm,text width =1.5cm, rounded corners,inner sep=1ex]{\verb"\textwidth"};%CD是左margin
\end{tikzpicture}
\end{document}
參考

  1. “Make your own .sty files”, Philipp, https://tex.stackexchange.com/questions/8750/make-your-own-sty-files ↩︎

  2. Michelle Krummel, LaTeX Tutorials (featuring Texmaker), https://www.youtube.com/watch?v=0ivLZh9xK1Q&list=PL1D4EAB31D3EBC449&index=1 ↩︎

  3. TH., “How to change font and font size of title in a class file?”, https://tex.stackexchange.com/questions/375649/how-to-change-font-and-font-size-of-title-in-a-class-file ↩︎

  4. LitBro,『Latex 对中文字体设置的一些解决』,https://www.cnblogs.com/LitBro/p/12074820.html ↩︎

  5. Alan Munn, “Change font of document title”, https://tex.stackexchange.com/questions/18507/change-font-of-document-title ↩︎

  6. xiazdong,「【LaTeX入门】06、设置页芯、页边距、页眉、页脚」,2013-05-07,https://blog.csdn.net/xiazdong/article/details/8893369 ↩︎

  7. “What is good practice when preparing a package for CTAN?”, https://tex.stackexchange.com/questions/25116/what-is-good-practice-when-preparing-a-package-for-ctan ↩︎

  8. “How do I create a LaTeX package?”, https://tex.stackexchange.com/questions/34175/how-do-i-create-a-latex-package/34176#34176 ↩︎

  9. “LATEX for package and class authors
    current version”, LATEX Project Team, 2024-9-15, https://www.latex-project.org/help/documentation/clsguide.pdf ↩︎

  10. LaTeXereXeTaL, cfr, “How do I print the TeX code itself in the pdf while typeset by default?”,
    https://tex.stackexchange.com/questions/740700/how-do-i-print-the-tex-code-itself-in-the-pdf-while-typeset-by-default/740706#740706 ↩︎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值