将前言文件转换为包 .sty-file

将前言文件转换为包 .sty-file

我有一个preamble.tex文件,我将其用于不同文档中。

%description: Basic Article in Cyrilics
% Based on a TeXnicCenter-Template by Gyorgy SZEIDL.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[12pt]{book}
\usepackage{textcase}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes}
\usetikzlibrary{shapes,arrows,calc}
\usetikzlibrary{trees}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{decorations.markings}
\usepackage{pgfplots}
%packages-------------------------------------------------------------------------------
\usepackage[cp1251]{inputenc}
\usepackage[T2A,T1]{fontenc}
\usepackage[ukrainian]{babel}
\pdfoutput=1  %For postig in ArXiv.org
\usepackage{literat}
\usepackage{indentfirst}
\usepackage{misccorr}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{subfigure}
\usepackage[colorlinks=true,
bookmarks,
bookmarksnumbered=true,
unicode,
pdfauthor={It's me}
]{hyperref}
\usepackage{color}
\usepackage{enumitem}
\usepackage[a4paper]{geometry}
\geometry{top=2cm, %поле сверху
          bottom=2.5cm, %поле снизу
          left=2.5cm, %поле справа
          right=2cm} %поле слева
%\usepackage{background}
%---------------Headers and footers---------------
\usepackage{fancyhdr}
\fancypagestyle{myfancy}{%   
    \fancyhf{}%
    \fancyfoot[ER]
        {
            \tikz[baseline={(0,0)},anchor=center] 
            \node [rectangle, text=white, fill = black!30, text width = 5cm]{\thepage\hfill};
        }%
    \fancyfoot[OL]
    {
            \tikz[baseline={(0,0)},anchor=center] 
            \node [rectangle, text=white, fill = black!30, text width = 5cm]{\hfill\thepage};
    }%
    \renewcommand{\headrulewidth}{0pt}%
    \renewcommand{\footrulewidth}{0pt}%
}%
\fancyhfoffset[ER]{5cm}
\fancyhfoffset[OL]{5cm}

%---------------Sections---------------
\usepackage{titlesec,titletoc,chngcntr, microtype}

\let\cleardoublepage\clearpage
\renewcommand{\chaptertitlename}{Глава}

\titleformat{\chapter}[display]
{\vspace*{-10ex}\Large}
{\titleline[l]{\textls[200]{\MakeTextUppercase{\chaptertitlename}}\ \thechapter}\vspace{6pt}\titlerule[.8pt]}
{\dimexpr-\baselineskip+6pt\relax}
{\bfseries\MakeUppercase}


\titleformat{\section}[block]
{\bfseries}
{\S\ \thesection.}
{\fontdimen2\font}
{}

\titlecontents{chapter}[0pt]
{}
{\textls[200]{\chaptertitlename} \thecontentslabel\ \bfseries}
{}
{\titlerule*[6pt]{.}\contentspage}
%[\addvspace{3pt}]

\titlecontents{section}[1.5em]
{}
{\S\ \makebox[1.5em][l]{\thecontentslabel.}}
{}
{\titlerule*[6pt]{.}\contentspage}

\makeatletter
\renewcommand\frontmatter{\cleardoublepage\@mainmatterfalse}
\renewcommand\mainmatter{\cleardoublepage\@mainmattertrue}
\makeatother
\renewcommand{\thechapter}{\Roman{chapter}}
\counterwithout{section}{chapter}

%---------------TOC---------------

\let\origtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
    \begingroup 
    \titleformat{\chapter}[display]
    {\Large}
    {\titleline[l]{\textls[200]{\MakeTextUppercase{\chaptertitlename}}\ \thechapter}\vspace{6pt}\titlerule[.8pt]}
    {\dimexpr-\baselineskip+6pt\relax}
    {\bfseries\MakeUppercase}%
    \origtableofcontents
    \endgroup}
%------------------------------------
\usepackage{amsthm}
\usepackage[framemethod=tikz]{mdframed}
\usepackage[most, breakable, many]{tcolorbox}
%------------emphz----------------
\newlength{\torninnersep}
\setlength{\torninnersep}{1.5mm}
\newlength{\tornamplitude}
\setlength{\tornamplitude}{1pt}
\newlength{\tornshift}
\setlength{\tornshift}{1.5mm}

