JelteF / PyLaTeX

A Python library for creating LaTeX files
https://jeltef.github.io/PyLaTeX/
MIT License
2.24k stars 287 forks source link

Using Custom documentclass #340

Open Cubba2412 opened 2 years ago

Cubba2412 commented 2 years ago

Hello.

I've been trying to use a custom documentclass which works fine when I load it in overleaf. However when compiling it via pylatex it gives me the error ! LaTeX Error: Two \LoadClass commands.. I am reading in the documentclass and adding it to the document as follows:

doc=Document(document_options='titlepage')
    with open(os.path.dirname(__file__) + '/../additionalPreamble.cls') as f:
        preamb = ''.join(f.readlines())
        doc.preamble.append(NoEscape(preamb))
    Reportclass = Command('documentclass',
                                options=['titlepage'],
                                arguments='Report')

It loads it correctly and the documentclass in the .tex file is shown as \documentclass[titlepage]{Report}. However the compilation fails as the Custom documentclass inherits from the article class:

additionalPreamble.cls:

\ProvidesClass{Report}[2021/21/10 v0.1 Report for python generation]
\NeedsTeXFormat{LaTeX2e}
\DeclareOption{draft}{\setlength\overfullrule{5pt}}
\DeclareOption{final}{\setlength\overfullrule{0pt}}

\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{article}
}
\ProcessOptions\relax
\LoadClass{article} % This is what makes it fail.
\RequirePackage[left=1.5cm,top=3cm,right=1.5cm,bottom=3cm,bindingoffset=0.5cm]{geometry}
\RequirePackage[none]{hyphenat}

How can I load this document class correctly?