Document ClassesMake function called before \begin{document} to insert text

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
Spaccana
Posts: 1
Joined: Thu Oct 26, 2023 9:38 am

Make function called before \begin{document} to insert text

Post by Spaccana »

I want the function \leaf to print text in the document. Because \leaf is called before \begin{document}, I get an error. What can I do?

Code: Select all

\documentclass[a4paper,10pt]{article}

\ExplSyntaxOn

\RequirePackage{geometry}

\cs_new_protected:Nn \scand_leaf:
  { \geometry { paperwidth=21cm, paperheight=21cm,
                left=8mm, right=8mm, top=8mm, bottom=8mm,
                includehead, includefoot }}

\cs_new_protected:Nn \mangan_leaf:
  { \geometry { b5paper, left=8mm, right=8mm, top=8mm, bottom=8mm,
                includehead, includefoot }}

\NewDocumentCommand {\leaf} { O{scand} }
  {
    \str_case:nnF {#1}
        {
          {scand}  { \scand_leaf: }
          {mangan} { \mangan_leaf: }
        }
      {
        \scand_leaf:
        %% \par leaf~Unsupported~Argument~#1
      }
  }

\ExplSyntaxOff

\leaf[alumin]  % Generate text in document that alumin is unrecognised

\begin{document}

Some Text

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Post Reply