\newcommand\emphz[1]{%
    \noindent
    \begin{tikzpicture}[
    pencildraw/.style={%
        decorate,
        decoration={
            random steps,
            segment length=2pt,
            amplitude=\tornamplitude
        }
    }%
    ]
    \node[
    preaction={
        fill=black!50,
        opacity=0.5,
        transform canvas={xshift=\tornshift,yshift=-\tornshift}
    },
    pencildraw,
    draw,
    fill=yellow!30,
    opacity=1,
    text width=\dimexpr
    \linewidth
    -2\torninnersep
    -2\tornamplitude
    -\pgflinewidth
    \relax,
    inner sep=\torninnersep,
    ] {#1};
    \end{tikzpicture}%
}
%--------------------------------------------
% \tcbuselibrary{skins,xparse}
\NewTColorBox[auto counter,number within=section]{solution}{+O{}}{%
    breakable, enhanced,colframe=gray,colback=white,coltitle=green!40!black,
    fonttitle=\bfseries,
    underlay={\begin{tcbclipinterior}
            \draw[help lines,step=5mm,blue!20!white,shift={(interior.north west)}]
            (interior.south west) grid (interior.north east);
        \end{tcbclipinterior}},
        title={Solution: },
        label={},
        attach title to upper=\quad,
        after upper={\par\hfill\textcolor{green!40!black}%
            {}},
        lowerbox=ignored,
        #1,
    }
\newtcolorbox[blend into=figures]{myfigure}[2][]{
    center title, 
    center upper,
    colupper=red!50!black,collower=green!50!black,
    float=!ht,
    title={#2},every float=\centering}



\newtcolorbox{problema}[1][\unskip]
{
    colframe=red!75!black,
    breakable,
    fonttitle=\bfseries,
    title={#1}
}

\def\problem#1#2#3{%
    \phantomsection\addcontentsline{toc}{section}{Задача: #1 № #2}
    \begin{problema}[Problem: #1 № #2]
        #3
    \end{problema}
    \setcounter{equation}{0}
}% 

但是当我尝试用它制作包装时:

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{MyBook}[2005/01/22]

%-----------------------
\RequirePackage{geometry}
%------------------Page geometry--------------------------------------------------
\DeclareOption{a4}{
        \geometry{
        top=2cm, %поле сверху
        bottom=2.5cm, %поле снизу
        left=2.5cm, %поле справа
        right=2cm} %поле слева
        }
\ExecuteOption{a4}
\ProcessOptions\relax
\RequirePackage{textcase}
\RequirePackage{tikz}
\usetikzlibrary{positioning, shapes, shapes,arrows,calc, trees, decorations.pathmorphing, decorations.pathmorphing, decorations.pathmorphing,  decorations.pathreplacing, decorations.markings}
%packages---------------------
\RequirePackage[cp1251]{inputenc}
\RequirePackage[T2A,T1]{fontenc}
\RequirePackage[ukrainian, russian]{babel}
\RequirePackage{literat}
\RequirePackage{indentfirst}
\RequirePackage{misccorr}
\RequirePackage{fancyhdr}
\RequirePackage{amsmath}
\RequirePackage{graphicx}
\RequirePackage{xcolor}
\RequirePackage{subfigure}
\RequirePackage[colorlinks=true,
bookmarks,
bookmarksnumbered=true,
unicode,
pdfauthor={It's me}]{hyperref}

\RequirePackage{enumitem}

\fancypagestyle{myfancy}{%   
    \fancyhf{}%
    \fancyfoot[ER]
    {
        \tikz[baseline={(0,0)},anchor=center] 
        \node [rectangle, text=white, fill = black!30, text width = 5cm]{\thepage\hfill};
    }%
    \fancyfoot[OL]
    {
        \tikz[baseline={(0,0)},anchor=center] 
        \node [rectangle, text=white, fill = black!30, text width = 5cm]{\hfill\thepage};
    }%
    \renewcommand{\headrulewidth}{0pt}%
    \renewcommand{\footrulewidth}{0pt}%
}%
\fancyhfoffset[ER]{5cm}
\fancyhfoffset[OL]{5cm}

%--------------Sections---------------
\RequirePackage{titlesec,titletoc,chngcntr, microtype}

\let\cleardoublepage\clearpage
\renewcommand{\chaptertitlename}{Глава}

\titleformat{\chapter}[display]
{\vspace*{-10ex}\Large}
{\titleline[l]{\textls[200]{\MakeTextUppercase{\chaptertitlename}}\ \thechapter}\vspace{6pt}\titlerule[.8pt]}
{\dimexpr-\baselineskip+6pt\relax}
{\bfseries\MakeUppercase}


\titleformat{\section}[block]
{\bfseries}
{\S\ \thesection.}
{\fontdimen2\font}
{}

\titlecontents{chapter}[0pt]
{}
{\textls[200]{\chaptertitlename} \thecontentslabel\ \bfseries}
{}
{\titlerule*[6pt]{.}\contentspage}
%[\addvspace{3pt}]

\titlecontents{section}[1.5em]
{}
{\S\ \makebox[1.5em][l]{\thecontentslabel.}}
{}
{\titlerule*[6pt]{.}\contentspage}

\renewcommand\frontmatter{\cleardoublepage\@mainmatterfalse}
\renewcommand\mainmatter{\cleardoublepage\@mainmattertrue}

\renewcommand{\thechapter}{\Roman{chapter}}
\counterwithout{section}{chapter}

%---------------TOC---------------

\let\origtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
    \begingroup 
    \titleformat{\chapter}[display]
    {\Large}
    {\titleline[l]{\textls[200]{\MakeTextUppercase{\chaptertitlename}}\ \thechapter}\vspace{6pt}\titlerule[.8pt]}
    {\dimexpr-\baselineskip+6pt\relax}
    {\bfseries\MakeUppercase}%
    \origtableofcontents
    \endgroup}
%------------------------------------
\RequirePackage{amsthm}
\RequirePackage[framemethod=tikz]{mdframed}
\RequirePackage[most, breakable, many]{tcolorbox}
%------------emphz----------------
\newlength{\torninnersep}
\setlength{\torninnersep}{1.5mm}
\newlength{\tornamplitude}
\setlength{\tornamplitude}{1pt}
\newlength{\tornshift}
\setlength{\tornshift}{1.5mm}

\newcommand\emphz[1]{%
    \noindent
    \begin{tikzpicture}[
    pencildraw/.style={%
        decorate,
        decoration={
            random steps,
            segment length=2pt,
            amplitude=\tornamplitude
        }
    }%
    ]
    \node[
    preaction={
        fill=black!50,
        opacity=0.5,
        transform canvas={xshift=\tornshift,yshift=-\tornshift}
    },
    pencildraw,
    draw,
    fill=yellow!30,
    opacity=1,
    text width=\dimexpr
    \linewidth
    -2\torninnersep
    -2\tornamplitude
    -\pgflinewidth
    \relax,
    inner sep=\torninnersep,
    ] {#1};
    \end{tikzpicture}%
}
%--------------------------------------------
% \tcbuselibrary{skins,xparse}
\NewTColorBox[auto counter,number within=section]{solution}{+O{}}{%
    breakable, enhanced,colframe=gray,colback=white,coltitle=green!40!black,
    fonttitle=\bfseries,
    underlay={\begin{tcbclipinterior}
            \draw[help lines,step=5mm,blue!20!white,shift={(interior.north west)}]
            (interior.south west) grid (interior.north east);
        \end{tcbclipinterior}},
        title={Розв'язок: },
        label={},
        attach title to upper=\quad,
        after upper={\par\hfill\textcolor{green!40!black}%
            {}},
        lowerbox=ignored,
        #1,
    }
    \newtcolorbox[blend into=figures]{myfigure}[2][]{
        center title, 
        center upper,
        colupper=red!50!black,collower=green!50!black,
        float=!ht,
        title={#2},every float=\centering}



    \newtcolorbox{problema}[1][\unskip]
    {
        colframe=red!75!black,
        breakable,
        fonttitle=\bfseries,
        title={#1}
    }

    \def\problem#1#2#3{%
        \phantomsection\addcontentsline{toc}{section}{Задача: #1 № #2}
        \begin{problema}[Задача: #1 № #2]
            #3
        \end{problema}
        \setcounter{equation}{0}
    }%

\endinput

然后我用file.tex

\documentclass[10pt]{book}
\usepackage{e:/projects/Latex/MyPackage/Mybook}

\begin{document}
some
\end{document}

并得到

Undefined control sequence. \ExecuteOptions{a4}

答案1

错误

\RequirePackage or \LoadClass in Options Section. 

意味着您在\DeclareOption和之间有这些命令,\ProcessOptions这是不允许的。具体来说,在这种情况下,您声明

\DeclareOption{a4}{
        \geometry{
        top=2cm, %поле сверху
        bottom=2.5cm, %поле снизу
        left=2.5cm, %поле справа
        right=2cm} %поле слева
        }

textcase但是你在使用之前加载了更多的包( )\ProcessOptions


问题编辑后,您的命令名称有拼写错误\ExecuteOption-s-,需要在之后\ProcesssOptions

\ProcessOptions\relax
\ExecuteOptions{a4}

虽然声明一个a4选项然后无条件执行它看起来很奇怪,所以它根本不是可选的,为什么不删除所有的选项处理并只执行命令呢\geometry

相关内容