3

I need to call my macro inside DeclareOption, but my macro is defined later (this is the main condition).

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{MyBook}[2014/12/12]
\DeclareOption{llstyle}{\mymacro}
\ProcessOptions\relax


\RequirePackage{titlesec}
\RequirePackage{textcase}

\def\@bookview{
\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}
}

\def\mymacro{%
  \@ifclassloaded{book}{\@bookview}{}
  \@ifclassloaded{extbook}{\@bookview}{}
}
\endinput

Since, the definition of the macro is made later, this situation causes an error.

sergiokapone
  • 5,578
  • 1
  • 16
  • 39
  • Why not define the macro before declaring it? – A.Ellett Dec 14 '14 at 17:59
  • @A.Ellett too easy:-) – David Carlisle Dec 14 '14 at 18:01
  • Note that you can \ProcessOptions at any point. – Ruben Dec 14 '14 at 18:07
  • Do you really want to execute the macro when calling the option 'some' or define it? In the first case you will definetely get an error message regarding \begin{document}. – Ruben Dec 14 '14 at 18:08
  • @ A.Ellett "Why not define the macro before declaring it?" because macro require packages, which is call later, besides I had some problems with defining macro before \ProcessOptions set here http://tex.stackexchange.com/questions/3122/i-get-an-error-when-using-executeoptions-together-with-usepackagegeometry – sergiokapone Dec 14 '14 at 18:18

1 Answers1

4

You haven't given much context, but perhaps

\DeclareOption{some}{\AtEndOfPackage{\mymacro}}
David Carlisle
  • 757,742