title: Python - Pylatex header?
body: <p>Currently I am making a .txt file with Python, to later transform it into a PDF file using PyLaTeX. This is the code I am using:</p>
  <pre><code>from pylatex import Document, PageStyle, LineBreak, Section, Subsection, Math, Alignat, LargeText, Center, MediumText
  from pylatex.utils import bold, italic, NoEscape
  import re
  from sympy import *
  import sympy as sp
  
  
  TituloPDF=&quot;Ejercicio 001&quot;
  archivotxt = &quot;%s.txt&quot;% TituloPDF
  texto = open(archivotxt,&quot;w&quot;)
  
  x = sp.Symbol('x', real=True)
  y = sp.Symbol('y', real=True)
  
  MatrizCoef=[y-x*y+1-x,-x*y]
  g=0
  
  texto.write(&quot;\\text{Para la ecuación diferencial:} \r&quot;)
  texto.write(&quot;\\left({%s}\\right)dy = \\left({%s}\\right)dx \r&quot;%(sp.latex(MatrizCoef[0]),sp.latex(MatrizCoef[1])))
  
  texto.close()
  
  class Math_LaTeX ():
      def __init__(self, doc):
          #---Inicializamos---
          self.doc = doc
  
          #---De aqui sacamos las ecuaciones del archivo .txt---
          equations = self.Read()
  
          #---Creamos el documento Latex---
          self.Create(equations)
  
          #---Creamos el PDF---
          self.doc.generate_pdf(filepath = TituloPDF, clean_tex = True, compiler = 'pdflatex')
  
      def Read(self):
          data = open(archivotxt, 'rt')
          equations = data.readlines()
          eqs = []
          for eq in equations:
              eqs.append(' '.join([line.strip() for line in eq.strip().splitlines()]))
          return eqs
  
      def Create(self, equations): 
          for eq in equations:
              with self.doc.create(Alignat(numbering = False, escape = False)) as math_eq:
                  math_eq.append(eq)        
  
  
  geometry_options = {
          &quot;head&quot;: &quot;0.5cm&quot;,
          &quot;left&quot;: &quot;0.5cm&quot;,
          &quot;right&quot;: &quot;0.5cm&quot;,
          &quot;bottom&quot;: &quot;2.5cm&quot;
          }
  doc = Document(geometry_options = geometry_options, inputenc = 'utf8')
  Math_LaTeX(doc)
  </code></pre>
  <p>I have worked well with it, however I would like to be able to customize the delivered PDF, currently this is the output:</p>
  <p>PDF Example</p>
  <p><img src="https://i.stack.imgur.com/GzFcW.png" alt="PDF Example" /></p>
  <p>The margin at the top is too much, besides that I would like to be able to add a heading, in short like this (Made in word):</p>
  <p>Word Example</p>
  <p><img src="https://i.stack.imgur.com/G8oD8.png" alt="Word Example" /></p>
  <p>The top margin is adequate, and it has a heading that appears on all the pages that my exercise requires.</p>
  <p>I would also like this heading to be able to be changed when a new exercise or example is introduced.</p>
  <p>I've read the PyLaTeX documentation, but I can't think of a way to include it all in one code. I would greatly appreciate your help.</p>