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.

  • 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 tex.stackexchange.com/questions/3122/… – sergiokapone Dec 14 '14 at 18:18
4

You haven't given much context, but perhaps

\DeclareOption{some}{\AtEndOfPackage{\mymacro}}
  • @David Carlisle You understand me correctly, thank you. – sergiokapone Dec 14 '14 at 18: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.