1

I have a preamble.tex file which I use for my purposes in different documents.

%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}
}% 

But when I try to made of it package:

\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

Then I use file.tex

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

\begin{document}
some
\end{document}

and get

Undefined control sequence. \ExecuteOptions{a4}
5

The error

\RequirePackage or \LoadClass in Options Section. 

means that you have these commands between \DeclareOption and \ProcessOptions which is not allowed. Specifically in this case you declare

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

But then you load more packages (textcase ) before you have used \ProcessOptions


After the question edit You have a typo in the command name \ExecuteOption-s- and it needs to be after \ProcesssOptions

\ProcessOptions\relax
\ExecuteOptions{a4}

although it seems odd to declare an a4 option but then unconditionally execute it, so it isn't optional at all, why not remove all the option handling and just execute the \geometry command?

  • When I use \documentclass{extbook}, I get an error Undefined control sequence. \ExecuteOptions{a4paper}, with \documentclass{book} all right. What's the matter? – sergiokapone Dec 10 '14 at 23:01
  • hard to guess as you have not shown a test document. also hard to see what the error message is in comment formatting, the undefined command is the last token on the first line of the message. you could edit the question 9or ask a new one) – David Carlisle Dec 10 '14 at 23:06
  • I found that if I use optional parameter [some] in documentclass like \documentclass[10pt]{book} then I get an error in \ExecuteOptions like "Undefined control sequence. \ExecuteOptions{mydefaultoption}", else if documentclass without any optional arguments all turns out well. – sergiokapone Dec 10 '14 at 23:16
  • @sergiokapone that means you have an error in your code, but if you don't show it it is hard to debug. Also it probaly mena syou have \usepackage{MyPackage/Mybook} which is wrong it should be \usepackage{Mybook} just as it is \usepackage{color} not \usepackage{texmf/tex/latex/color} – David Carlisle Dec 10 '14 at 23:19
  • 1
    @sergiokapone You have not passed it any options so the option handling is irrelevant anyway. th eusepackage should be \usepackage{Mybook} not \usepackage{e:/projects/Latex/MyPackage/Mybook} and option handling is only relevant of you use \usepackage[someoption]{Mybook} – David Carlisle Dec 11 '14 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.